diff options
| author | Alan Mackenzie | 2011-12-23 11:48:54 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2011-12-23 11:48:54 +0000 |
| commit | cb5e207c74eb289482bdab37d9c298ec88987062 (patch) | |
| tree | 13e01c719a9bae60ae25d697551d0c4a83d5b258 | |
| parent | 60ff536cc3ed1f53a6fd2d453894beca63888a72 (diff) | |
| download | emacs-cb5e207c74eb289482bdab37d9c298ec88987062.tar.gz emacs-cb5e207c74eb289482bdab37d9c298ec88987062.zip | |
Fix unstable fontification inside templates.
| -rw-r--r-- | lisp/ChangeLog | 18 | ||||
| -rw-r--r-- | lisp/progmodes/cc-fonts.el | 21 | ||||
| -rw-r--r-- | lisp/progmodes/cc-langs.el | 38 | ||||
| -rw-r--r-- | lisp/progmodes/cc-mode.el | 68 |
4 files changed, 98 insertions, 47 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 834244dcc72..f1a3a452367 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,21 @@ | |||
| 1 | 2011-12-23 Alan Mackenzie <acm@muc.de> | ||
| 2 | |||
| 3 | Fix unstable fontification inside templates. | ||
| 4 | |||
| 5 | * progmodes/cc-langs.el (c-before-font-lock-functions): newly | ||
| 6 | created from the singular version. The (c c++ objc) entry now | ||
| 7 | additionally has c-set-fl-decl-start. The other languages (apart | ||
| 8 | from AWK) have that as a single entry. | ||
| 9 | |||
| 10 | * progmodes/cc-fonts.el (c-font-lock-enclosing-decls): The | ||
| 11 | functionality for "local" declarations has been extracted to | ||
| 12 | c-set-fl-decl-start. | ||
| 13 | |||
| 14 | * progmodes/cc-mode.el: (c-common-init, c-after-change): Changes | ||
| 15 | due to pluralisation of c-before-font-lock-functions. | ||
| 16 | (c-set-fl-decl-start): New function, extracted from | ||
| 17 | c-font-lock-enclosing-decls and enhanced. | ||
| 18 | |||
| 1 | 2011-12-23 Juanma Barranquero <lekktu@gmail.com> | 19 | 2011-12-23 Juanma Barranquero <lekktu@gmail.com> |
| 2 | 20 | ||
| 3 | * desktop.el (desktop-internal-v2s): Fix typos in docstring (bug#10353). | 21 | * desktop.el (desktop-internal-v2s): Fix typos in docstring (bug#10353). |
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index c6c8bd107f6..97cfe808322 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el | |||
| @@ -1538,25 +1538,8 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 1538 | ;; prevent a repeat invocation. See elisp/lispref page "Search-based | 1538 | ;; prevent a repeat invocation. See elisp/lispref page "Search-based |
| 1539 | ;; Fontification". | 1539 | ;; Fontification". |
| 1540 | (let* ((paren-state (c-parse-state)) | 1540 | (let* ((paren-state (c-parse-state)) |
| 1541 | (start (point)) | 1541 | decl-context in-typedef ps-elt) |
| 1542 | (bod-lim (max (- (point) 500) (point-min))) | 1542 | ;; Are we in any nested struct/union/class/etc. braces? |
| 1543 | decl-context bo-decl in-typedef type-type ps-elt) | ||
| 1544 | |||
| 1545 | ;; First, are we actually in a "local" declaration? | ||
| 1546 | (setq decl-context (c-beginning-of-decl-1 bod-lim) | ||
| 1547 | bo-decl (point) | ||
| 1548 | in-typedef (looking-at c-typedef-key)) | ||
| 1549 | (if in-typedef (c-forward-token-2)) | ||
| 1550 | (when (and (eq (car decl-context) 'same) | ||
| 1551 | (< bo-decl start)) | ||
| 1552 | ;; Are we genuinely at a type? | ||
| 1553 | (setq type-type (c-forward-type t)) | ||
| 1554 | (if (and type-type | ||
| 1555 | (or (not (eq type-type 'maybe)) | ||
| 1556 | (looking-at c-symbol-key))) | ||
| 1557 | (c-font-lock-declarators limit t in-typedef))) | ||
| 1558 | |||
| 1559 | ;; Secondly, are we in any nested struct/union/class/etc. braces? | ||
| 1560 | (while paren-state | 1543 | (while paren-state |
| 1561 | (setq ps-elt (car paren-state) | 1544 | (setq ps-elt (car paren-state) |
| 1562 | paren-state (cdr paren-state)) | 1545 | paren-state (cdr paren-state)) |
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index 96f0887eec0..2b6dc7a9df7 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el | |||
| @@ -485,28 +485,34 @@ The functions are called even when font locking isn't enabled. | |||
| 485 | When the mode is initialized, the functions are called with | 485 | When the mode is initialized, the functions are called with |
| 486 | parameters \(point-min) and \(point-max).") | 486 | parameters \(point-min) and \(point-max).") |
| 487 | 487 | ||
| 488 | (c-lang-defconst c-before-font-lock-function | 488 | (c-lang-defconst c-before-font-lock-functions |
| 489 | "If non-nil, a function called just before font locking. | 489 | ;; For documentation see the following c-lang-defvar of the same name. |
| 490 | Typically it will extend the region about to be fontified \(see | 490 | ;; The value here may be a list of functions or a single function. |
| 491 | t 'c-set-fl-decl-start | ||
| 492 | (c c++ objc) '(c-neutralize-syntax-in-and-mark-CPP c-set-fl-decl-start) | ||
| 493 | awk 'c-awk-extend-and-syntax-tablify-region) | ||
| 494 | (c-lang-defvar c-before-font-lock-functions | ||
| 495 | (let ((fs (c-lang-const c-before-font-lock-functions))) | ||
| 496 | (if (listp fs) | ||
| 497 | fs | ||
| 498 | (list fs))) | ||
| 499 | "If non-nil, a list of functions called just before font locking. | ||
| 500 | Typically they will extend the region about to be fontified \(see | ||
| 491 | below) and will set `syntax-table' text properties on the region. | 501 | below) and will set `syntax-table' text properties on the region. |
| 492 | 502 | ||
| 493 | It takes 3 parameters, the BEG, END, and OLD-LEN supplied to | 503 | These functions will be run in the order given. Each of them |
| 494 | every after-change function; point is undefined on both entry and | 504 | takes 3 parameters, the BEG, END, and OLD-LEN supplied to every |
| 495 | exit; on entry, the buffer will have been widened and match-data | 505 | after-change function; point is undefined on both entry and exit; |
| 496 | will have been saved; the return value is ignored. | 506 | on entry, the buffer will have been widened and match-data will |
| 507 | have been saved; the return value is ignored. | ||
| 497 | 508 | ||
| 498 | The function may extend the region to be fontified by setting the | 509 | The functions may extend the region to be fontified by setting the |
| 499 | buffer local variables c-new-BEG and c-new-END. | 510 | buffer local variables c-new-BEG and c-new-END. |
| 500 | 511 | ||
| 501 | The function is called even when font locking is disabled. | 512 | The functions are called even when font locking is disabled. |
| 502 | 513 | ||
| 503 | When the mode is initialized, this function is called with | 514 | When the mode is initialized, these functions are called with |
| 504 | parameters \(point-min), \(point-max) and <buffer size>." | 515 | parameters \(point-min), \(point-max) and <buffer size>.") |
| 505 | t nil | ||
| 506 | (c c++ objc) 'c-neutralize-syntax-in-and-mark-CPP | ||
| 507 | awk 'c-awk-extend-and-syntax-tablify-region) | ||
| 508 | (c-lang-defvar c-before-font-lock-function | ||
| 509 | (c-lang-const c-before-font-lock-function)) | ||
| 510 | 516 | ||
| 511 | 517 | ||
| 512 | ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK). | 518 | ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK). |
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 36b95f4b3f5..01111d2b536 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el | |||
| @@ -633,13 +633,13 @@ compatible with old code; callers should always specify it." | |||
| 633 | (setq c-new-BEG (point-min)) | 633 | (setq c-new-BEG (point-min)) |
| 634 | (setq c-new-END (point-max)) | 634 | (setq c-new-END (point-max)) |
| 635 | (save-excursion | 635 | (save-excursion |
| 636 | (if c-get-state-before-change-functions | 636 | (mapc (lambda (fn) |
| 637 | (mapc (lambda (fn) | 637 | (funcall fn (point-min) (point-max))) |
| 638 | (funcall fn (point-min) (point-max))) | 638 | c-get-state-before-change-functions) |
| 639 | c-get-state-before-change-functions)) | 639 | (mapc (lambda (fn) |
| 640 | (if c-before-font-lock-function | 640 | (funcall fn (point-min) (point-max) |
| 641 | (funcall c-before-font-lock-function (point-min) (point-max) | 641 | (- (point-max) (point-min)))) |
| 642 | (- (point-max) (point-min)))))) | 642 | c-before-font-lock-functions))) |
| 643 | 643 | ||
| 644 | (set (make-local-variable 'outline-regexp) "[^#\n\^M]") | 644 | (set (make-local-variable 'outline-regexp) "[^#\n\^M]") |
| 645 | (set (make-local-variable 'outline-level) 'c-outline-level) | 645 | (set (make-local-variable 'outline-level) 'c-outline-level) |
| @@ -881,7 +881,7 @@ Note that the style variables are always made local to the buffer." | |||
| 881 | ;; Point is undefined both before and after this function call, the buffer | 881 | ;; Point is undefined both before and after this function call, the buffer |
| 882 | ;; has been widened, and match-data saved. The return value is ignored. | 882 | ;; has been widened, and match-data saved. The return value is ignored. |
| 883 | ;; | 883 | ;; |
| 884 | ;; This function is the C/C++/ObjC value of `c-before-font-lock-function'. | 884 | ;; This function is in the C/C++/ObjC value of `c-before-font-lock-functions'. |
| 885 | ;; | 885 | ;; |
| 886 | ;; Note: SPEED _MATTERS_ IN THIS FUNCTION!!! | 886 | ;; Note: SPEED _MATTERS_ IN THIS FUNCTION!!! |
| 887 | ;; | 887 | ;; |
| @@ -1026,7 +1026,7 @@ Note that the style variables are always made local to the buffer." | |||
| 1026 | ;; these caches from inside them, and we must thus be sure that this | 1026 | ;; these caches from inside them, and we must thus be sure that this |
| 1027 | ;; has already been executed. | 1027 | ;; has already been executed. |
| 1028 | ;; | 1028 | ;; |
| 1029 | ;; This calls the language variable c-before-font-lock-function, if non nil. | 1029 | ;; This calls the language variable c-before-font-lock-functions, if non nil. |
| 1030 | ;; This typically sets `syntax-table' properties. | 1030 | ;; This typically sets `syntax-table' properties. |
| 1031 | 1031 | ||
| 1032 | (c-save-buffer-state () | 1032 | (c-save-buffer-state () |
| @@ -1066,9 +1066,53 @@ Note that the style variables are always made local to the buffer." | |||
| 1066 | ;; larger than (beg end). | 1066 | ;; larger than (beg end). |
| 1067 | (setq c-new-BEG beg | 1067 | (setq c-new-BEG beg |
| 1068 | c-new-END end) | 1068 | c-new-END end) |
| 1069 | (if c-before-font-lock-function | 1069 | (save-excursion |
| 1070 | (save-excursion | 1070 | (mapc (lambda (fn) |
| 1071 | (funcall c-before-font-lock-function beg end old-len))))))) | 1071 | (funcall fn beg end old-len)) |
| 1072 | c-before-font-lock-functions)))))) | ||
| 1073 | |||
| 1074 | (defun c-set-fl-decl-start (beg end old-len) | ||
| 1075 | ;; If the beginning of line containing c-new-BEG is in the middle of a | ||
| 1076 | ;; "local" declaration (i.e. one which does not start outside of braces | ||
| 1077 | ;; enclosing this pos, such as a struct), set c-new-BEG to (at most) the | ||
| 1078 | ;; beginning of that declaration. Note that declarations, in this sense, | ||
| 1079 | ;; can be nested. c-new-BEG will be used later by c-font-lock-declarations. | ||
| 1080 | ;; | ||
| 1081 | ;; This function is an element of c-before-font-lock-functions, being called | ||
| 1082 | ;; (indirectly) from an after-change function. The after-change-functions' | ||
| 1083 | ;; parameters BEG, OLD and OLD-LEN are ignored here. | ||
| 1084 | (when font-lock-mode | ||
| 1085 | (goto-char (c-point 'bol c-new-BEG)) | ||
| 1086 | (let ((lit-limits (c-literal-limits)) | ||
| 1087 | bod-lim bo-decl) | ||
| 1088 | |||
| 1089 | (when lit-limits ; Comment or string. | ||
| 1090 | (goto-char (car lit-limits))) | ||
| 1091 | (setq bod-lim (max (- (point) 500) (point-min))) | ||
| 1092 | |||
| 1093 | (while | ||
| 1094 | ;; Go to a less nested declaration each time round this loop. | ||
| 1095 | (and | ||
| 1096 | (eq (car (c-beginning-of-decl-1 bod-lim)) 'same) | ||
| 1097 | (progn (setq bo-decl (point)) | ||
| 1098 | ;; Are we looking at a keyword such as "template" or | ||
| 1099 | ;; "typedef" which can decorate a type, or the type itself? | ||
| 1100 | (when (or (looking-at c-prefix-spec-kwds-re) | ||
| 1101 | (c-forward-type t)) | ||
| 1102 | ;; We've found another candidate position. | ||
| 1103 | (setq c-new-BEG (min c-new-BEG bo-decl)) | ||
| 1104 | (goto-char bo-decl)) | ||
| 1105 | t) | ||
| 1106 | ;; Try and go out a level to search again. | ||
| 1107 | (progn | ||
| 1108 | (c-backward-syntactic-ws bod-lim) | ||
| 1109 | (or (memq (char-before) '(?\( ?\[)) | ||
| 1110 | (and (eq (char-before) ?\<) | ||
| 1111 | (eq (c-get-char-property | ||
| 1112 | (1- (point)) 'syntax-table) | ||
| 1113 | c-<-as-paren-syntax)))) | ||
| 1114 | (not (bobp))) | ||
| 1115 | (backward-char))))) ; back over (, [, <. | ||
| 1072 | 1116 | ||
| 1073 | (defun c-after-font-lock-init () | 1117 | (defun c-after-font-lock-init () |
| 1074 | ;; Put on `font-lock-mode-hook'. | 1118 | ;; Put on `font-lock-mode-hook'. |