aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2016-01-04 22:29:33 +0000
committerAlan Mackenzie2016-01-04 22:35:13 +0000
commit33219d385bbb271e2812fef615c81df1983e61d9 (patch)
tree46cac377e8889942a509348739c3a4e5bb00f118
parent31a97acf43b7eb95f3ddc6ceca1682b35a5b1945 (diff)
downloademacs-33219d385bbb271e2812fef615c81df1983e61d9.tar.gz
emacs-33219d385bbb271e2812fef615c81df1983e61d9.zip
Apply text properties for <, > in new after-change function (C++ Java Modes).
These are category/syntax-table properties to give < and > paren syntax. Also apply certain `c-type' text properties to the insides of <..> constructs to ensure that identifiers contained by them get fontified. This patch fixes bug #681. * lisp/progmodes/cc-cmds.el (c-electric-lt-gt): Reformulate due to new after-change action. * lisp/progmodes/cc-engine.el (c-before-change-check-<>-operators): Expand change region to include <s and >s which might not be already marked as parens, rather than just when paren text properties are removed. (c-restore-<>-properties): New after-change function, which applies text properties marking < and > with paren syntax. * lisp/progmodes/cc-fonts.el (c-font-lock-declarations): Ensure `c-type' properties are applied to the interiors of <...> constructs, to ensure fontification of identifiers there. * lisp/progmodes/cc-langs.el (c-before-font-lock-functions): Add c-restore-<>-properties to this list for C++ and Java. * lisp/progmodes/cc-mode.el (c-common-init): When invoking c-before-font-lock-functions, exclude c-restore-<>-properties from the functions invoked. (c-before-change): Initialize c-new-BEG/END here (rather than c-after-change) to allow modification by before-change functions. (c-after-change): Amend c-new-END here, rather than initializing it and c-new-BEG.
-rw-r--r--lisp/progmodes/cc-cmds.el38
-rw-r--r--lisp/progmodes/cc-engine.el78
-rw-r--r--lisp/progmodes/cc-fonts.el25
-rw-r--r--lisp/progmodes/cc-langs.el9
-rw-r--r--lisp/progmodes/cc-mode.el17
5 files changed, 103 insertions, 64 deletions
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index a46f0488e76..6761de11700 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -1121,35 +1121,15 @@ numeric argument is supplied, or the point is inside a literal."
1121 (looking-at "<<")) 1121 (looking-at "<<"))
1122 (>= (match-end 0) final-pos))) 1122 (>= (match-end 0) final-pos)))
1123 1123
1124 ;; It's a >. Either a C++ >> operator. ...... 1124 ;; It's a >. Either a template/generic terminator ...
1125 (or (and (c-major-mode-is 'c++-mode) 1125 (or (c-get-char-property (1- final-pos) 'syntax-table)
1126 ;; or a C++ >> operator.
1127 (and (c-major-mode-is 'c++-mode)
1126 (progn 1128 (progn
1127 (goto-char (1- final-pos)) 1129 (goto-char (1- final-pos))
1128 (c-beginning-of-current-token) 1130 (c-beginning-of-current-token)
1129 (looking-at ">>")) 1131 (looking-at ">>"))
1130 (>= (match-end 0) final-pos)) 1132 (>= (match-end 0) final-pos))))))
1131 ;; ...., or search back for a < which isn't already marked as an
1132 ;; opening template delimiter.
1133 (save-restriction
1134 (widen)
1135 ;; Narrow to avoid `c-forward-<>-arglist' below searching past
1136 ;; our position.
1137 (narrow-to-region (point-min) final-pos)
1138 (goto-char final-pos)
1139 (while
1140 (and
1141 (progn
1142 (c-syntactic-skip-backward "^<;}" nil t)
1143 (eq (char-before) ?<))
1144 (progn
1145 (backward-char)
1146 (looking-at "\\s("))))
1147 (and (eq (char-after) ?<)
1148 (not (looking-at "\\s("))
1149 (progn (c-backward-syntactic-ws)
1150 (c-simple-skip-symbol-backward))
1151 (or (looking-at c-opt-<>-sexp-key)
1152 (not (looking-at c-keywords-regexp)))))))))
1153 1133
1154 (goto-char final-pos) 1134 (goto-char final-pos)
1155 (when found-delim 1135 (when found-delim
@@ -1157,11 +1137,9 @@ numeric argument is supplied, or the point is inside a literal."
1157 (when (and (eq (char-before) ?>) 1137 (when (and (eq (char-before) ?>)
1158 (not executing-kbd-macro) 1138 (not executing-kbd-macro)
1159 blink-paren-function) 1139 blink-paren-function)
1160 ;; Currently (2014-10-19), the syntax-table text properties on < and > 1140 ;; From now (2016-01-01), the syntax-table text properties on < and >
1161 ;; are only applied in code called during Emacs redisplay. We thus 1141 ;; are applied in an after-change function, not during redisplay. Hence
1162 ;; explicitly cause a redisplay so that these properties have been 1142 ;; we no longer need to call (sit-for 0) for blink paren to work.
1163 ;; applied when `blink-paren-function' gets called.
1164 (sit-for 0)
1165 (funcall blink-paren-function))))) 1143 (funcall blink-paren-function)))))
1166 1144
1167(defun c-electric-paren (arg) 1145(defun c-electric-paren (arg)
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 617c94aae08..2a35a647ff8 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -5577,8 +5577,9 @@ comment at the start of cc-engine.el for more info."
5577 5577
5578(defun c-before-change-check-<>-operators (beg end) 5578(defun c-before-change-check-<>-operators (beg end)
5579 ;; Unmark certain pairs of "< .... >" which are currently marked as 5579 ;; Unmark certain pairs of "< .... >" which are currently marked as
5580 ;; template/generic delimiters. (This marking is via syntax-table 5580 ;; template/generic delimiters. (This marking is via syntax-table text
5581 ;; text properties). 5581 ;; properties), and expand the (c-new-BEG c-new-END) region to include all
5582 ;; unmarked < and > operators within the certain bounds (see below).
5582 ;; 5583 ;;
5583 ;; These pairs are those which are in the current "statement" (i.e., 5584 ;; These pairs are those which are in the current "statement" (i.e.,
5584 ;; the region between the {, }, or ; before BEG and the one after 5585 ;; the region between the {, }, or ; before BEG and the one after
@@ -5597,38 +5598,40 @@ comment at the start of cc-engine.el for more info."
5597 (save-excursion 5598 (save-excursion
5598 (let ((beg-lit-limits (progn (goto-char beg) (c-literal-limits))) 5599 (let ((beg-lit-limits (progn (goto-char beg) (c-literal-limits)))
5599 (end-lit-limits (progn (goto-char end) (c-literal-limits))) 5600 (end-lit-limits (progn (goto-char end) (c-literal-limits)))
5600 new-beg new-end need-new-beg need-new-end) 5601 new-beg new-end beg-limit end-limit)
5601 ;; Locate the barrier before the changed region 5602 ;; Locate the earliest < after the barrier before the changed region,
5603 ;; which isn't already marked as a paren.
5602 (goto-char (if beg-lit-limits (car beg-lit-limits) beg)) 5604 (goto-char (if beg-lit-limits (car beg-lit-limits) beg))
5603 (c-syntactic-skip-backward "^;{}" (c-determine-limit 512)) 5605 (setq beg-limit (c-determine-limit 512))
5604 (setq new-beg (point))
5605 5606
5606 ;; Remove the syntax-table/category properties from each pertinent <...> 5607 ;; Remove the syntax-table/category properties from each pertinent <...>
5607 ;; pair. Firsly, the ones with the < before beg and > after beg. 5608 ;; pair. Firstly, the ones with the < before beg and > after beg....
5608 (while 5609 (while (progn (c-syntactic-skip-backward "^;{}<" beg-limit)
5609 (c-search-forward-char-property 'syntax-table c-<-as-paren-syntax beg) 5610 (eq (char-before) ?<))
5610 (if (c-clear-<-pair-props-if-match-after beg (1- (point))) 5611 (c-backward-token-2)
5611 (setq need-new-beg t))) 5612 (when (eq (char-after) ?<)
5613 (c-clear-<-pair-props-if-match-after beg)))
5614 (c-forward-syntactic-ws)
5615 (setq new-beg (point))
5612 5616
5613 ;; Locate the barrier after END. 5617 ;; ...Then the ones with < before end and > after end.
5614 (goto-char (if end-lit-limits (cdr end-lit-limits) end)) 5618 (goto-char (if end-lit-limits (cdr end-lit-limits) end))
5615 (c-syntactic-re-search-forward "[;{}]" (c-determine-+ve-limit 512) 'end) 5619 (setq end-limit (c-determine-+ve-limit 512))
5620 (while (and (c-syntactic-re-search-forward "[;{}>]" end-limit 'end)
5621 (eq (char-before) ?>))
5622 (c-end-of-current-token)
5623 (when (eq (char-before) ?>)
5624 (c-clear->-pair-props-if-match-before end (1- (point)))))
5625 (c-backward-syntactic-ws)
5616 (setq new-end (point)) 5626 (setq new-end (point))
5617 5627
5618 ;; Remove syntax-table properties from the remaining pertinent <...>
5619 ;; pairs, those with a > after end and < before end.
5620 (while (c-search-backward-char-property 'syntax-table c->-as-paren-syntax end)
5621 (if (c-clear->-pair-props-if-match-before end)
5622 (setq need-new-end t)))
5623
5624 ;; Extend the fontification region, if needed. 5628 ;; Extend the fontification region, if needed.
5625 (when need-new-beg 5629 (and new-beg
5626 (goto-char new-beg) 5630 (< new-beg c-new-BEG)
5627 (c-forward-syntactic-ws) 5631 (setq c-new-BEG new-beg))
5628 (and (< (point) c-new-BEG) (setq c-new-BEG (point)))) 5632 (and new-end
5629 5633 (> new-end c-new-END)
5630 (when need-new-end 5634 (setq c-new-END new-end)))))
5631 (and (> new-end c-new-END) (setq c-new-END new-end))))))
5632 5635
5633(defun c-after-change-check-<>-operators (beg end) 5636(defun c-after-change-check-<>-operators (beg end)
5634 ;; This is called from `after-change-functions' when 5637 ;; This is called from `after-change-functions' when
@@ -5668,7 +5671,28 @@ comment at the start of cc-engine.el for more info."
5668 (c-clear-<>-pair-props) 5671 (c-clear-<>-pair-props)
5669 (forward-char))))))) 5672 (forward-char)))))))
5670 5673
5671 5674(defun c-restore-<>-properties (_beg _end _old-len)
5675 ;; This function is called as an after-change function. It restores the
5676 ;; category/syntax-table properties on template/generic <..> pairs between
5677 ;; c-new-BEG and c-new-END. It may do hidden buffer changes.
5678 (c-save-buffer-state ((c-parse-and-markup-<>-arglists t)
5679 c-restricted-<>-arglists lit-limits)
5680 (goto-char c-new-BEG)
5681 (if (setq lit-limits (c-literal-limits))
5682 (goto-char (cdr lit-limits)))
5683 (while (and (< (point) c-new-END)
5684 (c-syntactic-re-search-forward "<" c-new-END 'bound))
5685 (backward-char)
5686 (save-excursion
5687 (c-backward-token-2)
5688 (setq c-restricted-<>-arglists
5689 (and (not (looking-at c-opt-<>-sexp-key))
5690 (progn (c-backward-syntactic-ws) ; to < or ,
5691 (and (memq (char-before) '(?< ?,))
5692 (not (eq (c-get-char-property (point) 'c-type)
5693 'c-decl-arg-start)))))))
5694 (or (c-forward-<>-arglist nil)
5695 (forward-char)))))
5672 5696
5673;; Handling of small scale constructs like types and names. 5697;; Handling of small scale constructs like types and names.
5674 5698
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index c2b2d72649f..f74e5cbf678 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -1205,6 +1205,9 @@ casts and declarations are fontified. Used on level 2 and higher."
1205 ;; Same as `max-type-decl-*', but used when we're before 1205 ;; Same as `max-type-decl-*', but used when we're before
1206 ;; `token-pos'. 1206 ;; `token-pos'.
1207 (max-type-decl-end-before-token 0) 1207 (max-type-decl-end-before-token 0)
1208 ;; End of <..> construct which has had c-<>-arg-sep c-type
1209 ;; properties set within it.
1210 (max-<>-end 0)
1208 ;; Set according to the context to direct the heuristics for 1211 ;; Set according to the context to direct the heuristics for
1209 ;; recognizing C++ templates. 1212 ;; recognizing C++ templates.
1210 c-restricted-<>-arglists 1213 c-restricted-<>-arglists
@@ -1347,6 +1350,28 @@ casts and declarations are fontified. Used on level 2 and higher."
1347 (setq decl-or-cast (c-forward-decl-or-cast-1 1350 (setq decl-or-cast (c-forward-decl-or-cast-1
1348 match-pos context last-cast-end)) 1351 match-pos context last-cast-end))
1349 1352
1353 ;; Ensure that c-<>-arg-sep c-type properties are in place on the
1354 ;; commas separating the arguments inside template/generic <..>s.
1355 (when (and (eq (char-before match-pos) ?<)
1356 (> match-pos max-<>-end))
1357 (save-excursion
1358 (goto-char match-pos)
1359 (c-backward-token-2)
1360 (if (and
1361 (eq (char-after) ?<)
1362 (let ((c-restricted-<>-arglists
1363 (save-excursion
1364 (c-backward-token-2)
1365 (and
1366 (not (looking-at c-opt-<>-sexp-key))
1367 (progn (c-backward-syntactic-ws)
1368 (memq (char-before) '(?\( ?,)))
1369 (not (eq (c-get-char-property (1- (point))
1370 'c-type)
1371 'c-decl-arg-start))))))
1372 (c-forward-<>-arglist nil)))
1373 (setq max-<>-end (point)))))
1374
1350 (cond 1375 (cond
1351 ((eq decl-or-cast 'cast) 1376 ((eq decl-or-cast 'cast)
1352 ;; Save the position after the previous cast so we can feed 1377 ;; Save the position after the previous cast so we can feed
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 8ae75277925..d7972b4ef83 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -499,8 +499,13 @@ parameters \(point-min) and \(point-max).")
499 ;; For documentation see the following c-lang-defvar of the same name. 499 ;; For documentation see the following c-lang-defvar of the same name.
500 ;; The value here may be a list of functions or a single function. 500 ;; The value here may be a list of functions or a single function.
501 t 'c-change-expand-fl-region 501 t 'c-change-expand-fl-region
502 (c c++ objc) '(c-neutralize-syntax-in-and-mark-CPP 502 (c objc) '(c-neutralize-syntax-in-and-mark-CPP
503 c-change-expand-fl-region) 503 c-change-expand-fl-region)
504 c++ '(c-neutralize-syntax-in-and-mark-CPP
505 c-restore-<>-properties
506 c-change-expand-fl-region)
507 java '(c-restore-<>-properties
508 c-change-expand-fl-region)
504 awk 'c-awk-extend-and-syntax-tablify-region) 509 awk 'c-awk-extend-and-syntax-tablify-region)
505(c-lang-defvar c-before-font-lock-functions 510(c-lang-defvar c-before-font-lock-functions
506 (let ((fs (c-lang-const c-before-font-lock-functions))) 511 (let ((fs (c-lang-const c-before-font-lock-functions)))
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 7f71700c650..e5be0b53b12 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -631,8 +631,11 @@ that requires a literal mode spec at compile time."
631 (font-lock-mode 1))) 631 (font-lock-mode 1)))
632 632
633;; Buffer local variables defining the region to be fontified by a font lock 633;; Buffer local variables defining the region to be fontified by a font lock
634;; after-change function. They are set in c-after-change to 634;; after-change function. They are initialized in c-before-change to
635;; after-change-functions' BEG and END, and may be modified by functions in 635;; before-change-functions' BEG and END. `c-new-END' is amended in
636;; c-after-change with after-change-functions' BEG, END, and OLD-LEN. These
637;; variables may be modified by any before/after-change function, in
638;; particular by functions in `c-get-state-before-change-functions' and
636;; `c-before-font-lock-functions'. 639;; `c-before-font-lock-functions'.
637(defvar c-new-BEG 0) 640(defvar c-new-BEG 0)
638(make-variable-buffer-local 'c-new-BEG) 641(make-variable-buffer-local 'c-new-BEG)
@@ -671,8 +674,9 @@ compatible with old code; callers should always specify it."
671 (funcall fn (point-min) (point-max))) 674 (funcall fn (point-min) (point-max)))
672 c-get-state-before-change-functions) 675 c-get-state-before-change-functions)
673 (mapc (lambda (fn) 676 (mapc (lambda (fn)
674 (funcall fn (point-min) (point-max) 677 (if (not (eq fn 'c-restore-<>-properties))
675 (- (point-max) (point-min)))) 678 (funcall fn (point-min) (point-max)
679 (- (point-max) (point-min)))))
676 c-before-font-lock-functions)))) 680 c-before-font-lock-functions))))
677 681
678 (set (make-local-variable 'outline-regexp) "[^#\n\^M]") 682 (set (make-local-variable 'outline-regexp) "[^#\n\^M]")
@@ -1032,6 +1036,8 @@ Note that the style variables are always made local to the buffer."
1032 c-just-done-before-change) ; guard against a spurious second 1036 c-just-done-before-change) ; guard against a spurious second
1033 ; invocation of before-change-functions. 1037 ; invocation of before-change-functions.
1034 (setq c-just-done-before-change t) 1038 (setq c-just-done-before-change t)
1039 ;; (c-new-BEG c-new-END) will be the region to fontify.
1040 (setq c-new-BEG beg c-new-END end)
1035 (setq c-maybe-stale-found-type nil) 1041 (setq c-maybe-stale-found-type nil)
1036 (save-restriction 1042 (save-restriction
1037 (save-match-data 1043 (save-match-data
@@ -1126,7 +1132,8 @@ Note that the style variables are always made local to the buffer."
1126 1132
1127 ;; (c-new-BEG c-new-END) will be the region to fontify. It may become 1133 ;; (c-new-BEG c-new-END) will be the region to fontify. It may become
1128 ;; larger than (beg end). 1134 ;; larger than (beg end).
1129 (setq c-new-BEG beg c-new-END end) 1135 ;; (setq c-new-BEG beg c-new-END end)
1136 (setq c-new-END (- (+ c-new-END (- end beg)) old-len))
1130 1137
1131 (unless (c-called-from-text-property-change-p) 1138 (unless (c-called-from-text-property-change-p)
1132 (setq c-just-done-before-change nil) 1139 (setq c-just-done-before-change nil)