comparison lisp/progmodes/c-mode.el @ 4201:8b53e0fa08b4

(indent-c-exp): If ENDPOS, always set OPOINT to the function start. And don'tindet a line which is past ENDPOS. Don't indent a comment on the first line if it's the only thing on that line.
author Richard M. Stallman <rms@gnu.org>
date Wed, 21 Jul 1993 08:44:36 +0000
parents a03d6cac1cd1
children 4d0dd361b49a
comparison
equal deleted inserted replaced
4200:3f5f55401364 4201:8b53e0fa08b4
967 (let (funbeg) 967 (let (funbeg)
968 ;; Find previous fcn-start. 968 ;; Find previous fcn-start.
969 (save-excursion (forward-char 1) 969 (save-excursion (forward-char 1)
970 (beginning-of-defun) 970 (beginning-of-defun)
971 (setq funbeg (point))) 971 (setq funbeg (point)))
972 (setq opoint funbeg)
972 ;; Try to find containing open, 973 ;; Try to find containing open,
973 ;; but don't scan past that fcn-start. 974 ;; but don't scan past that fcn-start.
974 (save-restriction 975 (save-restriction
975 (narrow-to-region funbeg (point)) 976 (narrow-to-region funbeg (point))
976 (condition-case nil 977 (condition-case nil
977 (save-excursion 978 (save-excursion
978 (backward-up-list 1) (point)) 979 (backward-up-list 1)
980 (point))
979 ;; We gave up: must be between fcns. 981 ;; We gave up: must be between fcns.
980 ;; Set opoint to beg of prev fcn 982 ;; Set opoint to beg of prev fcn
981 ;; since otherwise calculate-c-indent 983 ;; since otherwise calculate-c-indent
982 ;; will get wrong answers. 984 ;; will get wrong answers.
983 (error (setq opoint funbeg) 985 (error (setq opoint funbeg)
996 (save-excursion 998 (save-excursion
997 (let ((beg (point))) 999 (let ((beg (point)))
998 (and (re-search-forward 1000 (and (re-search-forward
999 comment-start-skip 1001 comment-start-skip
1000 (save-excursion (end-of-line) (point)) t) 1002 (save-excursion (end-of-line) (point)) t)
1003 ;; Make sure this isn't a comment alone on a line
1004 ;; (which should be indented like code instead).
1005 (save-excursion
1006 (goto-char (match-beginning 0))
1007 (skip-chars-backward " \t")
1008 (not (bolp)))
1001 ;; Make sure the comment starter we found 1009 ;; Make sure the comment starter we found
1002 ;; is not actually in a string or quoted. 1010 ;; is not actually in a string or quoted.
1003 (let ((new-state 1011 (let ((new-state
1004 (parse-partial-sexp beg (point) 1012 (parse-partial-sexp beg (point)
1005 nil nil state))) 1013 nil nil state)))
1058 (setcar contain-stack (or (car (cdr state)) 1066 (setcar contain-stack (or (car (cdr state))
1059 (save-excursion (forward-sexp -1) 1067 (save-excursion (forward-sexp -1)
1060 (point))))) 1068 (point)))))
1061 (forward-line 1) 1069 (forward-line 1)
1062 (skip-chars-forward " \t") 1070 (skip-chars-forward " \t")
1063 (if (eolp) 1071 ;; Don't really reindent if the line is just whitespace,
1072 ;; or if it is past the endpos.
1073 ;; (The exit test in the outer while
1074 ;; does not exit until we have passed the first line
1075 ;; past the region.)
1076 (if (or (eolp) (and endpos (>= (point) endpos)))
1064 nil 1077 nil
1065 (if (and (car indent-stack) 1078 (if (and (car indent-stack)
1066 (>= (car indent-stack) 0)) 1079 (>= (car indent-stack) 0))
1067 ;; Line is on an existing nesting level. 1080 ;; Line is on an existing nesting level.
1068 ;; Lines inside parens are handled specially. 1081 ;; Lines inside parens are handled specially.