GNU bug report logs - #5649
23.1.92; Indentation problems in C mode

Previous Next

Packages: emacs, cc-mode;

Reported by: mwd <at> md5i.com

Date: Thu, 25 Feb 2010 16:18:02 UTC

Severity: serious

Done: Chong Yidong <cyd <at> stupidchicken.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 5649 in the body.
You can then email your comments to 5649 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#5649; Package emacs. (Thu, 25 Feb 2010 16:18:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to mwd <at> md5i.com:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 25 Feb 2010 16:18:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Michael Welsh Duggan <mwd <at> cert.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 23.1.92; Indentation problems in C mode
Date: Thu, 25 Feb 2010 11:11:37 -0500
[Message part 1 (text/plain, inline)]
I'm getting some screwy indentation behavior from C mode.  From a
current bzr checkout/install of emacs, try the following recipe: 

emacs -Q foo.c                 | starts emacs on foo.c (included below)
C-u 7 C-n                      | move down 7 lines
TAB                            | indent, nothing changes (good)
C-p C-p                        | move up 2 lines
TAB C-n TAB C-n                | indent 2 lines, nothing changes (good)
TAB                            | line unindents by 2 (bad)
TAB                            | line re-indents (good, but strange)
TAB                            | no change this time

And here's another recipe for weirdness:

emacs -Q foo.c                 | starts emacs on foo.c (included below)
C-x h                          | select buffer
C-M-\                          | indent region everything from line 7
                               |   down to the while (0) unindents 2
C-u 5 C-n                      | move down to the do {
C-x ( TAB C-n C-x )            | define a macro to indent and move down
                               |   a line
C-x e e e e e e                | Indent each line, no change

Here's foo.c

[foo.c (text/plain, inline)]
#if !SK_ENABLE_IPV6
#  define skipaddrApplyCIDR(ipaddr, cidr)       \
  ipUnionApplyCIDRV4(&(ipaddr)->ip_ip, cidr)
#else
#  define skipaddrApplyCIDR(ipaddr, cidr)                       \
  do {								\
    if (skipaddrIsV6(ipaddr)) {					\
      ipUnionApplyCIDRV6(&((ipaddr)->ip_ip), cidr);		\
    } else {							\
      ipUnionApplyCIDRV4(&((ipaddr)->ip_ip), cidr);		\
    }								\
  } while (0)
#endif
[Message part 3 (text/plain, inline)]
In GNU Emacs 23.1.92.2 (i686-pc-linux-gnu, GTK+ Version 2.10.4)
 of 2010-02-19 on maru.green.cert.org
Windowing system distributor `The X.Org Foundation', version 11.0.70101000
configured using `configure  '--prefix=/home/mwd' '--without-toolkit-scroll-bars' '--with-gif=no''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=none
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Group

Minor modes in effect:
  gnus-undo-mode: t
  shell-dirtrack-mode: t
  display-time-mode: t
  diff-auto-refine-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t

Recent input:
<return> C-x h C-M-\ C-n C-n C-n C-n C-n C-n C-n C-n 
C-p <tab> C-o C-_ C-p <tab> C-n C-n C-n C-n C-b C-b 
} <tab> SPC <tab> C-p C-p C-p C-p C-p C-a C-p C-x h 
C-M-\ C-n C-n C-n C-n C-n C-n C-n <tab> C-n <tab> C-n 
<tab> C-n <tab> C-b C-b C-b C-b C-b C-b C-b C-b C-b 
C-b C-b \ <return> <tab> C-p C-x h C-M-\ C-n C-n C-n 
C-n C-n C-n C-n C-n C-p <tab> C-n <tab> C-n <tab> C-n 
<tab> C-n <tab> C-p C-p C-p C-p C-p <tab> C-p <tab> 
C-p <tab> C-p C-p C-p <tab> C-n C-a <tab> C-p C-a C-x 
h C-M-\ C-_ <switch-frame> M-x r e p o r e t - e m 
<tab> <backspace> <backspace> <backspace> <backspace> 
<backspace> <backspace> r t - e m <tab> <return> I 
n d e n t a t i o n SPC p r o b l e m s SPC i n SPC 
c c - m o d e <return> M-x c c - <tab> <tab> b <tab> 
<backspace> <backspace> <backspace> - <tab> b <tab> 
<backspace> r <tab> e <tab> <backspace> <backspace> 
s u <tab> <return> y M-p C-e <M-backspace> <M-backspace> 
C SPC m o d e <return> C-x o C-x k y e s <return> C-x 
0 M-v M-v C-n C-p C-n C-n C-n C-n C-n C-n C-n C-n C-n 
C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p 
C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p 
C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p 
C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p C-p 
C-p C-p C-p C-_ C-x k M-x r e p o r t - e m <tab> 
<return>

Recent messages:
Checking 39 files in /home/mwd/share/emacs/23.1.92/lisp/obsolete...
Checking 1 files in /home/mwd/share/emacs/23.1.92/leim...
Checking for load-path shadows...done
Making completion list... [4 times]
Do you want to submit a report on CC Mode? (y or n) 
Formatting bug report buffer.......
Please enter your report.  Type C-c C-c to send, C-c C-k to abort.
call-interactively: Beginning of buffer
Auto-saving...done
Undo!

Load-path shadows:
/afs/cert.org/usr/mwd/src/elisp/nnir hides /home/mwd/share/emacs/23.1.92/lisp/gnus/nnir

Features:
(reporter shadow emacsbug time-stamp tabify whitespace dabbrev
vc-dispatcher vc-svn flyspell ispell cc-mode cc-fonts cc-menus cc-cmds
cc-styles cc-align cc-engine cc-vars cc-defs help-mode view copyright
gnus-dup mule-util gnus-cite ansi-color mail-extr gnus-async gnus-bcklg
parse-time timezone sort gnus-ml disp-table byte-opt bytecomp
byte-compile nnml utf-7 utf7 nndraft nnmh tls nnimap imap gnus-agent
gnus-srvr gnus-score score-mode nnvirtual gnus-msg gnus-art mm-uu
mml2015 epg-config mm-view gnus-cache nnir edmacro kmacro gnus-sum
gnus-demon nntp gnus-group gnus-undo nnmail mail-source nnoo gnus-start
gnus-spec gnus-int gnus-range gnus-win uniquify tramp-imap assoc
tramp-gw tramp-fish tramp-smb tramp-cache tramp-ftp tramp-cmds tramp
auth-source advice help-fns advice-preload shell format-spec
tramp-compat trampver time smime dig server psvn cl cl-19 log-edit
pcvs-util add-log diff-mode easy-mmode pgg pgg-parse pgg-def message
sendmail ecomplete rfc822 mml easymenu mml-sec password-cache mm-decode
mm-bodies mm-encode mailcap mail-parse rfc2231 rfc2047 rfc2045 qp
ietf-drums mailabbrev gmm-utils mailheader canlock sha1 hex-util
hashcash gnus gnus-ems nnheader gnus-util netrc time-date mail-utils
mm-util mail-prsvr wid-edit generic-x dired-x dired-aux dired ange-ftp
regexp-opt comint ring tooltip ediff-hook vc-hooks lisp-float-type
mwheel x-win x-dnd font-setting tool-bar dnd fontset image fringe
lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar
mldrag mouse jit-lock font-lock syntax facemenu font-core frame cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese hebrew greek romanian slovak czech european ethiopic
indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple
abbrev loaddefs button minibuffer faces cus-face files text-properties
overlay md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dbusbind
system-font-setting font-render-setting gtk x-toolkit x multi-tty emacs)

-- 
Michael Welsh Duggan
(mwd <at> cert.org)

bug reassigned from package 'emacs' to 'emacs,cc-mode'. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 25 Feb 2010 17:44:02 GMT) Full text and rfc822 format available.

Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#5649; Package emacs,cc-mode. (Sat, 27 Feb 2010 00:13:01 GMT) Full text and rfc822 format available.

Message #10 received at 5649 <at> debbugs.gnu.org (full text, mbox):

From: Chong Yidong <cyd <at> stupidchicken.com>
To: Michael Welsh Duggan <mwd <at> cert.org>
Cc: Alan Mackenzie <acm <at> muc.de>, 5649 <at> debbugs.gnu.org
Subject: Re: bug#5649: 23.1.92; Indentation problems in C mode
Date: Fri, 26 Feb 2010 19:12:06 -0500
Michael Welsh Duggan <mwd <at> cert.org> writes:

> I'm getting some screwy indentation behavior from C mode.  From a
> current bzr checkout/install of emacs, try the following recipe:
>
> emacs -Q foo.c                 | starts emacs on foo.c (included below)
> C-u 7 C-n                      | move down 7 lines
> TAB                            | indent, nothing changes (good)
> C-p C-p                        | move up 2 lines
> TAB C-n TAB C-n                | indent 2 lines, nothing changes (good)
> TAB                            | line unindents by 2 (bad)
> TAB                            | line re-indents (good, but strange)
> TAB                            | no change this time

Thanks.  This is a regression vs Emacs 23.1, so we should definitely fix
it before releasing Emacs 23.2.

I can reproduce the bug with the Emacs 23.0.90, so it's be around since
at lease 12-09 last year.  However, I haven't yet had the time to do a
proper bisect.




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#5649; Package emacs,cc-mode. (Mon, 01 Mar 2010 11:32:01 GMT) Full text and rfc822 format available.

Message #13 received at 5649 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Chong Yidong <cyd <at> stupidchicken.com>
Cc: 5649 <at> debbugs.gnu.org, Michael Welsh Duggan <mwd <at> cert.org>
Subject: Re: bug#5649: 23.1.92; Indentation problems in C mode
Date: Mon, 1 Mar 2010 11:38:32 +0000
Hi, Michael and Yidong

On Fri, Feb 26, 2010 at 07:12:06PM -0500, Chong Yidong wrote:
> Michael Welsh Duggan <mwd <at> cert.org> writes:

> > I'm getting some screwy indentation behavior from C mode.  From a
> > current bzr checkout/install of emacs, try the following recipe:

> > emacs -Q foo.c                 | starts emacs on foo.c (included below)
> > C-u 7 C-n                      | move down 7 lines
> > TAB                            | indent, nothing changes (good)
> > C-p C-p                        | move up 2 lines
> > TAB C-n TAB C-n                | indent 2 lines, nothing changes (good)
> > TAB                            | line unindents by 2 (bad)
> > TAB                            | line re-indents (good, but strange)
> > TAB                            | no change this time

> Thanks.  This is a regression vs Emacs 23.1, so we should definitely fix
> it before releasing Emacs 23.2.

> I can reproduce the bug with the Emacs 23.0.90, so it's be around since
> at lease 12-09 last year.  However, I haven't yet had the time to do a
> proper bisect.

I've just committed the folowing patch, which should fix the bug:


=== modified file 'lisp/progmodes/cc-engine.el'
--- lisp/progmodes/cc-engine.el	2010-02-25 21:21:25 +0000
+++ lisp/progmodes/cc-engine.el	2010-03-01 11:23:59 +0000
@@ -2641,7 +2641,8 @@
 	;; (car c-state-cache).  There can be no open parens/braces/brackets
 	;; between `good-pos'/`good-pos-actual-macro-start' and (point-max),
 	;; due to the interface spec to this function.
-	(setq pos (if good-pos-actual-macro-end
+	(setq pos (if (and good-pos-actual-macro-end
+			   (> in-macro-start good-pos-actual-macro-start))
 		      (1+ good-pos-actual-macro-end) ; get outside the macro as
 					; marked by a `category' text property.
 		    good-pos))


Thanks for the clean and concise bug report!

-- 
Alan Mackenzie (Nuremberg, Germany).




Reply sent to Chong Yidong <cyd <at> stupidchicken.com>:
You have taken responsibility. (Mon, 01 Mar 2010 15:02:02 GMT) Full text and rfc822 format available.

Notification sent to mwd <at> md5i.com:
bug acknowledged by developer. (Mon, 01 Mar 2010 15:02:02 GMT) Full text and rfc822 format available.

Message #18 received at 5649-done <at> debbugs.gnu.org (full text, mbox):

From: Chong Yidong <cyd <at> stupidchicken.com>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 5649-done <at> debbugs.gnu.org, Michael Welsh Duggan <mwd <at> cert.org>
Subject: Re: bug#5649: 23.1.92; Indentation problems in C mode
Date: Mon, 01 Mar 2010 10:00:57 -0500
Alan Mackenzie <acm <at> muc.de> writes:
>
> I've just committed the folowing patch, which should fix the bug:

Thanks!




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#5649; Package emacs,cc-mode. (Mon, 01 Mar 2010 15:20:02 GMT) Full text and rfc822 format available.

Message #21 received at 5649 <at> debbugs.gnu.org (full text, mbox):

From: Michael Welsh Duggan <mwd <at> cert.org>
To: Alan Mackenzie <acm <at> muc.de>
Cc: Chong Yidong <cyd <at> stupidchicken.com>,
	"5649 <at> debbugs.gnu.org" <5649 <at> debbugs.gnu.org>
Subject: Re: bug#5649: 23.1.92; Indentation problems in C mode
Date: Mon, 01 Mar 2010 10:17:00 -0500
Alan Mackenzie <acm <at> muc.de> writes:

> Hi, Michael and Yidong
>
> On Fri, Feb 26, 2010 at 07:12:06PM -0500, Chong Yidong wrote:
>> Michael Welsh Duggan <mwd <at> cert.org> writes:
>
>> > I'm getting some screwy indentation behavior from C mode.  From a
>> > current bzr checkout/install of emacs, try the following recipe:
>
>> > emacs -Q foo.c                 | starts emacs on foo.c (included below)
>> > C-u 7 C-n                      | move down 7 lines
>> > TAB                            | indent, nothing changes (good)
>> > C-p C-p                        | move up 2 lines
>> > TAB C-n TAB C-n                | indent 2 lines, nothing changes (good)
>> > TAB                            | line unindents by 2 (bad)
>> > TAB                            | line re-indents (good, but strange)
>> > TAB                            | no change this time
>
>> Thanks.  This is a regression vs Emacs 23.1, so we should definitely fix
>> it before releasing Emacs 23.2.
>
>> I can reproduce the bug with the Emacs 23.0.90, so it's be around since
>> at lease 12-09 last year.  However, I haven't yet had the time to do a
>> proper bisect.
>
> I've just committed the folowing patch, which should fix the bug:

I'm afraid this causes a much more serious bug.  Recipe:

emacs -Q
Open a new C-mode file.  Then type the following:
#if FOO
#endif

int bar;

For me the following happens:  The #endif is not fontified.  The "int
bar" is not fontified.  The semicolon causes an error.  I have verified
that reverting the patch below goes back to the old behavior, so this
patch is what is causing the bug.


> === modified file 'lisp/progmodes/cc-engine.el'
> --- lisp/progmodes/cc-engine.el	2010-02-25 21:21:25 +0000
> +++ lisp/progmodes/cc-engine.el	2010-03-01 11:23:59 +0000
> @@ -2641,7 +2641,8 @@
>  	;; (car c-state-cache).  There can be no open parens/braces/brackets
>  	;; between `good-pos'/`good-pos-actual-macro-start' and (point-max),
>  	;; due to the interface spec to this function.
> -	(setq pos (if good-pos-actual-macro-end
> +	(setq pos (if (and good-pos-actual-macro-end
> +			   (> in-macro-start good-pos-actual-macro-start))
>  		      (1+ good-pos-actual-macro-end) ; get outside the macro as
>  					; marked by a `category' text property.
>  		    good-pos))
>
>
> Thanks for the clean and concise bug report!

-- 
Michael Welsh Duggan
(mwd <at> cert.org)




Did not alter fixed versions and reopened. Request was from Debbugs Internal Request <bug-gnu-emacs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 01 Mar 2010 16:00:03 GMT) Full text and rfc822 format available.

Severity set to 'serious' from 'normal' Request was from Chong Yidong <cyd <at> stupidchicken.com> to control <at> debbugs.gnu.org. (Mon, 01 Mar 2010 16:00:03 GMT) Full text and rfc822 format available.

Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#5649; Package emacs,cc-mode. (Mon, 01 Mar 2010 17:57:02 GMT) Full text and rfc822 format available.

Message #28 received at 5649 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Michael Welsh Duggan <mwd <at> cert.org>
Cc: Chong Yidong <cyd <at> stupidchicken.com>,
	"5649 <at> debbugs.gnu.org" <5649 <at> debbugs.gnu.org>
Subject: Re: bug#5649: 23.1.92; Indentation problems in C mode
Date: Mon, 1 Mar 2010 18:04:01 +0000
Hello, again,

On Mon, Mar 01, 2010 at 10:17:00AM -0500, Michael Welsh Duggan wrote:
> Alan Mackenzie <acm <at> muc.de> writes:

> > I've just committed the folowing patch, which should fix the bug:

> I'm afraid this causes a much more serious bug.  Recipe:

> emacs -Q
> Open a new C-mode file.  Then type the following:
> #if FOO
> #endif

> int bar;

Sorry.

> For me the following happens:  The #endif is not fontified.  The "int
> bar" is not fontified.  The semicolon causes an error.  I have verified
> that reverting the patch below goes back to the old behavior, so this
> patch is what is causing the bug.

Yes.

> > === modified file 'lisp/progmodes/cc-engine.el'
> > --- lisp/progmodes/cc-engine.el	2010-02-25 21:21:25 +0000
> > +++ lisp/progmodes/cc-engine.el	2010-03-01 11:23:59 +0000
> > @@ -2641,7 +2641,8 @@
> >  	;; (car c-state-cache).  There can be no open parens/braces/brackets
> >  	;; between `good-pos'/`good-pos-actual-macro-start' and (point-max),
> >  	;; due to the interface spec to this function.
> > -	(setq pos (if good-pos-actual-macro-end
> > +	(setq pos (if (and good-pos-actual-macro-end
> > +			   (> in-macro-start good-pos-actual-macro-start))
> >  		      (1+ good-pos-actual-macro-end) ; get outside the macro as
> >  					; marked by a `category' text property.
> >  		    good-pos))

I was thrown by my own bad commenting.  :-(  I've committed a correction
to this.  The relevant diff (wrt the buggy "middle" version) is:


=== modified file 'lisp/progmodes/cc-engine.el'
--- lisp/progmodes/cc-engine.el	2010-03-01 11:31:42 +0000
+++ lisp/progmodes/cc-engine.el	2010-03-01 17:42:35 +0000
@@ -2591,7 +2591,7 @@
   (save-restriction
     (narrow-to-region 1 (point-max))
     (save-excursion
-      (let* ((in-macro-start   ; point-max or beginning of macro containing it
+      (let* ((in-macro-start   ; start of macro containing (point-max) or nil.
 	      (save-excursion
 		(goto-char (point-max))
 		(and (c-beginning-of-macro)
@@ -2642,7 +2642,8 @@
 	;; between `good-pos'/`good-pos-actual-macro-start' and (point-max),
 	;; due to the interface spec to this function.
 	(setq pos (if (and good-pos-actual-macro-end
-			   (> in-macro-start good-pos-actual-macro-start))
+			   (not (eq good-pos-actual-macro-start
+				    in-macro-start)))
 		      (1+ good-pos-actual-macro-end) ; get outside the macro as
 					; marked by a `category' text property.
 		    good-pos))


> > Thanks for the clean and concise bug report!

I hope it's right now.

> -- 
> Michael Welsh Duggan
> (mwd <at> cert.org)

-- 
Alan Mackenzie (Nuremberg, Germany).




bug closed, send any further explanations to mwd <at> md5i.com Request was from Chong Yidong <cyd <at> stupidchicken.com> to control <at> debbugs.gnu.org. (Mon, 01 Mar 2010 18:45:02 GMT) Full text and rfc822 format available.

Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#5649; Package emacs,cc-mode. (Mon, 01 Mar 2010 18:56:01 GMT) Full text and rfc822 format available.

Message #33 received at 5649 <at> debbugs.gnu.org (full text, mbox):

From: Michael Welsh Duggan <mwd <at> cert.org>
To: Alan Mackenzie <acm <at> muc.de>
Cc: Chong Yidong <cyd <at> stupidchicken.com>,
	"5649 <at> debbugs.gnu.org" <5649 <at> debbugs.gnu.org>
Subject: Re: bug#5649: 23.1.92; Indentation problems in C mode
Date: Mon, 01 Mar 2010 13:40:25 -0500
Alan Mackenzie <acm <at> muc.de> writes:

> Hello, again,
>
> On Mon, Mar 01, 2010 at 10:17:00AM -0500, Michael Welsh Duggan wrote:
>> Alan Mackenzie <acm <at> muc.de> writes:
>
>> > I've just committed the folowing patch, which should fix the bug:
>
>> I'm afraid this causes a much more serious bug.  Recipe:
>
>> emacs -Q
>> Open a new C-mode file.  Then type the following:
>> #if FOO
>> #endif
>
>> int bar;

[...]

> I was thrown by my own bad commenting.  :-(  I've committed a correction
> to this.  The relevant diff (wrt the buggy "middle" version) is:

[...]

>> > Thanks for the clean and concise bug report!
>
> I hope it's right now.

This does now seem to work.  Thanks!

-- 
Michael Welsh Duggan
(mwd <at> cert.org)




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 30 Mar 2010 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 15 years and 85 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.