Commit abfc152b authored by Alan Mackenzie's avatar Alan Mackenzie Committed by Chong Yidong
Browse files

Proper fix for CC mode Bug#7722.

* lisp/progmodes/cc-fonts.el (c-font-lock-declarations): Remove a
narrow-to-region call that cuts context off the end (Bug#7722).

* lisp/progmodes/cc-engine.el (c-forward-<>-arglist-recur): Refactor
nested if-forms with a simple cond.
(c-forward-<>-arglist): Revert 2011-01-31 change.
parent d4eb88c7
2011-02-13 Alan Mackenzie <acm@muc.de>
* progmodes/cc-fonts.el (c-font-lock-declarations): Remove a
narrow-to-region call that cuts context off the end (Bug#7722).
* progmodes/cc-engine.el (c-forward-<>-arglist-recur): Refactor
nested if-forms with a simple cond.
(c-forward-<>-arglist): Revert 2011-01-31 change.
2011-02-13 Chong Yidong <cyd@stupidchicken.com>
 
* vc/log-view.el: New command log-view-toggle-entry-display for
......
......@@ -5371,8 +5371,6 @@ comment at the start of cc-engine.el for more info."
;; 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
......@@ -5398,8 +5396,7 @@ comment at the start of cc-engine.el for more info."
;; 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)))
......@@ -5416,14 +5413,6 @@ comment at the start of cc-engine.el for more info."
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.
......@@ -5455,9 +5444,11 @@ comment at the start of cc-engine.el for more info."
(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)
......@@ -5486,7 +5477,7 @@ comment at the start of cc-engine.el for more info."
(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 "[^>:-]>".
......@@ -5522,37 +5513,35 @@ comment at the start of cc-engine.el for more info."
;; 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)
......@@ -5567,8 +5556,13 @@ comment at the start of cc-engine.el for more info."
(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) ?&)
......
......@@ -1082,7 +1082,7 @@ casts and declarations are fontified. Used on level 2 and higher."
(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:
;;
......@@ -1094,9 +1094,9 @@ casts and declarations are fontified. Used on level 2 and higher."
;; "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
......@@ -1104,8 +1104,7 @@ casts and declarations are fontified. Used on level 2 and higher."
;; after the header).
(goto-char limit)
(skip-chars-forward c-nonsymbol-chars)
(point))
limit))
(point))))
(c-find-decl-spots
limit
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment