Fix spurious recognition of c-in-knr-argdecl.

This commit is contained in:
Alan Mackenzie 2012-02-07 15:19:52 +00:00
parent 667ced3a2d
commit 98d7371e7a
2 changed files with 21 additions and 10 deletions

View file

@ -1,3 +1,10 @@
2012-02-07 Alan Mackenzie <acm@muc.de>
Fix spurious recognition of c-in-knr-argdecl.
* progmodes/cc-engine.el (c-in-knr-argdecl): Check for '=' in a
putative K&R region.
2012-02-07 Alan Mackenzie <acm@muc.de>
* progmodes/cc-engine.el (c-forward-objc-directive): Prevent

View file

@ -7592,14 +7592,17 @@ comment at the start of cc-engine.el for more info."
(save-restriction
;; If we're in a macro, our search range is restricted to it. Narrow to
;; the searchable range.
(let* ((macro-start (c-query-macro-start))
(lim (max (or lim (point-min)) (or macro-start (point-min))))
(let* ((macro-start (save-excursion (and (c-beginning-of-macro) (point))))
(macro-end (save-excursion (and macro-start (c-end-of-macro) (point))))
(low-lim (max (or lim (point-min)) (or macro-start (point-min))))
before-lparen after-rparen
(pp-count-out 20)) ; Max number of paren/brace constructs before we give up
(narrow-to-region lim (c-point 'eol))
(pp-count-out 20)) ; Max number of paren/brace constructs before
; we give up
(narrow-to-region low-lim (or macro-end (point-max)))
;; Search backwards for the defun's argument list. We give up if we
;; encounter a "}" (end of a previous defun) or BOB.
;; encounter a "}" (end of a previous defun) an "=" (which can't be in
;; a knr region) or BOB.
;;
;; The criterion for a paren structure being the arg list is:
;; o - there is non-WS stuff after it but before any "{"; AND
@ -7619,12 +7622,13 @@ comment at the start of cc-engine.el for more info."
(catch 'knr
(while (> pp-count-out 0) ; go back one paren/bracket pair each time.
(setq pp-count-out (1- pp-count-out))
(c-syntactic-skip-backward "^)]}")
(c-syntactic-skip-backward "^)]}=")
(cond ((eq (char-before) ?\))
(setq after-rparen (point)))
((eq (char-before) ?\])
(setq after-rparen nil))
(t ; either } (hit previous defun) or no more parens/brackets
(t ; either } (hit previous defun) or = or no more
; parens/brackets.
(throw 'knr nil)))
(if after-rparen
@ -7640,18 +7644,18 @@ comment at the start of cc-engine.el for more info."
;; It can't be the arg list if next token is ; or {
(progn (goto-char after-rparen)
(c-forward-syntactic-ws)
(not (memq (char-after) '(?\; ?\{))))
(not (memq (char-after) '(?\; ?\{ ?\=))))
;; Is the thing preceding the list an identifier (the
;; function name), or a macro expansion?
(progn
(goto-char before-lparen)
(eq (c-backward-token-2) 0)
(or (c-on-identifier)
(or (eq (c-on-identifier) (point))
(and (eq (char-after) ?\))
(c-go-up-list-backward)
(eq (c-backward-token-2) 0)
(c-on-identifier))))
(eq (c-on-identifier) (point)))))
;; Have we got a non-empty list of comma-separated
;; identifiers?