Mercurial > emacs
comparison lisp/obsolete/c-mode.el @ 41609:f1391a41ece3
fixed {}() quoting
author | Sam Steingold <sds@gnu.org> |
---|---|
date | Tue, 27 Nov 2001 17:00:12 +0000 |
parents | 45db352a0971 |
children | 5223683cd329 |
comparison
equal
deleted
inserted
replaced
41608:45db352a0971 | 41609:f1391a41ece3 |
---|---|
792 (c-backward-to-start-of-do))) | 792 (c-backward-to-start-of-do))) |
793 ;; This is a `while' that ends a do-while. | 793 ;; This is a `while' that ends a do-while. |
794 (setq indent (save-excursion | 794 (setq indent (save-excursion |
795 (c-backward-to-start-of-do) | 795 (c-backward-to-start-of-do) |
796 (current-indentation)))) | 796 (current-indentation)))) |
797 ((= (following-char) ?}) | 797 ((= (following-char) ?\}) |
798 (setq indent (- indent c-indent-level))) | 798 (setq indent (- indent c-indent-level))) |
799 ((= (following-char) ?{) | 799 ((= (following-char) ?\{) |
800 (setq indent (+ indent c-brace-offset)))))) | 800 (setq indent (+ indent c-brace-offset)))))) |
801 (skip-chars-forward " \t") | 801 (skip-chars-forward " \t") |
802 (setq shift-amt (- indent (current-column))) | 802 (setq shift-amt (- indent (current-column))) |
803 (if (zerop shift-amt) | 803 (if (zerop shift-amt) |
804 (if (> (- (point-max) pos) (point)) | 804 (if (> (- (point-max) pos) (point)) |
837 ;; Indent like the previous top level line | 837 ;; Indent like the previous top level line |
838 ;; unless that ends in a closeparen without semicolon, | 838 ;; unless that ends in a closeparen without semicolon, |
839 ;; in which case this line is the first argument decl. | 839 ;; in which case this line is the first argument decl. |
840 (goto-char indent-point) | 840 (goto-char indent-point) |
841 (skip-chars-forward " \t") | 841 (skip-chars-forward " \t") |
842 (if (= (following-char) ?{) | 842 (if (= (following-char) ?\{) |
843 0 ; Unless it starts a function body | 843 0 ; Unless it starts a function body |
844 (c-backward-to-noncomment (or parse-start (point-min))) | 844 (c-backward-to-noncomment (or parse-start (point-min))) |
845 ;; Look at previous line that's at column 0 | 845 ;; Look at previous line that's at column 0 |
846 ;; to determine whether we are in top-level decls | 846 ;; to determine whether we are in top-level decls |
847 ;; or function's arg decls. Set basic-indent accordingly. | 847 ;; or function's arg decls. Set basic-indent accordingly. |
905 ;; ;; of a function definition, | 905 ;; ;; of a function definition, |
906 ;; ;; so following line is function name. | 906 ;; ;; so following line is function name. |
907 ;; (= (current-indentation) 0)) | 907 ;; (= (current-indentation) 0)) |
908 ;; 0 c-continued-statement-offset)) | 908 ;; 0 c-continued-statement-offset)) |
909 | 909 |
910 ((/= (char-after containing-sexp) ?{) | 910 ((/= (char-after containing-sexp) ?\{) |
911 ;; line is expression, not statement: | 911 ;; line is expression, not statement: |
912 ;; indent to just after the surrounding open. | 912 ;; indent to just after the surrounding open. |
913 (goto-char (1+ containing-sexp)) | 913 (goto-char (1+ containing-sexp)) |
914 (current-column)) | 914 (current-column)) |
915 (t | 915 (t |
956 ;; as a continuation. It is probably the | 956 ;; as a continuation. It is probably the |
957 ;; end of an enum type declaration. | 957 ;; end of an enum type declaration. |
958 (save-excursion | 958 (save-excursion |
959 (goto-char indent-point) | 959 (goto-char indent-point) |
960 (skip-chars-forward " \t") | 960 (skip-chars-forward " \t") |
961 (not (= (following-char) ?})))) | 961 (not (= (following-char) ?\})))) |
962 ;; This line is continuation of preceding line's statement; | 962 ;; This line is continuation of preceding line's statement; |
963 ;; indent c-continued-statement-offset more than the | 963 ;; indent c-continued-statement-offset more than the |
964 ;; previous line of the statement. | 964 ;; previous line of the statement. |
965 (progn | 965 (progn |
966 (c-backward-to-start-of-continued-exp containing-sexp) | 966 (c-backward-to-start-of-continued-exp containing-sexp) |
967 (+ c-continued-statement-offset (current-column) | 967 (+ c-continued-statement-offset (current-column) |
968 (if (save-excursion (goto-char indent-point) | 968 (if (save-excursion (goto-char indent-point) |
969 (skip-chars-forward " \t") | 969 (skip-chars-forward " \t") |
970 (eq (following-char) ?{)) | 970 (eq (following-char) ?\{)) |
971 c-continued-brace-offset 0))) | 971 c-continued-brace-offset 0))) |
972 ;; This line starts a new statement. | 972 ;; This line starts a new statement. |
973 ;; Position following last unclosed open. | 973 ;; Position following last unclosed open. |
974 (goto-char containing-sexp) | 974 (goto-char containing-sexp) |
975 ;; Is line first statement after an open-brace? | 975 ;; Is line first statement after an open-brace? |
1122 ;; (Exception: we can skip one semicolon before getting | 1122 ;; (Exception: we can skip one semicolon before getting |
1123 ;; to a the last token of the statement, unless that token | 1123 ;; to a the last token of the statement, unless that token |
1124 ;; is a close brace.) | 1124 ;; is a close brace.) |
1125 (if (save-excursion | 1125 (if (save-excursion |
1126 (forward-sexp 1) | 1126 (forward-sexp 1) |
1127 (or (and (not first) (= (preceding-char) ?})) | 1127 (or (and (not first) (= (preceding-char) ?\})) |
1128 (search-forward ";" next-start t | 1128 (search-forward ";" next-start t |
1129 (if (and first | 1129 (if (and first |
1130 (/= (preceding-char) ?})) | 1130 (/= (preceding-char) ?\})) |
1131 2 1)))) | 1131 2 1)))) |
1132 (setq done 'fail) | 1132 (setq done 'fail) |
1133 (setq first nil) | 1133 (setq first nil) |
1134 ;; If we go too far back in the buffer, we lose. | 1134 ;; If we go too far back in the buffer, we lose. |
1135 (if (< (point) limit) | 1135 (if (< (point) limit) |
1343 (>= (car indent-stack) 0)) | 1343 (>= (car indent-stack) 0)) |
1344 nil | 1344 nil |
1345 ;; Yes. | 1345 ;; Yes. |
1346 ;; Compute the standard indent for this level. | 1346 ;; Compute the standard indent for this level. |
1347 (let (val) | 1347 (let (val) |
1348 (if (= (char-after (car contain-stack)) ?{) | 1348 (if (= (char-after (car contain-stack)) ?\{) |
1349 (save-excursion | 1349 (save-excursion |
1350 (goto-char (car contain-stack)) | 1350 (goto-char (car contain-stack)) |
1351 (setq val (calculate-c-indent-after-brace))) | 1351 (setq val (calculate-c-indent-after-brace))) |
1352 (setq val (calculate-c-indent | 1352 (setq val (calculate-c-indent |
1353 (if (car indent-stack) | 1353 (if (car indent-stack) |
1359 (setq val (calculate-c-indent-within-comment))) | 1359 (setq val (calculate-c-indent-within-comment))) |
1360 (setcar indent-stack val))) | 1360 (setcar indent-stack val))) |
1361 ;; Adjust indent of this individual line | 1361 ;; Adjust indent of this individual line |
1362 ;; based on its predecessor. | 1362 ;; based on its predecessor. |
1363 ;; Handle continuation lines, if, else, while, and so on. | 1363 ;; Handle continuation lines, if, else, while, and so on. |
1364 (if (/= (char-after (car contain-stack)) ?{) | 1364 (if (/= (char-after (car contain-stack)) ?\{) |
1365 (setq this-indent (car indent-stack)) | 1365 (setq this-indent (car indent-stack)) |
1366 ;; Line is at statement level. | 1366 ;; Line is at statement level. |
1367 ;; Is it a new statement? Is it an else? | 1367 ;; Is it a new statement? Is it an else? |
1368 ;; Find last non-comment character before this line | 1368 ;; Find last non-comment character before this line |
1369 (save-excursion | 1369 (save-excursion |
1370 (setq this-point (point)) | 1370 (setq this-point (point)) |
1371 (setq at-else (and (looking-at "else\\b") | 1371 (setq at-else (and (looking-at "else\\b") |
1372 (not (looking-at "else\\s_")))) | 1372 (not (looking-at "else\\s_")))) |
1373 (setq at-brace (= (following-char) ?{)) | 1373 (setq at-brace (= (following-char) ?\{)) |
1374 (setq at-while (and (looking-at "while\\b") | 1374 (setq at-while (and (looking-at "while\\b") |
1375 (not (looking-at "while\\s_")))) | 1375 (not (looking-at "while\\s_")))) |
1376 (if (= (following-char) ?}) | 1376 (if (= (following-char) ?\}) |
1377 (setq this-indent (car indent-stack)) | 1377 (setq this-indent (car indent-stack)) |
1378 (c-backward-to-noncomment opoint) | 1378 (c-backward-to-noncomment opoint) |
1379 (if (not (memq (preceding-char) '(0 ?\, ?\; ?} ?: ?{))) | 1379 (if (not (memq (preceding-char) '(0 ?\, ?\; ?\} ?: ?\{))) |
1380 ;; Preceding line did not end in comma or semi; | 1380 ;; Preceding line did not end in comma or semi; |
1381 ;; indent this line c-continued-statement-offset | 1381 ;; indent this line c-continued-statement-offset |
1382 ;; more than previous. | 1382 ;; more than previous. |
1383 (progn | 1383 (progn |
1384 (c-backward-to-start-of-continued-exp (car contain-stack)) | 1384 (c-backward-to-start-of-continued-exp (car contain-stack)) |
1401 (and (looking-at "[A-Za-z]") | 1401 (and (looking-at "[A-Za-z]") |
1402 (save-excursion | 1402 (save-excursion |
1403 (forward-sexp 1) | 1403 (forward-sexp 1) |
1404 (looking-at ":")))) | 1404 (looking-at ":")))) |
1405 (setq this-indent (max 1 (+ this-indent c-label-offset)))) | 1405 (setq this-indent (max 1 (+ this-indent c-label-offset)))) |
1406 (if (= (following-char) ?}) | 1406 (if (= (following-char) ?\}) |
1407 (setq this-indent (- this-indent c-indent-level))) | 1407 (setq this-indent (- this-indent c-indent-level))) |
1408 (if (= (following-char) ?{) | 1408 (if (= (following-char) ?\{) |
1409 ;; Don't move an open-brace in column 0. | 1409 ;; Don't move an open-brace in column 0. |
1410 ;; This is good when constructs such as | 1410 ;; This is good when constructs such as |
1411 ;; `extern "C" {' surround a function definition | 1411 ;; `extern "C" {' surround a function definition |
1412 ;; that should be indented as usual. | 1412 ;; that should be indented as usual. |
1413 ;; It is also good for nested functions. | 1413 ;; It is also good for nested functions. |
1435 ;; is not actually in a string or quoted. | 1435 ;; is not actually in a string or quoted. |
1436 (let ((new-state | 1436 (let ((new-state |
1437 (parse-partial-sexp beg (point) | 1437 (parse-partial-sexp beg (point) |
1438 nil nil state))) | 1438 nil nil state))) |
1439 (and (not (nth 3 new-state)) (not (nth 5 new-state)))) | 1439 (and (not (nth 3 new-state)) (not (nth 5 new-state)))) |
1440 (indent-for-comment))))))))))))) | 1440 (indent-for-comment))))))))))) |
1441 | 1441 |
1442 ;; Look at all comment-start strings in the current line after point. | 1442 ;; Look at all comment-start strings in the current line after point. |
1443 ;; Return t if one of them starts a real comment. | 1443 ;; Return t if one of them starts a real comment. |
1444 ;; This is not used yet, because indent-for-comment | 1444 ;; This is not used yet, because indent-for-comment |
1445 ;; isn't smart enough to handle the cases this can find. | 1445 ;; isn't smart enough to handle the cases this can find. |