diff options
| author | Alan Mackenzie | 2007-08-25 16:50:26 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2007-08-25 16:50:26 +0000 |
| commit | a335046bf52834e718a2aebdd3b909a14ab1dc28 (patch) | |
| tree | 29852717b2f79d471ff34bd24bb69d025170eaed | |
| parent | d3a72478600aa4c52c7172faf7c6871d984be95d (diff) | |
| download | emacs-a335046bf52834e718a2aebdd3b909a14ab1dc28.tar.gz emacs-a335046bf52834e718a2aebdd3b909a14ab1dc28.zip | |
(c-brace-anchor-point): new function. (c-add-stmt-syntax): Give accurate
anchor points for "namespace", "extern" etc., rather than BOI. Fix
addition of spurious syntactic-symbol 'defun-block-intro, replacing it
with 'innamespace, etc.
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 81 |
1 files changed, 57 insertions, 24 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 97dcc61460f..d1a27d567fd 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -4067,7 +4067,6 @@ comment at the start of cc-engine.el for more info." | |||
| 4067 | ;; Changing the amount of (already existing) whitespace - don't do anything. | 4067 | ;; Changing the amount of (already existing) whitespace - don't do anything. |
| 4068 | ((and (c-partial-ws-p beg end) | 4068 | ((and (c-partial-ws-p beg end) |
| 4069 | (or (= beg end) ; removal of WS | 4069 | (or (= beg end) ; removal of WS |
| 4070 | ; (string-match "\\s *\\'" (nth 5 c-maybe-stale-found-type)) | ||
| 4071 | (string-match "^[ \t\n\r\f\v]*$" (nth 5 c-maybe-stale-found-type))))) | 4070 | (string-match "^[ \t\n\r\f\v]*$" (nth 5 c-maybe-stale-found-type))))) |
| 4072 | 4071 | ||
| 4073 | ;; The syntactic relationship which defined a "found type" has been | 4072 | ;; The syntactic relationship which defined a "found type" has been |
| @@ -5891,7 +5890,7 @@ comment at the start of cc-engine.el for more info." | |||
| 5891 | ;; "private:"/"protected:"/"public:"/"more:" looking like "public slots:". | 5890 | ;; "private:"/"protected:"/"public:"/"more:" looking like "public slots:". |
| 5892 | ;; Returns the symbol `qt-2kwds-colon'. | 5891 | ;; Returns the symbol `qt-2kwds-colon'. |
| 5893 | ;; (v) QT's construct "signals:". Returns the symbol `qt-1kwd-colon'. | 5892 | ;; (v) QT's construct "signals:". Returns the symbol `qt-1kwd-colon'. |
| 5894 | ;; (v) One of the keywords matched by `c-opt-extra-label-key' (without any | 5893 | ;; (vi) One of the keywords matched by `c-opt-extra-label-key' (without any |
| 5895 | ;; colon). Currently (2006-03), this applies only to Objective C's | 5894 | ;; colon). Currently (2006-03), this applies only to Objective C's |
| 5896 | ;; keywords "@private", "@protected", and "@public". Returns t. | 5895 | ;; keywords "@private", "@protected", and "@public". Returns t. |
| 5897 | ;; | 5896 | ;; |
| @@ -6117,8 +6116,7 @@ comment at the start of cc-engine.el for more info." | |||
| 6117 | (match-end 0))))) | 6116 | (match-end 0))))) |
| 6118 | 6117 | ||
| 6119 | (c-put-c-type-property (1- (point-max)) 'c-decl-end) | 6118 | (c-put-c-type-property (1- (point-max)) 'c-decl-end) |
| 6120 | (goto-char (point-max)) | 6119 | (goto-char (point-max))))) |
| 6121 | ))) | ||
| 6122 | 6120 | ||
| 6123 | (t | 6121 | (t |
| 6124 | ;; Not a label. | 6122 | ;; Not a label. |
| @@ -7197,6 +7195,23 @@ comment at the start of cc-engine.el for more info." | |||
| 7197 | ;; auto newline analysis. | 7195 | ;; auto newline analysis. |
| 7198 | (defvar c-auto-newline-analysis nil) | 7196 | (defvar c-auto-newline-analysis nil) |
| 7199 | 7197 | ||
| 7198 | (defun c-brace-anchor-point (bracepos) | ||
| 7199 | ;; BRACEPOS is the position of a brace in a construct like "namespace | ||
| 7200 | ;; Bar {". Return the anchor point in this construct; this is the | ||
| 7201 | ;; earliest symbol on the brace's line which isn't earlier than | ||
| 7202 | ;; "namespace". | ||
| 7203 | ;; | ||
| 7204 | ;; Currently (2007-08-17), "like namespace" means "matches | ||
| 7205 | ;; c-other-block-decl-kwds". It doesn't work with "class" or "struct" | ||
| 7206 | ;; or anything like that. | ||
| 7207 | (save-excursion | ||
| 7208 | (let ((boi (c-point 'boi bracepos))) | ||
| 7209 | (goto-char bracepos) | ||
| 7210 | (while (and (> (point) boi) | ||
| 7211 | (not (looking-at c-other-decl-block-key))) | ||
| 7212 | (c-backward-token-2)) | ||
| 7213 | (if (> (point) boi) (point) boi)))) | ||
| 7214 | |||
| 7200 | (defsubst c-add-syntax (symbol &rest args) | 7215 | (defsubst c-add-syntax (symbol &rest args) |
| 7201 | ;; A simple function to prepend a new syntax element to | 7216 | ;; A simple function to prepend a new syntax element to |
| 7202 | ;; `c-syntactic-context'. Using `setq' on it is unsafe since it | 7217 | ;; `c-syntactic-context'. Using `setq' on it is unsafe since it |
| @@ -7229,8 +7244,12 @@ comment at the start of cc-engine.el for more info." | |||
| 7229 | ;; | 7244 | ;; |
| 7230 | ;; Point is assumed to be at the prospective anchor point for the | 7245 | ;; Point is assumed to be at the prospective anchor point for the |
| 7231 | ;; given SYNTAX-SYMBOL. More syntax entries are added if we need to | 7246 | ;; given SYNTAX-SYMBOL. More syntax entries are added if we need to |
| 7232 | ;; skip past open parens and containing statements. All the added | 7247 | ;; skip past open parens and containing statements. Most of the added |
| 7233 | ;; syntax elements will get the same anchor point. | 7248 | ;; syntax elements will get the same anchor point - the exception is |
| 7249 | ;; for an anchor in a construct like "namespace"[*] - this is as early | ||
| 7250 | ;; as possible in the construct but on the same line as the {. | ||
| 7251 | ;; | ||
| 7252 | ;; [*] i.e. with a keyword matching c-other-block-decl-kwds. | ||
| 7234 | ;; | 7253 | ;; |
| 7235 | ;; SYNTAX-EXTRA-ARGS are a list of the extra arguments for the | 7254 | ;; SYNTAX-EXTRA-ARGS are a list of the extra arguments for the |
| 7236 | ;; syntax symbol. They are appended after the anchor point. | 7255 | ;; syntax symbol. They are appended after the anchor point. |
| @@ -7255,7 +7274,11 @@ comment at the start of cc-engine.el for more info." | |||
| 7255 | ;; now at the start. | 7274 | ;; now at the start. |
| 7256 | on-label) | 7275 | on-label) |
| 7257 | 7276 | ||
| 7258 | (apply 'c-add-syntax syntax-symbol nil syntax-extra-args) | 7277 | ;; Use point as the anchor point for "namespace", "extern", etc. |
| 7278 | (apply 'c-add-syntax syntax-symbol | ||
| 7279 | (if (rassq syntax-symbol c-other-decl-block-key-in-symbols-alist) | ||
| 7280 | (point) nil) | ||
| 7281 | syntax-extra-args) | ||
| 7259 | 7282 | ||
| 7260 | ;; Loop while we have to back out of containing blocks. | 7283 | ;; Loop while we have to back out of containing blocks. |
| 7261 | (while | 7284 | (while |
| @@ -7375,22 +7398,31 @@ comment at the start of cc-engine.el for more info." | |||
| 7375 | (setq step-type 'same | 7398 | (setq step-type 'same |
| 7376 | on-label nil)) | 7399 | on-label nil)) |
| 7377 | 7400 | ||
| 7401 | ;; Stepped out of a brace block. | ||
| 7378 | (setq step-type (c-beginning-of-statement-1 containing-sexp) | 7402 | (setq step-type (c-beginning-of-statement-1 containing-sexp) |
| 7379 | on-label (eq step-type 'label)) | 7403 | on-label (eq step-type 'label)) |
| 7380 | 7404 | ||
| 7381 | (if (and (eq step-type 'same) | 7405 | (if (and (eq step-type 'same) |
| 7382 | (/= paren-pos (point))) | 7406 | (/= paren-pos (point))) |
| 7383 | (save-excursion | 7407 | (let (inexpr) |
| 7384 | (goto-char paren-pos) | 7408 | (cond |
| 7385 | (let ((inexpr (c-looking-at-inexpr-block | 7409 | ((save-excursion |
| 7386 | (c-safe-position containing-sexp | 7410 | (goto-char paren-pos) |
| 7387 | paren-state) | 7411 | (setq inexpr (c-looking-at-inexpr-block |
| 7388 | containing-sexp))) | 7412 | (c-safe-position containing-sexp paren-state) |
| 7389 | (if (and inexpr | 7413 | containing-sexp))) |
| 7390 | (not (eq (car inexpr) 'inlambda))) | 7414 | (c-add-syntax (if (eq (car inexpr) 'inlambda) |
| 7391 | (c-add-syntax 'statement-block-intro nil) | 7415 | 'defun-block-intro |
| 7392 | (c-add-syntax 'defun-block-intro nil)))) | 7416 | 'statement-block-intro) |
| 7393 | (c-add-syntax 'statement-block-intro nil))) | 7417 | nil)) |
| 7418 | ((looking-at c-other-decl-block-key) | ||
| 7419 | (c-add-syntax | ||
| 7420 | (cdr (assoc (match-string 1) | ||
| 7421 | c-other-decl-block-key-in-symbols-alist)) | ||
| 7422 | (max (c-point 'boi paren-pos) (point)))) | ||
| 7423 | (t (c-add-syntax 'defun-block-intro nil)))) | ||
| 7424 | |||
| 7425 | (c-add-syntax 'statement-block-intro nil))) | ||
| 7394 | 7426 | ||
| 7395 | (if (= paren-pos boi) | 7427 | (if (= paren-pos boi) |
| 7396 | ;; Always done if the open brace was at boi. The | 7428 | ;; Always done if the open brace was at boi. The |
| @@ -7402,10 +7434,13 @@ comment at the start of cc-engine.el for more info." | |||
| 7402 | 7434 | ||
| 7403 | ;; Fill in the current point as the anchor for all the symbols | 7435 | ;; Fill in the current point as the anchor for all the symbols |
| 7404 | ;; added above. | 7436 | ;; added above. |
| 7405 | (let ((p c-syntactic-context)) | 7437 | (let ((p c-syntactic-context) q) |
| 7406 | (while (not (eq p syntax-last)) | 7438 | (while (not (eq p syntax-last)) |
| 7407 | (if (cdr (car p)) | 7439 | (setq q (cdr (car p))) ; e.g. (nil 28) [from (arglist-cont-nonempty nil 28)] |
| 7408 | (setcar (cdr (car p)) (point))) | 7440 | (while q |
| 7441 | (unless (car q) | ||
| 7442 | (setcar q (point))) | ||
| 7443 | (setq q (cdr q))) | ||
| 7409 | (setq p (cdr p)))) | 7444 | (setq p (cdr p)))) |
| 7410 | ))) | 7445 | ))) |
| 7411 | 7446 | ||
| @@ -8360,9 +8395,7 @@ comment at the start of cc-engine.el for more info." | |||
| 8360 | (if (c-keyword-member containing-decl-kwd | 8395 | (if (c-keyword-member containing-decl-kwd |
| 8361 | 'c-other-block-decl-kwds) | 8396 | 'c-other-block-decl-kwds) |
| 8362 | (progn | 8397 | (progn |
| 8363 | (goto-char containing-decl-open) | 8398 | (goto-char (c-brace-anchor-point containing-decl-open)) |
| 8364 | (unless (= (point) (c-point 'boi)) | ||
| 8365 | (goto-char containing-decl-start)) | ||
| 8366 | (c-add-stmt-syntax | 8399 | (c-add-stmt-syntax |
| 8367 | (if (string-equal (symbol-name containing-decl-kwd) | 8400 | (if (string-equal (symbol-name containing-decl-kwd) |
| 8368 | "extern") | 8401 | "extern") |