comparison lisp/textmodes/fill.el @ 10631:dc245bfecc3b

(fill-paragraph-function): New variable. (fill-paragraph): Use it.
author Richard M. Stallman <rms@gnu.org>
date Thu, 02 Feb 1995 09:50:23 +0000
parents 3b896847b849
children 6f9d0e697678
comparison
equal deleted inserted replaced
10630:3e851e5cab1f 10631:dc245bfecc3b
34 but it requires separator lines between paragraphs. 34 but it requires separator lines between paragraphs.
35 A value of nil means that any change in indentation starts a new paragraph.") 35 A value of nil means that any change in indentation starts a new paragraph.")
36 36
37 (defconst sentence-end-double-space t 37 (defconst sentence-end-double-space t
38 "*Non-nil means a single space does not end a sentence.") 38 "*Non-nil means a single space does not end a sentence.")
39
40 (defvar fill-paragraph-function nil
41 "Mode-specific function to fill a paragraph.")
39 42
40 (defun set-fill-prefix () 43 (defun set-fill-prefix ()
41 "Set the fill prefix to the current line up to point. 44 "Set the fill prefix to the current line up to point.
42 Filling expects lines to start with the fill prefix and 45 Filling expects lines to start with the fill prefix and
43 reinserts the fill prefix in each resulting line." 46 reinserts the fill prefix in each resulting line."
315 (forward-char skip-after)))) 318 (forward-char skip-after))))
316 319
317 (defun fill-paragraph (arg) 320 (defun fill-paragraph (arg)
318 "Fill paragraph at or after point. Prefix arg means justify as well. 321 "Fill paragraph at or after point. Prefix arg means justify as well.
319 If `sentence-end-double-space' is non-nil, then period followed by one 322 If `sentence-end-double-space' is non-nil, then period followed by one
320 space does not end a sentence, so don't break a line there." 323 space does not end a sentence, so don't break a line there.
324
325 If `fill-paragraph-function' is non-nil, we call it (passing our
326 argument to it), and if it returns non-nil, we simply return its value."
321 (interactive "P") 327 (interactive "P")
322 (let ((before (point))) 328 (or (and fill-paragraph-function
323 (save-excursion 329 (funcall fill-paragraph-function arg))
324 (forward-paragraph) 330 (let ((before (point)))
325 (or (bolp) (newline 1)) 331 (save-excursion
326 (let ((end (point)) 332 (forward-paragraph)
327 (beg (progn (backward-paragraph) (point)))) 333 (or (bolp) (newline 1))
328 (goto-char before) 334 (let ((end (point))
329 (if use-hard-newlines 335 (beg (progn (backward-paragraph) (point))))
330 ;; Can't use fill-region-as-paragraph, since this paragraph may 336 (goto-char before)
331 ;; still contain hard newlines. See fill-region. 337 (if use-hard-newlines
332 (fill-region beg end arg) 338 ;; Can't use fill-region-as-paragraph, since this paragraph may
333 (fill-region-as-paragraph beg end arg)))))) 339 ;; still contain hard newlines. See fill-region.
340 (fill-region beg end arg)
341 (fill-region-as-paragraph beg end arg)))))))
334 342
335 (defun fill-region (from to &optional justify nosqueeze to-eop) 343 (defun fill-region (from to &optional justify nosqueeze to-eop)
336 "Fill each of the paragraphs in the region. 344 "Fill each of the paragraphs in the region.
337 Prefix arg (non-nil third arg, if called from program) means justify as well. 345 Prefix arg (non-nil third arg, if called from program) means justify as well.
338 346