aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/textmodes/fill.el47
1 files changed, 37 insertions, 10 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index fd433f3456c..d9bf1e520d9 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -348,6 +348,8 @@ justification. Fourth arg NOSQUEEZE non-nil means not to make spaces
348between words canonical before filling. Fifth arg SQUEEZE-AFTER, if non-nil, 348between words canonical before filling. Fifth arg SQUEEZE-AFTER, if non-nil,
349means don't canonicalize spaces before that position. 349means don't canonicalize spaces before that position.
350 350
351Return the fill-prefix used for filling.
352
351If `sentence-end-double-space' is non-nil, then period followed by one 353If `sentence-end-double-space' is non-nil, then period followed by one
352space does not end a sentence, so don't break a line there." 354space does not end a sentence, so don't break a line there."
353 (interactive (progn 355 (interactive (progn
@@ -670,7 +672,18 @@ space does not end a sentence, so don't break a line there."
670 ;; Leave point after final newline. 672 ;; Leave point after final newline.
671 (goto-char (point-max))) 673 (goto-char (point-max)))
672 (unless (eobp) 674 (unless (eobp)
673 (forward-char 1))))) 675 (forward-char 1))
676 ;; Return the fill-prefix we used
677 fill-prefix)))
678
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))))
674 687
675(defun fill-paragraph (arg) 688(defun fill-paragraph (arg)
676 "Fill paragraph at or after point. Prefix arg means justify as well. 689 "Fill paragraph at or after point. Prefix arg means justify as well.
@@ -679,7 +692,9 @@ space does not end a sentence, so don't break a line there.
679the variable `fill-column' controls the width for filling. 692the variable `fill-column' controls the width for filling.
680 693
681If `fill-paragraph-function' is non-nil, we call it (passing our 694If `fill-paragraph-function' is non-nil, we call it (passing our
682argument to it), and if it returns non-nil, we simply return its value." 695argument to it), and if it returns non-nil, we simply return its value.
696
697If `fill-paragraph-function' is nil, return the fill-prefix used for filling."
683 (interactive (progn 698 (interactive (progn
684 (barf-if-buffer-read-only) 699 (barf-if-buffer-read-only)
685 (list (if current-prefix-arg 'full)))) 700 (list (if current-prefix-arg 'full))))
@@ -688,6 +703,8 @@ argument to it), and if it returns non-nil, we simply return its value."
688 fill-paragraph-function) 703 fill-paragraph-function)
689 (funcall function arg))) 704 (funcall function arg)))
690 (let ((before (point)) 705 (let ((before (point))
706 ;; Fill prefix used for filling the paragraph
707 fill-pfx
691 ;; If fill-paragraph is called recursively, 708 ;; If fill-paragraph is called recursively,
692 ;; don't give fill-paragraph-function a second chance. 709 ;; don't give fill-paragraph-function a second chance.
693 fill-paragraph-function) 710 fill-paragraph-function)
@@ -697,11 +714,17 @@ argument to it), and if it returns non-nil, we simply return its value."
697 (let ((end (point)) 714 (let ((end (point))
698 (beg (progn (backward-paragraph) (point)))) 715 (beg (progn (backward-paragraph) (point))))
699 (goto-char before) 716 (goto-char before)
700 (if use-hard-newlines 717 (setq fill-pfx
701 ;; Can't use fill-region-as-paragraph, since this paragraph 718 (if use-hard-newlines
702 ;; may still contain hard newlines. See fill-region. 719 ;; Can't use fill-region-as-paragraph, since this
703 (fill-region beg end arg) 720 ;; paragraph may still contain hard newlines. See
704 (fill-region-as-paragraph beg end arg))))))) 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)))
705 728
706(defun fill-region (from to &optional justify nosqueeze to-eop) 729(defun fill-region (from to &optional justify nosqueeze to-eop)
707 "Fill each of the paragraphs in the region. 730 "Fill each of the paragraphs in the region.
@@ -718,6 +741,8 @@ whitespace other than line breaks untouched, and fifth arg TO-EOP
718non-nil means to keep filling to the end of the paragraph (or next 741non-nil means to keep filling to the end of the paragraph (or next
719hard newline, if `use-hard-newlines' is on). 742hard newline, if `use-hard-newlines' is on).
720 743
744Return the fill-prefix used for filling the last paragraph.
745
721If `sentence-end-double-space' is non-nil, then period followed by one 746If `sentence-end-double-space' is non-nil, then period followed by one
722space does not end a sentence, so don't break a line there." 747space does not end a sentence, so don't break a line there."
723 (interactive (progn 748 (interactive (progn
@@ -726,7 +751,7 @@ space does not end a sentence, so don't break a line there."
726 (if current-prefix-arg 'full)))) 751 (if current-prefix-arg 'full))))
727 (unless (memq justify '(t nil none full center left right)) 752 (unless (memq justify '(t nil none full center left right))
728 (setq justify 'full)) 753 (setq justify 'full))
729 (let (end beg) 754 (let (end beg fill-pfx)
730 (save-restriction 755 (save-restriction
731 (goto-char (max from to)) 756 (goto-char (max from to))
732 (if to-eop 757 (if to-eop
@@ -756,8 +781,10 @@ space does not end a sentence, so don't break a line there."
756 (if (< (point) beg) 781 (if (< (point) beg)
757 (goto-char beg)) 782 (goto-char beg))
758 (if (>= (point) initial) 783 (if (>= (point) initial)
759 (fill-region-as-paragraph (point) end justify nosqueeze) 784 (setq fill-pfx
760 (goto-char end))))))) 785 (fill-region-as-paragraph (point) end justify nosqueeze))
786 (goto-char end))))
787 fill-pfx)))
761 788
762 789
763(defcustom default-justification 'left 790(defcustom default-justification 'left