aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/textmodes
diff options
context:
space:
mode:
authorRichard M. Stallman1997-09-14 20:27:34 +0000
committerRichard M. Stallman1997-09-14 20:27:34 +0000
commitf37bbf08858a55f6fff15798cded0eafd3652c2e (patch)
tree8d726c5ac652e352c4873e580e996a2d6abb78fb /lisp/textmodes
parente6f8e6f418541243b8a66aae7fa81515af467968 (diff)
downloademacs-f37bbf08858a55f6fff15798cded0eafd3652c2e.tar.gz
emacs-f37bbf08858a55f6fff15798cded0eafd3652c2e.zip
(canonically-space-region): Doc fix.
(fill-context-prefix): If the second line has the first line prefix, plus whitespace, use the part that the first line shares. (fill-individual-paragraphs): When prefix changes, usually get the new prefix from just one line, with an exception for indented first lines of paragraphs. Start a new paragraph when a line has extra indentation after the fill prefix.
Diffstat (limited to 'lisp/textmodes')
-rw-r--r--lisp/textmodes/fill.el57
1 files changed, 48 insertions, 9 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 5fd50ecc521..4741c0ffdc7 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -136,7 +136,7 @@ number equals or exceeds the local fill-column - right-margin difference."
136(defun canonically-space-region (beg end) 136(defun canonically-space-region (beg end)
137 "Remove extra spaces between words in region. 137 "Remove extra spaces between words in region.
138Leave one space between words, two at end of sentences or after colons 138Leave one space between words, two at end of sentences or after colons
139(depending on values of `sentence-end-double-space' and `colon-double-space'). 139\(depending on values of `sentence-end-double-space' and `colon-double-space').
140Remove indentation from each line." 140Remove indentation from each line."
141 (interactive "r") 141 (interactive "r")
142 (save-excursion 142 (save-excursion
@@ -217,7 +217,14 @@ act as a paragraph-separator."
217 first-line-prefix) 217 first-line-prefix)
218 ;; If the second line prefix is whitespace, use it. 218 ;; If the second line prefix is whitespace, use it.
219 (string-match "\\`[ \t]+\\'" second-line-prefix)) 219 (string-match "\\`[ \t]+\\'" second-line-prefix))
220 second-line-prefix)) 220 second-line-prefix
221 ;; If the second line has the first line prefix,
222 ;; plus whitespace, use the part that the first line shares.
223 (if (string-match (concat "\\`"
224 (regexp-quote first-line-prefix)
225 "[ \t]*\\'")
226 second-line-prefix)
227 first-line-prefix)))
221 ;; If we get a fill prefix from a one-line paragraph, 228 ;; If we get a fill prefix from a one-line paragraph,
222 ;; maybe change it to whitespace, 229 ;; maybe change it to whitespace,
223 ;; and check that it isn't a paragraph starter. 230 ;; and check that it isn't a paragraph starter.
@@ -915,10 +922,19 @@ MAIL-FLAG for a mail message, i. e. don't fill header lines."
915(defun fill-individual-paragraphs (min max &optional justify mailp) 922(defun fill-individual-paragraphs (min max &optional justify mailp)
916 "Fill paragraphs of uniform indentation within the region. 923 "Fill paragraphs of uniform indentation within the region.
917This command divides the region into \"paragraphs\", 924This command divides the region into \"paragraphs\",
918treating every change in indentation level as a paragraph boundary, 925treating every change in indentation level or prefix as a paragraph boundary,
919then fills each paragraph using its indentation level as the fill prefix. 926then fills each paragraph using its indentation level as the fill prefix.
920 927
921When calling from a program, pass range to fill as first two arguments. 928There is one special case where a change in indentation does not start
929a new paragraph. This is for text of this form:
930
931 foo> This line with extra indentation starts
932 foo> a paragraph that continues on more lines.
933
934These lines are filled together.
935
936When calling from a program, pass the range to fill
937as the first two arguments.
922 938
923Optional third and fourth arguments JUSTIFY and MAIL-FLAG: 939Optional third and fourth arguments JUSTIFY and MAIL-FLAG:
924JUSTIFY to justify paragraphs (prefix arg), 940JUSTIFY to justify paragraphs (prefix arg),
@@ -957,10 +973,32 @@ MAIL-FLAG for a mail message, i. e. don't fill header lines."
957 (if (not (and fill-prefix 973 (if (not (and fill-prefix
958 (looking-at fill-prefix-regexp))) 974 (looking-at fill-prefix-regexp)))
959 (setq fill-prefix 975 (setq fill-prefix
960 (or (let ((adaptive-fill-first-line-regexp "")) 976 ;; Get the prefix from just the first line
961 (fill-context-prefix 977 ;; ordinarily.
962 (point) 978 ;; But if using two lines gives us a shorter
963 (save-excursion (forward-line 2) (point)))) 979 ;; result, lacking some whitespace at the end,
980 ;; use that.
981 (or (let ((adaptive-fill-first-line-regexp "")
982 just-one-line-prefix
983 two-lines-prefix)
984 (setq just-one-line-prefix
985 (fill-context-prefix
986 (point)
987 (save-excursion (forward-line 1)
988 (point))))
989 (setq two-lines-prefix
990 (fill-context-prefix
991 (point)
992 (save-excursion (forward-line 2)
993 (point))))
994 (if (and just-one-line-prefix
995 two-lines-prefix
996 (string-match (concat "\\`"
997 (regexp-quote two-lines-prefix)
998 "[ \t]*\\'")
999 just-one-line-prefix))
1000 two-lines-prefix
1001 just-one-line-prefix))
964 (buffer-substring 1002 (buffer-substring
965 (point) 1003 (point)
966 (save-excursion (skip-chars-forward " \t") 1004 (save-excursion (skip-chars-forward " \t")
@@ -987,7 +1025,8 @@ MAIL-FLAG for a mail message, i. e. don't fill header lines."
987 (and (looking-at fill-prefix-regexp) 1025 (and (looking-at fill-prefix-regexp)
988 (save-excursion 1026 (save-excursion
989 (not (progn (forward-char (length fill-prefix)) 1027 (not (progn (forward-char (length fill-prefix))
990 (or (looking-at paragraph-separate) 1028 (or (looking-at "[ \t]")
1029 (looking-at paragraph-separate)
991 (looking-at paragraph-start)))))))))) 1030 (looking-at paragraph-start))))))))))
992 ;; Fill this paragraph, but don't add a newline at the end. 1031 ;; Fill this paragraph, but don't add a newline at the end.
993 (let ((had-newline (bolp))) 1032 (let ((had-newline (bolp)))