aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1997-06-11 06:51:29 +0000
committerRichard M. Stallman1997-06-11 06:51:29 +0000
commit849f04e14de8ce4e1379d31e705f70c069fb6400 (patch)
tree5b345518af59acfd2c7676d8f24b9c281e7201e4
parentf52b232edd36b4348aafe5a922857a06eeb8f813 (diff)
downloademacs-849f04e14de8ce4e1379d31e705f70c069fb6400.tar.gz
emacs-849f04e14de8ce4e1379d31e705f70c069fb6400.zip
(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.
-rw-r--r--lisp/textmodes/fill.el64
1 files changed, 51 insertions, 13 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 47ae163cbcf..552bd4fb68c 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -76,12 +76,28 @@ reinserts the fill prefix in each resulting line."
76 :type 'boolean 76 :type 'boolean
77 :group 'fill) 77 :group 'fill)
78 78
79(defcustom adaptive-fill-regexp "[ \t]*\\([#;>*]+ +\\)?" 79(defcustom adaptive-fill-regexp "[ \t]*\\([-|#;>*]+ *\\|(?[0-9]+[.)] *\\)*"
80 "*Regexp to match text at start of line that constitutes indentation. 80 "*Regexp to match text at start of line that constitutes indentation.
81If Adaptive Fill mode is enabled, whatever text matches this pattern 81If Adaptive Fill mode is enabled, a prefix matching this pattern
82on the second line of a paragraph is used as the standard indentation 82on the first and second lines of a paragraph is used as the
83for the paragraph. If the paragraph has just one line, the indentation 83standard indentation for the whole paragraph.
84is taken from that line." 84
85If the paragraph has just one line, the indentation is taken from that
86line, but in that case `adaptive-fill-first-line-regexp' also plays
87a role."
88 :type 'regexp
89 :group 'fill)
90
91(defcustom adaptive-fill-first-line-regexp "\\`[ \t]*$`//'"
92 "*Regexp specifying whether to set fill prefix from a one-line paragraph.
93When a paragraph has just one line, then after `adaptive-fill-regexp'
94finds the prefix at the beginning of the line, if it doesn't
95match this regexp, it is replaced with whitespace.
96
97By default, this regexp matches sequences of just spaces and tabs.
98
99However, we never use a prefix from a one-line paragraph
100if it would act as a paragraph-starter on the second line."
85 :type 'regexp 101 :type 'regexp
86 :group 'fill) 102 :group 'fill)
87 103
@@ -156,9 +172,12 @@ Remove indentation from each line."
156 172
157(defun fill-context-prefix (from to &optional first-line-regexp) 173(defun fill-context-prefix (from to &optional first-line-regexp)
158 "Compute a fill prefix from the text between FROM and TO. 174 "Compute a fill prefix from the text between FROM and TO.
159This uses the variables `adaptive-fill-prefix' and `adaptive-fill-function'. 175This uses the variables `adaptive-fill-prefix' and `adaptive-fill-function'
160If FIRST-LINE-REGEXP is non-nil, then when taking a prefix from the 176and `adaptive-fill-first-line-regexp'. `paragraph-start' also plays a role;
161first line, insist it must match FIRST-LINE-REGEXP." 177we reject a prefix based on a one-line paragraph if that prefix would
178act as a paragraph-separator."
179 (or first-line-regexp
180 (setq first-line-regexp adaptive-fill-first-line-regexp))
162 (save-excursion 181 (save-excursion
163 (goto-char from) 182 (goto-char from)
164 (if (eolp) (forward-line 1)) 183 (if (eolp) (forward-line 1))
@@ -178,11 +197,30 @@ first line, insist it must match FIRST-LINE-REGEXP."
178 (cond ((and adaptive-fill-regexp (looking-at adaptive-fill-regexp)) 197 (cond ((and adaptive-fill-regexp (looking-at adaptive-fill-regexp))
179 (buffer-substring-no-properties start (match-end 0))) 198 (buffer-substring-no-properties start (match-end 0)))
180 (adaptive-fill-function (funcall adaptive-fill-function))))) 199 (adaptive-fill-function (funcall adaptive-fill-function)))))
181 (and result 200 (if at-second
182 (or at-second 201 ;; If we get a fill prefix from the second line,
183 (null first-line-regexp) 202 ;; make sure it's on the first line too.
184 (string-match first-line-regexp result)) 203 (save-excursion
185 result))))) 204 (forward-line -1)
205 (if (looking-at (regexp-quote result))
206 result))
207 ;; If we get a fill prefix from a one-line paragraph,
208 ;; maybe change it to whitespace,
209 ;; and check that it isn't a paragraph starter.
210 (if result
211 (progn
212 ;; If RESULT comes from the first line,
213 ;; see if it seems reasonable to use for all lines.
214 ;; If not, replace it with whitespace.
215 (or (and first-line-regexp
216 (string-match first-line-regexp result))
217 (and comment-start-skip
218 (string-match comment-start-skip result))
219 (setq result (make-string (string-width result) ?\ )))
220 ;; But either way, reject it if it indicates
221 ;; the start of a paragraph.
222 (if (not (eq 0 (string-match paragraph-start result)))
223 result))))))))
186 224
187(defun fill-region-as-paragraph (from to &optional justify 225(defun fill-region-as-paragraph (from to &optional justify
188 nosqueeze squeeze-after) 226 nosqueeze squeeze-after)