Mercurial > emacs
comparison lisp/progmodes/c-mode.el @ 12486:e2e84d24f0d4
(calculate-c-indent-after-brace): New function.
(calculate-c-indent, indent-c-exp): Use it.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 07 Jul 1995 13:29:18 +0000 |
parents | 245837225a31 |
children | dca7533ebb9e |
comparison
equal
deleted
inserted
replaced
12485:df3f81ceb780 | 12486:e2e84d24f0d4 |
---|---|
880 ;; Compensate to get the column where | 880 ;; Compensate to get the column where |
881 ;; an ordinary statement would start. | 881 ;; an ordinary statement would start. |
882 (if (= (following-char) ?\{) c-brace-offset 0))))) | 882 (if (= (following-char) ?\{) c-brace-offset 0))))) |
883 ;; If no previous statement, | 883 ;; If no previous statement, |
884 ;; indent it relative to line brace is on. | 884 ;; indent it relative to line brace is on. |
885 ;; For open brace in column zero, don't let statement | 885 (calculate-c-indent-after-brace)))))))) |
886 ;; start there too. If c-indent-level is zero, | 886 |
887 ;; use c-brace-offset + c-continued-statement-offset instead. | 887 (defun calculate-c-indent-after-brace () |
888 ;; For open-braces not the first thing in a line, | 888 "Return the proper C indent for the first line after an open-brace. |
889 ;; add in c-brace-imaginary-offset. | 889 This function is called with point before the brace." |
890 (+ (if (and (bolp) (zerop c-indent-level)) | 890 ;; For open brace in column zero, don't let statement |
891 (+ c-brace-offset c-continued-statement-offset) | 891 ;; start there too. If c-indent-level is zero, |
892 c-indent-level) | 892 ;; use c-brace-offset + c-continued-statement-offset instead. |
893 ;; Move back over whitespace before the openbrace. | 893 ;; For open-braces not the first thing in a line, |
894 ;; If openbrace is not first nonwhite thing on the line, | 894 ;; add in c-brace-imaginary-offset. |
895 ;; add the c-brace-imaginary-offset. | 895 (+ (if (and (bolp) (zerop c-indent-level)) |
896 (progn (skip-chars-backward " \t") | 896 (+ c-brace-offset c-continued-statement-offset) |
897 (if (bolp) 0 c-brace-imaginary-offset)) | 897 c-indent-level) |
898 ;; If the openbrace is preceded by a parenthesized exp, | 898 ;; Move back over whitespace before the openbrace. |
899 ;; move to the beginning of that; | 899 ;; If openbrace is not first nonwhite thing on the line, |
900 ;; possibly a different line | 900 ;; add the c-brace-imaginary-offset. |
901 (progn | 901 (progn (skip-chars-backward " \t") |
902 (if (eq (preceding-char) ?\)) | 902 (if (bolp) 0 c-brace-imaginary-offset)) |
903 (forward-sexp -1)) | 903 ;; If the openbrace is preceded by a parenthesized exp, |
904 ;; Get initial indentation of the line we are on. | 904 ;; move to the beginning of that; |
905 (current-indentation)))))))))) | 905 ;; possibly a different line |
906 (progn | |
907 (if (eq (preceding-char) ?\)) | |
908 (forward-sexp -1)) | |
909 ;; Get initial indentation of the line we are on. | |
910 (current-indentation)))) | |
906 | 911 |
907 (defun calculate-c-indent-within-comment (&optional after-star) | 912 (defun calculate-c-indent-within-comment (&optional after-star) |
908 "Return the indentation amount for line inside a block comment. | 913 "Return the indentation amount for line inside a block comment. |
909 Optional arg AFTER-STAR means, if lines in the comment have a leading star, | 914 Optional arg AFTER-STAR means, if lines in the comment have a leading star, |
910 return the indentation of the text that would follow this star." | 915 return the indentation of the text that would follow this star." |
1218 ;; Compute the standard indent for this level. | 1223 ;; Compute the standard indent for this level. |
1219 (let (val) | 1224 (let (val) |
1220 (if (= (char-after (car contain-stack)) ?{) | 1225 (if (= (char-after (car contain-stack)) ?{) |
1221 (save-excursion | 1226 (save-excursion |
1222 (goto-char (car contain-stack)) | 1227 (goto-char (car contain-stack)) |
1223 (setq val (+ c-indent-level (current-column)))) | 1228 (setq val (calculate-c-indent-after-brace))) |
1224 (setq val (calculate-c-indent | 1229 (setq val (calculate-c-indent |
1225 (if (car indent-stack) | 1230 (if (car indent-stack) |
1226 (- (car indent-stack)) | 1231 (- (car indent-stack)) |
1227 opoint)))) | 1232 opoint)))) |
1228 ;; t means we are in a block comment and should | 1233 ;; t means we are in a block comment and should |