Mercurial > emacs
changeset 18221:5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
second line of the paragraph, verify the first line has it too.
(adaptive-fill-regexp): Allow - and |;
allow spaces within the prefix. Allow numeric headings.
(adaptive-fill-first-line-regexp): New variable.
(fill-context-prefix): Use adaptive-fill-first-line-regexp.
If prefix from first line seems unreasonable, use whitespace instead.
Reject it entirely only if it is a paragraph-starter.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 11 Jun 1997 06:51:29 +0000 |
parents | 36a61aa59b9d |
children | b7ad635feeb8 |
files | lisp/textmodes/fill.el |
diffstat | 1 files changed, 51 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/textmodes/fill.el Wed Jun 11 04:51:57 1997 +0000 +++ b/lisp/textmodes/fill.el Wed Jun 11 06:51:29 1997 +0000 @@ -76,12 +76,28 @@ :type 'boolean :group 'fill) -(defcustom adaptive-fill-regexp "[ \t]*\\([#;>*]+ +\\)?" +(defcustom adaptive-fill-regexp "[ \t]*\\([-|#;>*]+ *\\|(?[0-9]+[.)] *\\)*" "*Regexp to match text at start of line that constitutes indentation. -If Adaptive Fill mode is enabled, whatever text matches this pattern -on the second line of a paragraph is used as the standard indentation -for the paragraph. If the paragraph has just one line, the indentation -is taken from that line." +If Adaptive Fill mode is enabled, a prefix matching this pattern +on the first and second lines of a paragraph is used as the +standard indentation for the whole paragraph. + +If the paragraph has just one line, the indentation is taken from that +line, but in that case `adaptive-fill-first-line-regexp' also plays +a role." + :type 'regexp + :group 'fill) + +(defcustom adaptive-fill-first-line-regexp "\\`[ \t]*$`//'" + "*Regexp specifying whether to set fill prefix from a one-line paragraph. +When a paragraph has just one line, then after `adaptive-fill-regexp' +finds the prefix at the beginning of the line, if it doesn't +match this regexp, it is replaced with whitespace. + +By default, this regexp matches sequences of just spaces and tabs. + +However, we never use a prefix from a one-line paragraph +if it would act as a paragraph-starter on the second line." :type 'regexp :group 'fill) @@ -156,9 +172,12 @@ (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 `adaptive-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." +This uses the variables `adaptive-fill-prefix' and `adaptive-fill-function' +and `adaptive-fill-first-line-regexp'. `paragraph-start' also plays a role; +we reject a prefix based on a one-line paragraph if that prefix would +act as a paragraph-separator." + (or first-line-regexp + (setq first-line-regexp adaptive-fill-first-line-regexp)) (save-excursion (goto-char from) (if (eolp) (forward-line 1)) @@ -178,11 +197,30 @@ (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))))) + (if at-second + ;; If we get a fill prefix from the second line, + ;; make sure it's on the first line too. + (save-excursion + (forward-line -1) + (if (looking-at (regexp-quote result)) + result)) + ;; If we get a fill prefix from a one-line paragraph, + ;; maybe change it to whitespace, + ;; and check that it isn't a paragraph starter. + (if result + (progn + ;; If RESULT comes from the first line, + ;; see if it seems reasonable to use for all lines. + ;; If not, replace it with whitespace. + (or (and first-line-regexp + (string-match first-line-regexp result)) + (and comment-start-skip + (string-match comment-start-skip result)) + (setq result (make-string (string-width result) ?\ ))) + ;; But either way, reject it if it indicates + ;; the start of a paragraph. + (if (not (eq 0 (string-match paragraph-start result))) + result)))))))) (defun fill-region-as-paragraph (from to &optional justify nosqueeze squeeze-after)