Mercurial > emacs
comparison lisp/progmodes/c-mode.el @ 1804:fe2bebf150c7
* 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.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Sat, 16 Jan 1993 06:04:16 +0000 |
parents | e0463f021e2f |
children | 04fb1d3d6992 |
comparison
equal
deleted
inserted
replaced
1803:5752a95053f2 | 1804:fe2bebf150c7 |
---|---|
125 (define-key c-mode-map \"{\" 'electric-c-semi)") | 125 (define-key c-mode-map \"{\" 'electric-c-semi)") |
126 | 126 |
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, |
129 regardless of where in the line point is when the TAB command is used.") | 129 regardless 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. |
133 Expression and list commands understand all C brackets. | 138 Expression and list commands understand all C brackets. |
134 Tab indents for C code. | 139 Tab indents for C code. |
421 (or (= (following-char) ?#) | 426 (or (= (following-char) ?#) |
422 ;; Colon is special only after a label, or case .... | 427 ;; Colon is special only after a label, or case .... |
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") |
430 (< (point) end))) | 435 (< (point) end))) |
431 (progn | 436 (progn |
513 ((looking-at "[ \t]*#") | 518 ((looking-at "[ \t]*#") |
514 (setq indent 0)) | 519 (setq indent 0)) |
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) |
522 (looking-at ":")))) | 527 (looking-at ":")))) |
523 (setq indent (max 1 (+ indent c-label-offset)))) | 528 (setq indent (max 1 (+ indent c-label-offset)))) |
1077 (- (car indent-stack)) | 1082 (- (car indent-stack)) |
1078 opoint)))) | 1083 opoint)))) |
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) |
1086 (looking-at ":")))) | 1091 (looking-at ":")))) |
1087 (setq this-indent (max 1 (+ this-indent c-label-offset)))) | 1092 (setq this-indent (max 1 (+ this-indent c-label-offset)))) |