aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Blandy1993-01-16 06:04:16 +0000
committerJim Blandy1993-01-16 06:04:16 +0000
commit3a65941e41fb91642792e02b6f284dcb0cca030b (patch)
treef3223042db66b0f642e208014ca3428b03a44f91
parentcf7cb199e517cc684378abe078474d1737d2663d (diff)
downloademacs-3a65941e41fb91642792e02b6f284dcb0cca030b.tar.gz
emacs-3a65941e41fb91642792e02b6f284dcb0cca030b.zip
* c-mode.el (c-switch-label-regexp): New constant.
(electric-c-terminator, c-indent-line, indent-c-exp): Use it to correctly recognize default labels in switch statements.
-rw-r--r--lisp/progmodes/c-mode.el11
1 files changed, 8 insertions, 3 deletions
diff --git a/lisp/progmodes/c-mode.el b/lisp/progmodes/c-mode.el
index 56db49bc5c5..7bdfbdf8031 100644
--- a/lisp/progmodes/c-mode.el
+++ b/lisp/progmodes/c-mode.el
@@ -127,6 +127,11 @@ If you do not want a leading newline before braces then use:
127(defconst c-tab-always-indent t 127(defconst c-tab-always-indent t
128 "*Non-nil means TAB in C mode should always reindent the current line, 128 "*Non-nil means TAB in C mode should always reindent the current line,
129regardless of where in the line point is when the TAB command is used.") 129regardless of where in the line point is when the TAB command is used.")
130
131;;; Regular expression used internally to recognize labels in switch
132;;; statements.
133(defconst c-switch-label-regexp "case[ \t'/(]\\|default\\(\\S_\\|'\\)")
134
130 135
131(defun c-mode () 136(defun c-mode ()
132 "Major mode for editing C code. 137 "Major mode for editing C code.
@@ -423,7 +428,7 @@ preserving the comment indentation or line-starting decorations."
423 ;; So quickly rule out most other uses of colon 428 ;; So quickly rule out most other uses of colon
424 ;; and do no indentation for them. 429 ;; and do no indentation for them.
425 (and (eq last-command-char ?:) 430 (and (eq last-command-char ?:)
426 (not (looking-at "case[ \t'/(]\\|default\\>")) 431 (not (looking-at c-switch-label-regexp))
427 (save-excursion 432 (save-excursion
428 (skip-chars-forward "a-zA-Z0-9_$") 433 (skip-chars-forward "a-zA-Z0-9_$")
429 (skip-chars-forward " \t") 434 (skip-chars-forward " \t")
@@ -515,7 +520,7 @@ Return the amount the indentation changed by."
515 (t 520 (t
516 (skip-chars-forward " \t") 521 (skip-chars-forward " \t")
517 (if (listp indent) (setq indent (car indent))) 522 (if (listp indent) (setq indent (car indent)))
518 (cond ((or (looking-at "case[ \t'/(]\\|default\\>") 523 (cond ((or (looking-at c-switch-label-regexp)
519 (and (looking-at "[A-Za-z]") 524 (and (looking-at "[A-Za-z]")
520 (save-excursion 525 (save-excursion
521 (forward-sexp 1) 526 (forward-sexp 1)
@@ -1079,7 +1084,7 @@ ENDPOS is encountered."
1079 (setcar indent-stack 1084 (setcar indent-stack
1080 (setq this-indent val)))) 1085 (setq this-indent val))))
1081 ;; Adjust line indentation according to its contents 1086 ;; Adjust line indentation according to its contents
1082 (if (or (looking-at "case[ \t'/(]\\|default\\>") 1087 (if (or (looking-at c-switch-label-regexp)
1083 (and (looking-at "[A-Za-z]") 1088 (and (looking-at "[A-Za-z]")
1084 (save-excursion 1089 (save-excursion
1085 (forward-sexp 1) 1090 (forward-sexp 1)