;; cc-mode requires cc-fonts.
(declare-function c-fontify-recorded-types-and-refs "cc-fonts" ())
-(defvar c-forward-<>-arglist-recur-depth)
-
(defun c-forward-<>-arglist (all-types)
;; The point is assumed to be at a "<". Try to treat it as the open
;; paren of an angle bracket arglist and move forward to the
;; If `c-record-type-identifiers' is set then activate
;; recording of any found types that constitute an argument in
;; the arglist.
- (c-record-found-types (if c-record-type-identifiers t))
- (c-forward-<>-arglist-recur--depth 0))
+ (c-record-found-types (if c-record-type-identifiers t)))
(if (catch 'angle-bracket-arglist-escape
(setq c-record-found-types
(c-forward-<>-arglist-recur all-types)))
nil)))
(defun c-forward-<>-arglist-recur (all-types)
-
- ;; Temporary workaround for Bug#7722.
- (when (boundp 'c-forward-<>-arglist-recur--depth)
- (if (> c-forward-<>-arglist-recur--depth 200)
- (error "Max recursion depth reached in <> arglist")
- (setq c-forward-<>-arglist-recur--depth
- (1+ c-forward-<>-arglist-recur--depth))))
-
;; Recursive part of `c-forward-<>-arglist'.
;;
;; This function might do hidden buffer changes.
(goto-char start)
nil))
- (forward-char)
+ (forward-char) ; Forward over the opening '<'.
(unless (looking-at c-<-op-cont-regexp)
+ ;; go forward one non-alphanumeric character (group) per iteration of
+ ;; this loop.
(while (and
(progn
(c-forward-syntactic-ws)
(c-forward-type)
(c-forward-syntactic-ws))))))
- (setq pos (point))
+ (setq pos (point)) ; e.g. first token inside the '<'
;; Note: These regexps exploit the match order in \| so
;; that "<>" is matched by "<" rather than "[^>:-]>".
;; Either an operator starting with '<' or a nested arglist.
(setq pos (point))
(let (id-start id-end subres keyword-match)
- (if (if (looking-at c-<-op-cont-regexp)
- (setq tmp (match-end 0))
- (setq tmp pos)
- (backward-char)
- (not
- (and
-
- (save-excursion
- ;; There's always an identifier before an angle
- ;; bracket arglist, or a keyword in
- ;; `c-<>-type-kwds' or `c-<>-arglist-kwds'.
- (c-backward-syntactic-ws)
- (setq id-end (point))
- (c-simple-skip-symbol-backward)
- (when (or (setq keyword-match
- (looking-at c-opt-<>-sexp-key))
- (not (looking-at c-keywords-regexp)))
- (setq id-start (point))))
-
- (setq subres
- (let ((c-promote-possible-types t)
- (c-record-found-types t))
- (c-forward-<>-arglist-recur
- (and keyword-match
- (c-keyword-member
- (c-keyword-sym (match-string 1))
- 'c-<>-type-kwds)))))
- )))
-
- ;; It was not an angle bracket arglist.
- (goto-char tmp)
+ (cond
+ ;; The '<' begins a multi-char operator.
+ ((looking-at c-<-op-cont-regexp)
+ (setq tmp (match-end 0))
+ (goto-char (match-end 0)))
+ ;; We're at a nested <.....>
+ ((progn
+ (setq tmp pos)
+ (backward-char) ; to the '<'
+ (and
+ (save-excursion
+ ;; There's always an identifier before an angle
+ ;; bracket arglist, or a keyword in `c-<>-type-kwds'
+ ;; or `c-<>-arglist-kwds'.
+ (c-backward-syntactic-ws)
+ (setq id-end (point))
+ (c-simple-skip-symbol-backward)
+ (when (or (setq keyword-match
+ (looking-at c-opt-<>-sexp-key))
+ (not (looking-at c-keywords-regexp)))
+ (setq id-start (point))))
+ (setq subres
+ (let ((c-promote-possible-types t)
+ (c-record-found-types t))
+ (c-forward-<>-arglist-recur
+ (and keyword-match
+ (c-keyword-member
+ (c-keyword-sym (match-string 1))
+ 'c-<>-type-kwds)))))))
;; It was an angle bracket arglist.
(setq c-record-found-types subres)
(c-forward-syntactic-ws)
(looking-at c-opt-identifier-concat-key)))
(c-record-ref-id (cons id-start id-end))
- (c-record-type-id (cons id-start id-end))))))
- t)
+ (c-record-type-id (cons id-start id-end)))))
+
+ ;; At a "less than" operator.
+ (t
+ (forward-char)
+ )))
+ t) ; carry on looping.
((and (not c-restricted-<>-arglists)
(or (and (eq (char-before) ?&)
(boundp 'parse-sexp-lookup-properties))))
;; Below we fontify a whole declaration even when it crosses the limit,
- ;; to avoid gaps when lazy-lock fontifies the file a screenful at a
+ ;; to avoid gaps when jit/lazy-lock fontifies the file a block at a
;; time. That is however annoying during editing, e.g. the following is
;; a common situation while the first line is being written:
;;
;; "some_other_variable" as an identifier, and the latter will not
;; correct itself until the second line is changed. To avoid that we
;; narrow to the limit if the region to fontify is a single line.
- (narrow-to-region
- (point-min)
- (if (<= limit (c-point 'bonl))
+ (if (<= limit (c-point 'bonl))
+ (narrow-to-region
+ (point-min)
(save-excursion
;; Narrow after any operator chars following the limit though,
;; since those characters can be useful in recognizing a
;; after the header).
(goto-char limit)
(skip-chars-forward c-nonsymbol-chars)
- (point))
- limit))
+ (point))))
(c-find-decl-spots
limit