diff options
| author | Alan Mackenzie | 2019-07-28 13:30:38 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2019-07-28 13:30:38 +0000 |
| commit | dcba39b445e8f71c5f8df34a38ae8fc726a51843 (patch) | |
| tree | a417520b3d343bf3b50008ddfa42ccb60f7a0a90 | |
| parent | ba952d654ad005826a6a219fa97b49af30193cca (diff) | |
| download | emacs-dcba39b445e8f71c5f8df34a38ae8fc726a51843.tar.gz emacs-dcba39b445e8f71c5f8df34a38ae8fc726a51843.zip | |
CC Mode. Fix (c-beginning-of-defun -1) getting stuck with structs.
In particular, with an initialization such as struct foo {..} bar = {...};
* lisp/progmodes/cc-cmds.el (c-forward-to-nth-EOF-{): Rename to
c-forward-to-nth-EOF-\;-or-}, and when the starting (or ending) position is in
the "variable" part of a struct/class/union/enum/etc., move to after the
terminating semicolon. Adjust the counting such that N only gets decremented
on a successful movement over {..}.
(c-beginning-of-defun, c-end-of-defun): Rename the calls to
c-forward-to-nth-EOF-}, as above.
| -rw-r--r-- | lisp/progmodes/cc-cmds.el | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index efc6747de48..2ccdc1d0bc8 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el | |||
| @@ -1775,7 +1775,7 @@ defun." | |||
| 1775 | (setq arg (1+ arg))) | 1775 | (setq arg (1+ arg))) |
| 1776 | (if (< arg 0) | 1776 | (if (< arg 0) |
| 1777 | (c-while-widening-to-decl-block | 1777 | (c-while-widening-to-decl-block |
| 1778 | (< (setq arg (- (c-forward-to-nth-EOF-} (- arg) where))) 0))) | 1778 | (< (setq arg (- (c-forward-to-nth-EOF-\;-or-} (- arg) where))) 0))) |
| 1779 | ;; Move forward to the next opening brace.... | 1779 | ;; Move forward to the next opening brace.... |
| 1780 | (when (and (= arg 0) | 1780 | (when (and (= arg 0) |
| 1781 | (progn | 1781 | (progn |
| @@ -1811,10 +1811,11 @@ defun." | |||
| 1811 | (c-keep-region-active) | 1811 | (c-keep-region-active) |
| 1812 | (= arg 0))))) | 1812 | (= arg 0))))) |
| 1813 | 1813 | ||
| 1814 | (defun c-forward-to-nth-EOF-} (n where) | 1814 | (defun c-forward-to-nth-EOF-\;-or-} (n where) |
| 1815 | ;; Skip to the closing brace of the Nth function after point. If | 1815 | ;; Skip to the closing brace or semicolon of the Nth function after point. |
| 1816 | ;; point is inside a function, this counts as the first. Point must be | 1816 | ;; We move to a semicolon only for things like structs which don't end at a |
| 1817 | ;; outside any comment/string or macro. | 1817 | ;; closing brace. If point is inside a function, this counts as the first. |
| 1818 | ;; Point must be outside any comment/string or macro. | ||
| 1818 | ;; | 1819 | ;; |
| 1819 | ;; N must be strictly positive. | 1820 | ;; N must be strictly positive. |
| 1820 | ;; WHERE describes the position of point, one of the symbols `at-header', | 1821 | ;; WHERE describes the position of point, one of the symbols `at-header', |
| @@ -1836,23 +1837,24 @@ defun." | |||
| 1836 | (forward-sexp) | 1837 | (forward-sexp) |
| 1837 | (setq n (1- n))) | 1838 | (setq n (1- n))) |
| 1838 | ((eq where 'in-trailer) | 1839 | ((eq where 'in-trailer) |
| 1839 | (c-syntactic-skip-backward "^}") | 1840 | ;; The actual movement is done below. |
| 1840 | (setq n (1- n))) | 1841 | (setq n (1- n))) |
| 1841 | ((memq where '(at-function-end outwith-function at-header in-header)) | 1842 | ((memq where '(at-function-end outwith-function at-header in-header)) |
| 1842 | (when (c-syntactic-re-search-forward "{" nil 'eob) | 1843 | (when (c-syntactic-re-search-forward "{" nil 'eob) |
| 1843 | (backward-char) | 1844 | (backward-char) |
| 1844 | (forward-sexp) | 1845 | (forward-sexp) |
| 1845 | (setq n (1- n)))) | 1846 | (setq n (1- n)))) |
| 1846 | (t (error "c-forward-to-nth-EOF-}: `where' is %s" where))) | 1847 | (t (error "c-forward-to-nth-EOF-\\;-or-}: `where' is %s" where))) |
| 1848 | |||
| 1849 | (when (c-in-function-trailer-p) | ||
| 1850 | (c-syntactic-re-search-forward ";" nil 'eob t)) | ||
| 1847 | 1851 | ||
| 1848 | ;; Each time round the loop, go forward to a "}" at the outermost level. | 1852 | ;; Each time round the loop, go forward to a "}" at the outermost level. |
| 1849 | (while (and (> n 0) (not (eobp))) | 1853 | (while (and (> n 0) (not (eobp))) |
| 1850 | ;(c-parse-state) ; This call speeds up the following one by a factor | ||
| 1851 | ; of ~6. Hmmm. 2006/4/5. | ||
| 1852 | (when (c-syntactic-re-search-forward "{" nil 'eob) | 1854 | (when (c-syntactic-re-search-forward "{" nil 'eob) |
| 1853 | (backward-char) | 1855 | (backward-char) |
| 1854 | (forward-sexp)) | 1856 | (forward-sexp) |
| 1855 | (setq n (1- n))) | 1857 | (setq n (1- n)))) |
| 1856 | n) | 1858 | n) |
| 1857 | 1859 | ||
| 1858 | (defun c-end-of-defun (&optional arg) | 1860 | (defun c-end-of-defun (&optional arg) |
| @@ -1907,7 +1909,7 @@ the open-parenthesis that starts a defun; see `beginning-of-defun'." | |||
| 1907 | ;; Move forward to the } of a function | 1909 | ;; Move forward to the } of a function |
| 1908 | (if (> arg 0) | 1910 | (if (> arg 0) |
| 1909 | (c-while-widening-to-decl-block | 1911 | (c-while-widening-to-decl-block |
| 1910 | (> (setq arg (c-forward-to-nth-EOF-} arg where)) 0)))) | 1912 | (> (setq arg (c-forward-to-nth-EOF-\;-or-} arg where)) 0)))) |
| 1911 | 1913 | ||
| 1912 | ;; Do we need to move forward from the brace to the semicolon? | 1914 | ;; Do we need to move forward from the brace to the semicolon? |
| 1913 | (when (eq arg 0) | 1915 | (when (eq arg 0) |