Mercurial > emacs
comparison lisp/textmodes/fill.el @ 12557:34e9427fe8f5
(canonically-space-region): Doc fix.
(fill-region-as-paragraph): In adaptive-fill-mode,
if paragraph has one line, take the fill prefix from it.
(adaptive-fill-regexp): Doc fix.
(fill-individual-paragraphs): Use `adaptive-fill-regexp'
to determine `fill-prefix' if `adaptive-fill-mode' is non-nil.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Mon, 17 Jul 1995 22:50:30 +0000 |
parents | d6d785d96455 |
children | 86c8fb2284de |
comparison
equal
deleted
inserted
replaced
12556:fb1b760f6636 | 12557:34e9427fe8f5 |
---|---|
59 | 59 |
60 (defconst adaptive-fill-regexp "[ \t]*\\([#;>*]+ +\\)?" | 60 (defconst adaptive-fill-regexp "[ \t]*\\([#;>*]+ +\\)?" |
61 "*Regexp to match text at start of line that constitutes indentation. | 61 "*Regexp to match text at start of line that constitutes indentation. |
62 If Adaptive Fill mode is enabled, whatever text matches this pattern | 62 If Adaptive Fill mode is enabled, whatever text matches this pattern |
63 on the second line of a paragraph is used as the standard indentation | 63 on the second line of a paragraph is used as the standard indentation |
64 for the paragraph.") | 64 for the paragraph. If the paragraph has just one line, the indentation |
65 is taken from that line.") | |
65 | 66 |
66 (defun current-fill-column () | 67 (defun current-fill-column () |
67 "Return the fill-column to use for this line. | 68 "Return the fill-column to use for this line. |
68 The fill-column to use for a buffer is stored in the variable `fill-column', | 69 The fill-column to use for a buffer is stored in the variable `fill-column', |
69 but can be locally modified by the `right-margin' text property, which is | 70 but can be locally modified by the `right-margin' text property, which is |
90 (max here-col fill-col))))) | 91 (max here-col fill-col))))) |
91 | 92 |
92 (defun canonically-space-region (beg end) | 93 (defun canonically-space-region (beg end) |
93 "Remove extra spaces between words in region. | 94 "Remove extra spaces between words in region. |
94 Puts one space between words in region; two between sentences. | 95 Puts one space between words in region; two between sentences. |
95 Remove indenation from each line." | 96 Remove indentation from each line." |
96 (interactive "r") | 97 (interactive "r") |
97 (save-excursion | 98 (save-excursion |
98 (goto-char beg) | 99 (goto-char beg) |
99 ;; Nuke tabs; they get screwed up in a fill. | 100 ;; Nuke tabs; they get screwed up in a fill. |
100 ;; This is quick, but loses when a tab follows the end of a sentence. | 101 ;; This is quick, but loses when a tab follows the end of a sentence. |
178 (if (and adaptive-fill-mode | 179 (if (and adaptive-fill-mode |
179 (or (null fill-prefix) (string= fill-prefix ""))) | 180 (or (null fill-prefix) (string= fill-prefix ""))) |
180 (save-excursion | 181 (save-excursion |
181 (goto-char from) | 182 (goto-char from) |
182 (if (eolp) (forward-line 1)) | 183 (if (eolp) (forward-line 1)) |
183 (forward-line 1) | 184 ;; Move to the second line unless there is just one. |
185 (let ((firstline (point))) | |
186 (forward-line 1) | |
187 (if (>= (point) to) | |
188 (goto-char firstline))) | |
184 (move-to-left-margin) | 189 (move-to-left-margin) |
185 (if (< (point) to) | 190 (let ((start (point))) |
186 (let ((start (point))) | 191 (re-search-forward adaptive-fill-regexp) |
187 (re-search-forward adaptive-fill-regexp) | 192 (setq fill-prefix (buffer-substring start (point))) |
188 (setq fill-prefix (buffer-substring start (point))) | 193 (set-text-properties 0 (length fill-prefix) nil |
189 (set-text-properties 0 (length fill-prefix) nil | 194 fill-prefix)) |
190 fill-prefix))) | |
191 ;; If paragraph has only one line, don't assume in general | |
192 ;; that additional lines would have the same starting | |
193 ;; decoration. Assume no indentation. | |
194 )) | 195 )) |
195 | 196 |
196 (save-restriction | 197 (save-restriction |
197 (goto-char from) | 198 (goto-char from) |
198 (beginning-of-line) | 199 (beginning-of-line) |
760 ;; Update the fill-prefix on the first line | 761 ;; Update the fill-prefix on the first line |
761 ;; and whenever the prefix good so far is too long. | 762 ;; and whenever the prefix good so far is too long. |
762 (if (not (and fill-prefix | 763 (if (not (and fill-prefix |
763 (looking-at fill-prefix-regexp))) | 764 (looking-at fill-prefix-regexp))) |
764 (setq fill-prefix | 765 (setq fill-prefix |
765 (buffer-substring (point) | 766 (if (and adaptive-fill-mode adaptive-fill-regexp |
766 (save-excursion (skip-chars-forward " \t") (point))) | 767 (looking-at (concat "\\(" adaptive-fill-regexp "\\)"))) |
768 (match-string 1) | |
769 (buffer-substring (point) | |
770 (save-excursion (skip-chars-forward " \t") (point)))) | |
767 fill-prefix-regexp | 771 fill-prefix-regexp |
768 (regexp-quote fill-prefix))) | 772 (regexp-quote fill-prefix))) |
769 (forward-line 1) | 773 (forward-line 1) |
770 ;; Now stop the loop if end of paragraph. | 774 ;; Now stop the loop if end of paragraph. |
771 (and (not (eobp)) | 775 (and (not (eobp)) |