Doc fixes. Add :version to new options.
[emacs.git] / lisp / textmodes / fill.el
blobd9bf1e520d957ed15cad2b2353bba9702e008b78
1 ;;; fill.el --- fill commands for Emacs
3 ;; Copyright (C) 1985, 86, 92, 94, 95, 96, 97, 1999 Free Software Foundation, Inc.
5 ;; Keywords: wp
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
24 ;;; Commentary:
26 ;; All the commands for filling text. These are documented in the Emacs
27 ;; manual.
29 ;;; Code:
31 (defcustom fill-individual-varying-indent nil
32 "*Controls criterion for a new paragraph in `fill-individual-paragraphs'.
33 Non-nil means changing indent doesn't end a paragraph.
34 That mode can handle paragraphs with extra indentation on the first line,
35 but it requires separator lines between paragraphs.
36 A value of nil means that any change in indentation starts a new paragraph."
37 :type 'boolean
38 :group 'fill)
40 (defcustom sentence-end-double-space t
41 "*Non-nil means a single space does not end a sentence.
42 This is relevant for filling. See also `sentence-end-without-period'
43 and `colon-double-space'.
45 If you change this, you should also change `sentence-end'. See Info
46 node `Sentences'."
47 :type 'boolean
48 :group 'fill)
50 (defcustom colon-double-space nil
51 "*Non-nil means put two spaces after a colon when filling."
52 :type 'boolean
53 :group 'fill)
55 (defcustom sentence-end-without-period nil
56 "*Non-nil means a sentence will end without a period.
57 For example, a sentence in Thai text ends with double space but
58 without a period."
59 :type 'boolean
60 :group 'fill)
62 (defvar fill-paragraph-function nil
63 "Mode-specific function to fill a paragraph, or nil if there is none.
64 If the function returns nil, then `fill-paragraph' does its normal work.")
66 (defvar enable-kinsoku t
67 "*Non-nil means enable \"kinsoku\" processing on filling paragraph.
68 Kinsoku processing is designed to prevent certain characters from being
69 placed at the beginning or end of a line by filling.
70 See the documentation of `kinsoku' for more information.")
72 (defun set-fill-prefix ()
73 "Set the fill prefix to the current line up to point.
74 Filling expects lines to start with the fill prefix and
75 reinserts the fill prefix in each resulting line."
76 (interactive)
77 (setq fill-prefix (buffer-substring
78 (save-excursion (move-to-left-margin) (point))
79 (point)))
80 (if (equal fill-prefix "")
81 (setq fill-prefix nil))
82 (if fill-prefix
83 (message "fill-prefix: \"%s\"" fill-prefix)
84 (message "fill-prefix cancelled")))
86 (defcustom adaptive-fill-mode t
87 "*Non-nil means determine a paragraph's fill prefix from its text."
88 :type 'boolean
89 :group 'fill)
91 (defcustom adaptive-fill-regexp
92 (purecopy "[ \t]*\\([-|#;>*]+ *\\|(?[0-9]+[.)] *\\)*")
93 "*Regexp to match text at start of line that constitutes indentation.
94 If Adaptive Fill mode is enabled, a prefix matching this pattern
95 on the first and second lines of a paragraph is used as the
96 standard indentation for the whole paragraph.
98 If the paragraph has just one line, the indentation is taken from that
99 line, but in that case `adaptive-fill-first-line-regexp' also plays
100 a role."
101 :type 'regexp
102 :group 'fill)
104 (defcustom adaptive-fill-first-line-regexp "\\`[ \t]*\\'"
105 "*Regexp specifying whether to set fill prefix from a one-line paragraph.
106 When a paragraph has just one line, then after `adaptive-fill-regexp'
107 finds the prefix at the beginning of the line, if it doesn't
108 match this regexp, it is replaced with whitespace.
110 By default, this regexp matches sequences of just spaces and tabs.
112 However, we never use a prefix from a one-line paragraph
113 if it would act as a paragraph-starter on the second line."
114 :type 'regexp
115 :group 'fill)
117 (defcustom adaptive-fill-function nil
118 "*Function to call to choose a fill prefix for a paragraph.
119 This function is used when `adaptive-fill-regexp' does not match."
120 :type 'function
121 :group 'fill)
123 (defvar fill-indent-according-to-mode nil
124 "Whether or not filling should try to use the major mode's indentation.")
126 (defun current-fill-column ()
127 "Return the fill-column to use for this line.
128 The fill-column to use for a buffer is stored in the variable `fill-column',
129 but can be locally modified by the `right-margin' text property, which is
130 subtracted from `fill-column'.
132 The fill column to use for a line is the first column at which the column
133 number equals or exceeds the local fill-column - right-margin difference."
134 (save-excursion
135 (if fill-column
136 (let* ((here (progn (beginning-of-line) (point)))
137 (here-col 0)
138 (eol (progn (end-of-line) (point)))
139 margin fill-col change col)
140 ;; Look separately at each region of line with a different
141 ;; right-margin.
142 (while (and (setq margin (get-text-property here 'right-margin)
143 fill-col (- fill-column (or margin 0))
144 change (text-property-not-all
145 here eol 'right-margin margin))
146 (progn (goto-char (1- change))
147 (setq col (current-column))
148 (< col fill-col)))
149 (setq here change
150 here-col col))
151 (max here-col fill-col)))))
153 (defun canonically-space-region (beg end)
154 "Remove extra spaces between words in region.
155 Leave one space between words, two at end of sentences or after colons
156 \(depending on values of `sentence-end-double-space', `colon-double-space',
157 and `sentence-end-without-period').
158 Remove indentation from each line."
159 (interactive "*r")
160 (save-excursion
161 (goto-char beg)
162 ;; Nuke tabs; they get screwed up in a fill.
163 ;; This is quick, but loses when a tab follows the end of a sentence.
164 ;; Actually, it is difficult to tell that from "Mr.\tSmith".
165 ;; Blame the typist.
166 (subst-char-in-region beg end ?\t ?\ )
167 (while (and (< (point) end)
168 (re-search-forward " *" end t))
169 (delete-region
170 (+ (match-beginning 0)
171 ;; Determine number of spaces to leave:
172 (save-excursion
173 (skip-chars-backward " ]})\"'")
174 (cond ((and sentence-end-double-space
175 (or (memq (preceding-char) '(?. ?? ?!))
176 (and sentence-end-without-period
177 (= (char-syntax (preceding-char)) ?w)))) 2)
178 ((and colon-double-space
179 (= (preceding-char) ?:)) 2)
180 ((char-equal (preceding-char) ?\n) 0)
181 (t 1))))
182 (match-end 0)))
183 ;; Make sure sentences ending at end of line get an extra space.
184 ;; loses on split abbrevs ("Mr.\nSmith")
185 (goto-char beg)
186 (let ((eol-double-space-re (if colon-double-space
187 "[.?!:][])}\"']*$"
188 "[.?!][])}\"']*$")))
189 (while (and (< (point) end)
190 (re-search-forward eol-double-space-re end t))
191 ;; We insert before markers in case a caller such as
192 ;; do-auto-fill has done a save-excursion with point at the end
193 ;; of the line and wants it to stay at the end of the line.
194 (insert-before-markers-and-inherit ? )))))
196 (defun fill-common-string-prefix (s1 s2)
197 "Return the longest common prefix of strings S1 and S2, or nil if none."
198 (let ((cmp (compare-strings s1 nil nil s2 nil nil)))
199 (if (eq cmp t)
201 (setq cmp (1- (abs cmp)))
202 (unless (zerop cmp)
203 (substring s1 0 cmp)))))
205 (defun fill-context-prefix (from to &optional first-line-regexp)
206 "Compute a fill prefix from the text between FROM and TO.
207 This uses the variables `adaptive-fill-regexp' and `adaptive-fill-function'
208 and `adaptive-fill-first-line-regexp'. `paragraph-start' also plays a role;
209 we reject a prefix based on a one-line paragraph if that prefix would
210 act as a paragraph-separator."
211 (or first-line-regexp
212 (setq first-line-regexp adaptive-fill-first-line-regexp))
213 (save-excursion
214 (goto-char from)
215 (if (eolp) (forward-line 1))
216 ;; Move to the second line unless there is just one.
217 (let ((firstline (point))
218 first-line-prefix
219 ;; Non-nil if we are on the second line.
220 at-second
221 second-line-prefix
222 start)
223 (move-to-left-margin)
224 (setq start (point))
225 (setq first-line-prefix
226 (cond ((looking-at paragraph-start) nil)
227 ((and adaptive-fill-regexp (looking-at adaptive-fill-regexp))
228 (buffer-substring-no-properties start (match-end 0)))
229 (adaptive-fill-function (funcall adaptive-fill-function))))
230 (forward-line 1)
231 (if (>= (point) to)
232 (goto-char firstline)
233 (setq at-second t)
234 (move-to-left-margin)
235 (setq start (point))
236 (setq second-line-prefix
237 (cond ((looking-at paragraph-start) nil)
238 ((and adaptive-fill-regexp
239 (looking-at adaptive-fill-regexp))
240 (buffer-substring-no-properties start (match-end 0)))
241 (adaptive-fill-function
242 (funcall adaptive-fill-function)))))
243 (if at-second
244 ;; If we get a fill prefix from the second line,
245 ;; make sure it or something compatible is on the first line too.
246 (and second-line-prefix first-line-prefix
247 ;; If the first line has the second line prefix too, use it.
248 (if (or (string-match (concat "\\`"
249 (regexp-quote second-line-prefix)
250 "\\(\\'\\|[ \t]\\)")
251 first-line-prefix)
252 ;; If the second line prefix is whitespace, use it.
253 (string-match "\\`[ \t]+\\'" second-line-prefix))
254 second-line-prefix
256 ;; If using the common prefix of first-line-prefix
257 ;; and second-line-prefix leads to problems, consider
258 ;; to restore the code below that's commented out,
259 ;; and document why a common prefix cannot be used.
261 ; ;; If the second line has the first line prefix,
262 ; ;; plus whitespace, use the part that the first line shares.
263 ; (if (string-match (concat "\\`"
264 ; (regexp-quote first-line-prefix)
265 ; "[ \t]*\\'")
266 ; second-line-prefix)
267 ; first-line-prefix)))
269 ;; Use the longest common substring of both prefixes,
270 ;; if there is one.
271 (fill-common-string-prefix first-line-prefix
272 second-line-prefix)))
273 ;; If we get a fill prefix from a one-line paragraph,
274 ;; maybe change it to whitespace,
275 ;; and check that it isn't a paragraph starter.
276 (if first-line-prefix
277 (let ((result
278 ;; If first-line-prefix comes from the first line,
279 ;; see if it seems reasonable to use for all lines.
280 ;; If not, replace it with whitespace.
281 (if (or (and first-line-regexp
282 (string-match first-line-regexp
283 first-line-prefix))
284 (and comment-start-skip
285 (string-match comment-start-skip
286 first-line-prefix)))
287 first-line-prefix
288 (make-string (string-width first-line-prefix) ?\ ))))
289 ;; But either way, reject it if it indicates the start
290 ;; of a paragraph when text follows it.
291 (if (not (eq 0 (string-match paragraph-start
292 (concat result "a"))))
293 result)))))))
295 (defvar fill-nobreak-predicate nil
296 "If non-nil, a predicate for recognizing places not to break a line.
297 The predicate is called with no arguments, with point at the place
298 to be tested. If it returns t, fill commands do not break the line there.")
300 ;; Put `fill-find-break-point-function' property to charsets which
301 ;; require special functions to find line breaking point.
302 (let ((alist '((katakana-jisx0201 . kinsoku)
303 (chinese-gb2312 . kinsoku)
304 (japanese-jisx0208 . kinsoku)
305 (japanese-jisx0212 . kinsoku)
306 (chinese-big5-1 . kinsoku)
307 (chinese-big5-2 . kinsoku))))
308 (while alist
309 (put-charset-property (car (car alist)) 'fill-find-break-point-function
310 (cdr (car alist)))
311 (setq alist (cdr alist))))
313 (defun fill-find-break-point (limit)
314 "Move point to a proper line breaking position of the current line.
315 Don't move back past the buffer position LIMIT.
317 This function is called when we are going to break the current line
318 after or before a non-ascii character. If the charset of the
319 character has the property `fill-find-break-point-function', this
320 function calls the property value as a function with one arg LINEBEG.
321 If the charset has no such property, do nothing."
322 (let* ((ch (following-char))
323 (charset (char-charset ch))
324 func)
325 (if (eq charset 'ascii)
326 (setq ch (preceding-char)
327 charset (char-charset ch)))
328 (if (charsetp charset)
329 (setq func
330 (get-charset-property charset 'fill-find-break-point-function)))
331 (if (and func (fboundp func))
332 (funcall func limit))))
334 (defun fill-region-as-paragraph (from to &optional justify
335 nosqueeze squeeze-after)
336 "Fill the region as one paragraph.
337 It removes any paragraph breaks in the region and extra newlines at the end,
338 indents and fills lines between the margins given by the
339 `current-left-margin' and `current-fill-column' functions.
340 \(In most cases, the variable `fill-column' controls the width.)
341 It leaves point at the beginning of the line following the paragraph.
343 Normally performs justification according to the `current-justification'
344 function, but with a prefix arg, does full justification instead.
346 From a program, optional third arg JUSTIFY can specify any type of
347 justification. Fourth arg NOSQUEEZE non-nil means not to make spaces
348 between words canonical before filling. Fifth arg SQUEEZE-AFTER, if non-nil,
349 means don't canonicalize spaces before that position.
351 Return the fill-prefix used for filling.
353 If `sentence-end-double-space' is non-nil, then period followed by one
354 space does not end a sentence, so don't break a line there."
355 (interactive (progn
356 (barf-if-buffer-read-only)
357 (list (region-beginning) (region-end)
358 (if current-prefix-arg 'full))))
359 (unless (memq justify '(t nil none full center left right))
360 (setq justify 'full))
361 ;; Arrange for undoing the fill to restore point.
362 (if (and buffer-undo-list (not (eq buffer-undo-list t)))
363 (setq buffer-undo-list (cons (point) buffer-undo-list)))
365 ;; Make sure "to" is the endpoint.
366 (goto-char (min from to))
367 (setq to (max from to))
368 ;; Ignore blank lines at beginning of region.
369 (skip-chars-forward " \t\n")
371 (let ((from-plus-indent (point))
372 (oneleft nil))
374 (beginning-of-line)
375 (setq from (point))
377 ;; Delete all but one soft newline at end of region.
378 ;; And leave TO before that one.
379 (goto-char to)
380 (while (and (> (point) from) (eq ?\n (char-after (1- (point)))))
381 (if (and oneleft
382 (not (and use-hard-newlines
383 (get-text-property (1- (point)) 'hard))))
384 (delete-backward-char 1)
385 (backward-char 1)
386 (setq oneleft t)))
387 (setq to (point))
388 ;; ;; If there was no newline, and there is text in the paragraph, then
389 ;; ;; create a newline.
390 ;; (if (and (not oneleft) (> to from-plus-indent))
391 ;; (newline))
392 (goto-char from-plus-indent))
394 (if (not (> to (point)))
395 nil ; There is no paragraph, only whitespace: exit now.
397 (or justify (setq justify (current-justification)))
399 ;; Don't let Adaptive Fill mode alter the fill prefix permanently.
400 (let ((fill-prefix fill-prefix))
401 ;; Figure out how this paragraph is indented, if desired.
402 (if (and adaptive-fill-mode
403 (or (null fill-prefix) (string= fill-prefix "")))
404 (setq fill-prefix (fill-context-prefix from to)))
406 (save-restriction
407 (goto-char from)
408 (beginning-of-line)
409 (narrow-to-region (point) to)
411 (if (not justify) ; filling disabled: just check indentation
412 (progn
413 (goto-char from)
414 (while (not (eobp))
415 (if (and (not (eolp))
416 (< (current-indentation) (current-left-margin)))
417 (indent-to-left-margin))
418 (forward-line 1)))
420 (if use-hard-newlines
421 (remove-text-properties from (point-max) '(hard nil)))
422 ;; Make sure first line is indented (at least) to left margin...
423 (if (or (memq justify '(right center))
424 (< (current-indentation) (current-left-margin)))
425 (indent-to-left-margin))
426 ;; Delete the fill prefix from every line except the first.
427 ;; The first line may not even have a fill prefix.
428 (goto-char from)
429 (let ((fpre (and fill-prefix (not (equal fill-prefix ""))
430 (concat "[ \t]*"
431 (regexp-quote fill-prefix)
432 "[ \t]*"))))
433 (and fpre
434 (progn
435 (if (>= (+ (current-left-margin) (length fill-prefix))
436 (current-fill-column))
437 (error "fill-prefix too long for specified width"))
438 (goto-char from)
439 (forward-line 1)
440 (while (not (eobp))
441 (if (looking-at fpre)
442 (delete-region (point) (match-end 0)))
443 (forward-line 1))
444 (goto-char from)
445 (if (looking-at fpre)
446 (goto-char (match-end 0)))
447 (setq from (point)))))
448 ;; Remove indentation from lines other than the first.
449 (beginning-of-line 2)
450 (indent-region (point) (point-max) 0)
451 (goto-char from)
453 ;; FROM, and point, are now before the text to fill,
454 ;; but after any fill prefix on the first line.
456 ;; Make sure sentences ending at end of line get an extra space.
457 ;; loses on split abbrevs ("Mr.\nSmith")
458 (let ((eol-double-space-re (if colon-double-space
459 "[.?!:][])}\"']*$"
460 "[.?!][])}\"']*$")))
461 (while (re-search-forward eol-double-space-re nil t)
462 (or (eobp) (insert-and-inherit ?\ ))))
464 (goto-char from)
465 (if enable-multibyte-characters
466 ;; Delete unnecessay newlines surrounded by words. The
467 ;; character category `|' means that we can break a line
468 ;; at the character. And, charset property
469 ;; `nospace-between-words' tells how to concatenate
470 ;; words. If the value is non-nil, never put spaces
471 ;; between words, thus delete a newline between them.
472 ;; If the value is nil, delete a newline only when a
473 ;; character preceding a newline has text property
474 ;; `nospace-between-words'.
475 (while (search-forward "\n" nil t)
476 (let ((prev (char-before (match-beginning 0)))
477 (next (following-char)))
478 (if (and (or (aref (char-category-set next) ?|)
479 (aref (char-category-set prev) ?|))
480 (or (get-charset-property (char-charset prev)
481 'nospace-between-words)
482 (get-text-property (1- (match-beginning 0))
483 'nospace-between-words)))
484 (delete-char -1)))))
486 (goto-char from)
487 (skip-chars-forward " \t")
488 ;; Then change all newlines to spaces.
489 (subst-char-in-region from (point-max) ?\n ?\ )
490 (if (and nosqueeze (not (eq justify 'full)))
492 (canonically-space-region (or squeeze-after (point)) (point-max))
493 (goto-char (point-max))
494 (delete-horizontal-space)
495 (insert-and-inherit " "))
496 (goto-char (point-min))
498 ;; This is the actual filling loop.
499 (let ((prefixcol 0) linebeg)
500 (while (not (eobp))
501 (setq linebeg (point))
502 (move-to-column (1+ (current-fill-column)))
503 (if (eobp)
504 (or nosqueeze (delete-horizontal-space))
505 ;; Move back to the point where we can break the line
506 ;; at. We break the line between word or after/before
507 ;; the character which has character category `|'. We
508 ;; search space, \c| followed by a character, or \c|
509 ;; following a character. If not found, place
510 ;; the point at linebeg.
511 (if (re-search-backward " \\|\\c|.\\|.\\c|" linebeg 0)
512 ;; In case of space, we place the point at next to
513 ;; the point where the break occurs acutually,
514 ;; because we don't want to change the following
515 ;; logic of original Emacs. In case of \c|, the
516 ;; point is at the place where the break occurs.
517 (forward-char 1))
518 ;; Don't break after a period followed by just one space.
519 ;; Move back to the previous place to break.
520 ;; The reason is that if a period ends up at the end of a line,
521 ;; further fills will assume it ends a sentence.
522 ;; If we now know it does not end a sentence,
523 ;; avoid putting it at the end of the line.
524 (while (or (and sentence-end-double-space
525 (> (point) (+ linebeg 2))
526 (eq (preceding-char) ?\ )
527 (not (eq (following-char) ?\ ))
528 (eq (char-after (- (point) 2)) ?\.)
529 (progn (forward-char -2) t))
530 (and fill-nobreak-predicate
531 (funcall fill-nobreak-predicate)
532 (goto-char (match-beginning 0))))
533 (if (re-search-backward " \\|\\c|.\\|.\\c|" linebeg 0)
534 (forward-char 1)))
535 ;; If the left margin and fill prefix by themselves
536 ;; pass the fill-column. or if they are zero
537 ;; but we have no room for even one word,
538 ;; keep at least one word or a character which has
539 ;; category `|'anyway .
540 ;; This handles ALL BUT the first line of the paragraph.
541 (if (if (zerop prefixcol)
542 (save-excursion
543 (skip-chars-backward " \t" linebeg)
544 (bolp))
545 (>= prefixcol (current-column)))
546 ;; Ok, skip at least one word or one \c| character.
547 ;; Meanwhile, don't stop at a period followed by one space.
548 (let ((first t))
549 (move-to-column prefixcol)
550 (while (and (not (eobp))
551 (or first
552 (and (not (bobp))
553 sentence-end-double-space
554 (save-excursion
555 (forward-char -1)
556 (and (looking-at "\\. ")
557 (not (looking-at "\\. ")))))
558 (and fill-nobreak-predicate
559 (funcall fill-nobreak-predicate))))
560 ;; Find a breakable point while ignoring the
561 ;; following spaces.
562 (skip-chars-forward " \t")
563 (if (looking-at "\\c|")
564 (forward-char 1)
565 (let ((pos (save-excursion
566 (skip-chars-forward "^ \n\t")
567 (point))))
568 (if (re-search-forward "\\c|" pos t)
569 (forward-char -1)
570 (goto-char pos))))
571 (setq first nil)))
572 ;; Normally, move back over the single space between
573 ;; the words.
574 (if (= (preceding-char) ?\ ) (forward-char -1))
576 (if enable-multibyte-characters
577 ;; If we are going to break the line after or
578 ;; before a non-ascii character, we may have to
579 ;; run a special function for the charset of the
580 ;; character to find the correct break point.
581 (if (not (and (eq (charset-after (1- (point))) 'ascii)
582 (eq (charset-after (point)) 'ascii)))
583 ;; Make sure we take SOMETHING after the
584 ;; fill prefix if any.
585 (fill-find-break-point
586 (save-excursion
587 (goto-char linebeg)
588 (move-to-column prefixcol)
589 (point))))))
591 ;; If the left margin and fill prefix by themselves
592 ;; pass the fill-column, keep at least one word.
593 ;; This handles the first line of the paragraph.
594 (if (and (zerop prefixcol)
595 (let ((fill-point (point)) nchars)
596 (save-excursion
597 (move-to-left-margin)
598 (setq nchars (- fill-point (point)))
599 (or (< nchars 0)
600 (and fill-prefix
601 (< nchars (length fill-prefix))
602 (string= (buffer-substring (point)
603 fill-point)
604 (substring fill-prefix
605 0 nchars)))))))
606 ;; Ok, skip at least one word. But
607 ;; don't stop at a period followed by just one space.
608 (let ((first t))
609 (while (and (not (eobp))
610 (or first
611 (and (not (bobp))
612 sentence-end-double-space
613 (save-excursion
614 (forward-char -1)
615 (and (looking-at "\\. ")
616 (not (looking-at "\\. ")))))
617 (and fill-nobreak-predicate
618 (funcall fill-nobreak-predicate))))
619 ;; Find a breakable point while ignoring the
620 ;; following spaces.
621 (skip-chars-forward " \t")
622 (if (looking-at "\\c|")
623 (forward-char 1)
624 (let ((pos (save-excursion
625 (skip-chars-forward "^ \n\t")
626 (point))))
627 (if (re-search-forward "\\c|" pos t)
628 (forward-char -1)
629 (goto-char pos))))
630 (setq first nil))))
631 ;; Check again to see if we got to the end of the paragraph.
632 (if (save-excursion (skip-chars-forward " \t") (eobp))
633 (or nosqueeze (delete-horizontal-space))
634 ;; Replace whitespace here with one newline, then
635 ;; indent to left margin.
636 (skip-chars-backward " \t")
637 (if (and (= (following-char) ?\ )
638 (or (aref (char-category-set (preceding-char)) ?|)
639 (looking-at "[ \t]+\\c|")))
640 ;; We need one space at end of line so that
641 ;; further filling won't delete it. NOTE: We
642 ;; intentionally leave this one space to
643 ;; distingush the case that user wants to put
644 ;; space between \c| characters.
645 (forward-char 1))
646 (insert ?\n)
647 ;; Give newline the properties of the space(s) it replaces
648 (set-text-properties (1- (point)) (point)
649 (text-properties-at (point)))
650 (if (or fill-prefix
651 (not fill-indent-according-to-mode)
652 (memq indent-line-function
653 ;; Brain dead "indenting" functions.
654 '(indent-relative-maybe indent-relative)))
655 (indent-to-left-margin)
656 (indent-according-to-mode))
657 ;; Insert the fill prefix after indentation.
658 ;; Set prefixcol so whitespace in the prefix won't get lost.
659 (and fill-prefix (not (equal fill-prefix ""))
660 (progn
661 (insert-and-inherit fill-prefix)
662 (setq prefixcol (current-column))))))
663 ;; Justify the line just ended, if desired.
664 (if justify
665 (if (save-excursion (skip-chars-forward " \t") (eobp))
666 (progn
667 (delete-horizontal-space)
668 (justify-current-line justify t t))
669 (forward-line -1)
670 (justify-current-line justify nil t)
671 (forward-line 1))))))
672 ;; Leave point after final newline.
673 (goto-char (point-max)))
674 (unless (eobp)
675 (forward-char 1))
676 ;; Return the fill-prefix we used
677 fill-prefix)))
679 (defsubst skip-line-prefix (prefix)
680 "If point is inside the string PREFIX at the beginning of line, move past it."
681 (when (and prefix
682 (< (- (point) (line-beginning-position)) (length prefix))
683 (save-excursion
684 (beginning-of-line)
685 (looking-at (regexp-quote prefix))))
686 (goto-char (match-end 0))))
688 (defun fill-paragraph (arg)
689 "Fill paragraph at or after point. Prefix arg means justify as well.
690 If `sentence-end-double-space' is non-nil, then period followed by one
691 space does not end a sentence, so don't break a line there.
692 the variable `fill-column' controls the width for filling.
694 If `fill-paragraph-function' is non-nil, we call it (passing our
695 argument to it), and if it returns non-nil, we simply return its value.
697 If `fill-paragraph-function' is nil, return the fill-prefix used for filling."
698 (interactive (progn
699 (barf-if-buffer-read-only)
700 (list (if current-prefix-arg 'full))))
701 (or (and fill-paragraph-function
702 (let ((function fill-paragraph-function)
703 fill-paragraph-function)
704 (funcall function arg)))
705 (let ((before (point))
706 ;; Fill prefix used for filling the paragraph
707 fill-pfx
708 ;; If fill-paragraph is called recursively,
709 ;; don't give fill-paragraph-function a second chance.
710 fill-paragraph-function)
711 (save-excursion
712 (forward-paragraph)
713 (or (bolp) (newline 1))
714 (let ((end (point))
715 (beg (progn (backward-paragraph) (point))))
716 (goto-char before)
717 (setq fill-pfx
718 (if use-hard-newlines
719 ;; Can't use fill-region-as-paragraph, since this
720 ;; paragraph may still contain hard newlines. See
721 ;; fill-region.
722 (fill-region beg end arg)
723 (fill-region-as-paragraph beg end arg)))))
724 ;; See if point ended up inside the fill-prefix, and if so, move
725 ;; past it.
726 (skip-line-prefix fill-pfx)
727 fill-pfx)))
729 (defun fill-region (from to &optional justify nosqueeze to-eop)
730 "Fill each of the paragraphs in the region.
731 A prefix arg means justify as well.
732 Ordinarily the variable `fill-column' controls the width.
734 Noninteractively, the third argument JUSTIFY specifies which
735 kind of justification to do: `full', `left', `right', `center',
736 or `none' (equivalent to nil). t means handle each paragraph
737 as specified by its text properties.
739 The fourth arg NOSQUEEZE non-nil means to leave
740 whitespace other than line breaks untouched, and fifth arg TO-EOP
741 non-nil means to keep filling to the end of the paragraph (or next
742 hard newline, if `use-hard-newlines' is on).
744 Return the fill-prefix used for filling the last paragraph.
746 If `sentence-end-double-space' is non-nil, then period followed by one
747 space does not end a sentence, so don't break a line there."
748 (interactive (progn
749 (barf-if-buffer-read-only)
750 (list (region-beginning) (region-end)
751 (if current-prefix-arg 'full))))
752 (unless (memq justify '(t nil none full center left right))
753 (setq justify 'full))
754 (let (end beg fill-pfx)
755 (save-restriction
756 (goto-char (max from to))
757 (if to-eop
758 (progn (skip-chars-backward "\n")
759 (forward-paragraph)))
760 (setq end (point))
761 (goto-char (setq beg (min from to)))
762 (beginning-of-line)
763 (narrow-to-region (point) end)
764 (while (not (eobp))
765 (let ((initial (point))
766 end)
767 ;; If using hard newlines, break at every one for filling
768 ;; purposes rather than using paragraph breaks.
769 (if use-hard-newlines
770 (progn
771 (while (and (setq end (text-property-any (point) (point-max)
772 'hard t))
773 (not (= ?\n (char-after end)))
774 (not (= end (point-max))))
775 (goto-char (1+ end)))
776 (setq end (if end (min (point-max) (1+ end)) (point-max)))
777 (goto-char initial))
778 (forward-paragraph 1)
779 (setq end (point))
780 (forward-paragraph -1))
781 (if (< (point) beg)
782 (goto-char beg))
783 (if (>= (point) initial)
784 (setq fill-pfx
785 (fill-region-as-paragraph (point) end justify nosqueeze))
786 (goto-char end))))
787 fill-pfx)))
790 (defcustom default-justification 'left
791 "*Method of justifying text not otherwise specified.
792 Possible values are `left', `right', `full', `center', or `none'.
793 The requested kind of justification is done whenever lines are filled.
794 The `justification' text-property can locally override this variable.
795 This variable automatically becomes buffer-local when set in any fashion."
796 :type '(choice (const left)
797 (const right)
798 (const full)
799 (const center)
800 (const none))
801 :group 'fill)
802 (make-variable-buffer-local 'default-justification)
804 (defun current-justification ()
805 "How should we justify this line?
806 This returns the value of the text-property `justification',
807 or the variable `default-justification' if there is no text-property.
808 However, it returns nil rather than `none' to mean \"don't justify\"."
809 (let ((j (or (get-text-property
810 ;; Make sure we're looking at paragraph body.
811 (save-excursion (skip-chars-forward " \t")
812 (if (and (eobp) (not (bobp)))
813 (1- (point)) (point)))
814 'justification)
815 default-justification)))
816 (if (eq 'none j)
818 j)))
820 (defun set-justification (begin end value &optional whole-par)
821 "Set the region's justification style.
822 The kind of justification to use is prompted for.
823 If the mark is not active, this command operates on the current paragraph.
824 If the mark is active, the region is used. However, if the beginning and end
825 of the region are not at paragraph breaks, they are moved to the beginning and
826 end of the paragraphs they are in.
827 If `use-hard-newlines' is true, all hard newlines are taken to be paragraph
828 breaks.
830 When calling from a program, operates just on region between BEGIN and END,
831 unless optional fourth arg WHOLE-PAR is non-nil. In that case bounds are
832 extended to include entire paragraphs as in the interactive command."
833 (interactive (list (if mark-active (region-beginning) (point))
834 (if mark-active (region-end) (point))
835 (let ((s (completing-read
836 "Set justification to: "
837 '(("left") ("right") ("full")
838 ("center") ("none"))
839 nil t)))
840 (if (equal s "") (error ""))
841 (intern s))
843 (save-excursion
844 (save-restriction
845 (if whole-par
846 (let ((paragraph-start (if use-hard-newlines "." paragraph-start))
847 (paragraph-ignore-fill-prefix (if use-hard-newlines t
848 paragraph-ignore-fill-prefix)))
849 (goto-char begin)
850 (while (and (bolp) (not (eobp))) (forward-char 1))
851 (backward-paragraph)
852 (setq begin (point))
853 (goto-char end)
854 (skip-chars-backward " \t\n" begin)
855 (forward-paragraph)
856 (setq end (point))))
858 (narrow-to-region (point-min) end)
859 (unjustify-region begin (point-max))
860 (put-text-property begin (point-max) 'justification value)
861 (fill-region begin (point-max) nil t))))
863 (defun set-justification-none (b e)
864 "Disable automatic filling for paragraphs in the region.
865 If the mark is not active, this applies to the current paragraph."
866 (interactive (list (if mark-active (region-beginning) (point))
867 (if mark-active (region-end) (point))))
868 (set-justification b e 'none t))
870 (defun set-justification-left (b e)
871 "Make paragraphs in the region left-justified.
872 This is usually the default, but see the variable `default-justification'.
873 If the mark is not active, this applies to the current paragraph."
874 (interactive (list (if mark-active (region-beginning) (point))
875 (if mark-active (region-end) (point))))
876 (set-justification b e 'left t))
878 (defun set-justification-right (b e)
879 "Make paragraphs in the region right-justified:
880 Flush at the right margin and ragged on the left.
881 If the mark is not active, this applies to the current paragraph."
882 (interactive (list (if mark-active (region-beginning) (point))
883 (if mark-active (region-end) (point))))
884 (set-justification b e 'right t))
886 (defun set-justification-full (b e)
887 "Make paragraphs in the region fully justified:
888 This makes lines flush on both margins by inserting spaces between words.
889 If the mark is not active, this applies to the current paragraph."
890 (interactive (list (if mark-active (region-beginning) (point))
891 (if mark-active (region-end) (point))))
892 (set-justification b e 'full t))
894 (defun set-justification-center (b e)
895 "Make paragraphs in the region centered.
896 If the mark is not active, this applies to the current paragraph."
897 (interactive (list (if mark-active (region-beginning) (point))
898 (if mark-active (region-end) (point))))
899 (set-justification b e 'center t))
901 ;; A line has up to six parts:
903 ;; >>> hello.
904 ;; [Indent-1][FP][ Indent-2 ][text][trailing whitespace][newline]
906 ;; "Indent-1" is the left-margin indentation; normally it ends at column
907 ;; given by the `current-left-margin' function.
908 ;; "FP" is the fill-prefix. It can be any string, including whitespace.
909 ;; "Indent-2" is added to justify a line if the `current-justification' is
910 ;; `center' or `right'. In `left' and `full' justification regions, any
911 ;; whitespace there is part of the line's text, and should not be changed.
912 ;; Trailing whitespace is not counted as part of the line length when
913 ;; center- or right-justifying.
915 ;; All parts of the line are optional, although the final newline can
916 ;; only be missing on the last line of the buffer.
918 (defun justify-current-line (&optional how eop nosqueeze)
919 "Do some kind of justification on this line.
920 Normally does full justification: adds spaces to the line to make it end at
921 the column given by `current-fill-column'.
922 Optional first argument HOW specifies alternate type of justification:
923 it can be `left', `right', `full', `center', or `none'.
924 If HOW is t, will justify however the `current-justification' function says to.
925 If HOW is nil or missing, full justification is done by default.
926 Second arg EOP non-nil means that this is the last line of the paragraph, so
927 it will not be stretched by full justification.
928 Third arg NOSQUEEZE non-nil means to leave interior whitespace unchanged,
929 otherwise it is made canonical."
930 (interactive "*")
931 (if (eq t how) (setq how (or (current-justification) 'none))
932 (if (null how) (setq how 'full)
933 (or (memq how '(none left right center))
934 (setq how 'full))))
935 (or (memq how '(none left)) ; No action required for these.
936 (let ((fc (current-fill-column))
937 (pos (point-marker))
938 fp-end ; point at end of fill prefix
939 beg ; point at beginning of line's text
940 end ; point at end of line's text
941 indent ; column of `beg'
942 endcol ; column of `end'
943 ncols ; new indent point or offset
944 (nspaces 0) ; number of spaces between words
945 ; in line (not space characters)
946 fracspace ; fractional amount of space to be
947 ; added between each words
948 (curr-fracspace 0) ; current fractional space amount
949 count)
950 (end-of-line)
951 ;; Check if this is the last line of the paragraph.
952 (if (and use-hard-newlines (null eop)
953 (get-text-property (point) 'hard))
954 (setq eop t))
955 (skip-chars-backward " \t")
956 ;; Quick exit if it appears to be properly justified already
957 ;; or there is no text.
958 (if (or (bolp)
959 (and (memq how '(full right))
960 (= (current-column) fc)))
962 (setq end (point))
963 (beginning-of-line)
964 (skip-chars-forward " \t")
965 ;; Skip over fill-prefix.
966 (if (and fill-prefix
967 (not (string-equal fill-prefix ""))
968 (equal fill-prefix
969 (buffer-substring
970 (point) (min (point-max) (+ (length fill-prefix)
971 (point))))))
972 (forward-char (length fill-prefix))
973 (if (and adaptive-fill-mode
974 (looking-at adaptive-fill-regexp))
975 (goto-char (match-end 0))))
976 (setq fp-end (point))
977 (skip-chars-forward " \t")
978 ;; This is beginning of the line's text.
979 (setq indent (current-column))
980 (setq beg (point))
981 (goto-char end)
982 (setq endcol (current-column))
984 ;; HOW can't be null or left--we would have exited already
985 (cond ((eq 'right how)
986 (setq ncols (- fc endcol))
987 (if (< ncols 0)
988 ;; Need to remove some indentation
989 (delete-region
990 (progn (goto-char fp-end)
991 (if (< (current-column) (+ indent ncols))
992 (move-to-column (+ indent ncols) t))
993 (point))
994 (progn (move-to-column indent) (point)))
995 ;; Need to add some
996 (goto-char beg)
997 (indent-to (+ indent ncols))
998 ;; If point was at beginning of text, keep it there.
999 (if (= beg pos)
1000 (move-marker pos (point)))))
1002 ((eq 'center how)
1003 ;; Figure out how much indentation is needed
1004 (setq ncols (+ (current-left-margin)
1005 (/ (- fc (current-left-margin) ;avail. space
1006 (- endcol indent)) ;text width
1007 2)))
1008 (if (< ncols indent)
1009 ;; Have too much indentation - remove some
1010 (delete-region
1011 (progn (goto-char fp-end)
1012 (if (< (current-column) ncols)
1013 (move-to-column ncols t))
1014 (point))
1015 (progn (move-to-column indent) (point)))
1016 ;; Have too little - add some
1017 (goto-char beg)
1018 (indent-to ncols)
1019 ;; If point was at beginning of text, keep it there.
1020 (if (= beg pos)
1021 (move-marker pos (point)))))
1023 ((eq 'full how)
1024 ;; Insert extra spaces between words to justify line
1025 (save-restriction
1026 (narrow-to-region beg end)
1027 (or nosqueeze
1028 (canonically-space-region beg end))
1029 (goto-char (point-max))
1030 ;; count word spaces in line
1031 (while (search-backward " " nil t)
1032 (setq nspaces (1+ nspaces))
1033 (skip-chars-backward " "))
1034 (setq ncols (- fc endcol))
1035 ;; Ncols is number of additional space chars needed
1036 (if (and (> ncols 0) (> nspaces 0) (not eop))
1037 (progn
1038 (setq curr-fracspace (+ ncols (/ (1+ nspaces) 2))
1039 count nspaces)
1040 (while (> count 0)
1041 (skip-chars-forward " ")
1042 (insert-and-inherit
1043 (make-string (/ curr-fracspace nspaces) ?\ ))
1044 (search-forward " " nil t)
1045 (setq count (1- count)
1046 curr-fracspace
1047 (+ (% curr-fracspace nspaces) ncols)))))))
1048 (t (error "Unknown justification value"))))
1049 (goto-char pos)
1050 (move-marker pos nil)))
1051 nil)
1053 (defun unjustify-current-line ()
1054 "Remove justification whitespace from current line.
1055 If the line is centered or right-justified, this function removes any
1056 indentation past the left margin. If the line is full-justified, it removes
1057 extra spaces between words. It does nothing in other justification modes."
1058 (let ((justify (current-justification)))
1059 (cond ((eq 'left justify) nil)
1060 ((eq nil justify) nil)
1061 ((eq 'full justify) ; full justify: remove extra spaces
1062 (beginning-of-line-text)
1063 (canonically-space-region (point) (line-end-position)))
1064 ((memq justify '(center right))
1065 (save-excursion
1066 (move-to-left-margin nil t)
1067 ;; Position ourselves after any fill-prefix.
1068 (if (and fill-prefix
1069 (not (string-equal fill-prefix ""))
1070 (equal fill-prefix
1071 (buffer-substring
1072 (point) (min (point-max) (+ (length fill-prefix)
1073 (point))))))
1074 (forward-char (length fill-prefix)))
1075 (delete-region (point) (progn (skip-chars-forward " \t")
1076 (point))))))))
1078 (defun unjustify-region (&optional begin end)
1079 "Remove justification whitespace from region.
1080 For centered or right-justified regions, this function removes any indentation
1081 past the left margin from each line. For full-justified lines, it removes
1082 extra spaces between words. It does nothing in other justification modes.
1083 Arguments BEGIN and END are optional; default is the whole buffer."
1084 (save-excursion
1085 (save-restriction
1086 (if end (narrow-to-region (point-min) end))
1087 (goto-char (or begin (point-min)))
1088 (while (not (eobp))
1089 (unjustify-current-line)
1090 (forward-line 1)))))
1093 (defun fill-nonuniform-paragraphs (min max &optional justifyp citation-regexp)
1094 "Fill paragraphs within the region, allowing varying indentation within each.
1095 This command divides the region into \"paragraphs\",
1096 only at paragraph-separator lines, then fills each paragraph
1097 using as the fill prefix the smallest indentation of any line
1098 in the paragraph.
1100 When calling from a program, pass range to fill as first two arguments.
1102 Optional third and fourth arguments JUSTIFY and MAIL-FLAG:
1103 JUSTIFY to justify paragraphs (prefix arg),
1104 When filling a mail message, pass a regexp for CITATION-REGEXP
1105 which will match the prefix of a line which is a citation marker
1106 plus whitespace, but no other kind of prefix.
1107 Also, if CITATION-REGEXP is non-nil, don't fill header lines."
1108 (interactive (progn
1109 (barf-if-buffer-read-only)
1110 (list (region-beginning) (region-end)
1111 (if current-prefix-arg 'full))))
1112 (let ((fill-individual-varying-indent t))
1113 (fill-individual-paragraphs min max justifyp citation-regexp)))
1115 (defun fill-individual-paragraphs (min max &optional justify citation-regexp)
1116 "Fill paragraphs of uniform indentation within the region.
1117 This command divides the region into \"paragraphs\",
1118 treating every change in indentation level or prefix as a paragraph boundary,
1119 then fills each paragraph using its indentation level as the fill prefix.
1121 There is one special case where a change in indentation does not start
1122 a new paragraph. This is for text of this form:
1124 foo> This line with extra indentation starts
1125 foo> a paragraph that continues on more lines.
1127 These lines are filled together.
1129 When calling from a program, pass the range to fill
1130 as the first two arguments.
1132 Optional third and fourth arguments JUSTIFY and MAIL-FLAG:
1133 JUSTIFY to justify paragraphs (prefix arg),
1134 When filling a mail message, pass a regexp for CITATION-REGEXP
1135 which will match the prefix of a line which is a citation marker
1136 plus whitespace, but no other kind of prefix.
1137 Also, if CITATION-REGEXP is non-nil, don't fill header lines."
1138 (interactive (progn
1139 (barf-if-buffer-read-only)
1140 (list (region-beginning) (region-end)
1141 (if current-prefix-arg 'full))))
1142 (save-restriction
1143 (save-excursion
1144 (goto-char min)
1145 (beginning-of-line)
1146 (narrow-to-region (point) max)
1147 (if citation-regexp
1148 (while (and (not (eobp))
1149 (or (looking-at "[ \t]*[^ \t\n]+:")
1150 (looking-at "[ \t]*$")))
1151 (if (looking-at "[ \t]*[^ \t\n]+:")
1152 (search-forward "\n\n" nil 'move)
1153 (forward-line 1))))
1154 (narrow-to-region (point) max)
1155 ;; Loop over paragraphs.
1156 (while (let ((here (point)))
1157 ;; Skip over all paragraph-separating lines
1158 ;; so as to not include them in any paragraph.
1159 (while (and (not (eobp))
1160 (progn (move-to-left-margin)
1161 (and (not (eobp))
1162 (looking-at paragraph-separate))))
1163 (forward-line 1))
1164 (skip-chars-forward " \t\n") (not (eobp)))
1165 (move-to-left-margin)
1166 (let ((start (point))
1167 fill-prefix fill-prefix-regexp)
1168 ;; Find end of paragraph, and compute the smallest fill-prefix
1169 ;; that fits all the lines in this paragraph.
1170 (while (progn
1171 ;; Update the fill-prefix on the first line
1172 ;; and whenever the prefix good so far is too long.
1173 (if (not (and fill-prefix
1174 (looking-at fill-prefix-regexp)))
1175 (setq fill-prefix
1176 (fill-individual-paragraphs-prefix
1177 citation-regexp)
1178 fill-prefix-regexp (regexp-quote fill-prefix)))
1179 (forward-line 1)
1180 (if (bolp)
1181 ;; If forward-line went past a newline,
1182 ;; move further to the left margin.
1183 (move-to-left-margin))
1184 ;; Now stop the loop if end of paragraph.
1185 (and (not (eobp))
1186 (if fill-individual-varying-indent
1187 ;; If this line is a separator line, with or
1188 ;; without prefix, end the paragraph.
1189 (and
1190 (not (looking-at paragraph-separate))
1191 (save-excursion
1192 (not (and (looking-at fill-prefix-regexp)
1193 (progn (forward-char
1194 (length fill-prefix))
1195 (looking-at
1196 paragraph-separate))))))
1197 ;; If this line has more or less indent
1198 ;; than the fill prefix wants, end the paragraph.
1199 (and (looking-at fill-prefix-regexp)
1200 ;; If fill prefix is shorter than a new
1201 ;; fill prefix computed here, end paragraph.
1202 (let ((this-line-fill-prefix
1203 (fill-individual-paragraphs-prefix
1204 citation-regexp)))
1205 (>= (length fill-prefix)
1206 (length this-line-fill-prefix)))
1207 (save-excursion
1208 (not (progn (forward-char
1209 (length fill-prefix))
1210 (or (looking-at "[ \t]")
1211 (looking-at paragraph-separate)
1212 (looking-at paragraph-start)))))
1213 (not (and (equal fill-prefix "")
1214 citation-regexp
1215 (looking-at citation-regexp))))))))
1216 ;; Fill this paragraph, but don't add a newline at the end.
1217 (let ((had-newline (bolp)))
1218 (fill-region-as-paragraph start (point) justify)
1219 (if (and (bolp) (not had-newline))
1220 (delete-char -1))))))))
1222 (defun fill-individual-paragraphs-prefix (citation-regexp)
1223 (or (let ((adaptive-fill-first-line-regexp "")
1224 just-one-line-prefix
1225 two-lines-prefix
1226 one-line-citation-part
1227 two-lines-citation-part
1228 adjusted-two-lines-citation-part)
1229 (setq just-one-line-prefix
1230 (fill-context-prefix
1231 (point)
1232 (line-beginning-position 2)))
1233 (setq two-lines-prefix
1234 (fill-context-prefix
1235 (point)
1236 (line-beginning-position 2)))
1237 (when just-one-line-prefix
1238 (setq one-line-citation-part
1239 (if citation-regexp
1240 (fill-individual-paragraphs-citation just-one-line-prefix
1241 citation-regexp)
1242 just-one-line-prefix)))
1243 (when two-lines-prefix
1244 (setq two-lines-citation-part
1245 (if citation-regexp
1246 (fill-individual-paragraphs-citation two-lines-prefix
1247 citation-regexp)
1248 just-one-line-prefix))
1249 (or two-lines-citation-part (setq two-lines-citation-part ""))
1250 (setq adjusted-two-lines-citation-part
1251 (substring two-lines-citation-part 0
1252 (string-match "[ \t]*\\'"
1253 two-lines-citation-part))))
1254 ;; See if the citation part of JUST-ONE-LINE-PREFIX
1255 ;; is the same as that of TWO-LINES-PREFIX,
1256 ;; except perhaps with longer whitespace.
1257 (if (and just-one-line-prefix
1258 two-lines-prefix
1259 (string-match (concat "\\`"
1260 (regexp-quote
1261 adjusted-two-lines-citation-part)
1262 "[ \t]*\\'")
1263 one-line-citation-part)
1264 (>= (string-width one-line-citation-part)
1265 (string-width two-lines-citation-part)))
1266 two-lines-prefix
1267 just-one-line-prefix))
1268 (buffer-substring
1269 (point)
1270 (save-excursion (skip-chars-forward " \t")
1271 (point)))))
1273 (defun fill-individual-paragraphs-citation (string citation-regexp)
1274 (string-match citation-regexp
1275 string)
1276 (match-string 0 string))
1278 ;;; fill.el ends here