aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1998-07-13 02:11:16 +0000
committerRichard M. Stallman1998-07-13 02:11:16 +0000
commitb3a0387c097887208de85ec20a84a84fa47f15bd (patch)
treeaa9de07d05fa8ed7ec7a87a736948a9f902acf2a
parent706e3d859134f07a7dbc54827356d83551b3fdc4 (diff)
downloademacs-b3a0387c097887208de85ec20a84a84fa47f15bd.tar.gz
emacs-b3a0387c097887208de85ec20a84a84fa47f15bd.zip
(fill-individual-paragraphs-prefix): New
subroutine taken from fill-individual-paragraphs. Really check that JUST-ONE-LINE-PREFIX is longer than TWO-LINES-PREFIX in its whitespace. (fill-individual-paragraphs-citation): New subroutine. (fill-nonuniform-paragraphs): Arg MAILP renamed. (fill-individual-paragraphs): Arg MAILP renamed.
-rw-r--r--lisp/textmodes/fill.el114
1 files changed, 69 insertions, 45 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 18f06a7e8d5..0886ecfb152 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -947,7 +947,7 @@ Arguments BEGIN and END are optional; default is the whole buffer."
947 (forward-line 1))))) 947 (forward-line 1)))))
948 948
949 949
950(defun fill-nonuniform-paragraphs (min max &optional justifyp mailp) 950(defun fill-nonuniform-paragraphs (min max &optional justifyp citation-regexp)
951 "Fill paragraphs within the region, allowing varying indentation within each. 951 "Fill paragraphs within the region, allowing varying indentation within each.
952This command divides the region into \"paragraphs\", 952This command divides the region into \"paragraphs\",
953only at paragraph-separator lines, then fills each paragraph 953only at paragraph-separator lines, then fills each paragraph
@@ -958,13 +958,16 @@ When calling from a program, pass range to fill as first two arguments.
958 958
959Optional third and fourth arguments JUSTIFY and MAIL-FLAG: 959Optional third and fourth arguments JUSTIFY and MAIL-FLAG:
960JUSTIFY to justify paragraphs (prefix arg), 960JUSTIFY to justify paragraphs (prefix arg),
961MAIL-FLAG for a mail message, i. e. don't fill header lines." 961When filling a mail message, pass a regexp for CITATION-REGEXP
962which will match the prefix of a line which is a citation marker
963plus whitespace, but no other kind of prefix.
964Also, if CITATION-REGEXP is non-nil, don't fill header lines."
962 (interactive (list (region-beginning) (region-end) 965 (interactive (list (region-beginning) (region-end)
963 (if current-prefix-arg 'full))) 966 (if current-prefix-arg 'full)))
964 (let ((fill-individual-varying-indent t)) 967 (let ((fill-individual-varying-indent t))
965 (fill-individual-paragraphs min max justifyp mailp))) 968 (fill-individual-paragraphs min max justifyp citation-regexp)))
966 969
967(defun fill-individual-paragraphs (min max &optional justify mailp) 970(defun fill-individual-paragraphs (min max &optional justify citation-regexp)
968 "Fill paragraphs of uniform indentation within the region. 971 "Fill paragraphs of uniform indentation within the region.
969This command divides the region into \"paragraphs\", 972This command divides the region into \"paragraphs\",
970treating every change in indentation level or prefix as a paragraph boundary, 973treating every change in indentation level or prefix as a paragraph boundary,
@@ -983,7 +986,10 @@ as the first two arguments.
983 986
984Optional third and fourth arguments JUSTIFY and MAIL-FLAG: 987Optional third and fourth arguments JUSTIFY and MAIL-FLAG:
985JUSTIFY to justify paragraphs (prefix arg), 988JUSTIFY to justify paragraphs (prefix arg),
986MAIL-FLAG for a mail message, i. e. don't fill header lines." 989When filling a mail message, pass a regexp for CITATION-REGEXP
990which will match the prefix of a line which is a citation marker
991plus whitespace, but no other kind of prefix.
992Also, if CITATION-REGEXP is non-nil, don't fill header lines."
987 (interactive (list (region-beginning) (region-end) 993 (interactive (list (region-beginning) (region-end)
988 (if current-prefix-arg 'full))) 994 (if current-prefix-arg 'full)))
989 (save-restriction 995 (save-restriction
@@ -991,7 +997,7 @@ MAIL-FLAG for a mail message, i. e. don't fill header lines."
991 (goto-char min) 997 (goto-char min)
992 (beginning-of-line) 998 (beginning-of-line)
993 (narrow-to-region (point) max) 999 (narrow-to-region (point) max)
994 (if mailp 1000 (if citation-regexp
995 (while (and (not (eobp)) 1001 (while (and (not (eobp))
996 (or (looking-at "[ \t]*[^ \t\n]+:") 1002 (or (looking-at "[ \t]*[^ \t\n]+:")
997 (looking-at "[ \t]*$"))) 1003 (looking-at "[ \t]*$")))
@@ -1020,45 +1026,7 @@ MAIL-FLAG for a mail message, i. e. don't fill header lines."
1020 (if (not (and fill-prefix 1026 (if (not (and fill-prefix
1021 (looking-at fill-prefix-regexp))) 1027 (looking-at fill-prefix-regexp)))
1022 (setq fill-prefix 1028 (setq fill-prefix
1023 ;; Get the prefix from just the first line 1029 (fill-individual-paragraphs-prefix citation-regexp)
1024 ;; ordinarily.
1025 ;; But if using two lines gives us a shorter
1026 ;; result, lacking some whitespace at the end,
1027 ;; use that.
1028 (or (let ((adaptive-fill-first-line-regexp "")
1029 just-one-line-prefix
1030 two-lines-prefix
1031 adjusted-two-lines-prefix)
1032 (setq just-one-line-prefix
1033 (fill-context-prefix
1034 (point)
1035 (save-excursion (forward-line 1)
1036 (point))))
1037 (setq two-lines-prefix
1038 (fill-context-prefix
1039 (point)
1040 (save-excursion (forward-line 2)
1041 (point))))
1042 (when two-lines-prefix
1043 (setq adjusted-two-lines-prefix
1044 (substring two-lines-prefix 0
1045 (string-match "[ \t]*\\'"
1046 two-lines-prefix))))
1047 ;; See if JUST-ONE-LINE-PREFIX
1048 ;; is the same as TWO-LINES-PREFIX
1049 ;; except perhaps with longer whitespace.
1050 (if (and just-one-line-prefix
1051 two-lines-prefix
1052 (string-match (concat "\\`"
1053 (regexp-quote adjusted-two-lines-prefix)
1054 "[ \t]*\\'")
1055 just-one-line-prefix))
1056 two-lines-prefix
1057 just-one-line-prefix))
1058 (buffer-substring
1059 (point)
1060 (save-excursion (skip-chars-forward " \t")
1061 (point))))
1062 fill-prefix-regexp (regexp-quote fill-prefix))) 1030 fill-prefix-regexp (regexp-quote fill-prefix)))
1063 (forward-line 1) 1031 (forward-line 1)
1064 (if (bolp) 1032 (if (bolp)
@@ -1089,4 +1057,60 @@ MAIL-FLAG for a mail message, i. e. don't fill header lines."
1089 (fill-region-as-paragraph start (point) justify) 1057 (fill-region-as-paragraph start (point) justify)
1090 (or had-newline (delete-char -1)))))))) 1058 (or had-newline (delete-char -1))))))))
1091 1059
1060(defun fill-individual-paragraphs-prefix (citation-regexp)
1061 (or (let ((adaptive-fill-first-line-regexp "")
1062 just-one-line-prefix
1063 two-lines-prefix
1064 one-line-citation-part
1065 two-lines-citation-part
1066 adjusted-two-lines-citation-part)
1067 (setq just-one-line-prefix
1068 (fill-context-prefix
1069 (point)
1070 (save-excursion (forward-line 1)
1071 (point))))
1072 (setq two-lines-prefix
1073 (fill-context-prefix
1074 (point)
1075 (save-excursion (forward-line 2)
1076 (point))))
1077 (when just-one-line-prefix
1078 (setq one-line-citation-part
1079 (if citation-regexp
1080 (fill-individual-paragraphs-citation just-one-line-prefix
1081 citation-regexp)
1082 just-one-line-prefix)))
1083 (when two-lines-prefix
1084 (setq two-lines-citation-part
1085 (if citation-regexp
1086 (fill-individual-paragraphs-citation two-lines-prefix
1087 citation-regexp)
1088 just-one-line-prefix))
1089 (setq adjusted-two-lines-citation-part
1090 (substring two-lines-citation-part 0
1091 (string-match "[ \t]*\\'"
1092 two-lines-citation-part))))
1093 ;; See if the citation part of JUST-ONE-LINE-PREFIX
1094 ;; is the same as that of TWO-LINES-PREFIX,
1095 ;; except perhaps with longer whitespace.
1096 (if (and just-one-line-prefix
1097 two-lines-prefix
1098 (string-match (concat "\\`"
1099 (regexp-quote adjusted-two-lines-citation-part)
1100 "[ \t]*\\'")
1101 one-line-citation-part)
1102 (>= (string-width one-line-citation-part)
1103 (string-width two-lines-citation-part)))
1104 two-lines-prefix
1105 just-one-line-prefix))
1106 (buffer-substring
1107 (point)
1108 (save-excursion (skip-chars-forward " \t")
1109 (point)))))
1110
1111(defun fill-individual-paragraphs-citation (string citation-regexp)
1112 (string-match citation-regexp
1113 string)
1114 (match-string 0 string))
1115
1092;;; fill.el ends here 1116;;; fill.el ends here