comparison lisp/emacs-lisp/lisp-mode.el @ 48119:df3f64f68cfe

(lisp-fill-paragraph): Use match-string and line-beginning-position. Don't bother making paragraph-start a superset of paragraph-separate.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 02 Nov 2002 01:38:03 +0000
parents bd315b9fa3f0
children ebfdb0351da6
comparison
equal deleted inserted replaced
48118:40e2242be50f 48119:df3f64f68cfe
1077 (cond 1077 (cond
1078 1078
1079 ;; A line with nothing but a comment on it? 1079 ;; A line with nothing but a comment on it?
1080 ((looking-at "[ \t]*;[; \t]*") 1080 ((looking-at "[ \t]*;[; \t]*")
1081 (setq has-comment t 1081 (setq has-comment t
1082 comment-fill-prefix (buffer-substring (match-beginning 0) 1082 comment-fill-prefix (match-string 0)))
1083 (match-end 0))))
1084 1083
1085 ;; A line with some code, followed by a comment? Remember that the 1084 ;; A line with some code, followed by a comment? Remember that the
1086 ;; semi which starts the comment shouldn't be part of a string or 1085 ;; semi which starts the comment shouldn't be part of a string or
1087 ;; character. 1086 ;; character.
1088 ((let ((state (syntax-ppss (line-end-position)))) 1087 ((let ((state (syntax-ppss (line-end-position))))
1091 (looking-at ";+[\t ]*"))) 1090 (looking-at ";+[\t ]*")))
1092 (setq has-comment t has-code-and-comment t) 1091 (setq has-comment t has-code-and-comment t)
1093 (setq comment-fill-prefix 1092 (setq comment-fill-prefix
1094 (concat (make-string (/ (current-column) tab-width) ?\t) 1093 (concat (make-string (/ (current-column) tab-width) ?\t)
1095 (make-string (% (current-column) tab-width) ?\ ) 1094 (make-string (% (current-column) tab-width) ?\ )
1096 (buffer-substring (match-beginning 0) (match-end 0))))))) 1095 (match-string 0))))))
1097 1096
1098 (if (not has-comment) 1097 (if (not has-comment)
1099 ;; `paragraph-start' is set here (not in the buffer-local 1098 ;; `paragraph-start' is set here (not in the buffer-local
1100 ;; variable so that `forward-paragraph' et al work as 1099 ;; variable so that `forward-paragraph' et al work as
1101 ;; expected) so that filling (doc) strings works sensibly. 1100 ;; expected) so that filling (doc) strings works sensibly.
1129 (while (progn (forward-line 1) 1128 (while (progn (forward-line 1)
1130 (looking-at "[ \t]*;"))) 1129 (looking-at "[ \t]*;")))
1131 (point))) 1130 (point)))
1132 1131
1133 ;; Lines with only semicolons on them can be paragraph boundaries. 1132 ;; Lines with only semicolons on them can be paragraph boundaries.
1134 (let* ((paragraph-start (concat paragraph-start "\\|[ \t;]*$")) 1133 (let* ((paragraph-separate (concat paragraph-separate "\\|[ \t;]*$"))
1135 (paragraph-separate (concat paragraph-start "\\|[ \t;]*$"))
1136 (paragraph-ignore-fill-prefix nil) 1134 (paragraph-ignore-fill-prefix nil)
1137 (fill-prefix comment-fill-prefix) 1135 (fill-prefix comment-fill-prefix)
1138 (after-line (if has-code-and-comment 1136 (after-line (if has-code-and-comment
1139 (save-excursion 1137 (line-beginning-position 2)))
1140 (forward-line 1) (point))))
1141 (end (progn 1138 (end (progn
1142 (forward-paragraph) 1139 (forward-paragraph)
1143 (or (bolp) (newline 1)) 1140 (or (bolp) (newline 1))
1144 (point))) 1141 (point)))
1145 ;; If this comment starts on a line with code, 1142 ;; If this comment starts on a line with code,
1152 justify nil 1149 justify nil
1153 (save-excursion 1150 (save-excursion
1154 (goto-char beg) 1151 (goto-char beg)
1155 (if (looking-at fill-prefix) 1152 (if (looking-at fill-prefix)
1156 nil 1153 nil
1157 (re-search-forward comment-start-skip) 1154 (re-search-forward comment-start-skip))))))))
1158 (point))))))))
1159 t)) 1155 t))
1160 1156
1161 (defun indent-code-rigidly (start end arg &optional nochange-regexp) 1157 (defun indent-code-rigidly (start end arg &optional nochange-regexp)
1162 "Indent all lines of code, starting in the region, sideways by ARG columns. 1158 "Indent all lines of code, starting in the region, sideways by ARG columns.
1163 Does not affect lines starting inside comments or strings, assuming that 1159 Does not affect lines starting inside comments or strings, assuming that