[17971] in Athena Bugs
emacs: cc-mode brace-elseif-brace cleanup broken
daemon@ATHENA.MIT.EDU (Tom Yu)
Sat Jul 8 17:25:48 2000
Date: Sat, 8 Jul 2000 17:25:43 -0400 (EDT)
Message-Id: <200007082125.RAA22070@saint-elmos-fire.mit.edu>
To: bugs@MIT.EDU
From: Tom Yu <tlyu@MIT.EDU>
In GNU Emacs 20.3.1 (sparc-sun-solaris2.6, X toolkit)
of Mon Jul 12 1999 on whirlpool.mit.edu
configured using `configure --with-x-toolkit --sharedstatedir=/var/tmp --with-pop --with-hesiod --with-kerberos'
Please describe exactly what actions triggered the bug
and the precise symptoms of the bug:
[This is in Athena 8.3.27 Solaris]
If auto-newline state is turned on in cc-mode and c-cleanup-list
contains both brace-elseif-brace and brace-else-brace, and
c-hanging-braces-alist contains the element '(substatement-open after)
[this may actually not be required to reproduce; I don't have time to
double-check] then if you type in a piece of C code that looks like:
;;;;;;;;;;;;;;;;;;;; beg example
int
a(void)
{
if (x) {
b();
} else {
a();
}
if (x) {
a();
}
else if (y) {
;;;;;;;;;;;;;;;;;;;; end example
then the brace following the "} else if (y)" will not trigger the
brace-elseif-brace cleanup. This is due to the brace-else-brace
cleanup code's matching of the preceding "} else {" without being
wrapped in a save-excursion, causing the brace-elseif-brace cleanup to
have the wrong value of point when it does its searching.
This may have been fixed in some more recent revision of cc-mode; I
haven't checked. Anyway, a patch is included that appears to do the
right thing:
*** /usr/athena/share/emacs/20.3/lisp/progmodes/cc-cmds.el Wed Dec 16 15:00:48 1998
--- cc-cmds.el Sat Jul 8 17:06:23 2000
***************
*** 316,328 ****
(if (and c-auto-newline
(memq 'brace-else-brace c-cleanup-list)
(eq last-command-char ?\{)
! (re-search-backward "}[ \t\n]*else[ \t\n]*{" nil t)
! (progn
(setq mbeg (match-beginning 0)
mend (match-end 0))
(= mend here))
(not (c-in-literal)))
(progn
(delete-region mbeg mend)
(insert "} else {")))
;; clean up brace-elseif-brace
--- 316,329 ----
(if (and c-auto-newline
(memq 'brace-else-brace c-cleanup-list)
(eq last-command-char ?\{)
! (save-excursion
! (re-search-backward "}[ \t\n]*else[ \t\n]*{" nil t)
(setq mbeg (match-beginning 0)
mend (match-end 0))
(= mend here))
(not (c-in-literal)))
(progn
+ (goto-char mbeg)
(delete-region mbeg mend)
(insert "} else {")))
;; clean up brace-elseif-brace
***************
*** 329,336 ****
(if (and c-auto-newline
(memq 'brace-elseif-brace c-cleanup-list)
(eq last-command-char ?\{)
- (re-search-backward "}[ \t\n]*else[ \t\n]+if[ \t\n]*" nil t)
(save-excursion
(goto-char (match-end 0))
(c-safe (forward-sexp 1))
(skip-chars-forward " \t\n")
--- 330,338 ----
(if (and c-auto-newline
(memq 'brace-elseif-brace c-cleanup-list)
(eq last-command-char ?\{)
(save-excursion
+ (re-search-backward "}[ \t\n]*else[ \t\n]+if[ \t\n]*"
+ nil t)
(goto-char (match-end 0))
(c-safe (forward-sexp 1))
(skip-chars-forward " \t\n")
***************
*** 339,344 ****
--- 341,347 ----
(= here (1+ (point))))
(not (c-in-literal)))
(progn
+ (goto-char mbeg)
(delete-region mbeg mend)
(insert "} else if ")))
(goto-char (- (point-max) pos))
Recent input:
( ) DEL y ) SPC { b a r ( ) ; } i f SPC ( x ) SPC {
f o o ( ) ; } e l s e SPC { b a r ( ) ; } i f SPC (
x ) SPC { f o o ( ) ; { C-p C-a C-k } e l s e SPC i
f SPC ( y ) SPC { ESC o 5 ESC o 3 C-p ESC C-g ESC x
r e p o r t - b u TAB DEL DEL DEL TAB RET
Recent messages:
Mark set
Mismatched parentheses
End of buffer
Auto-saving...
Auto-saving...done
Mark set
End of buffer
Mismatched parentheses
Loading emacsbug...
Loading emacsbug...done