diff options
| author | Alan Mackenzie | 2011-07-18 17:15:24 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2011-07-18 17:15:24 +0000 |
| commit | bf2c1571f4085d3b52f37370f0bcdf7a23c53a50 (patch) | |
| tree | 8b7969950d109f84ef0e230266730ce5f33e4e2b | |
| parent | 8f8eda06a29b37f0a963c6347012eae802cc1849 (diff) | |
| download | emacs-bf2c1571f4085d3b52f37370f0bcdf7a23c53a50.tar.gz emacs-bf2c1571f4085d3b52f37370f0bcdf7a23c53a50.zip | |
CC Mode: Fontify declarators properly when, e.g., a jit-lock chunk begins
inside a declaration. Changed cc-engine.el, cc-langs.el, cc-fonts.el.
| -rw-r--r-- | lisp/ChangeLog | 16 | ||||
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 8 | ||||
| -rw-r--r-- | lisp/progmodes/cc-fonts.el | 47 | ||||
| -rw-r--r-- | lisp/progmodes/cc-langs.el | 2 |
4 files changed, 69 insertions, 4 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f320398975c..0ea3d94a01f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,19 @@ | |||
| 1 | 2011-07-18 Alan Mackenzie <acm@muc.de> | ||
| 2 | |||
| 3 | Fontify declarators properly when, e.g., a jit-lock chunk begins | ||
| 4 | inside a declaration. | ||
| 5 | |||
| 6 | * progmodes/cc-langs.el (c-symbol-chars): Correct a typo. | ||
| 7 | |||
| 8 | * progmodes/cc-fonts.el (c-font-lock-enclosing-decls): New | ||
| 9 | function. | ||
| 10 | (c-complex-decl-matchers): Insert reference to | ||
| 11 | c-font-lock-enclosing-decls. | ||
| 12 | |||
| 13 | * progmodes/cc-engine.el (c-backward-single-comment): | ||
| 14 | (c-backward-comments): Bind open-paren-in-column-0-is-defun-start | ||
| 15 | to nil around calls to (forward-comment -1). | ||
| 16 | |||
| 1 | 2011-07-17 Lars Magne Ingebrigtsen <larsi@gnus.org> | 17 | 2011-07-17 Lars Magne Ingebrigtsen <larsi@gnus.org> |
| 2 | 18 | ||
| 3 | * image.el (put-image): Doc typo fix. | 19 | * image.el (put-image): Doc typo fix. |
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 38f66b4504e..a6fd28be21d 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -1301,12 +1301,13 @@ This function does not do any hidden buffer changes." | |||
| 1301 | ;; same line. | 1301 | ;; same line. |
| 1302 | (re-search-forward "\\=\\s *[\n\r]" start t) | 1302 | (re-search-forward "\\=\\s *[\n\r]" start t) |
| 1303 | 1303 | ||
| 1304 | (if (if (forward-comment -1) | 1304 | (if (if (let (open-paren-in-column-0-is-defun-start) (forward-comment -1)) |
| 1305 | (if (eolp) | 1305 | (if (eolp) |
| 1306 | ;; If forward-comment above succeeded and we're at eol | 1306 | ;; If forward-comment above succeeded and we're at eol |
| 1307 | ;; then the newline we moved over above didn't end a | 1307 | ;; then the newline we moved over above didn't end a |
| 1308 | ;; line comment, so we give it another go. | 1308 | ;; line comment, so we give it another go. |
| 1309 | (forward-comment -1) | 1309 | (let (open-paren-in-column-0-is-defun-start) |
| 1310 | (forward-comment -1)) | ||
| 1310 | t)) | 1311 | t)) |
| 1311 | 1312 | ||
| 1312 | ;; Emacs <= 20 and XEmacs move back over the closer of a | 1313 | ;; Emacs <= 20 and XEmacs move back over the closer of a |
| @@ -1333,7 +1334,8 @@ comment at the start of cc-engine.el for more info." | |||
| 1333 | ;; return t when moving backwards at bob. | 1334 | ;; return t when moving backwards at bob. |
| 1334 | (not (bobp)) | 1335 | (not (bobp)) |
| 1335 | 1336 | ||
| 1336 | (if (forward-comment -1) | 1337 | (if (let (open-paren-in-column-0-is-defun-start) |
| 1338 | (forward-comment -1)) | ||
| 1337 | (if (looking-at "\\*/") | 1339 | (if (looking-at "\\*/") |
| 1338 | ;; Emacs <= 20 and XEmacs move back over the | 1340 | ;; Emacs <= 20 and XEmacs move back over the |
| 1339 | ;; closer of a block comment that lacks an opener. | 1341 | ;; closer of a block comment that lacks an opener. |
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index 600bbc76e9a..0500d48ddbc 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el | |||
| @@ -1346,6 +1346,50 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 1346 | (c-font-lock-declarators limit t nil))) | 1346 | (c-font-lock-declarators limit t nil))) |
| 1347 | nil) | 1347 | nil) |
| 1348 | 1348 | ||
| 1349 | (defun c-font-lock-enclosing-decls (limit) | ||
| 1350 | ;; Fontify the declarators of (nested) declarations we're in the middle of. | ||
| 1351 | ;; This is mainly for when a jit-lock etc. chunk starts inside the brace | ||
| 1352 | ;; block of a struct/union/class, etc. | ||
| 1353 | ;; | ||
| 1354 | ;; This function will be called from font-lock for a region bounded by POINT | ||
| 1355 | ;; and LIMIT, as though it were to identify a keyword for | ||
| 1356 | ;; font-lock-keyword-face. It always returns NIL to inhibit this and | ||
| 1357 | ;; prevent a repeat invocation. See elisp/lispref page "Search-based | ||
| 1358 | ;; Fontification". | ||
| 1359 | (let* ((paren-state (c-parse-state)) | ||
| 1360 | (start (point)) | ||
| 1361 | decl-context bo-decl in-typedef type-type ps-elt) | ||
| 1362 | |||
| 1363 | ;; First, are we actually in a "local" declaration? | ||
| 1364 | (setq decl-context (c-beginning-of-decl-1) | ||
| 1365 | bo-decl (point) | ||
| 1366 | in-typedef (looking-at c-typedef-key)) | ||
| 1367 | (if in-typedef (c-forward-token-2)) | ||
| 1368 | (when (and (eq (car decl-context) 'same) | ||
| 1369 | (< bo-decl start)) | ||
| 1370 | ;; Are we genuinely at a type? | ||
| 1371 | (setq type-type (c-forward-type t)) | ||
| 1372 | (if (and type-type | ||
| 1373 | (or (not (eq type-type 'maybe)) | ||
| 1374 | (looking-at c-symbol-key))) | ||
| 1375 | (c-font-lock-declarators limit t in-typedef))) | ||
| 1376 | |||
| 1377 | ;; Secondly, are we in any nested struct/union/class/etc. braces? | ||
| 1378 | (while paren-state | ||
| 1379 | (setq ps-elt (car paren-state) | ||
| 1380 | paren-state (cdr paren-state)) | ||
| 1381 | (when (and (atom ps-elt) | ||
| 1382 | (eq (char-after ps-elt) ?\{)) | ||
| 1383 | (goto-char ps-elt) | ||
| 1384 | (setq decl-context (c-beginning-of-decl-1) | ||
| 1385 | in-typedef (looking-at c-typedef-key)) | ||
| 1386 | (if in-typedef (c-forward-token-2)) | ||
| 1387 | (when (looking-at c-opt-block-decls-with-vars-key) | ||
| 1388 | (goto-char ps-elt) | ||
| 1389 | (when (c-safe (c-forward-sexp)) | ||
| 1390 | (c-forward-syntactic-ws) | ||
| 1391 | (c-font-lock-declarators limit t in-typedef))))))) | ||
| 1392 | |||
| 1349 | (c-lang-defconst c-simple-decl-matchers | 1393 | (c-lang-defconst c-simple-decl-matchers |
| 1350 | "Simple font lock matchers for types and declarations. These are used | 1394 | "Simple font lock matchers for types and declarations. These are used |
| 1351 | on level 2 only and so aren't combined with `c-complex-decl-matchers'." | 1395 | on level 2 only and so aren't combined with `c-complex-decl-matchers'." |
| @@ -1452,6 +1496,9 @@ on level 2 only and so aren't combined with `c-complex-decl-matchers'." | |||
| 1452 | ;; Fontify all declarations, casts and normal labels. | 1496 | ;; Fontify all declarations, casts and normal labels. |
| 1453 | c-font-lock-declarations | 1497 | c-font-lock-declarations |
| 1454 | 1498 | ||
| 1499 | ;; Fontify declarators when POINT is within their declaration. | ||
| 1500 | c-font-lock-enclosing-decls | ||
| 1501 | |||
| 1455 | ;; Fontify angle bracket arglists like templates in C++. | 1502 | ;; Fontify angle bracket arglists like templates in C++. |
| 1456 | ,@(when (c-lang-const c-recognize-<>-arglists) | 1503 | ,@(when (c-lang-const c-recognize-<>-arglists) |
| 1457 | `(c-font-lock-<>-arglists)) | 1504 | `(c-font-lock-<>-arglists)) |
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index a6459e1724f..9ce23a080d6 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el | |||
| @@ -523,7 +523,7 @@ operator at the top level." | |||
| 523 | 523 | ||
| 524 | (c-lang-defconst c-symbol-chars | 524 | (c-lang-defconst c-symbol-chars |
| 525 | "Set of characters that can be part of a symbol. | 525 | "Set of characters that can be part of a symbol. |
| 526 | This is on the form that fits inside [ ] in a regexp." | 526 | This is of the form that fits inside [ ] in a regexp." |
| 527 | ;; Pike note: With the backquote identifiers this would include most | 527 | ;; Pike note: With the backquote identifiers this would include most |
| 528 | ;; operator chars too, but they are handled with other means instead. | 528 | ;; operator chars too, but they are handled with other means instead. |
| 529 | t (concat c-alnum "_$") | 529 | t (concat c-alnum "_$") |