diff options
| author | Martin Stjernholm | 2003-11-16 16:55:08 +0000 |
|---|---|---|
| committer | Martin Stjernholm | 2003-11-16 16:55:08 +0000 |
| commit | 037558bfd948e55ab902497ccea5cb1a6b499990 (patch) | |
| tree | 244014359dd5d8ac6804abf982abd4bcb4b41d63 | |
| parent | 7c402969951c97a2d878c16f7f4c18152258e1f9 (diff) | |
| download | emacs-037558bfd948e55ab902497ccea5cb1a6b499990.tar.gz emacs-037558bfd948e55ab902497ccea5cb1a6b499990.zip | |
CC Mode update (5.30.8).
| -rw-r--r-- | lisp/ChangeLog | 64 | ||||
| -rw-r--r-- | lisp/progmodes/cc-align.el | 37 | ||||
| -rw-r--r-- | lisp/progmodes/cc-cmds.el | 31 | ||||
| -rw-r--r-- | lisp/progmodes/cc-defs.el | 30 | ||||
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 373 | ||||
| -rw-r--r-- | lisp/progmodes/cc-fonts.el | 6 | ||||
| -rw-r--r-- | lisp/progmodes/cc-vars.el | 19 |
7 files changed, 349 insertions, 211 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f2b7ff351c4..06c1f96324b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,67 @@ | |||
| 1 | 2003-11-16 Martin Stjernholm <bug-cc-mode@gnu.org> | ||
| 2 | |||
| 3 | * cc-engine.el (c-guess-continued-construct, | ||
| 4 | c-guess-basic-syntax): Check a little more carefully if it's a | ||
| 5 | function declaration when an unknown construct followed by a block | ||
| 6 | is found inside a statement context. This avoids macros followed | ||
| 7 | by blocks to be taken as function declarations. | ||
| 8 | |||
| 9 | (c-guess-continued-construct): Changed the analysis of a statement | ||
| 10 | continuation with a brace open to `substatement-block', for | ||
| 11 | consistency with recognized statements. | ||
| 12 | |||
| 13 | (c-add-stmt-syntax): Don't continue to the surrounding sexp if the | ||
| 14 | start is in a position so that `c-beginning-of-statement-1' jumped | ||
| 15 | to the beginning of the same statement. | ||
| 16 | |||
| 17 | * cc-fonts.el, cc-engine.el (c-forward-<>-arglist-recur): Don't | ||
| 18 | accept binary operators in the arglist if we're in a function call | ||
| 19 | context, i.e. if `c-restricted-<>-arglists' is set. That avoids | ||
| 20 | template recognition in cases like "if (a < b || c > d)". | ||
| 21 | |||
| 22 | (c-restricted-<>-arglists): New more appropriate name for | ||
| 23 | `c-disallow-comma-in-<>-arglists'. | ||
| 24 | |||
| 25 | Accessing functions updated for the variable name change. | ||
| 26 | |||
| 27 | * cc-engine.el (c-syntactic-re-search-forward): Fix bug where the | ||
| 28 | match data could get clobbered if NOT-INSIDE-TOKEN is used. | ||
| 29 | |||
| 30 | * cc-engine.el (c-beginning-of-statement-1): Don't allow parens in | ||
| 31 | labels. | ||
| 32 | |||
| 33 | (c-backward-to-decl-anchor): Use `c-beginning-of-statement-1' | ||
| 34 | instead of duplicating parts of it. This fixes bogus label | ||
| 35 | recognition. | ||
| 36 | |||
| 37 | * cc-align.el (c-gnu-impose-minimum): Reverted to the old method | ||
| 38 | of checking the context in which to apply the minimum indentation, | ||
| 39 | so that it isn't enforced in e.g. namespace blocks. | ||
| 40 | |||
| 41 | * cc-vars.el (c-inside-block-syms): New constant used by | ||
| 42 | `c-gnu-impose-minimum'. It's defined close to `c-offsets-alist' | ||
| 43 | to somewhat reduce the risk of becoming stale. | ||
| 44 | |||
| 45 | * cc-cmds.el, cc-engine.el (c-shift-line-indentation): Moved from | ||
| 46 | cc-cmds to cc-engine to allow use from cc-align. | ||
| 47 | |||
| 48 | * cc-engine.el (c-beginning-of-inheritance-list): Cope with fully | ||
| 49 | qualified identifiers containing "::". | ||
| 50 | |||
| 51 | * cc-defs.el (c-make-keywords-re): Added kludge for bug in | ||
| 52 | `regexp-opt' in Emacs 20 and XEmacs when strings contain newlines. | ||
| 53 | |||
| 54 | * cc-vars.el (c-emacs-features): Use a space in front of the name | ||
| 55 | of the temporary buffer. That also avoids dumping problems in | ||
| 56 | XEmacs due to undo info being left around after the buffer is | ||
| 57 | killed. | ||
| 58 | |||
| 59 | * cc-engine.el (c-in-knr-argdecl): Look closer at the function | ||
| 60 | arglist to see if it's a K&R style declaration. | ||
| 61 | |||
| 62 | (c-guess-basic-syntax): CASE 5B.2: Check with `c-in-knr-argdecl' | ||
| 63 | before returning `knr-argdecl-intro'. | ||
| 64 | |||
| 1 | 2003-11-16 John Wiegley <johnw@newartisans.com> | 65 | 2003-11-16 John Wiegley <johnw@newartisans.com> |
| 2 | 66 | ||
| 3 | * eshell/em-ls.el (eshell-ls-file): Instead of making the size | 67 | * eshell/em-ls.el (eshell-ls-file): Instead of making the size |
diff --git a/lisp/progmodes/cc-align.el b/lisp/progmodes/cc-align.el index 00f9323795f..b51a304c531 100644 --- a/lisp/progmodes/cc-align.el +++ b/lisp/progmodes/cc-align.el | |||
| @@ -1121,35 +1121,20 @@ ACTION associated with `block-close' syntax." | |||
| 1121 | '(before after))))) | 1121 | '(before after))))) |
| 1122 | 1122 | ||
| 1123 | (defun c-gnu-impose-minimum () | 1123 | (defun c-gnu-impose-minimum () |
| 1124 | "Imposes a minimum indentation for lines inside a top-level construct. | 1124 | "Imposes a minimum indentation for lines inside code blocks. |
| 1125 | The variable `c-label-minimum-indentation' specifies the minimum | 1125 | The variable `c-label-minimum-indentation' specifies the minimum |
| 1126 | indentation amount." | 1126 | indentation amount." |
| 1127 | 1127 | ||
| 1128 | ;; Don't adjust macro or comment-only lines. | 1128 | (when (and (not |
| 1129 | (unless (or (assq 'cpp-macro c-syntactic-context) | 1129 | ;; Don't adjust macro or comment-only lines. |
| 1130 | (assq 'comment-intro c-syntactic-context)) | 1130 | (or (assq 'cpp-macro c-syntactic-context) |
| 1131 | 1131 | (assq 'comment-intro c-syntactic-context))) | |
| 1132 | (let ((paren-state (save-excursion | 1132 | (c-intersect-lists c-inside-block-syms c-syntactic-context) |
| 1133 | ;; Get the parenthesis state, but skip past | 1133 | (save-excursion |
| 1134 | ;; an initial closing paren on the line since | 1134 | (back-to-indentation) |
| 1135 | ;; the close brace of a block shouldn't be | 1135 | (< (current-column) c-label-minimum-indentation))) |
| 1136 | ;; considered to be inside the block. | 1136 | (c-shift-line-indentation (- c-label-minimum-indentation |
| 1137 | (back-to-indentation) | 1137 | (current-indentation))))) |
| 1138 | (when (looking-at "\\s\)") | ||
| 1139 | (forward-char)) | ||
| 1140 | (c-parse-state)))) | ||
| 1141 | |||
| 1142 | ;; Search for an enclosing brace on paren-state. | ||
| 1143 | (while (and paren-state | ||
| 1144 | (not (and (integer-or-marker-p (car paren-state)) | ||
| 1145 | (eq (char-after (car paren-state)) ?{)))) | ||
| 1146 | (setq paren-state (cdr paren-state))) | ||
| 1147 | |||
| 1148 | (when paren-state | ||
| 1149 | (save-excursion | ||
| 1150 | (back-to-indentation) | ||
| 1151 | (if (zerop (current-column)) | ||
| 1152 | (insert-char ?\ c-label-minimum-indentation t))))))) | ||
| 1153 | 1138 | ||
| 1154 | 1139 | ||
| 1155 | ;; Useful for c-hanging-semi&comma-criteria | 1140 | ;; Useful for c-hanging-semi&comma-criteria |
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index d0056183d51..c6f60d3dcc0 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el | |||
| @@ -54,37 +54,6 @@ | |||
| 54 | 54 | ||
| 55 | (defvar c-fix-backslashes t) | 55 | (defvar c-fix-backslashes t) |
| 56 | 56 | ||
| 57 | (defun c-shift-line-indentation (shift-amt) | ||
| 58 | ;; This function does not do any hidden buffer changes. | ||
| 59 | (let ((pos (- (point-max) (point))) | ||
| 60 | (c-macro-start c-macro-start) | ||
| 61 | tmp-char-inserted) | ||
| 62 | (if (zerop shift-amt) | ||
| 63 | nil | ||
| 64 | (when (and (c-query-and-set-macro-start) | ||
| 65 | (looking-at "[ \t]*\\\\$") | ||
| 66 | (save-excursion | ||
| 67 | (skip-chars-backward " \t") | ||
| 68 | (bolp))) | ||
| 69 | (insert ?x) | ||
| 70 | (backward-char) | ||
| 71 | (setq tmp-char-inserted t)) | ||
| 72 | (unwind-protect | ||
| 73 | (let ((col (current-indentation))) | ||
| 74 | (delete-region (c-point 'bol) (c-point 'boi)) | ||
| 75 | (beginning-of-line) | ||
| 76 | (indent-to (+ col shift-amt))) | ||
| 77 | (when tmp-char-inserted | ||
| 78 | (delete-char 1)))) | ||
| 79 | ;; If initial point was within line's indentation and we're not on | ||
| 80 | ;; a line with a line continuation in a macro, position after the | ||
| 81 | ;; indentation. Else stay at same point in text. | ||
| 82 | (if (and (< (point) (c-point 'boi)) | ||
| 83 | (not tmp-char-inserted)) | ||
| 84 | (back-to-indentation) | ||
| 85 | (if (> (- (point-max) pos) (point)) | ||
| 86 | (goto-char (- (point-max) pos)))))) | ||
| 87 | |||
| 88 | (defun c-indent-line (&optional syntax quiet ignore-point-pos) | 57 | (defun c-indent-line (&optional syntax quiet ignore-point-pos) |
| 89 | "Indent the current line according to the syntactic context, | 58 | "Indent the current line according to the syntactic context, |
| 90 | if `c-syntactic-indentation' is non-nil. Optional SYNTAX is the | 59 | if `c-syntactic-indentation' is non-nil. Optional SYNTAX is the |
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el index cef04a32a5d..dca12c67285 100644 --- a/lisp/progmodes/cc-defs.el +++ b/lisp/progmodes/cc-defs.el | |||
| @@ -105,7 +105,7 @@ | |||
| 105 | 105 | ||
| 106 | ;;; Variables also used at compile time. | 106 | ;;; Variables also used at compile time. |
| 107 | 107 | ||
| 108 | (defconst c-version "5.30.7" | 108 | (defconst c-version "5.30.8" |
| 109 | "CC Mode version number.") | 109 | "CC Mode version number.") |
| 110 | 110 | ||
| 111 | (defconst c-version-sym (intern c-version)) | 111 | (defconst c-version-sym (intern c-version)) |
| @@ -1001,8 +1001,8 @@ This function does not do any hidden buffer changes." | |||
| 1001 | 1001 | ||
| 1002 | (defun c-make-keywords-re (adorn list &optional mode) | 1002 | (defun c-make-keywords-re (adorn list &optional mode) |
| 1003 | "Make a regexp that matches all the strings the list. | 1003 | "Make a regexp that matches all the strings the list. |
| 1004 | Duplicates in the list are removed. The regexp may contain zero or | 1004 | Duplicates in the list are removed. The resulting regexp may contain |
| 1005 | more submatch expressions. | 1005 | zero or more submatch expressions. |
| 1006 | 1006 | ||
| 1007 | If ADORN is non-nil there will be at least one submatch and the first | 1007 | If ADORN is non-nil there will be at least one submatch and the first |
| 1008 | matches the whole keyword, and the regexp will also not match a prefix | 1008 | matches the whole keyword, and the regexp will also not match a prefix |
| @@ -1010,6 +1010,7 @@ of any identifier. Adorned regexps cannot be appended. The language | |||
| 1010 | variable `c-nonsymbol-key' is used to make the adornment. The | 1010 | variable `c-nonsymbol-key' is used to make the adornment. The |
| 1011 | optional MODE specifies the language to get it in. The default is the | 1011 | optional MODE specifies the language to get it in. The default is the |
| 1012 | current language (taken from `c-buffer-is-cc-mode')." | 1012 | current language (taken from `c-buffer-is-cc-mode')." |
| 1013 | |||
| 1013 | (let (unique) | 1014 | (let (unique) |
| 1014 | (dolist (elt list) | 1015 | (dolist (elt list) |
| 1015 | (unless (member elt unique) | 1016 | (unless (member elt unique) |
| @@ -1017,6 +1018,27 @@ current language (taken from `c-buffer-is-cc-mode')." | |||
| 1017 | (setq list unique)) | 1018 | (setq list unique)) |
| 1018 | (if list | 1019 | (if list |
| 1019 | (let ((re (c-regexp-opt list))) | 1020 | (let ((re (c-regexp-opt list))) |
| 1021 | |||
| 1022 | ;; Emacs < 21 and XEmacs (all versions so far) has a buggy | ||
| 1023 | ;; regexp-opt that doesn't always cope with strings containing | ||
| 1024 | ;; newlines. This kludge doesn't handle shy parens correctly | ||
| 1025 | ;; so we can't advice regexp-opt directly with it. | ||
| 1026 | (let (fail-list) | ||
| 1027 | (while list | ||
| 1028 | (and (string-match "\n" (car list)) ; To speed it up a little. | ||
| 1029 | (not (string-match (concat "\\`\\(" re "\\)\\'") | ||
| 1030 | (car list))) | ||
| 1031 | (setq fail-list (cons (car list) fail-list))) | ||
| 1032 | (setq list (cdr list))) | ||
| 1033 | (when fail-list | ||
| 1034 | (setq re (concat re | ||
| 1035 | "\\|" | ||
| 1036 | (mapconcat 'regexp-quote | ||
| 1037 | (sort fail-list | ||
| 1038 | (lambda (a b) | ||
| 1039 | (> (length a) (length b)))) | ||
| 1040 | "\\|"))))) | ||
| 1041 | |||
| 1020 | ;; Add our own grouping parenthesis around re instead of | 1042 | ;; Add our own grouping parenthesis around re instead of |
| 1021 | ;; passing adorn to `regexp-opt', since in XEmacs it makes the | 1043 | ;; passing adorn to `regexp-opt', since in XEmacs it makes the |
| 1022 | ;; top level grouping "shy". | 1044 | ;; top level grouping "shy". |
| @@ -1026,10 +1048,12 @@ current language (taken from `c-buffer-is-cc-mode')." | |||
| 1026 | (c-get-lang-constant 'c-nonsymbol-key nil mode) | 1048 | (c-get-lang-constant 'c-nonsymbol-key nil mode) |
| 1027 | "\\|$\\)") | 1049 | "\\|$\\)") |
| 1028 | re)) | 1050 | re)) |
| 1051 | |||
| 1029 | ;; Produce a regexp that matches nothing. | 1052 | ;; Produce a regexp that matches nothing. |
| 1030 | (if adorn | 1053 | (if adorn |
| 1031 | "\\(\\<\\>\\)" | 1054 | "\\(\\<\\>\\)" |
| 1032 | "\\<\\>"))) | 1055 | "\\<\\>"))) |
| 1056 | |||
| 1033 | (put 'c-make-keywords-re 'lisp-indent-function 1) | 1057 | (put 'c-make-keywords-re 'lisp-indent-function 1) |
| 1034 | 1058 | ||
| 1035 | 1059 | ||
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 51e58c76ba1..2e907589304 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -197,6 +197,75 @@ | |||
| 197 | (make-variable-buffer-local 'c-type-decl-end-used) | 197 | (make-variable-buffer-local 'c-type-decl-end-used) |
| 198 | 198 | ||
| 199 | 199 | ||
| 200 | ;; Basic handling of preprocessor directives. | ||
| 201 | |||
| 202 | ;; This is a dynamically bound cache used together with | ||
| 203 | ;; `c-query-macro-start' and `c-query-and-set-macro-start'. It only | ||
| 204 | ;; works as long as point doesn't cross a macro boundary. | ||
| 205 | (defvar c-macro-start 'unknown) | ||
| 206 | |||
| 207 | (defsubst c-query-and-set-macro-start () | ||
| 208 | ;; This function does not do any hidden buffer changes. | ||
| 209 | (if (symbolp c-macro-start) | ||
| 210 | (setq c-macro-start (save-excursion | ||
| 211 | (and (c-beginning-of-macro) | ||
| 212 | (point)))) | ||
| 213 | c-macro-start)) | ||
| 214 | |||
| 215 | (defsubst c-query-macro-start () | ||
| 216 | ;; This function does not do any hidden buffer changes. | ||
| 217 | (if (symbolp c-macro-start) | ||
| 218 | (save-excursion | ||
| 219 | (and (c-beginning-of-macro) | ||
| 220 | (point))) | ||
| 221 | c-macro-start)) | ||
| 222 | |||
| 223 | (defun c-beginning-of-macro (&optional lim) | ||
| 224 | "Go to the beginning of a preprocessor directive. | ||
| 225 | Leave point at the beginning of the directive and return t if in one, | ||
| 226 | otherwise return nil and leave point unchanged. | ||
| 227 | |||
| 228 | This function does not do any hidden buffer changes." | ||
| 229 | (when c-opt-cpp-prefix | ||
| 230 | (let ((here (point))) | ||
| 231 | (save-restriction | ||
| 232 | (if lim (narrow-to-region lim (point-max))) | ||
| 233 | (beginning-of-line) | ||
| 234 | (while (eq (char-before (1- (point))) ?\\) | ||
| 235 | (forward-line -1)) | ||
| 236 | (back-to-indentation) | ||
| 237 | (if (and (<= (point) here) | ||
| 238 | (looking-at c-opt-cpp-start)) | ||
| 239 | t | ||
| 240 | (goto-char here) | ||
| 241 | nil))))) | ||
| 242 | |||
| 243 | (defun c-end-of-macro () | ||
| 244 | "Go to the end of a preprocessor directive. | ||
| 245 | More accurately, move point to the end of the closest following line | ||
| 246 | that doesn't end with a line continuation backslash. | ||
| 247 | |||
| 248 | This function does not do any hidden buffer changes." | ||
| 249 | (while (progn | ||
| 250 | (end-of-line) | ||
| 251 | (when (and (eq (char-before) ?\\) | ||
| 252 | (not (eobp))) | ||
| 253 | (forward-char) | ||
| 254 | t)))) | ||
| 255 | |||
| 256 | (defun c-forward-to-cpp-define-body () | ||
| 257 | ;; Assuming point is at the "#" that introduces a preprocessor | ||
| 258 | ;; directive, it's moved forward to the start of the definition body | ||
| 259 | ;; if it's a "#define". Non-nil is returned in this case, in all | ||
| 260 | ;; other cases nil is returned and point isn't moved. | ||
| 261 | (when (and (looking-at | ||
| 262 | (concat "#[ \t]*" | ||
| 263 | "define[ \t]+\\(\\sw\\|_\\)+\\(\([^\)]*\)\\)?" | ||
| 264 | "\\([ \t]\\|\\\\\n\\)*")) | ||
| 265 | (not (= (match-end 0) (c-point 'eol)))) | ||
| 266 | (goto-char (match-end 0)))) | ||
| 267 | |||
| 268 | |||
| 200 | ;;; Basic utility functions. | 269 | ;;; Basic utility functions. |
| 201 | 270 | ||
| 202 | (defun c-syntactic-content (from to) | 271 | (defun c-syntactic-content (from to) |
| @@ -268,6 +337,37 @@ | |||
| 268 | (defvar c-literal-faces | 337 | (defvar c-literal-faces |
| 269 | '(font-lock-comment-face font-lock-string-face)) | 338 | '(font-lock-comment-face font-lock-string-face)) |
| 270 | 339 | ||
| 340 | (defun c-shift-line-indentation (shift-amt) | ||
| 341 | ;; This function does not do any hidden buffer changes. | ||
| 342 | (let ((pos (- (point-max) (point))) | ||
| 343 | (c-macro-start c-macro-start) | ||
| 344 | tmp-char-inserted) | ||
| 345 | (if (zerop shift-amt) | ||
| 346 | nil | ||
| 347 | (when (and (c-query-and-set-macro-start) | ||
| 348 | (looking-at "[ \t]*\\\\$") | ||
| 349 | (save-excursion | ||
| 350 | (skip-chars-backward " \t") | ||
| 351 | (bolp))) | ||
| 352 | (insert ?x) | ||
| 353 | (backward-char) | ||
| 354 | (setq tmp-char-inserted t)) | ||
| 355 | (unwind-protect | ||
| 356 | (let ((col (current-indentation))) | ||
| 357 | (delete-region (c-point 'bol) (c-point 'boi)) | ||
| 358 | (beginning-of-line) | ||
| 359 | (indent-to (+ col shift-amt))) | ||
| 360 | (when tmp-char-inserted | ||
| 361 | (delete-char 1)))) | ||
| 362 | ;; If initial point was within line's indentation and we're not on | ||
| 363 | ;; a line with a line continuation in a macro, position after the | ||
| 364 | ;; indentation. Else stay at same point in text. | ||
| 365 | (if (and (< (point) (c-point 'boi)) | ||
| 366 | (not tmp-char-inserted)) | ||
| 367 | (back-to-indentation) | ||
| 368 | (if (> (- (point-max) pos) (point)) | ||
| 369 | (goto-char (- (point-max) pos)))))) | ||
| 370 | |||
| 271 | 371 | ||
| 272 | ;; Some debug tools to visualize various special positions. This | 372 | ;; Some debug tools to visualize various special positions. This |
| 273 | ;; debug code isn't as portable as the rest of CC Mode. | 373 | ;; debug code isn't as portable as the rest of CC Mode. |
| @@ -592,7 +692,7 @@ COMMA-DELIM is non-nil then ',' is treated likewise." | |||
| 592 | 692 | ||
| 593 | ;; The PDA state handling. | 693 | ;; The PDA state handling. |
| 594 | ;; | 694 | ;; |
| 595 | ;; Refer to the description of the PDA in the openining | 695 | ;; Refer to the description of the PDA in the opening |
| 596 | ;; comments. In the following OR form, the first leaf | 696 | ;; comments. In the following OR form, the first leaf |
| 597 | ;; attempts to handles one of the specific actions detailed | 697 | ;; attempts to handles one of the specific actions detailed |
| 598 | ;; (e.g., finding token "if" whilst in state `else-boundary'). | 698 | ;; (e.g., finding token "if" whilst in state `else-boundary'). |
| @@ -769,7 +869,9 @@ COMMA-DELIM is non-nil then ',' is treated likewise." | |||
| 769 | sym 'boundary) | 869 | sym 'boundary) |
| 770 | (throw 'loop t))) ; like a C "continue". Analyze the next sexp. | 870 | (throw 'loop t))) ; like a C "continue". Analyze the next sexp. |
| 771 | 871 | ||
| 772 | (when (and (numberp c-maybe-labelp) (not ignore-labels)) | 872 | (when (and (numberp c-maybe-labelp) |
| 873 | (not ignore-labels) | ||
| 874 | (not (looking-at "\\s\("))) | ||
| 773 | ;; c-crosses-statement-barrier-p has found a colon, so | 875 | ;; c-crosses-statement-barrier-p has found a colon, so |
| 774 | ;; we might be in a label now. | 876 | ;; we might be in a label now. |
| 775 | (if (not after-labels-pos) | 877 | (if (not after-labels-pos) |
| @@ -1012,75 +1114,6 @@ This function does not do any hidden buffer changes." | |||
| 1012 | t)))))) | 1114 | t)))))) |
| 1013 | 1115 | ||
| 1014 | 1116 | ||
| 1015 | ;; Basic handling of preprocessor directives. | ||
| 1016 | |||
| 1017 | ;; This is a dynamically bound cache used together with | ||
| 1018 | ;; `c-query-macro-start' and `c-query-and-set-macro-start'. It only | ||
| 1019 | ;; works as long as point doesn't cross a macro boundary. | ||
| 1020 | (defvar c-macro-start 'unknown) | ||
| 1021 | |||
| 1022 | (defsubst c-query-and-set-macro-start () | ||
| 1023 | ;; This function does not do any hidden buffer changes. | ||
| 1024 | (if (symbolp c-macro-start) | ||
| 1025 | (setq c-macro-start (save-excursion | ||
| 1026 | (and (c-beginning-of-macro) | ||
| 1027 | (point)))) | ||
| 1028 | c-macro-start)) | ||
| 1029 | |||
| 1030 | (defsubst c-query-macro-start () | ||
| 1031 | ;; This function does not do any hidden buffer changes. | ||
| 1032 | (if (symbolp c-macro-start) | ||
| 1033 | (save-excursion | ||
| 1034 | (and (c-beginning-of-macro) | ||
| 1035 | (point))) | ||
| 1036 | c-macro-start)) | ||
| 1037 | |||
| 1038 | (defun c-beginning-of-macro (&optional lim) | ||
| 1039 | "Go to the beginning of a preprocessor directive. | ||
| 1040 | Leave point at the beginning of the directive and return t if in one, | ||
| 1041 | otherwise return nil and leave point unchanged. | ||
| 1042 | |||
| 1043 | This function does not do any hidden buffer changes." | ||
| 1044 | (when c-opt-cpp-prefix | ||
| 1045 | (let ((here (point))) | ||
| 1046 | (save-restriction | ||
| 1047 | (if lim (narrow-to-region lim (point-max))) | ||
| 1048 | (beginning-of-line) | ||
| 1049 | (while (eq (char-before (1- (point))) ?\\) | ||
| 1050 | (forward-line -1)) | ||
| 1051 | (back-to-indentation) | ||
| 1052 | (if (and (<= (point) here) | ||
| 1053 | (looking-at c-opt-cpp-start)) | ||
| 1054 | t | ||
| 1055 | (goto-char here) | ||
| 1056 | nil))))) | ||
| 1057 | |||
| 1058 | (defun c-end-of-macro () | ||
| 1059 | "Go to the end of a preprocessor directive. | ||
| 1060 | More accurately, move point to the end of the closest following line | ||
| 1061 | that doesn't end with a line continuation backslash. | ||
| 1062 | |||
| 1063 | This function does not do any hidden buffer changes." | ||
| 1064 | (while (progn | ||
| 1065 | (end-of-line) | ||
| 1066 | (when (and (eq (char-before) ?\\) | ||
| 1067 | (not (eobp))) | ||
| 1068 | (forward-char) | ||
| 1069 | t)))) | ||
| 1070 | |||
| 1071 | (defun c-forward-to-cpp-define-body () | ||
| 1072 | ;; Assuming point is at the "#" that introduces a preprocessor | ||
| 1073 | ;; directive, it's moved forward to the start of the definition body | ||
| 1074 | ;; if it's a "#define". Non-nil is returned in this case, in all | ||
| 1075 | ;; other cases nil is returned and point isn't moved. | ||
| 1076 | (when (and (looking-at | ||
| 1077 | (concat "#[ \t]*" | ||
| 1078 | "define[ \t]+\\(\\sw\\|_\\)+\\(\([^\)]*\)\\)?" | ||
| 1079 | "\\([ \t]\\|\\\\\n\\)*")) | ||
| 1080 | (not (= (match-end 0) (c-point 'eol)))) | ||
| 1081 | (goto-char (match-end 0)))) | ||
| 1082 | |||
| 1083 | |||
| 1084 | ;; Tools for skipping over syntactic whitespace. | 1117 | ;; Tools for skipping over syntactic whitespace. |
| 1085 | 1118 | ||
| 1086 | ;; The following functions use text properties to cache searches over | 1119 | ;; The following functions use text properties to cache searches over |
| @@ -2451,7 +2484,8 @@ syntactic whitespace." | |||
| 2451 | (< check-pos | 2484 | (< check-pos |
| 2452 | (save-excursion | 2485 | (save-excursion |
| 2453 | (goto-char check-pos) | 2486 | (goto-char check-pos) |
| 2454 | (c-end-of-current-token last-token-end-pos) | 2487 | (save-match-data |
| 2488 | (c-end-of-current-token last-token-end-pos)) | ||
| 2455 | (setq last-token-end-pos (point)))))) | 2489 | (setq last-token-end-pos (point)))))) |
| 2456 | ;; Match inside a token. | 2490 | ;; Match inside a token. |
| 2457 | (cond ((<= (point) bound) | 2491 | (cond ((<= (point) bound) |
| @@ -2516,9 +2550,7 @@ syntactic whitespace." | |||
| 2516 | i.e. don't stop at positions inside syntactic whitespace or string | 2550 | i.e. don't stop at positions inside syntactic whitespace or string |
| 2517 | literals. Preprocessor directives are also ignored, with the exception | 2551 | literals. Preprocessor directives are also ignored, with the exception |
| 2518 | of the one that the point starts within, if any. If LIMIT is given, | 2552 | of the one that the point starts within, if any. If LIMIT is given, |
| 2519 | it's assumed to be at a syntactically relevant position. | 2553 | it's assumed to be at a syntactically relevant position." |
| 2520 | |||
| 2521 | This function does not do any hidden buffer changes." | ||
| 2522 | 2554 | ||
| 2523 | (let ((start (point)) | 2555 | (let ((start (point)) |
| 2524 | ;; A list of syntactically relevant positions in descending | 2556 | ;; A list of syntactically relevant positions in descending |
| @@ -3351,9 +3383,20 @@ This function does not do any hidden buffer changes." | |||
| 3351 | (defvar c-promote-possible-types nil) | 3383 | (defvar c-promote-possible-types nil) |
| 3352 | 3384 | ||
| 3353 | ;; Dynamically bound variable that instructs `c-forward-<>-arglist' to | 3385 | ;; Dynamically bound variable that instructs `c-forward-<>-arglist' to |
| 3354 | ;; not accept arglists that contain more than one argument. It's used | 3386 | ;; not accept arglists that contain binary operators. |
| 3355 | ;; to handle ambiguous cases like "foo (a < b, c > d)" better. | 3387 | ;; |
| 3356 | (defvar c-disallow-comma-in-<>-arglists nil) | 3388 | ;; This is primarily used to handle C++ template arglists. C++ |
| 3389 | ;; disambiguates them by checking whether the preceding name is a | ||
| 3390 | ;; template or not. We can't do that, so we assume it is a template | ||
| 3391 | ;; if it can be parsed as one. That usually works well since | ||
| 3392 | ;; comparison expressions on the forms "a < b > c" or "a < b, c > d" | ||
| 3393 | ;; in almost all cases would be pointless. | ||
| 3394 | ;; | ||
| 3395 | ;; However, in function arglists, e.g. in "foo (a < b, c > d)", we | ||
| 3396 | ;; should let the comma separate the function arguments instead. And | ||
| 3397 | ;; in a context where the value of the expression is taken, e.g. in | ||
| 3398 | ;; "if (a < b || c > d)", it's probably not a template. | ||
| 3399 | (defvar c-restricted-<>-arglists nil) | ||
| 3357 | 3400 | ||
| 3358 | ;; Dynamically bound variables that instructs `c-forward-name', | 3401 | ;; Dynamically bound variables that instructs `c-forward-name', |
| 3359 | ;; `c-forward-type' and `c-forward-<>-arglist' to record the ranges of | 3402 | ;; `c-forward-type' and `c-forward-<>-arglist' to record the ranges of |
| @@ -3494,7 +3537,7 @@ This function does not do any hidden buffer changes." | |||
| 3494 | (eq (char-after) ?<) | 3537 | (eq (char-after) ?<) |
| 3495 | (c-forward-<>-arglist (c-keyword-member kwd-sym 'c-<>-type-kwds) | 3538 | (c-forward-<>-arglist (c-keyword-member kwd-sym 'c-<>-type-kwds) |
| 3496 | (or c-record-type-identifiers | 3539 | (or c-record-type-identifiers |
| 3497 | c-disallow-comma-in-<>-arglists))) | 3540 | c-restricted-<>-arglists))) |
| 3498 | (c-forward-syntactic-ws) | 3541 | (c-forward-syntactic-ws) |
| 3499 | (setq safe-pos (point))) | 3542 | (setq safe-pos (point))) |
| 3500 | 3543 | ||
| @@ -3543,16 +3586,7 @@ This function does not do any hidden buffer changes." | |||
| 3543 | ;; necessary if the various side effects, e.g. recording of type | 3586 | ;; necessary if the various side effects, e.g. recording of type |
| 3544 | ;; ranges, are important. Setting REPARSE to t only applies | 3587 | ;; ranges, are important. Setting REPARSE to t only applies |
| 3545 | ;; recursively to nested angle bracket arglists if | 3588 | ;; recursively to nested angle bracket arglists if |
| 3546 | ;; `c-disallow-comma-in-<>-arglists' is set. | 3589 | ;; `c-restricted-<>-arglists' is set. |
| 3547 | ;; | ||
| 3548 | ;; This is primarily used in C++ to mark up template arglists. C++ | ||
| 3549 | ;; disambiguates them by checking whether the preceding name is a | ||
| 3550 | ;; template or not. We can't do that, so we assume it is a template | ||
| 3551 | ;; if it can be parsed as one. This usually works well since | ||
| 3552 | ;; comparison expressions on the forms "a < b > c" or "a < b, c > d" | ||
| 3553 | ;; in almost all cases would be pointless. Cases like function | ||
| 3554 | ;; calls on the form "foo (a < b, c > d)" needs to be handled | ||
| 3555 | ;; specially through the `c-disallow-comma-in-<>-arglists' variable. | ||
| 3556 | 3590 | ||
| 3557 | (let ((start (point)) | 3591 | (let ((start (point)) |
| 3558 | ;; If `c-record-type-identifiers' is set then activate | 3592 | ;; If `c-record-type-identifiers' is set then activate |
| @@ -3683,11 +3717,18 @@ This function does not do any hidden buffer changes." | |||
| 3683 | (forward-char) | 3717 | (forward-char) |
| 3684 | t) | 3718 | t) |
| 3685 | 3719 | ||
| 3686 | ;; Note: This regexp exploits the match order in | 3720 | ;; Note: These regexps exploit the match order in \| so |
| 3687 | ;; \| so that "<>" is matched by "<" rather than | 3721 | ;; that "<>" is matched by "<" rather than "[^>:-]>". |
| 3688 | ;; "[^>:-]>". | ||
| 3689 | (c-syntactic-re-search-forward | 3722 | (c-syntactic-re-search-forward |
| 3690 | "[<;{},]\\|\\([^>:-]>\\)" nil 'move t t 1) | 3723 | (if c-restricted-<>-arglists |
| 3724 | ;; Stop on ',', '|', '&', '+' and '-' to catch | ||
| 3725 | ;; common binary operators that could be between | ||
| 3726 | ;; two comparison expressions "a<b" and "c>d". | ||
| 3727 | "[<;{},|&+-]\\|\\([^>:-]>\\)" | ||
| 3728 | ;; Otherwise we still stop on ',' to find the | ||
| 3729 | ;; argument start positions. | ||
| 3730 | "[<;{},]\\|\\([^>:-]>\\)") | ||
| 3731 | nil 'move t t 1) | ||
| 3691 | 3732 | ||
| 3692 | ;; If the arglist starter has lost its open paren | 3733 | ;; If the arglist starter has lost its open paren |
| 3693 | ;; syntax but not the closer, we won't find the | 3734 | ;; syntax but not the closer, we won't find the |
| @@ -3776,7 +3817,7 @@ This function does not do any hidden buffer changes." | |||
| 3776 | (c-keyword-sym (match-string 1)) | 3817 | (c-keyword-sym (match-string 1)) |
| 3777 | 'c-<>-type-kwds)) | 3818 | 'c-<>-type-kwds)) |
| 3778 | (and reparse | 3819 | (and reparse |
| 3779 | c-disallow-comma-in-<>-arglists)))) | 3820 | c-restricted-<>-arglists)))) |
| 3780 | ))) | 3821 | ))) |
| 3781 | 3822 | ||
| 3782 | ;; It was not an angle bracket arglist. | 3823 | ;; It was not an angle bracket arglist. |
| @@ -3812,7 +3853,7 @@ This function does not do any hidden buffer changes." | |||
| 3812 | t) | 3853 | t) |
| 3813 | 3854 | ||
| 3814 | ((and (eq (char-before) ?,) | 3855 | ((and (eq (char-before) ?,) |
| 3815 | (not c-disallow-comma-in-<>-arglists)) | 3856 | (not c-restricted-<>-arglists)) |
| 3816 | ;; Just another argument. Record the position. The | 3857 | ;; Just another argument. Record the position. The |
| 3817 | ;; type check stuff that made us stop at it is at | 3858 | ;; type check stuff that made us stop at it is at |
| 3818 | ;; the top of the loop. | 3859 | ;; the top of the loop. |
| @@ -3959,7 +4000,7 @@ This function does not do any hidden buffer changes." | |||
| 3959 | (when (let ((c-record-type-identifiers nil) | 4000 | (when (let ((c-record-type-identifiers nil) |
| 3960 | (c-record-found-types nil)) | 4001 | (c-record-found-types nil)) |
| 3961 | (c-forward-<>-arglist | 4002 | (c-forward-<>-arglist |
| 3962 | nil c-disallow-comma-in-<>-arglists)) | 4003 | nil c-restricted-<>-arglists)) |
| 3963 | (c-forward-syntactic-ws) | 4004 | (c-forward-syntactic-ws) |
| 3964 | (setq pos (point)) | 4005 | (setq pos (point)) |
| 3965 | (if (and c-opt-identifier-concat-key | 4006 | (if (and c-opt-identifier-concat-key |
| @@ -4202,7 +4243,7 @@ This function does not do any hidden buffer changes." | |||
| 4202 | (c-with-syntax-table c++-template-syntax-table | 4243 | (c-with-syntax-table c++-template-syntax-table |
| 4203 | (c-backward-token-2 0 t lim) | 4244 | (c-backward-token-2 0 t lim) |
| 4204 | (while (and (or (looking-at c-symbol-start) | 4245 | (while (and (or (looking-at c-symbol-start) |
| 4205 | (looking-at "[<,]")) | 4246 | (looking-at "[<,]\\|::")) |
| 4206 | (zerop (c-backward-token-2 1 t lim)))) | 4247 | (zerop (c-backward-token-2 1 t lim)))) |
| 4207 | (skip-chars-forward "^:")))) | 4248 | (skip-chars-forward "^:")))) |
| 4208 | 4249 | ||
| @@ -4326,8 +4367,7 @@ brace." | |||
| 4326 | ;; position that bounds the backward search for the argument list. | 4367 | ;; position that bounds the backward search for the argument list. |
| 4327 | ;; | 4368 | ;; |
| 4328 | ;; Note: A declaration level context is assumed; the test can return | 4369 | ;; Note: A declaration level context is assumed; the test can return |
| 4329 | ;; false positives for statements. This test is even more easily | 4370 | ;; false positives for statements. |
| 4330 | ;; fooled than `c-just-after-func-arglist-p'. | ||
| 4331 | 4371 | ||
| 4332 | (save-excursion | 4372 | (save-excursion |
| 4333 | (save-restriction | 4373 | (save-restriction |
| @@ -4337,13 +4377,12 @@ brace." | |||
| 4337 | ;; check that it's followed by some symbol before the next ';' | 4377 | ;; check that it's followed by some symbol before the next ';' |
| 4338 | ;; or '{'. If it does, it's the header of the K&R argdecl we're | 4378 | ;; or '{'. If it does, it's the header of the K&R argdecl we're |
| 4339 | ;; in. | 4379 | ;; in. |
| 4340 | (if lim (narrow-to-region lim (point))) | 4380 | (if lim (narrow-to-region lim (c-point 'eol))) |
| 4341 | (let ((outside-macro (not (c-query-macro-start))) | 4381 | (let ((outside-macro (not (c-query-macro-start))) |
| 4342 | paren-end) | 4382 | paren-end) |
| 4343 | 4383 | ||
| 4344 | (catch 'done | 4384 | (catch 'done |
| 4345 | (while (if (and (c-safe (setq paren-end | 4385 | (while (if (and (setq paren-end (c-down-list-backward (point))) |
| 4346 | (c-down-list-backward (point)))) | ||
| 4347 | (eq (char-after paren-end) ?\))) | 4386 | (eq (char-after paren-end) ?\))) |
| 4348 | (progn | 4387 | (progn |
| 4349 | (goto-char (1+ paren-end)) | 4388 | (goto-char (1+ paren-end)) |
| @@ -4354,7 +4393,26 @@ brace." | |||
| 4354 | (and (progn | 4393 | (and (progn |
| 4355 | (c-forward-syntactic-ws) | 4394 | (c-forward-syntactic-ws) |
| 4356 | (looking-at "\\w\\|\\s_")) | 4395 | (looking-at "\\w\\|\\s_")) |
| 4357 | (c-safe (c-up-list-backward paren-end)) | 4396 | |
| 4397 | (save-excursion | ||
| 4398 | ;; The function header in a K&R declaration should only | ||
| 4399 | ;; contain identifiers separated by comma. It should | ||
| 4400 | ;; also contain at least one identifier since there | ||
| 4401 | ;; wouldn't be anything to declare in the K&R region | ||
| 4402 | ;; otherwise. | ||
| 4403 | (when (c-go-up-list-backward paren-end) | ||
| 4404 | (forward-char) | ||
| 4405 | (catch 'knr-ok | ||
| 4406 | (while t | ||
| 4407 | (c-forward-syntactic-ws) | ||
| 4408 | (if (or (looking-at c-known-type-key) | ||
| 4409 | (looking-at c-keywords-regexp)) | ||
| 4410 | (throw 'knr-ok nil)) | ||
| 4411 | (c-forward-token-2) | ||
| 4412 | (if (eq (char-after) ?,) | ||
| 4413 | (forward-char) | ||
| 4414 | (throw 'knr-ok (and (eq (char-after) ?\)) | ||
| 4415 | (= (point) paren-end)))))))) | ||
| 4358 | 4416 | ||
| 4359 | (save-excursion | 4417 | (save-excursion |
| 4360 | ;; If it's a K&R declaration then we're now at the | 4418 | ;; If it's a K&R declaration then we're now at the |
| @@ -4405,24 +4463,12 @@ brace." | |||
| 4405 | (if start | 4463 | (if start |
| 4406 | (goto-char start))))) | 4464 | (goto-char start))))) |
| 4407 | 4465 | ||
| 4408 | (defun c-backward-to-decl-anchor (&optional lim) | 4466 | (defsubst c-backward-to-decl-anchor (&optional lim) |
| 4409 | ;; Assuming point is at a brace that opens the block of a top level | 4467 | ;; Assuming point is at a brace that opens the block of a top level |
| 4410 | ;; declaration of some kind, move to the proper anchor point for | 4468 | ;; declaration of some kind, move to the proper anchor point for |
| 4411 | ;; that block. | 4469 | ;; that block. |
| 4412 | (unless (= (point) (c-point 'boi)) | 4470 | (unless (= (point) (c-point 'boi)) |
| 4413 | ;; What we have below is actually an extremely stripped variant of | 4471 | (c-beginning-of-statement-1 lim))) |
| 4414 | ;; c-beginning-of-statement-1. | ||
| 4415 | (let ((pos (point)) c-maybe-labelp) | ||
| 4416 | ;; Switch syntax table to avoid stopping at line continuations. | ||
| 4417 | (save-restriction | ||
| 4418 | (if lim (narrow-to-region lim (point-max))) | ||
| 4419 | (while (and (progn | ||
| 4420 | (c-backward-syntactic-ws) | ||
| 4421 | (c-safe (goto-char (scan-sexps (point) -1)) t)) | ||
| 4422 | (not (c-crosses-statement-barrier-p (point) pos)) | ||
| 4423 | (not c-maybe-labelp)) | ||
| 4424 | (setq pos (point))) | ||
| 4425 | (goto-char pos))))) | ||
| 4426 | 4472 | ||
| 4427 | (defun c-search-decl-header-end () | 4473 | (defun c-search-decl-header-end () |
| 4428 | ;; Search forward for the end of the "header" of the current | 4474 | ;; Search forward for the end of the "header" of the current |
| @@ -4619,7 +4665,7 @@ brace." | |||
| 4619 | nil))) | 4665 | nil))) |
| 4620 | 4666 | ||
| 4621 | (defun c-beginning-of-member-init-list (&optional limit) | 4667 | (defun c-beginning-of-member-init-list (&optional limit) |
| 4622 | ;; Goes to the beginning of a member init list (i.e. just after the | 4668 | ;; Go to the beginning of a member init list (i.e. just after the |
| 4623 | ;; ':') if inside one. Returns t in that case, nil otherwise. | 4669 | ;; ':') if inside one. Returns t in that case, nil otherwise. |
| 4624 | (or limit | 4670 | (or limit |
| 4625 | (setq limit (point-min))) | 4671 | (setq limit (point-min))) |
| @@ -5196,7 +5242,7 @@ brace." | |||
| 5196 | (eq step-type 'label) | 5242 | (eq step-type 'label) |
| 5197 | (/= savepos boi)) | 5243 | (/= savepos boi)) |
| 5198 | 5244 | ||
| 5199 | (progn | 5245 | (let ((save-step-type step-type)) |
| 5200 | ;; Current position might not be good enough; | 5246 | ;; Current position might not be good enough; |
| 5201 | ;; skip backward another statement. | 5247 | ;; skip backward another statement. |
| 5202 | (setq step-type (c-beginning-of-statement-1 | 5248 | (setq step-type (c-beginning-of-statement-1 |
| @@ -5228,14 +5274,20 @@ brace." | |||
| 5228 | (c-add-syntax 'substatement nil)) | 5274 | (c-add-syntax 'substatement nil)) |
| 5229 | 5275 | ||
| 5230 | (setq boi (c-point 'boi)) | 5276 | (setq boi (c-point 'boi)) |
| 5231 | (/= (point) savepos))))) | 5277 | (if (= (point) savepos) |
| 5278 | (progn | ||
| 5279 | (setq step-type save-step-type) | ||
| 5280 | nil) | ||
| 5281 | t))))) | ||
| 5232 | 5282 | ||
| 5233 | (setq savepos (point) | 5283 | (setq savepos (point) |
| 5234 | at-comment nil)) | 5284 | at-comment nil)) |
| 5235 | (setq at-comment nil) | 5285 | (setq at-comment nil) |
| 5236 | 5286 | ||
| 5237 | (when (and (eq step-type 'same) | 5287 | (when (and containing-sexp |
| 5238 | containing-sexp) | 5288 | (if (memq step-type '(nil same)) |
| 5289 | (/= (point) boi) | ||
| 5290 | (eq step-type 'label))) | ||
| 5239 | (goto-char containing-sexp) | 5291 | (goto-char containing-sexp) |
| 5240 | 5292 | ||
| 5241 | ;; Don't stop in the middle of a special brace list opener | 5293 | ;; Don't stop in the middle of a special brace list opener |
| @@ -5395,21 +5447,32 @@ brace." | |||
| 5395 | 5447 | ||
| 5396 | ;; CASE B.3: The body of a function declared inside a normal | 5448 | ;; CASE B.3: The body of a function declared inside a normal |
| 5397 | ;; block. Can occur e.g. in Pike and when using gcc | 5449 | ;; block. Can occur e.g. in Pike and when using gcc |
| 5398 | ;; extensions. Might also trigger it with some macros followed | 5450 | ;; extensions, but watch out for macros followed by blocks. |
| 5399 | ;; by blocks, and this gives sane indentation then too. | ||
| 5400 | ;; C.f. cases E, 16F and 17G. | 5451 | ;; C.f. cases E, 16F and 17G. |
| 5401 | ((and (not (c-looking-at-bos)) | 5452 | ((and (not (c-looking-at-bos)) |
| 5402 | (eq (c-beginning-of-statement-1 containing-sexp nil nil t) | 5453 | (eq (c-beginning-of-statement-1 containing-sexp nil nil t) |
| 5403 | 'same)) | 5454 | 'same) |
| 5455 | (save-excursion | ||
| 5456 | ;; Look for a type followed by a symbol, i.e. the start of a | ||
| 5457 | ;; function declaration. Doesn't work for declarations like | ||
| 5458 | ;; "int *foo() ..."; we'd need to refactor the more competent | ||
| 5459 | ;; analysis in `c-font-lock-declarations' for that. | ||
| 5460 | (and (c-forward-type) | ||
| 5461 | (progn | ||
| 5462 | (c-forward-syntactic-ws) | ||
| 5463 | (looking-at c-symbol-start))))) | ||
| 5404 | (c-add-stmt-syntax 'defun-open nil t nil | 5464 | (c-add-stmt-syntax 'defun-open nil t nil |
| 5405 | containing-sexp paren-state)) | 5465 | containing-sexp paren-state)) |
| 5406 | 5466 | ||
| 5407 | ;; CASE B.4: Continued statement with block open. | 5467 | ;; CASE B.4: Continued statement with block open. The most |
| 5468 | ;; accurate analysis is perhaps `statement-cont' together with | ||
| 5469 | ;; `block-open' but we play DWIM and use `substatement-open' | ||
| 5470 | ;; instead. The rationaly is that this typically is a macro | ||
| 5471 | ;; followed by a block which makes it very similar to a | ||
| 5472 | ;; statement with a substatement block. | ||
| 5408 | (t | 5473 | (t |
| 5409 | (goto-char beg-of-same-or-containing-stmt) | 5474 | (c-add-stmt-syntax 'substatement-open nil nil nil |
| 5410 | (c-add-stmt-syntax 'statement-cont nil nil nil | 5475 | containing-sexp paren-state)) |
| 5411 | containing-sexp paren-state) | ||
| 5412 | (c-add-syntax 'block-open)) | ||
| 5413 | )) | 5476 | )) |
| 5414 | 5477 | ||
| 5415 | ;; CASE C: iostream insertion or extraction operator | 5478 | ;; CASE C: iostream insertion or extraction operator |
| @@ -5428,8 +5491,8 @@ brace." | |||
| 5428 | ((and (save-excursion | 5491 | ((and (save-excursion |
| 5429 | ;; Check that the next token is a '{'. This works as | 5492 | ;; Check that the next token is a '{'. This works as |
| 5430 | ;; long as no language that allows nested function | 5493 | ;; long as no language that allows nested function |
| 5431 | ;; definitions doesn't allow stuff like member init | 5494 | ;; definitions allows stuff like member init lists, K&R |
| 5432 | ;; lists, K&R declarations or throws clauses there. | 5495 | ;; declarations or throws clauses there. |
| 5433 | ;; | 5496 | ;; |
| 5434 | ;; Note that we do a forward search for something ahead | 5497 | ;; Note that we do a forward search for something ahead |
| 5435 | ;; of the indentation line here. That's not good since | 5498 | ;; of the indentation line here. That's not good since |
| @@ -5440,7 +5503,16 @@ brace." | |||
| 5440 | (eq (char-after) ?{)) | 5503 | (eq (char-after) ?{)) |
| 5441 | (not (c-looking-at-bos)) | 5504 | (not (c-looking-at-bos)) |
| 5442 | (eq (c-beginning-of-statement-1 containing-sexp nil nil t) | 5505 | (eq (c-beginning-of-statement-1 containing-sexp nil nil t) |
| 5443 | 'same)) | 5506 | 'same) |
| 5507 | (save-excursion | ||
| 5508 | ;; Look for a type followed by a symbol, i.e. the start of a | ||
| 5509 | ;; function declaration. Doesn't work for declarations like "int | ||
| 5510 | ;; *foo() ..."; we'd need to refactor the more competent analysis | ||
| 5511 | ;; in `c-font-lock-declarations' for that. | ||
| 5512 | (and (c-forward-type) | ||
| 5513 | (progn | ||
| 5514 | (c-forward-syntactic-ws) | ||
| 5515 | (looking-at c-symbol-start))))) | ||
| 5444 | (c-add-stmt-syntax 'func-decl-cont nil t nil | 5516 | (c-add-stmt-syntax 'func-decl-cont nil t nil |
| 5445 | containing-sexp paren-state)) | 5517 | containing-sexp paren-state)) |
| 5446 | 5518 | ||
| @@ -5852,7 +5924,8 @@ This function does not do any hidden buffer changes." | |||
| 5852 | ;; should be relative to the ctor's indentation | 5924 | ;; should be relative to the ctor's indentation |
| 5853 | ) | 5925 | ) |
| 5854 | ;; CASE 5B.2: K&R arg decl intro | 5926 | ;; CASE 5B.2: K&R arg decl intro |
| 5855 | (c-recognize-knr-p | 5927 | ((and c-recognize-knr-p |
| 5928 | (c-in-knr-argdecl lim)) | ||
| 5856 | (c-beginning-of-statement-1 lim) | 5929 | (c-beginning-of-statement-1 lim) |
| 5857 | (c-add-syntax 'knr-argdecl-intro (c-point 'boi)) | 5930 | (c-add-syntax 'knr-argdecl-intro (c-point 'boi)) |
| 5858 | (if inclass-p | 5931 | (if inclass-p |
| @@ -6493,16 +6566,24 @@ This function does not do any hidden buffer changes." | |||
| 6493 | (c-add-syntax 'inline-close (point)))) | 6566 | (c-add-syntax 'inline-close (point)))) |
| 6494 | ;; CASE 16F: Can be a defun-close of a function declared | 6567 | ;; CASE 16F: Can be a defun-close of a function declared |
| 6495 | ;; in a statement block, e.g. in Pike or when using gcc | 6568 | ;; in a statement block, e.g. in Pike or when using gcc |
| 6496 | ;; extensions. Might also trigger it with some macros | 6569 | ;; extensions, but watch out for macros followed by |
| 6497 | ;; followed by blocks, and this gives sane indentation | 6570 | ;; blocks. Let it through to be handled below. |
| 6498 | ;; then too. Let it through to be handled below. | ||
| 6499 | ;; C.f. cases B.3 and 17G. | 6571 | ;; C.f. cases B.3 and 17G. |
| 6500 | ((and (not inenclosing-p) | 6572 | ((and (not inenclosing-p) |
| 6501 | lim | 6573 | lim |
| 6502 | (save-excursion | 6574 | (save-excursion |
| 6503 | (and (not (c-looking-at-bos)) | 6575 | (and (not (c-looking-at-bos)) |
| 6504 | (eq (c-beginning-of-statement-1 lim nil nil t) 'same) | 6576 | (eq (c-beginning-of-statement-1 lim nil nil t) 'same) |
| 6505 | (setq placeholder (point))))) | 6577 | (setq placeholder (point)) |
| 6578 | ;; Look for a type or identifier followed by a | ||
| 6579 | ;; symbol, i.e. the start of a function declaration. | ||
| 6580 | ;; Doesn't work for declarations like "int *foo() | ||
| 6581 | ;; ..."; we'd need to refactor the more competent | ||
| 6582 | ;; analysis in `c-font-lock-declarations' for that. | ||
| 6583 | (c-forward-type) | ||
| 6584 | (progn | ||
| 6585 | (c-forward-syntactic-ws) | ||
| 6586 | (looking-at c-symbol-start))))) | ||
| 6506 | (back-to-indentation) | 6587 | (back-to-indentation) |
| 6507 | (if (/= (point) containing-sexp) | 6588 | (if (/= (point) containing-sexp) |
| 6508 | (goto-char placeholder)) | 6589 | (goto-char placeholder)) |
| @@ -6627,13 +6708,21 @@ This function does not do any hidden buffer changes." | |||
| 6627 | (c-add-syntax 'defun-block-intro (point))) | 6708 | (c-add-syntax 'defun-block-intro (point))) |
| 6628 | ;; CASE 17G: First statement in a function declared inside | 6709 | ;; CASE 17G: First statement in a function declared inside |
| 6629 | ;; a normal block. This can occur in Pike and with | 6710 | ;; a normal block. This can occur in Pike and with |
| 6630 | ;; e.g. the gcc extensions. Might also trigger it with | 6711 | ;; e.g. the gcc extensions, but watch out for macros |
| 6631 | ;; some macros followed by blocks, and this gives sane | 6712 | ;; followed by blocks. C.f. cases B.3 and 16F. |
| 6632 | ;; indentation then too. C.f. cases B.3 and 16F. | ||
| 6633 | ((save-excursion | 6713 | ((save-excursion |
| 6634 | (and (not (c-looking-at-bos)) | 6714 | (and (not (c-looking-at-bos)) |
| 6635 | (eq (c-beginning-of-statement-1 lim nil nil t) 'same) | 6715 | (eq (c-beginning-of-statement-1 lim nil nil t) 'same) |
| 6636 | (setq placeholder (point)))) | 6716 | (setq placeholder (point)) |
| 6717 | ;; Look for a type or identifier followed by a | ||
| 6718 | ;; symbol, i.e. the start of a function declaration. | ||
| 6719 | ;; Doesn't work for declarations like "int *foo() | ||
| 6720 | ;; ..."; we'd need to refactor the more competent | ||
| 6721 | ;; analysis in `c-font-lock-declarations' for that. | ||
| 6722 | (c-forward-type) | ||
| 6723 | (progn | ||
| 6724 | (c-forward-syntactic-ws) | ||
| 6725 | (looking-at c-symbol-start)))) | ||
| 6637 | (back-to-indentation) | 6726 | (back-to-indentation) |
| 6638 | (if (/= (point) containing-sexp) | 6727 | (if (/= (point) containing-sexp) |
| 6639 | (goto-char placeholder)) | 6728 | (goto-char placeholder)) |
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index c5a587f41e5..27c604b3f33 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el | |||
| @@ -894,7 +894,7 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 894 | 894 | ||
| 895 | (save-restriction | 895 | (save-restriction |
| 896 | (let (start-pos | 896 | (let (start-pos |
| 897 | c-disallow-comma-in-<>-arglists | 897 | c-restricted-<>-arglists |
| 898 | ;; Nonzero if the `c-decl-prefix-re' match is in an arglist context, | 898 | ;; Nonzero if the `c-decl-prefix-re' match is in an arglist context, |
| 899 | ;; as opposed to a statement-level context. The major difference is | 899 | ;; as opposed to a statement-level context. The major difference is |
| 900 | ;; that "," works as declaration delimiter in an arglist context, | 900 | ;; that "," works as declaration delimiter in an arglist context, |
| @@ -1050,11 +1050,11 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 1050 | ;; If we're in a normal arglist context we don't want to | 1050 | ;; If we're in a normal arglist context we don't want to |
| 1051 | ;; recognize commas in nested angle bracket arglists since | 1051 | ;; recognize commas in nested angle bracket arglists since |
| 1052 | ;; those commas could be part of our own arglist. | 1052 | ;; those commas could be part of our own arglist. |
| 1053 | c-disallow-comma-in-<>-arglists | 1053 | c-restricted-<>-arglists |
| 1054 | (and c-recognize-<>-arglists | 1054 | (and c-recognize-<>-arglists |
| 1055 | (eq arglist-type 'other))) | 1055 | (eq arglist-type 'other))) |
| 1056 | 1056 | ||
| 1057 | (when (and c-disallow-comma-in-<>-arglists | 1057 | (when (and c-restricted-<>-arglists |
| 1058 | (/= arglist-match ?,)) | 1058 | (/= arglist-match ?,)) |
| 1059 | ;; We're standing at the start of a normal arglist so remove any | 1059 | ;; We're standing at the start of a normal arglist so remove any |
| 1060 | ;; angle bracket arglists containing commas that's been | 1060 | ;; angle bracket arglists containing commas that's been |
diff --git a/lisp/progmodes/cc-vars.el b/lisp/progmodes/cc-vars.el index 0485bf3332f..f21531c2f22 100644 --- a/lisp/progmodes/cc-vars.el +++ b/lisp/progmodes/cc-vars.el | |||
| @@ -878,12 +878,11 @@ This hook gets called after a line is indented by the mode." | |||
| 878 | :group 'c) | 878 | :group 'c) |
| 879 | 879 | ||
| 880 | (defcustom-c-stylevar c-label-minimum-indentation 1 | 880 | (defcustom-c-stylevar c-label-minimum-indentation 1 |
| 881 | "*Minimum indentation for lines inside of top-level constructs. | 881 | "*Minimum indentation for lines inside code blocks. |
| 882 | This variable typically only affects code using the `gnu' style, which | 882 | This variable typically only affects code using the `gnu' style, which |
| 883 | mandates a minimum of one space in front of every line inside | 883 | mandates a minimum of one space in front of every line inside code |
| 884 | top-level constructs. Specifically, the function | 884 | blocks. Specifically, the function `c-gnu-impose-minimum' on your |
| 885 | `c-gnu-impose-minimum' on your `c-special-indent-hook' is what | 885 | `c-special-indent-hook' is what enforces this." |
| 886 | enforces this." | ||
| 887 | :type 'integer | 886 | :type 'integer |
| 888 | :group 'c) | 887 | :group 'c) |
| 889 | 888 | ||
| @@ -1271,6 +1270,14 @@ Here is the current list of valid syntactic element symbols: | |||
| 1271 | (get 'c-offsets-alist 'c-stylevar-fallback))) | 1270 | (get 'c-offsets-alist 'c-stylevar-fallback))) |
| 1272 | :group 'c) | 1271 | :group 'c) |
| 1273 | 1272 | ||
| 1273 | ;; The syntactic symbols that can occur inside code blocks. Used by | ||
| 1274 | ;; `c-gnu-impose-minimum'. | ||
| 1275 | (defconst c-inside-block-syms | ||
| 1276 | '(defun-block-intro block-open block-close statement statement-cont | ||
| 1277 | statement-block-intro statement-case-intro statement-case-open | ||
| 1278 | substatement substatement-open substatement-label case-label label | ||
| 1279 | do-while-closure else-clause catch-clause inlambda)) | ||
| 1280 | |||
| 1274 | (defcustom c-style-variables-are-local-p t | 1281 | (defcustom c-style-variables-are-local-p t |
| 1275 | "*Whether style variables should be buffer local by default. | 1282 | "*Whether style variables should be buffer local by default. |
| 1276 | If non-nil, then all indentation style related variables will be made | 1283 | If non-nil, then all indentation style related variables will be made |
| @@ -1575,7 +1582,7 @@ Set from `c-comment-prefix-regexp' at mode initialization.") | |||
| 1575 | '1-bit) | 1582 | '1-bit) |
| 1576 | list))) | 1583 | list))) |
| 1577 | 1584 | ||
| 1578 | (let ((buf (generate-new-buffer "test")) | 1585 | (let ((buf (generate-new-buffer " test")) |
| 1579 | parse-sexp-lookup-properties | 1586 | parse-sexp-lookup-properties |
| 1580 | parse-sexp-ignore-comments | 1587 | parse-sexp-ignore-comments |
| 1581 | lookup-syntax-properties) | 1588 | lookup-syntax-properties) |