* bug#4289: 23.1; Incorrect indentation in C, following certain 'case' labels
@ 2009-08-29 20:59 Benjamin Moody
2009-08-31 20:05 ` Alan Mackenzie
0 siblings, 1 reply; 2+ messages in thread
From: Benjamin Moody @ 2009-08-29 20:59 UTC (permalink / raw
To: bug-gnu-emacs
In Emacs 23.1, I've found an issue with the indentation rules for C
mode. In some circumstances, following a series of multiple labels,
the second and subsequent statements are not indented properly. For
example, in the following code:
void foo(int x)
{
switch (x) {
case 1:
case 2:
printf("aaa");
break;
case '3':
case '4':
printf("bbb");
break;
}
}
the second 'break' statement should be indented by 4 spaces, to align
with the 'printf'.
This problem seems to appear when there are multiple labels (either
normal named labels, 'case' labels, or 'default' labels) in a row,
with no intervening statments, and either the first or the last such
label is a 'case' label with a character constant as its value.
This problem does NOT occur with Emacs 22.3. It does occur in C++ and
ObjC modes as well. It affects indentation using either TAB or M-x
indent-region.
A workaround is to place the character constant(s) in parentheses.
This is obviously not a serious problem, but it is a somewhat annoying
one which would be nice to see fixed.
Benjamin Moody
In GNU Emacs 23.1.1 (x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
of 2009-08-03 on nautilus, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.10402000
configured using `configure '--build=x86_64-linux-gnu' '--host=x86_64-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var/lib' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs23:/etc/emacs:/usr/local/share/emacs/23.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/23.1/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/23.1/leim' '--with-x=yes' '--with-x-toolkit=athena' '--with-toolkit-scroll-bars' 'build_alias=x86_64-linux-gnu' 'host_alias=x86_64-linux-gnu' 'CFLAGS=-DDEBIAN -g -O2' 'LDFLAGS=-g' 'CPPFLAGS=''
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: nil
locale-coding-system: utf-8-unix
default-enable-multibyte-characters: t
Major mode: C/l
Minor modes in effect:
iswitchb-mode: t
tooltip-mode: t
mouse-wheel-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
global-auto-composition-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
column-number-mode: t
line-number-mode: t
abbrev-mode: t
Recent input:
<help-echo> C-x C-f / t m p / t e s t . c <return>
v o i d SPC f o o ( i n t SPC x ) <return> { <return>
<tab> s w i t c h SPC ( x ) SPC { <return> <tab> c
a s d e <backspace> <backspace> e 1 SPC <backspace>
<backspace> SPC 1 : <return> <tab> c a s e SPC 2 :
<return> <tab> p r i n t f ( " a a a " ) ; <return>
<tab> b r e a k ; <return> <return> <tab> c a s e SPC
' 3 ' : <return> <tab> c a s e SPC ' 4 ' : <return>
<tab> p r i n t f ( " b b b " ) ; <return> <tab> b
r e a k j ; <backspace> <backspace> ; <return> } <S-return>
} <return> M-x r e p o r t - e m a <tab> <return>
Recent messages:
Setting up ede...
Loading `eieio': old-style backquotes detected!
Setting up ede...done
Setting up eieio...done
Setting up semantic...done
Setting up speedbar...done
Setting up cedet-contrib...done
Loading /etc/emacs/site-start.d/55ecb.el (source)...done
For information about GNU Emacs and the GNU system, type C-h C-a.
(New file)
^ permalink raw reply [flat|nested] 2+ messages in thread
* bug#4289: 23.1; Incorrect indentation in C, following certain 'case' labels
2009-08-29 20:59 bug#4289: 23.1; Incorrect indentation in C, following certain 'case' labels Benjamin Moody
@ 2009-08-31 20:05 ` Alan Mackenzie
0 siblings, 0 replies; 2+ messages in thread
From: Alan Mackenzie @ 2009-08-31 20:05 UTC (permalink / raw
To: Benjamin Moody, 4289; +Cc: bug-gnu-emacs
Hi, Benjamin!
On Sat, Aug 29, 2009 at 04:59:54PM -0400, Benjamin Moody wrote:
> In Emacs 23.1, I've found an issue with the indentation rules for C
> mode. In some circumstances, following a series of multiple labels,
> the second and subsequent statements are not indented properly. For
> example, in the following code:
> void foo(int x)
> {
> switch (x) {
> case 1:
> case 2:
> printf("aaa");
> break;
> case '3':
> case '4':
> printf("bbb");
> break;
> }
> }
> the second 'break' statement should be indented by 4 spaces, to align
> with the 'printf'.
Indeed it should.
> This problem seems to appear when there are multiple labels (either
> normal named labels, 'case' labels, or 'default' labels) in a row,
> with no intervening statments, and either the first or the last such
> label is a 'case' label with a character constant as its value.
> This problem does NOT occur with Emacs 22.3. It does occur in C++ and
> ObjC modes as well. It affects indentation using either TAB or M-x
> indent-region.
> A workaround is to place the character constant(s) in parentheses.
Yuck!
> This is obviously not a serious problem, ...
I might disagree about that.
> ... but it is a somewhat annoying one which would be nice to see fixed.
OK. Would you please test the patch below, which I think fixes it. Once
you've applied the patch, please rebuild the CC Mode files as follows:
M-x byte-compile-file cc-langs.el
M-x byte-compile-file cc-engine.el
M-x byte-compile-file cc-mode.el
(This is needed because cc-{engine,mode}.el use macros contained in
cc-langs.el.) Then restart Emacs if necessary, then test your file.
Thank you indeed for such a wonderfully clear, concise and helpful bug
report!
Index: cc-engine.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/cc-engine.el,v
retrieving revision 1.76
diff -c -r1.76 cc-engine.el
*** cc-engine.el 29 Aug 2009 02:07:45 -0000 1.76
--- cc-engine.el 31 Aug 2009 19:55:19 -0000
***************
*** 1067,1074 ****
(not (eq ret 'beginning))
(looking-at c-case-kwds-regexp))
(if (< after-case:-pos start)
! (setq pos after-case:-pos)
! (setq ret 'label)))
;; Skip over the unary operators that can start the statement.
(while (progn
--- 1067,1075 ----
(not (eq ret 'beginning))
(looking-at c-case-kwds-regexp))
(if (< after-case:-pos start)
! (setq pos after-case:-pos))
! (if (eq ret 'same)
! (setq ret 'label)))
;; Skip over the unary operators that can start the statement.
(while (progn
Index: cc-langs.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/cc-langs.el,v
retrieving revision 1.67
diff -c -r1.67 cc-langs.el
*** cc-langs.el 19 May 2009 22:35:07 -0000 1.67
--- cc-langs.el 31 Aug 2009 19:55:21 -0000
***************
*** 2885,2891 ****
i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
t (concat
;; Don't allow string literals.
! "[\"']\\|"
;; All keywords except `c-label-kwds' and `c-protection-kwds'.
(c-make-keywords-re t
(set-difference (c-lang-const c-keywords)
--- 2885,2891 ----
i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
t (concat
;; Don't allow string literals.
! "\"\\|"
;; All keywords except `c-label-kwds' and `c-protection-kwds'.
(c-make-keywords-re t
(set-difference (c-lang-const c-keywords)
> Benjamin Moody
--
Alan Mackenzie (Nuremberg, Germany)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-08-31 20:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-29 20:59 bug#4289: 23.1; Incorrect indentation in C, following certain 'case' labels Benjamin Moody
2009-08-31 20:05 ` Alan Mackenzie
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.