aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/textmodes/fill.el34
1 files changed, 23 insertions, 11 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 85223d14f1d..f83de9f765e 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -130,24 +130,36 @@ Remove indentation from each line."
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.
135This uses the variables `adapive-fill-prefix' and `adaptive-fill-function'." 135This uses the variables `adapive-fill-prefix' and `adaptive-fill-function'.
136If FIRST-LINE-REGEXP is non-nil, then when taking a prefix from the
137first 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.