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.
This commit is contained in:
parent
31a97acf43
commit
33219d385b
5 changed files with 103 additions and 64 deletions
|
@ -1121,35 +1121,15 @@ numeric argument is supplied, or the point is inside a literal."
|
||||||
(looking-at "<<"))
|
(looking-at "<<"))
|
||||||
(>= (match-end 0) final-pos)))
|
(>= (match-end 0) final-pos)))
|
||||||
|
|
||||||
;; It's a >. Either a C++ >> operator. ......
|
;; It's a >. Either a template/generic terminator ...
|
||||||
(or (and (c-major-mode-is 'c++-mode)
|
(or (c-get-char-property (1- final-pos) 'syntax-table)
|
||||||
|
;; or a C++ >> operator.
|
||||||
|
(and (c-major-mode-is 'c++-mode)
|
||||||
(progn
|
(progn
|
||||||
(goto-char (1- final-pos))
|
(goto-char (1- final-pos))
|
||||||
(c-beginning-of-current-token)
|
(c-beginning-of-current-token)
|
||||||
(looking-at ">>"))
|
(looking-at ">>"))
|
||||||
(>= (match-end 0) final-pos))
|
(>= (match-end 0) final-pos))))))
|
||||||
;; ...., or search back for a < which isn't already marked as an
|
|
||||||
;; opening template delimiter.
|
|
||||||
(save-restriction
|
|
||||||
(widen)
|
|
||||||
;; Narrow to avoid `c-forward-<>-arglist' below searching past
|
|
||||||
;; our position.
|
|
||||||
(narrow-to-region (point-min) final-pos)
|
|
||||||
(goto-char final-pos)
|
|
||||||
(while
|
|
||||||
(and
|
|
||||||
(progn
|
|
||||||
(c-syntactic-skip-backward "^<;}" nil t)
|
|
||||||
(eq (char-before) ?<))
|
|
||||||
(progn
|
|
||||||
(backward-char)
|
|
||||||
(looking-at "\\s("))))
|
|
||||||
(and (eq (char-after) ?<)
|
|
||||||
(not (looking-at "\\s("))
|
|
||||||
(progn (c-backward-syntactic-ws)
|
|
||||||
(c-simple-skip-symbol-backward))
|
|
||||||
(or (looking-at c-opt-<>-sexp-key)
|
|
||||||
(not (looking-at c-keywords-regexp)))))))))
|
|
||||||
|
|
||||||
(goto-char final-pos)
|
(goto-char final-pos)
|
||||||
(when found-delim
|
(when found-delim
|
||||||
|
@ -1157,11 +1137,9 @@ numeric argument is supplied, or the point is inside a literal."
|
||||||
(when (and (eq (char-before) ?>)
|
(when (and (eq (char-before) ?>)
|
||||||
(not executing-kbd-macro)
|
(not executing-kbd-macro)
|
||||||
blink-paren-function)
|
blink-paren-function)
|
||||||
;; Currently (2014-10-19), the syntax-table text properties on < and >
|
;; From now (2016-01-01), the syntax-table text properties on < and >
|
||||||
;; are only applied in code called during Emacs redisplay. We thus
|
;; are applied in an after-change function, not during redisplay. Hence
|
||||||
;; explicitly cause a redisplay so that these properties have been
|
;; we no longer need to call (sit-for 0) for blink paren to work.
|
||||||
;; applied when `blink-paren-function' gets called.
|
|
||||||
(sit-for 0)
|
|
||||||
(funcall blink-paren-function)))))
|
(funcall blink-paren-function)))))
|
||||||
|
|
||||||
(defun c-electric-paren (arg)
|
(defun c-electric-paren (arg)
|
||||||
|
|
|
@ -5577,8 +5577,9 @@ comment at the start of cc-engine.el for more info."
|
||||||
|
|
||||||
(defun c-before-change-check-<>-operators (beg end)
|
(defun c-before-change-check-<>-operators (beg end)
|
||||||
;; Unmark certain pairs of "< .... >" which are currently marked as
|
;; Unmark certain pairs of "< .... >" which are currently marked as
|
||||||
;; template/generic delimiters. (This marking is via syntax-table
|
;; template/generic delimiters. (This marking is via syntax-table text
|
||||||
;; text properties).
|
;; properties), and expand the (c-new-BEG c-new-END) region to include all
|
||||||
|
;; unmarked < and > operators within the certain bounds (see below).
|
||||||
;;
|
;;
|
||||||
;; These pairs are those which are in the current "statement" (i.e.,
|
;; These pairs are those which are in the current "statement" (i.e.,
|
||||||
;; the region between the {, }, or ; before BEG and the one after
|
;; 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."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(let ((beg-lit-limits (progn (goto-char beg) (c-literal-limits)))
|
(let ((beg-lit-limits (progn (goto-char beg) (c-literal-limits)))
|
||||||
(end-lit-limits (progn (goto-char end) (c-literal-limits)))
|
(end-lit-limits (progn (goto-char end) (c-literal-limits)))
|
||||||
new-beg new-end need-new-beg need-new-end)
|
new-beg new-end beg-limit end-limit)
|
||||||
;; Locate the barrier before the changed region
|
;; Locate the earliest < after the barrier before the changed region,
|
||||||
|
;; which isn't already marked as a paren.
|
||||||
(goto-char (if beg-lit-limits (car beg-lit-limits) beg))
|
(goto-char (if beg-lit-limits (car beg-lit-limits) beg))
|
||||||
(c-syntactic-skip-backward "^;{}" (c-determine-limit 512))
|
(setq beg-limit (c-determine-limit 512))
|
||||||
(setq new-beg (point))
|
|
||||||
|
|
||||||
;; Remove the syntax-table/category properties from each pertinent <...>
|
;; Remove the syntax-table/category properties from each pertinent <...>
|
||||||
;; pair. Firsly, the ones with the < before beg and > after beg.
|
;; pair. Firstly, the ones with the < before beg and > after beg....
|
||||||
(while
|
(while (progn (c-syntactic-skip-backward "^;{}<" beg-limit)
|
||||||
(c-search-forward-char-property 'syntax-table c-<-as-paren-syntax beg)
|
(eq (char-before) ?<))
|
||||||
(if (c-clear-<-pair-props-if-match-after beg (1- (point)))
|
(c-backward-token-2)
|
||||||
(setq need-new-beg t)))
|
(when (eq (char-after) ?<)
|
||||||
|
(c-clear-<-pair-props-if-match-after beg)))
|
||||||
|
(c-forward-syntactic-ws)
|
||||||
|
(setq new-beg (point))
|
||||||
|
|
||||||
;; Locate the barrier after END.
|
;; ...Then the ones with < before end and > after end.
|
||||||
(goto-char (if end-lit-limits (cdr end-lit-limits) end))
|
(goto-char (if end-lit-limits (cdr end-lit-limits) end))
|
||||||
(c-syntactic-re-search-forward "[;{}]" (c-determine-+ve-limit 512) 'end)
|
(setq end-limit (c-determine-+ve-limit 512))
|
||||||
|
(while (and (c-syntactic-re-search-forward "[;{}>]" end-limit 'end)
|
||||||
|
(eq (char-before) ?>))
|
||||||
|
(c-end-of-current-token)
|
||||||
|
(when (eq (char-before) ?>)
|
||||||
|
(c-clear->-pair-props-if-match-before end (1- (point)))))
|
||||||
|
(c-backward-syntactic-ws)
|
||||||
(setq new-end (point))
|
(setq new-end (point))
|
||||||
|
|
||||||
;; Remove syntax-table properties from the remaining pertinent <...>
|
|
||||||
;; pairs, those with a > after end and < before end.
|
|
||||||
(while (c-search-backward-char-property 'syntax-table c->-as-paren-syntax end)
|
|
||||||
(if (c-clear->-pair-props-if-match-before end)
|
|
||||||
(setq need-new-end t)))
|
|
||||||
|
|
||||||
;; Extend the fontification region, if needed.
|
;; Extend the fontification region, if needed.
|
||||||
(when need-new-beg
|
(and new-beg
|
||||||
(goto-char new-beg)
|
(< new-beg c-new-BEG)
|
||||||
(c-forward-syntactic-ws)
|
(setq c-new-BEG new-beg))
|
||||||
(and (< (point) c-new-BEG) (setq c-new-BEG (point))))
|
(and new-end
|
||||||
|
(> new-end c-new-END)
|
||||||
(when need-new-end
|
(setq c-new-END new-end)))))
|
||||||
(and (> new-end c-new-END) (setq c-new-END new-end))))))
|
|
||||||
|
|
||||||
(defun c-after-change-check-<>-operators (beg end)
|
(defun c-after-change-check-<>-operators (beg end)
|
||||||
;; This is called from `after-change-functions' when
|
;; This is called from `after-change-functions' when
|
||||||
|
@ -5668,7 +5671,28 @@ comment at the start of cc-engine.el for more info."
|
||||||
(c-clear-<>-pair-props)
|
(c-clear-<>-pair-props)
|
||||||
(forward-char)))))))
|
(forward-char)))))))
|
||||||
|
|
||||||
|
(defun c-restore-<>-properties (_beg _end _old-len)
|
||||||
|
;; This function is called as an after-change function. It restores the
|
||||||
|
;; category/syntax-table properties on template/generic <..> pairs between
|
||||||
|
;; c-new-BEG and c-new-END. It may do hidden buffer changes.
|
||||||
|
(c-save-buffer-state ((c-parse-and-markup-<>-arglists t)
|
||||||
|
c-restricted-<>-arglists lit-limits)
|
||||||
|
(goto-char c-new-BEG)
|
||||||
|
(if (setq lit-limits (c-literal-limits))
|
||||||
|
(goto-char (cdr lit-limits)))
|
||||||
|
(while (and (< (point) c-new-END)
|
||||||
|
(c-syntactic-re-search-forward "<" c-new-END 'bound))
|
||||||
|
(backward-char)
|
||||||
|
(save-excursion
|
||||||
|
(c-backward-token-2)
|
||||||
|
(setq c-restricted-<>-arglists
|
||||||
|
(and (not (looking-at c-opt-<>-sexp-key))
|
||||||
|
(progn (c-backward-syntactic-ws) ; to < or ,
|
||||||
|
(and (memq (char-before) '(?< ?,))
|
||||||
|
(not (eq (c-get-char-property (point) 'c-type)
|
||||||
|
'c-decl-arg-start)))))))
|
||||||
|
(or (c-forward-<>-arglist nil)
|
||||||
|
(forward-char)))))
|
||||||
|
|
||||||
;; Handling of small scale constructs like types and names.
|
;; Handling of small scale constructs like types and names.
|
||||||
|
|
||||||
|
|
|
@ -1205,6 +1205,9 @@ casts and declarations are fontified. Used on level 2 and higher."
|
||||||
;; Same as `max-type-decl-*', but used when we're before
|
;; Same as `max-type-decl-*', but used when we're before
|
||||||
;; `token-pos'.
|
;; `token-pos'.
|
||||||
(max-type-decl-end-before-token 0)
|
(max-type-decl-end-before-token 0)
|
||||||
|
;; End of <..> construct which has had c-<>-arg-sep c-type
|
||||||
|
;; properties set within it.
|
||||||
|
(max-<>-end 0)
|
||||||
;; Set according to the context to direct the heuristics for
|
;; Set according to the context to direct the heuristics for
|
||||||
;; recognizing C++ templates.
|
;; recognizing C++ templates.
|
||||||
c-restricted-<>-arglists
|
c-restricted-<>-arglists
|
||||||
|
@ -1347,6 +1350,28 @@ casts and declarations are fontified. Used on level 2 and higher."
|
||||||
(setq decl-or-cast (c-forward-decl-or-cast-1
|
(setq decl-or-cast (c-forward-decl-or-cast-1
|
||||||
match-pos context last-cast-end))
|
match-pos context last-cast-end))
|
||||||
|
|
||||||
|
;; Ensure that c-<>-arg-sep c-type properties are in place on the
|
||||||
|
;; commas separating the arguments inside template/generic <..>s.
|
||||||
|
(when (and (eq (char-before match-pos) ?<)
|
||||||
|
(> match-pos max-<>-end))
|
||||||
|
(save-excursion
|
||||||
|
(goto-char match-pos)
|
||||||
|
(c-backward-token-2)
|
||||||
|
(if (and
|
||||||
|
(eq (char-after) ?<)
|
||||||
|
(let ((c-restricted-<>-arglists
|
||||||
|
(save-excursion
|
||||||
|
(c-backward-token-2)
|
||||||
|
(and
|
||||||
|
(not (looking-at c-opt-<>-sexp-key))
|
||||||
|
(progn (c-backward-syntactic-ws)
|
||||||
|
(memq (char-before) '(?\( ?,)))
|
||||||
|
(not (eq (c-get-char-property (1- (point))
|
||||||
|
'c-type)
|
||||||
|
'c-decl-arg-start))))))
|
||||||
|
(c-forward-<>-arglist nil)))
|
||||||
|
(setq max-<>-end (point)))))
|
||||||
|
|
||||||
(cond
|
(cond
|
||||||
((eq decl-or-cast 'cast)
|
((eq decl-or-cast 'cast)
|
||||||
;; Save the position after the previous cast so we can feed
|
;; Save the position after the previous cast so we can feed
|
||||||
|
|
|
@ -499,7 +499,12 @@ parameters \(point-min) and \(point-max).")
|
||||||
;; For documentation see the following c-lang-defvar of the same name.
|
;; For documentation see the following c-lang-defvar of the same name.
|
||||||
;; The value here may be a list of functions or a single function.
|
;; The value here may be a list of functions or a single function.
|
||||||
t 'c-change-expand-fl-region
|
t 'c-change-expand-fl-region
|
||||||
(c c++ objc) '(c-neutralize-syntax-in-and-mark-CPP
|
(c objc) '(c-neutralize-syntax-in-and-mark-CPP
|
||||||
|
c-change-expand-fl-region)
|
||||||
|
c++ '(c-neutralize-syntax-in-and-mark-CPP
|
||||||
|
c-restore-<>-properties
|
||||||
|
c-change-expand-fl-region)
|
||||||
|
java '(c-restore-<>-properties
|
||||||
c-change-expand-fl-region)
|
c-change-expand-fl-region)
|
||||||
awk 'c-awk-extend-and-syntax-tablify-region)
|
awk 'c-awk-extend-and-syntax-tablify-region)
|
||||||
(c-lang-defvar c-before-font-lock-functions
|
(c-lang-defvar c-before-font-lock-functions
|
||||||
|
|
|
@ -631,8 +631,11 @@ that requires a literal mode spec at compile time."
|
||||||
(font-lock-mode 1)))
|
(font-lock-mode 1)))
|
||||||
|
|
||||||
;; Buffer local variables defining the region to be fontified by a font lock
|
;; Buffer local variables defining the region to be fontified by a font lock
|
||||||
;; after-change function. They are set in c-after-change to
|
;; after-change function. They are initialized in c-before-change to
|
||||||
;; after-change-functions' BEG and END, and may be modified by functions in
|
;; before-change-functions' BEG and END. `c-new-END' is amended in
|
||||||
|
;; c-after-change with after-change-functions' BEG, END, and OLD-LEN. These
|
||||||
|
;; variables may be modified by any before/after-change function, in
|
||||||
|
;; particular by functions in `c-get-state-before-change-functions' and
|
||||||
;; `c-before-font-lock-functions'.
|
;; `c-before-font-lock-functions'.
|
||||||
(defvar c-new-BEG 0)
|
(defvar c-new-BEG 0)
|
||||||
(make-variable-buffer-local 'c-new-BEG)
|
(make-variable-buffer-local 'c-new-BEG)
|
||||||
|
@ -671,8 +674,9 @@ compatible with old code; callers should always specify it."
|
||||||
(funcall fn (point-min) (point-max)))
|
(funcall fn (point-min) (point-max)))
|
||||||
c-get-state-before-change-functions)
|
c-get-state-before-change-functions)
|
||||||
(mapc (lambda (fn)
|
(mapc (lambda (fn)
|
||||||
|
(if (not (eq fn 'c-restore-<>-properties))
|
||||||
(funcall fn (point-min) (point-max)
|
(funcall fn (point-min) (point-max)
|
||||||
(- (point-max) (point-min))))
|
(- (point-max) (point-min)))))
|
||||||
c-before-font-lock-functions))))
|
c-before-font-lock-functions))))
|
||||||
|
|
||||||
(set (make-local-variable 'outline-regexp) "[^#\n\^M]")
|
(set (make-local-variable 'outline-regexp) "[^#\n\^M]")
|
||||||
|
@ -1032,6 +1036,8 @@ Note that the style variables are always made local to the buffer."
|
||||||
c-just-done-before-change) ; guard against a spurious second
|
c-just-done-before-change) ; guard against a spurious second
|
||||||
; invocation of before-change-functions.
|
; invocation of before-change-functions.
|
||||||
(setq c-just-done-before-change t)
|
(setq c-just-done-before-change t)
|
||||||
|
;; (c-new-BEG c-new-END) will be the region to fontify.
|
||||||
|
(setq c-new-BEG beg c-new-END end)
|
||||||
(setq c-maybe-stale-found-type nil)
|
(setq c-maybe-stale-found-type nil)
|
||||||
(save-restriction
|
(save-restriction
|
||||||
(save-match-data
|
(save-match-data
|
||||||
|
@ -1126,7 +1132,8 @@ Note that the style variables are always made local to the buffer."
|
||||||
|
|
||||||
;; (c-new-BEG c-new-END) will be the region to fontify. It may become
|
;; (c-new-BEG c-new-END) will be the region to fontify. It may become
|
||||||
;; larger than (beg end).
|
;; larger than (beg end).
|
||||||
(setq c-new-BEG beg c-new-END end)
|
;; (setq c-new-BEG beg c-new-END end)
|
||||||
|
(setq c-new-END (- (+ c-new-END (- end beg)) old-len))
|
||||||
|
|
||||||
(unless (c-called-from-text-property-change-p)
|
(unless (c-called-from-text-property-change-p)
|
||||||
(setq c-just-done-before-change nil)
|
(setq c-just-done-before-change nil)
|
||||||
|
|
Loading…
Add table
Reference in a new issue