[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#7918: [PATCH] cc-mode: only the first clause of a for-loop should be
From: |
Alan Mackenzie |
Subject: |
bug#7918: [PATCH] cc-mode: only the first clause of a for-loop should be checked for declarations |
Date: |
Fri, 1 Apr 2016 16:18:19 +0000 |
User-agent: |
Mutt/1.5.24 (2015-08-30) |
Hello, Daniel.
On Tue, Mar 01, 2016 at 10:05:47AM -0800, Daniel Colascione wrote:
> On 03/01/2016 10:02 AM, Alan Mackenzie wrote:
> > On Fri, Feb 26, 2016 at 04:48:13PM +1030, Lars Ingebrigtsen wrote:
> >> Daniel Colascione <dan.colascione@gmail.com> writes:
> >>> // This code has no variable declarations
> >>> void foo() {
> >>> for (; (DWORD) a * b ;)
> >>> ;
> >>> for (; a * b ;)
> >>> ;
> >>> }
> It's been years since I even thought about that code. If you're up for
> it, I'd rather you supply a separate fix.
OK, here goes:
diff -r f19a4ffb060b cc-fonts.el
--- a/cc-fonts.el Fri Apr 01 12:23:17 2016 +0000
+++ b/cc-fonts.el Fri Apr 01 16:10:57 2016 +0000
@@ -1206,8 +1206,20 @@
'font-lock-keyword-face)
(looking-at c-not-decl-init-keywords))
(and c-macro-with-semi-re
- (looking-at c-macro-with-semi-re))) ; 2008-11-04
- ;; Don't do anything more if we're looking at a keyword that
+ (looking-at c-macro-with-semi-re)) ; 2008-11-04
+ (save-excursion ; A construct after a ; in a `for' statement
+ ; can't be a declaration.
+ (and (c-go-up-list-backward)
+ (eq (char-after) ?\()
+ (progn (c-backward-syntactic-ws)
+ (c-simple-skip-symbol-backward))
+ (looking-at c-paren-stmt-key)
+ (progn (goto-char match-pos)
+ (while (and (eq (char-before) ?\))
+ (c-go-list-backward))
+ (c-backward-syntactic-ws))
+ (eq (char-before) ?\;)))))
+ ;; Don't do anything more if we're looking at something that
;; can't start a declaration.
t
Could you do the usual with this patch, please, then if everything's OK,
I can commit it to the emacs-25 branch. Thanks!
--
Alan Mackenzie (Nuremberg, Germany).
- bug#7918: [PATCH] cc-mode: only the first clause of a for-loop should be checked for declarations,
Alan Mackenzie <=