Mercurial > emacs
comparison lisp/textmodes/fill.el @ 13586:292e11b5f9c6
(fill-context-prefix): New arg first-line-regexp.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 18 Nov 1995 16:42:57 +0000 |
parents | 85697e02a482 |
children | f85b6bd0f925 |
comparison
equal
deleted
inserted
replaced
13585:dc00b7be6593 | 13586:292e11b5f9c6 |
---|---|
128 (goto-char beg) | 128 (goto-char beg) |
129 (while (and (< (point) end) | 129 (while (and (< (point) end) |
130 (re-search-forward "[.?!][])}\"']*$" end t)) | 130 (re-search-forward "[.?!][])}\"']*$" end t)) |
131 (insert-and-inherit ? )))) | 131 (insert-and-inherit ? )))) |
132 | 132 |
133 (defun fill-context-prefix (from to) | 133 (defun fill-context-prefix (from to &optional first-line-regexp) |
134 "Compute a fill prefix from the text between FROM and TO. | 134 "Compute a fill prefix from the text between FROM and TO. |
135 This uses the variables `adapive-fill-prefix' and `adaptive-fill-function'." | 135 This uses the variables `adapive-fill-prefix' and `adaptive-fill-function'. |
136 If FIRST-LINE-REGEXP is non-nil, then when taking a prefix from the | |
137 first line, insist it must match FIRST-LINE-REGEXP." | |
136 (save-excursion | 138 (save-excursion |
137 (goto-char from) | 139 (goto-char from) |
138 (if (eolp) (forward-line 1)) | 140 (if (eolp) (forward-line 1)) |
139 ;; Move to the second line unless there is just one. | 141 ;; Move to the second line unless there is just one. |
140 (let ((firstline (point))) | 142 (let ((firstline (point)) |
143 ;; Non-nil if we are on the second line. | |
144 at-second | |
145 result) | |
141 (forward-line 1) | 146 (forward-line 1) |
142 (if (>= (point) to) | 147 (if (>= (point) to) |
143 (goto-char firstline))) | 148 (goto-char firstline) |
144 (move-to-left-margin) | 149 (setq at-second t)) |
145 (let ((start (point)) | 150 (move-to-left-margin) |
146 (eol (save-excursion (end-of-line) (point)))) | 151 (let ((start (point)) |
147 (if (not (looking-at paragraph-start)) | 152 (eol (save-excursion (end-of-line) (point)))) |
148 (cond ((and adaptive-fill-regexp (looking-at adaptive-fill-regexp)) | 153 (setq result |
149 (buffer-substring-no-properties start (match-end 0))) | 154 (if (not (looking-at paragraph-start)) |
150 (adaptive-fill-function (funcall adaptive-fill-function))))))) | 155 (cond ((and adaptive-fill-regexp (looking-at adaptive-fill-regexp)) |
156 (buffer-substring-no-properties start (match-end 0))) | |
157 (adaptive-fill-function (funcall adaptive-fill-function))))) | |
158 (and result | |
159 (or at-second | |
160 (null first-line-regexp) | |
161 (string-match first-line-regexp result)) | |
162 result))))) | |
151 | 163 |
152 (defun fill-region-as-paragraph (from to &optional justify nosqueeze) | 164 (defun fill-region-as-paragraph (from to &optional justify nosqueeze) |
153 "Fill the region as one paragraph. | 165 "Fill the region as one paragraph. |
154 It removes any paragraph breaks in the region and extra newlines at the end, | 166 It removes any paragraph breaks in the region and extra newlines at the end, |
155 indents and fills lines between the margins given by the | 167 indents and fills lines between the margins given by the |