From: Richard M. Stallman Date: Sat, 18 Nov 1995 16:42:57 +0000 (+0000) Subject: (fill-context-prefix): New arg first-line-regexp. X-Git-Tag: emacs-19.34~2274 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0bcfa3ac91f3aec6e792125d24a05f17ccf0f91c;p=emacs.git (fill-context-prefix): New arg first-line-regexp. --- 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." (re-search-forward "[.?!][])}\"']*$" end t)) (insert-and-inherit ? )))) -(defun fill-context-prefix (from to) +(defun fill-context-prefix (from to &optional first-line-regexp) "Compute a fill prefix from the text between FROM and TO. -This uses the variables `adapive-fill-prefix' and `adaptive-fill-function'." +This uses the variables `adapive-fill-prefix' and `adaptive-fill-function'. +If FIRST-LINE-REGEXP is non-nil, then when taking a prefix from the +first line, insist it must match FIRST-LINE-REGEXP." (save-excursion (goto-char from) (if (eolp) (forward-line 1)) ;; Move to the second line unless there is just one. - (let ((firstline (point))) + (let ((firstline (point)) + ;; Non-nil if we are on the second line. + at-second + result) (forward-line 1) (if (>= (point) to) - (goto-char firstline))) - (move-to-left-margin) - (let ((start (point)) - (eol (save-excursion (end-of-line) (point)))) - (if (not (looking-at paragraph-start)) - (cond ((and adaptive-fill-regexp (looking-at adaptive-fill-regexp)) - (buffer-substring-no-properties start (match-end 0))) - (adaptive-fill-function (funcall adaptive-fill-function))))))) + (goto-char firstline) + (setq at-second t)) + (move-to-left-margin) + (let ((start (point)) + (eol (save-excursion (end-of-line) (point)))) + (setq result + (if (not (looking-at paragraph-start)) + (cond ((and adaptive-fill-regexp (looking-at adaptive-fill-regexp)) + (buffer-substring-no-properties start (match-end 0))) + (adaptive-fill-function (funcall adaptive-fill-function))))) + (and result + (or at-second + (null first-line-regexp) + (string-match first-line-regexp result)) + result))))) (defun fill-region-as-paragraph (from to &optional justify nosqueeze) "Fill the region as one paragraph.