diff options
| author | Alan Mackenzie | 2019-05-02 20:53:47 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2019-05-02 20:53:47 +0000 |
| commit | d9f62fceaf2915c67f6917c668af6ff4aacc26a7 (patch) | |
| tree | b690acb6e6052d1d5e376654614475a58603e1ff | |
| parent | 17a722982cca4e8e643c7a9102903e820e784cc6 (diff) | |
| download | emacs-d9f62fceaf2915c67f6917c668af6ff4aacc26a7.tar.gz emacs-d9f62fceaf2915c67f6917c668af6ff4aacc26a7.zip | |
Fix fontification of first item in CC Mode macro without parentheses
* lisp/progmodes/cc-engine.el (c-find-decl-prefix-search): Handle the new
matching possibility (of a #define construct) in the new
c-decl-prefix-or-start-re.
(c-find-decl-spots): Allow the initial search for an in-macro starting point
settle on the # of #define, to facilitate the regexp matching in
c-find-decl-prefix-search.
* lisp/progmodes/cc-langs.el (c-anchored-hash-define-no-parens): New lang
const.
(c-literal-start-regexp): Correct what was always supposed to be a "generic
string" regexp element.
(c-decl-prefix-or-start-re): Enhance also to match "#define <identifier>".
(c-dposr-cpp-macro-depth): New lang variable and lang constant.
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 45 | ||||
| -rw-r--r-- | lisp/progmodes/cc-langs.el | 44 |
2 files changed, 67 insertions, 22 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index f9e570e9f3f..7e6a46ea6e0 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -5692,7 +5692,10 @@ comment at the start of cc-engine.el for more info." | |||
| 5692 | (setq cfd-re-match cfd-limit) | 5692 | (setq cfd-re-match cfd-limit) |
| 5693 | nil) | 5693 | nil) |
| 5694 | ((c-got-face-at | 5694 | ((c-got-face-at |
| 5695 | (if (setq cfd-re-match (match-end 1)) | 5695 | (if (setq cfd-re-match |
| 5696 | (or (match-end 1) | ||
| 5697 | (and c-dposr-cpp-macro-depth | ||
| 5698 | (match-end (1+ c-dposr-cpp-macro-depth))))) | ||
| 5696 | ;; Matched the end of a token preceding a decl spot. | 5699 | ;; Matched the end of a token preceding a decl spot. |
| 5697 | (progn | 5700 | (progn |
| 5698 | (goto-char cfd-re-match) | 5701 | (goto-char cfd-re-match) |
| @@ -5703,15 +5706,19 @@ comment at the start of cc-engine.el for more info." | |||
| 5703 | c-literal-faces) | 5706 | c-literal-faces) |
| 5704 | ;; Pseudo match inside a comment or string literal. Skip out | 5707 | ;; Pseudo match inside a comment or string literal. Skip out |
| 5705 | ;; of comments and string literals. | 5708 | ;; of comments and string literals. |
| 5706 | (while (progn | 5709 | (while |
| 5707 | (unless | 5710 | (progn |
| 5708 | (and (match-end 1) | 5711 | (unless |
| 5709 | (c-got-face-at (1- (point)) c-literal-faces) | 5712 | (and |
| 5710 | (not (c-got-face-at (point) c-literal-faces))) | 5713 | (or (match-end 1) |
| 5711 | (goto-char (c-next-single-property-change | 5714 | (and c-dposr-cpp-macro-depth |
| 5712 | (point) 'face nil cfd-limit))) | 5715 | (match-end (1+ c-dposr-cpp-macro-depth)))) |
| 5713 | (and (< (point) cfd-limit) | 5716 | (c-got-face-at (1- (point)) c-literal-faces) |
| 5714 | (c-got-face-at (point) c-literal-faces)))) | 5717 | (not (c-got-face-at (point) c-literal-faces))) |
| 5718 | (goto-char (c-next-single-property-change | ||
| 5719 | (point) 'face nil cfd-limit))) | ||
| 5720 | (and (< (point) cfd-limit) | ||
| 5721 | (c-got-face-at (point) c-literal-faces)))) | ||
| 5715 | t) ; Continue the loop over pseudo matches. | 5722 | t) ; Continue the loop over pseudo matches. |
| 5716 | ((and c-opt-identifier-concat-key | 5723 | ((and c-opt-identifier-concat-key |
| 5717 | (match-string 1) | 5724 | (match-string 1) |
| @@ -5863,7 +5870,7 @@ comment at the start of cc-engine.el for more info." | |||
| 5863 | ;; before the point, and do the first `c-decl-prefix-or-start-re' | 5870 | ;; before the point, and do the first `c-decl-prefix-or-start-re' |
| 5864 | ;; search unless we're at bob. | 5871 | ;; search unless we're at bob. |
| 5865 | 5872 | ||
| 5866 | (let (start-in-literal start-in-macro syntactic-pos) | 5873 | (let (start-in-literal start-in-macro syntactic-pos hash-define-pos) |
| 5867 | ;; Must back up a bit since we look for the end of the previous | 5874 | ;; Must back up a bit since we look for the end of the previous |
| 5868 | ;; statement or declaration, which is earlier than the first | 5875 | ;; statement or declaration, which is earlier than the first |
| 5869 | ;; returned match. | 5876 | ;; returned match. |
| @@ -6018,7 +6025,21 @@ comment at the start of cc-engine.el for more info." | |||
| 6018 | ;; The only syntactic ws in macros are comments. | 6025 | ;; The only syntactic ws in macros are comments. |
| 6019 | (c-backward-comments) | 6026 | (c-backward-comments) |
| 6020 | (or (bobp) (backward-char)) | 6027 | (or (bobp) (backward-char)) |
| 6021 | (c-beginning-of-current-token)) | 6028 | (c-beginning-of-current-token) |
| 6029 | ;; If we're in a macro without argument parentheses, we could have | ||
| 6030 | ;; now ended up at the macro's identifier. We need to be at #define | ||
| 6031 | ;; for `c-find-decl-prefix-search' to find the first token of the | ||
| 6032 | ;; macro's expansion. | ||
| 6033 | (when (and (c-on-identifier) | ||
| 6034 | (setq hash-define-pos | ||
| 6035 | (save-excursion | ||
| 6036 | (and | ||
| 6037 | (zerop (c-backward-token-2 2)) ; over define, # | ||
| 6038 | (save-excursion | ||
| 6039 | (beginning-of-line) | ||
| 6040 | (looking-at c-opt-cpp-macro-define-id)) | ||
| 6041 | (point))))) | ||
| 6042 | (goto-char hash-define-pos))) | ||
| 6022 | 6043 | ||
| 6023 | (start-in-literal | 6044 | (start-in-literal |
| 6024 | ;; If we're in a comment it can only be the closest | 6045 | ;; If we're in a comment it can only be the closest |
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index 00c581a06a9..8b7e4ef7c09 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el | |||
| @@ -979,6 +979,14 @@ definition, or nil if the language doesn't have any." | |||
| 979 | (c-lang-defvar c-opt-cpp-macro-define-id | 979 | (c-lang-defvar c-opt-cpp-macro-define-id |
| 980 | (c-lang-const c-opt-cpp-macro-define-id)) | 980 | (c-lang-const c-opt-cpp-macro-define-id)) |
| 981 | 981 | ||
| 982 | (c-lang-defconst c-anchored-hash-define-no-parens | ||
| 983 | ;; Regexp matching everything up to the end of a cpp define which has no | ||
| 984 | ;; argument parentheses. Or nil in languages which don't have them. | ||
| 985 | t (if (c-lang-const c-opt-cpp-macro-define) | ||
| 986 | (concat (c-lang-const c-anchored-cpp-prefix) | ||
| 987 | (c-lang-const c-opt-cpp-macro-define) | ||
| 988 | "[ \t]+\\(\\sw\\|_\\)+\\([^(a-zA-Z0-9_]\\|$\\)"))) | ||
| 989 | |||
| 982 | (c-lang-defconst c-cpp-expr-directives | 990 | (c-lang-defconst c-cpp-expr-directives |
| 983 | "List of cpp directives (without the prefix) that are followed by an | 991 | "List of cpp directives (without the prefix) that are followed by an |
| 984 | expression." | 992 | expression." |
| @@ -1614,7 +1622,7 @@ starter." | |||
| 1614 | t (concat (c-lang-const c-comment-start-regexp) | 1622 | t (concat (c-lang-const c-comment-start-regexp) |
| 1615 | "\\|" | 1623 | "\\|" |
| 1616 | (if (memq 'gen-string-delim c-emacs-features) | 1624 | (if (memq 'gen-string-delim c-emacs-features) |
| 1617 | "\"|" | 1625 | "\"\\|\\s|" |
| 1618 | "\""))) | 1626 | "\""))) |
| 1619 | (c-lang-defvar c-literal-start-regexp (c-lang-const c-literal-start-regexp)) | 1627 | (c-lang-defvar c-literal-start-regexp (c-lang-const c-literal-start-regexp)) |
| 1620 | 1628 | ||
| @@ -3183,24 +3191,40 @@ constructs." | |||
| 3183 | ;; token that might precede such a construct, e.g. ';', '}' or '{'. | 3191 | ;; token that might precede such a construct, e.g. ';', '}' or '{'. |
| 3184 | ;; It's built from `c-decl-prefix-re'. | 3192 | ;; It's built from `c-decl-prefix-re'. |
| 3185 | ;; | 3193 | ;; |
| 3186 | ;; If the first submatch did not match, the match of the whole | 3194 | ;; If the first submatch did not match, we have either a #define construct |
| 3187 | ;; regexp is taken to be at the first token in the declaration. | 3195 | ;; without parentheses or the match of the whole regexp is taken to be at |
| 3188 | ;; `c-decl-start-re' is not checked in this case. | 3196 | ;; the first token in the declaration. `c-decl-start-re' is not checked in |
| 3197 | ;; these cases. | ||
| 3189 | ;; | 3198 | ;; |
| 3190 | ;; Design note: The reason the same regexp is used to match both | 3199 | ;; Design note: The reason the same regexp is used to match both |
| 3191 | ;; tokens that precede declarations and start them is to avoid an | 3200 | ;; tokens that precede declarations and start them is to avoid an |
| 3192 | ;; extra regexp search from the previous declaration spot in | 3201 | ;; extra regexp search from the previous declaration spot in |
| 3193 | ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on | 3202 | ;; `c-find-decl-spots'. Users of `c-find-decl-spots' also count on |
| 3194 | ;; that it finds all declaration/cast/label starts in approximately | 3203 | ;; it finding all declaration/cast/label starts in approximately |
| 3195 | ;; linear order, so we can't do the searches in two separate passes. | 3204 | ;; linear order, so we can't do the searches in two separate passes. |
| 3196 | t (if (c-lang-const c-decl-start-kwds) | 3205 | t (cond |
| 3197 | (concat (c-lang-const c-decl-prefix-re) | 3206 | ((and (c-lang-const c-decl-start-kwds) |
| 3198 | "\\|" | 3207 | (c-lang-const c-anchored-hash-define-no-parens)) |
| 3199 | (c-make-keywords-re t (c-lang-const c-decl-start-kwds))) | 3208 | (concat (c-lang-const c-decl-prefix-re) |
| 3200 | (c-lang-const c-decl-prefix-re))) | 3209 | "\\|" (c-lang-const c-anchored-hash-define-no-parens) |
| 3210 | "\\|" (c-make-keywords-re t (c-lang-const c-decl-start-kwds)))) | ||
| 3211 | ((c-lang-const c-decl-start-kwds) | ||
| 3212 | (concat (c-lang-const c-decl-prefix-re) | ||
| 3213 | "\\|" (c-make-keywords-re t (c-lang-const c-decl-start-kwds)))) | ||
| 3214 | ((c-lang-const c-anchored-hash-define-no-parens) | ||
| 3215 | (concat (c-lang-const c-decl-prefix-re) | ||
| 3216 | "\\|" (c-lang-const c-anchored-hash-define-no-parens))) | ||
| 3217 | (t (c-lang-const c-decl-prefix-re)))) | ||
| 3201 | (c-lang-defvar c-decl-prefix-or-start-re | 3218 | (c-lang-defvar c-decl-prefix-or-start-re |
| 3202 | (c-lang-const c-decl-prefix-or-start-re)) | 3219 | (c-lang-const c-decl-prefix-or-start-re)) |
| 3203 | 3220 | ||
| 3221 | (c-lang-defconst c-dposr-cpp-macro-depth | ||
| 3222 | ;; The match number of `c-anchored-hash-define-no-parens''s first match | ||
| 3223 | ;; within `c-decl-prefix-or-start-re', or nil if there is no such component. | ||
| 3224 | t (if (c-lang-const c-anchored-hash-define-no-parens) | ||
| 3225 | (1+ (regexp-opt-depth (c-lang-const c-decl-prefix-re))))) | ||
| 3226 | (c-lang-defvar c-dposr-cpp-macro-depth (c-lang-const c-dposr-cpp-macro-depth)) | ||
| 3227 | |||
| 3204 | (c-lang-defconst c-cast-parens | 3228 | (c-lang-defconst c-cast-parens |
| 3205 | ;; List containing the paren characters that can open a cast, or nil in | 3229 | ;; List containing the paren characters that can open a cast, or nil in |
| 3206 | ;; languages without casts. | 3230 | ;; languages without casts. |