annotate lisp/textmodes/fill.el @ 13839:d597ac78b00e

(fill-paragraph-function): Doc fix.
author Richard M. Stallman <rms@gnu.org>
date Sun, 24 Dec 1995 23:30:18 +0000
parents f85b6bd0f925
children 6758b889a7c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 638
diff changeset
1 ;;; fill.el --- fill commands for Emacs
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 638
diff changeset
2
11234
4d2a2fe1d8d7 Update copyright.
Karl Heuer <kwzh@gnu.org>
parents: 11178
diff changeset
3 ;; Copyright (C) 1985, 1986, 1992, 1994, 1995 Free Software Foundation, Inc.
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 821
diff changeset
4
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
5 ;; Keywords: wp
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
6
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
8
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
12 ;; any later version.
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
13
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
17 ;; GNU General Public License for more details.
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
18
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
22
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2109
diff changeset
23 ;;; Commentary:
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2109
diff changeset
24
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2109
diff changeset
25 ;; All the commands for filling text. These are documented in the Emacs
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2109
diff changeset
26 ;; manual.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2109
diff changeset
27
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 732
diff changeset
28 ;;; Code:
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
29
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
30 (defconst fill-individual-varying-indent nil
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
31 "*Controls criterion for a new paragraph in `fill-individual-paragraphs'.
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
32 Non-nil means changing indent doesn't end a paragraph.
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
33 That mode can handle paragraphs with extra indentation on the first line,
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
34 but it requires separator lines between paragraphs.
5770
92dd602768d2 (sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5291
diff changeset
35 A value of nil means that any change in indentation starts a new paragraph.")
92dd602768d2 (sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5291
diff changeset
36
92dd602768d2 (sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5291
diff changeset
37 (defconst sentence-end-double-space t
92dd602768d2 (sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5291
diff changeset
38 "*Non-nil means a single space does not end a sentence.")
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
39
12752
86c8fb2284de (fill-region-as-paragraph): Don't find adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents: 12557
diff changeset
40 (defconst colon-double-space nil
86c8fb2284de (fill-region-as-paragraph): Don't find adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents: 12557
diff changeset
41 "*Non-nil means put two spaces after a colon when filling.")
86c8fb2284de (fill-region-as-paragraph): Don't find adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents: 12557
diff changeset
42
10631
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
43 (defvar fill-paragraph-function nil
13839
d597ac78b00e (fill-paragraph-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 13713
diff changeset
44 "Mode-specific function to fill a paragraph, or nil if there is none.
d597ac78b00e (fill-paragraph-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 13713
diff changeset
45 If the function returns nil, then `fill-paragraph' does its normal work.")
10631
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
46
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
47 (defun set-fill-prefix ()
5770
92dd602768d2 (sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5291
diff changeset
48 "Set the fill prefix to the current line up to point.
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
49 Filling expects lines to start with the fill prefix and
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
50 reinserts the fill prefix in each resulting line."
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
51 (interactive)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
52 (setq fill-prefix (buffer-substring
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
53 (save-excursion (move-to-left-margin) (point))
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
54 (point)))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
55 (if (equal fill-prefix "")
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
56 (setq fill-prefix nil))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
57 (if fill-prefix
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
58 (message "fill-prefix: \"%s\"" fill-prefix)
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
59 (message "fill-prefix cancelled")))
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
60
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
61 (defconst adaptive-fill-mode t
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
62 "*Non-nil means determine a paragraph's fill prefix from its text.")
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
63
10989
f4693d66f90c (adaptive-fill-regexp): Skip # or ;.
Richard M. Stallman <rms@gnu.org>
parents: 10988
diff changeset
64 (defconst adaptive-fill-regexp "[ \t]*\\([#;>*]+ +\\)?"
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
65 "*Regexp to match text at start of line that constitutes indentation.
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
66 If Adaptive Fill mode is enabled, whatever text matches this pattern
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
67 on the second line of a paragraph is used as the standard indentation
12557
34e9427fe8f5 (canonically-space-region): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 12429
diff changeset
68 for the paragraph. If the paragraph has just one line, the indentation
34e9427fe8f5 (canonically-space-region): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 12429
diff changeset
69 is taken from that line.")
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
70
13172
219ce06d0e63 (adaptive-fill-function): Change defun to defvar.
Richard M. Stallman <rms@gnu.org>
parents: 12752
diff changeset
71 (defvar adaptive-fill-function nil
12752
86c8fb2284de (fill-region-as-paragraph): Don't find adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents: 12557
diff changeset
72 "*Function to call to choose a fill prefix for a paragraph.
86c8fb2284de (fill-region-as-paragraph): Don't find adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents: 12557
diff changeset
73 This function is used when `adaptive-fill-regexp' does not match.")
86c8fb2284de (fill-region-as-paragraph): Don't find adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents: 12557
diff changeset
74
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
75 (defun current-fill-column ()
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
76 "Return the fill-column to use for this line.
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
77 The fill-column to use for a buffer is stored in the variable `fill-column',
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
78 but can be locally modified by the `right-margin' text property, which is
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
79 subtracted from `fill-column'.
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
80
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
81 The fill column to use for a line is the first column at which the column
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
82 number equals or exceeds the local fill-column - right-margin difference."
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
83 (save-excursion
12429
d6d785d96455 (current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents: 11448
diff changeset
84 (if fill-column
d6d785d96455 (current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents: 11448
diff changeset
85 (let* ((here (progn (beginning-of-line) (point)))
d6d785d96455 (current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents: 11448
diff changeset
86 (here-col 0)
d6d785d96455 (current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents: 11448
diff changeset
87 (eol (progn (end-of-line) (point)))
d6d785d96455 (current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents: 11448
diff changeset
88 margin fill-col change col)
d6d785d96455 (current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents: 11448
diff changeset
89 ;; Look separately at each region of line with a different right-margin.
d6d785d96455 (current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents: 11448
diff changeset
90 (while (and (setq margin (get-text-property here 'right-margin)
d6d785d96455 (current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents: 11448
diff changeset
91 fill-col (- fill-column (or margin 0))
d6d785d96455 (current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents: 11448
diff changeset
92 change (text-property-not-all
d6d785d96455 (current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents: 11448
diff changeset
93 here eol 'right-margin margin))
d6d785d96455 (current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents: 11448
diff changeset
94 (progn (goto-char (1- change))
d6d785d96455 (current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents: 11448
diff changeset
95 (setq col (current-column))
d6d785d96455 (current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents: 11448
diff changeset
96 (< col fill-col)))
d6d785d96455 (current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents: 11448
diff changeset
97 (setq here change
d6d785d96455 (current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents: 11448
diff changeset
98 here-col col))
d6d785d96455 (current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents: 11448
diff changeset
99 (max here-col fill-col)))))
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
100
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
101 (defun canonically-space-region (beg end)
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
102 "Remove extra spaces between words in region.
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
103 Puts one space between words in region; two between sentences.
12557
34e9427fe8f5 (canonically-space-region): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 12429
diff changeset
104 Remove indentation from each line."
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
105 (interactive "r")
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
106 (save-excursion
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
107 (goto-char beg)
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
108 ;; Nuke tabs; they get screwed up in a fill.
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
109 ;; This is quick, but loses when a tab follows the end of a sentence.
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
110 ;; Actually, it is difficult to tell that from "Mr.\tSmith".
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
111 ;; Blame the typist.
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
112 (subst-char-in-region beg end ?\t ?\ )
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
113 (while (and (< (point) end)
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
114 (re-search-forward " *" end t))
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
115 (delete-region
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
116 (+ (match-beginning 0)
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
117 ;; Determine number of spaces to leave:
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
118 (save-excursion
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
119 (skip-chars-backward " ]})\"'")
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
120 (cond ((and sentence-end-double-space
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
121 (memq (preceding-char) '(?. ?? ?!))) 2)
12752
86c8fb2284de (fill-region-as-paragraph): Don't find adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents: 12557
diff changeset
122 ((and colon-double-space
86c8fb2284de (fill-region-as-paragraph): Don't find adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents: 12557
diff changeset
123 (= (preceding-char) ?:)) 2)
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
124 ((char-equal (preceding-char) ?\n) 0)
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
125 (t 1))))
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
126 (match-end 0)))
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
127 ;; Make sure sentences ending at end of line get an extra space.
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
128 ;; loses on split abbrevs ("Mr.\nSmith")
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
129 (goto-char beg)
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
130 (while (and (< (point) end)
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
131 (re-search-forward "[.?!][])}\"']*$" end t))
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
132 (insert-and-inherit ? ))))
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
133
13586
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
134 (defun fill-context-prefix (from to &optional first-line-regexp)
13473
4492ba9a0757 (fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents: 13172
diff changeset
135 "Compute a fill prefix from the text between FROM and TO.
13713
f85b6bd0f925 (fill-context-prefix): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 13586
diff changeset
136 This uses the variables `adaptive-fill-prefix' and `adaptive-fill-function'.
13586
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
137 If FIRST-LINE-REGEXP is non-nil, then when taking a prefix from the
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
138 first line, insist it must match FIRST-LINE-REGEXP."
13473
4492ba9a0757 (fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents: 13172
diff changeset
139 (save-excursion
4492ba9a0757 (fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents: 13172
diff changeset
140 (goto-char from)
4492ba9a0757 (fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents: 13172
diff changeset
141 (if (eolp) (forward-line 1))
4492ba9a0757 (fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents: 13172
diff changeset
142 ;; Move to the second line unless there is just one.
13586
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
143 (let ((firstline (point))
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
144 ;; Non-nil if we are on the second line.
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
145 at-second
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
146 result)
13473
4492ba9a0757 (fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents: 13172
diff changeset
147 (forward-line 1)
4492ba9a0757 (fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents: 13172
diff changeset
148 (if (>= (point) to)
13586
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
149 (goto-char firstline)
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
150 (setq at-second t))
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
151 (move-to-left-margin)
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
152 (let ((start (point))
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
153 (eol (save-excursion (end-of-line) (point))))
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
154 (setq result
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
155 (if (not (looking-at paragraph-start))
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
156 (cond ((and adaptive-fill-regexp (looking-at adaptive-fill-regexp))
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
157 (buffer-substring-no-properties start (match-end 0)))
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
158 (adaptive-fill-function (funcall adaptive-fill-function)))))
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
159 (and result
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
160 (or at-second
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
161 (null first-line-regexp)
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
162 (string-match first-line-regexp result))
292e11b5f9c6 (fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents: 13578
diff changeset
163 result)))))
13473
4492ba9a0757 (fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents: 13172
diff changeset
164
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
165 (defun fill-region-as-paragraph (from to &optional justify nosqueeze)
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
166 "Fill the region as one paragraph.
13578
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
167 It removes any paragraph breaks in the region and extra newlines at the end,
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
168 indents and fills lines between the margins given by the
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
169 `current-left-margin' and `current-fill-column' functions.
13578
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
170 It leaves point at the beginning of the line following the paragraph.
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
171
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
172 Normally performs justification according to the `current-justification'
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
173 function, but with a prefix arg, does full justification instead.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
174
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
175 From a program, optional third arg JUSTIFY can specify any type of
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
176 justification, and fourth arg NOSQUEEZE non-nil means not to make spaces
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
177 between words canonical before filling.
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
178
5770
92dd602768d2 (sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5291
diff changeset
179 If `sentence-end-double-space' is non-nil, then period followed by one
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
180 space does not end a sentence, so don't break a line there."
11356
4be78e93d1be (fill-region-as-paragraph): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 11282
diff changeset
181 (interactive (list (region-beginning) (region-end)
4be78e93d1be (fill-region-as-paragraph): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 11282
diff changeset
182 (if current-prefix-arg 'full)))
1332
955ebdb98095 (fill-paragraph): Don't actually change point before
Richard M. Stallman <rms@gnu.org>
parents: 1067
diff changeset
183 ;; Arrange for undoing the fill to restore point.
955ebdb98095 (fill-paragraph): Don't actually change point before
Richard M. Stallman <rms@gnu.org>
parents: 1067
diff changeset
184 (if (and buffer-undo-list (not (eq buffer-undo-list t)))
955ebdb98095 (fill-paragraph): Don't actually change point before
Richard M. Stallman <rms@gnu.org>
parents: 1067
diff changeset
185 (setq buffer-undo-list (cons (point) buffer-undo-list)))
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
186
13578
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
187 ;; Make sure "to" is the endpoint.
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
188 (goto-char (min from to))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
189 (setq to (max from to))
13578
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
190 ;; Ignore blank lines at beginning of region.
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
191 (skip-chars-forward " \t\n")
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
192
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
193 (let ((from-plus-indent (point))
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
194 (oneleft nil))
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
195
13578
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
196 (beginning-of-line)
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
197 (setq from (point))
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
198
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
199 ;; Delete all but one soft newline at end of region.
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
200 (goto-char to)
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
201 (while (and (> (point) from) (eq ?\n (char-after (1- (point)))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
202 (if (and oneleft
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
203 (not (and use-hard-newlines
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
204 (get-text-property (1- (point)) 'hard))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
205 (delete-backward-char 1)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
206 (backward-char 1)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
207 (setq oneleft t)))
13578
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
208 (setq to (point))
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
209
13578
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
210 ;; If there was no newline, and there is text in the paragraph, then
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
211 ;; create a newline.
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
212 (if (and (not oneleft) (> to from-plus-indent))
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
213 (newline))
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
214 (goto-char from-plus-indent))
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
215
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
216 (if (not (> to (point)))
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
217 nil ; There is no paragraph, only whitespace: exit now.
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
218
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
219 (or justify (setq justify (current-justification)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
220
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
221 ;; Don't let Adaptive Fill mode alter the fill prefix permanently.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
222 (let ((fill-prefix fill-prefix))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
223 ;; Figure out how this paragraph is indented, if desired.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
224 (if (and adaptive-fill-mode
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
225 (or (null fill-prefix) (string= fill-prefix "")))
13473
4492ba9a0757 (fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents: 13172
diff changeset
226 (setq fill-prefix (fill-context-prefix from to)))
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
227
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
228 (save-restriction
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
229 (goto-char from)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
230 (beginning-of-line)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
231 (narrow-to-region (point) to)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
232
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
233 (if (not justify) ; filling disabled: just check indentation
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
234 (progn
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
235 (goto-char from)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
236 (while (not (eobp))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
237 (if (and (not (eolp))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
238 (< (current-indentation) (current-left-margin)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
239 (indent-to-left-margin))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
240 (forward-line 1)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
241
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
242 (if use-hard-newlines
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
243 (remove-text-properties from (point-max) '(hard nil)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
244 ;; Make sure first line is indented (at least) to left margin...
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
245 (if (or (memq justify '(right center))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
246 (< (current-indentation) (current-left-margin)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
247 (indent-to-left-margin))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
248 ;; Delete the fill prefix from every line except the first.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
249 ;; The first line may not even have a fill prefix.
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
250 (goto-char from)
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
251 (let ((fpre (and fill-prefix (not (equal fill-prefix ""))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
252 (concat "[ \t]*"
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
253 (regexp-quote fill-prefix)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
254 "[ \t]*"))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
255 (and fpre
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
256 (progn
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
257 (if (>= (+ (current-left-margin) (length fill-prefix))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
258 (current-fill-column))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
259 (error "fill-prefix too long for specified width"))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
260 (goto-char from)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
261 (forward-line 1)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
262 (while (not (eobp))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
263 (if (looking-at fpre)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
264 (delete-region (point) (match-end 0)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
265 (forward-line 1))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
266 (goto-char from)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
267 (and (looking-at fpre) (goto-char (match-end 0)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
268 (setq from (point)))))
11178
7d4805feb413 (fill-region-as-paragraph): Remove fill-prefix first, then remove indentation.
Richard M. Stallman <rms@gnu.org>
parents: 10989
diff changeset
269 ;; Remove indentation from lines other than the first.
7d4805feb413 (fill-region-as-paragraph): Remove fill-prefix first, then remove indentation.
Richard M. Stallman <rms@gnu.org>
parents: 10989
diff changeset
270 (beginning-of-line 2)
7d4805feb413 (fill-region-as-paragraph): Remove fill-prefix first, then remove indentation.
Richard M. Stallman <rms@gnu.org>
parents: 10989
diff changeset
271 (indent-region (point) (point-max) 0)
7d4805feb413 (fill-region-as-paragraph): Remove fill-prefix first, then remove indentation.
Richard M. Stallman <rms@gnu.org>
parents: 10989
diff changeset
272 (goto-char from)
7d4805feb413 (fill-region-as-paragraph): Remove fill-prefix first, then remove indentation.
Richard M. Stallman <rms@gnu.org>
parents: 10989
diff changeset
273
7d4805feb413 (fill-region-as-paragraph): Remove fill-prefix first, then remove indentation.
Richard M. Stallman <rms@gnu.org>
parents: 10989
diff changeset
274 ;; FROM, and point, are now before the text to fill,
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
275 ;; but after any fill prefix on the first line.
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
276
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
277 ;; Make sure sentences ending at end of line get an extra space.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
278 ;; loses on split abbrevs ("Mr.\nSmith")
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
279 (while (re-search-forward "[.?!][])}\"']*$" nil t)
13473
4492ba9a0757 (fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents: 13172
diff changeset
280 (or (eobp) (insert-and-inherit ?\ )))
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
281 (goto-char from)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
282 (skip-chars-forward " \t")
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
283 ;; Then change all newlines to spaces.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
284 (subst-char-in-region from (point-max) ?\n ?\ )
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
285 (if (and nosqueeze (not (eq justify 'full)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
286 nil
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
287 (canonically-space-region (point) (point-max))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
288 (goto-char (point-max))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
289 (delete-horizontal-space)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
290 (insert-and-inherit " "))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
291 (goto-char (point-min))
218
d492f16a8743 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 75
diff changeset
292
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
293 ;; This is the actual filling loop.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
294 (let ((prefixcol 0) linebeg)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
295 (while (not (eobp))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
296 (setq linebeg (point))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
297 (move-to-column (1+ (current-fill-column)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
298 (if (eobp)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
299 (or nosqueeze (delete-horizontal-space))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
300 ;; Move back to start of word.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
301 (skip-chars-backward "^ \n" linebeg)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
302 ;; Don't break after a period followed by just one space.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
303 ;; Move back to the previous place to break.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
304 ;; The reason is that if a period ends up at the end of a line,
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
305 ;; further fills will assume it ends a sentence.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
306 ;; If we now know it does not end a sentence,
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
307 ;; avoid putting it at the end of the line.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
308 (if sentence-end-double-space
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
309 (while (and (> (point) (+ linebeg 2))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
310 (eq (preceding-char) ?\ )
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
311 (not (eq (following-char) ?\ ))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
312 (eq (char-after (- (point) 2)) ?\.))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
313 (forward-char -2)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
314 (skip-chars-backward "^ \n" linebeg)))
13549
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
315 ;; If the left margin and fill prefix by themselves
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
316 ;; pass the fill-column, keep at least one word.
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
317 ;; This handles ALL BUT the first line of the paragraph.
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
318 (if (if (zerop prefixcol)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
319 (save-excursion
13578
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
320 (skip-chars-backward " \t" linebeg)
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
321 (bolp))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
322 (>= prefixcol (current-column)))
13549
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
323 ;; Ok, skip at least one word.
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
324 ;; Meanwhile, don't stop at a period followed by one space.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
325 (let ((first t))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
326 (move-to-column prefixcol)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
327 (while (and (not (eobp))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
328 (or first
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
329 (and (not (bobp))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
330 sentence-end-double-space
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
331 (save-excursion (forward-char -1)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
332 (and (looking-at "\\. ")
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
333 (not (looking-at "\\. ")))))))
13578
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
334 (skip-chars-forward " \t")
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
335 (skip-chars-forward "^ \n\t")
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
336 (setq first nil)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
337 ;; Normally, move back over the single space between the words.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
338 (forward-char -1))
13549
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
339 ;; If the left margin and fill prefix by themselves
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
340 ;; pass the fill-column, keep at least one word.
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
341 ;; This handles the first line of the paragraph.
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
342 (if (and (zerop prefixcol)
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
343 (let ((fill-point (point)) nchars)
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
344 (save-excursion
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
345 (move-to-left-margin)
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
346 (setq nchars (- fill-point (point)))
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
347 (or (< nchars 0)
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
348 (and fill-prefix
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
349 (< nchars (length fill-prefix))
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
350 (string= (buffer-substring (point) fill-point)
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
351 (substring fill-prefix 0 nchars)))))))
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
352 ;; Ok, skip at least one word. But
f8afa95d197e (fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents: 13548
diff changeset
353 ;; don't stop at a period followed by just one space.
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
354 (let ((first t))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
355 (while (and (not (eobp))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
356 (or first
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
357 (and (not (bobp))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
358 sentence-end-double-space
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
359 (save-excursion (forward-char -1)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
360 (and (looking-at "\\. ")
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
361 (not (looking-at "\\. ")))))))
13578
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
362 (skip-chars-forward " \t")
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
363 (skip-chars-forward "^ \t\n")
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
364 (setq first nil))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
365 ;; Replace whitespace here with one newline, then indent to left
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
366 ;; margin.
13578
85697e02a482 (fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents: 13549
diff changeset
367 (skip-chars-backward " \t")
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
368 (insert ?\n)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
369 ;; Give newline the properties of the space(s) it replaces
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
370 (set-text-properties (1- (point)) (point)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
371 (text-properties-at (point)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
372 (indent-to-left-margin)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
373 ;; Insert the fill prefix after indentation.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
374 ;; Set prefixcol so whitespace in the prefix won't get lost.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
375 (and fill-prefix (not (equal fill-prefix ""))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
376 (progn
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
377 (insert-and-inherit fill-prefix)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
378 (setq prefixcol (current-column)))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
379 ;; Justify the line just ended, if desired.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
380 (if justify
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
381 (if (eobp)
11356
4be78e93d1be (fill-region-as-paragraph): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 11282
diff changeset
382 (justify-current-line justify t t)
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
383 (forward-line -1)
11356
4be78e93d1be (fill-region-as-paragraph): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 11282
diff changeset
384 (justify-current-line justify nil t)
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
385 (forward-line 1))))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
386 ;; Leave point after final newline.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
387 (goto-char (point-max)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
388 (forward-char 1))))
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
389
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
390 (defun fill-paragraph (arg)
5770
92dd602768d2 (sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5291
diff changeset
391 "Fill paragraph at or after point. Prefix arg means justify as well.
92dd602768d2 (sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5291
diff changeset
392 If `sentence-end-double-space' is non-nil, then period followed by one
10631
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
393 space does not end a sentence, so don't break a line there.
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
394
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
395 If `fill-paragraph-function' is non-nil, we call it (passing our
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
396 argument to it), and if it returns non-nil, we simply return its value."
11448
b0a7e8ff84ad (fill-paragraph, fill-region, fill-nonuniform-paragraphs)
Richard M. Stallman <rms@gnu.org>
parents: 11356
diff changeset
397 (interactive (list (if current-prefix-arg 'full)))
10631
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
398 (or (and fill-paragraph-function
10636
6f9d0e697678 (fill-paragraph): Bind fill-paragraph-function to nil before calling it.
Richard M. Stallman <rms@gnu.org>
parents: 10631
diff changeset
399 (let ((function fill-paragraph-function)
6f9d0e697678 (fill-paragraph): Bind fill-paragraph-function to nil before calling it.
Richard M. Stallman <rms@gnu.org>
parents: 10631
diff changeset
400 fill-paragraph-function)
6f9d0e697678 (fill-paragraph): Bind fill-paragraph-function to nil before calling it.
Richard M. Stallman <rms@gnu.org>
parents: 10631
diff changeset
401 (funcall function arg)))
10631
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
402 (let ((before (point)))
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
403 (save-excursion
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
404 (forward-paragraph)
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
405 (or (bolp) (newline 1))
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
406 (let ((end (point))
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
407 (beg (progn (backward-paragraph) (point))))
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
408 (goto-char before)
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
409 (if use-hard-newlines
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
410 ;; Can't use fill-region-as-paragraph, since this paragraph may
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
411 ;; still contain hard newlines. See fill-region.
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
412 (fill-region beg end arg)
dc245bfecc3b (fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 10543
diff changeset
413 (fill-region-as-paragraph beg end arg)))))))
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
414
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
415 (defun fill-region (from to &optional justify nosqueeze to-eop)
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
416 "Fill each of the paragraphs in the region.
5770
92dd602768d2 (sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5291
diff changeset
417 Prefix arg (non-nil third arg, if called from program) means justify as well.
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
418
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
419 Noninteractively, fourth arg NOSQUEEZE non-nil means to leave
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
420 whitespace other than line breaks untouched, and fifth arg TO-EOP
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
421 non-nil means to keep filling to the end of the paragraph (or next
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
422 hard newline, if `use-hard-newlines' is on).
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
423
5770
92dd602768d2 (sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5291
diff changeset
424 If `sentence-end-double-space' is non-nil, then period followed by one
92dd602768d2 (sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 5291
diff changeset
425 space does not end a sentence, so don't break a line there."
11448
b0a7e8ff84ad (fill-paragraph, fill-region, fill-nonuniform-paragraphs)
Richard M. Stallman <rms@gnu.org>
parents: 11356
diff changeset
426 (interactive (list (region-beginning) (region-end)
b0a7e8ff84ad (fill-paragraph, fill-region, fill-nonuniform-paragraphs)
Richard M. Stallman <rms@gnu.org>
parents: 11356
diff changeset
427 (if current-prefix-arg 'full)))
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
428 (let (end beg)
10110
18d52489f138 (fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents: 9706
diff changeset
429 (save-restriction
18d52489f138 (fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents: 9706
diff changeset
430 (goto-char (max from to))
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
431 (if to-eop
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
432 (progn (skip-chars-backward "\n")
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
433 (forward-paragraph)))
10110
18d52489f138 (fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents: 9706
diff changeset
434 (setq end (point))
18d52489f138 (fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents: 9706
diff changeset
435 (goto-char (setq beg (min from to)))
18d52489f138 (fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents: 9706
diff changeset
436 (beginning-of-line)
18d52489f138 (fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents: 9706
diff changeset
437 (narrow-to-region (point) end)
18d52489f138 (fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents: 9706
diff changeset
438 (while (not (eobp))
18d52489f138 (fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents: 9706
diff changeset
439 (let ((initial (point))
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
440 end)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
441 ;; If using hard newlines, break at every one for filling
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
442 ;; purposes rather than using paragraph breaks.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
443 (if use-hard-newlines
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
444 (progn
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
445 (while (and (setq end (text-property-any (point) (point-max)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
446 'hard t))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
447 (not (= ?\n (char-after end)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
448 (not (= end (point-max))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
449 (goto-char (1+ end)))
11282
3da60d3584c4 (fill-region): Avoid error on reaching end of buffer.
Richard M. Stallman <rms@gnu.org>
parents: 11247
diff changeset
450 (setq end (if end (min (point-max) (1+ end)) (point-max)))
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
451 (goto-char initial))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
452 (forward-paragraph 1)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
453 (setq end (point))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
454 (forward-paragraph -1))
10110
18d52489f138 (fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents: 9706
diff changeset
455 (if (< (point) beg)
18d52489f138 (fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents: 9706
diff changeset
456 (goto-char beg))
18d52489f138 (fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents: 9706
diff changeset
457 (if (>= (point) initial)
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
458 (fill-region-as-paragraph (point) end justify nosqueeze)
10110
18d52489f138 (fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents: 9706
diff changeset
459 (goto-char end)))))))
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
460
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
461
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
462 (defconst default-justification 'left
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
463 "*Method of justifying text not otherwise specified.
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
464 Possible values are `left', `right', `full', `center', or `none'.
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
465 The requested kind of justification is done whenever lines are filled.
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
466 The `justification' text-property can locally override this variable.
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
467 This variable automatically becomes buffer-local when set in any fashion.")
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
468 (make-variable-buffer-local 'default-justification)
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
469
10472
82ff279a4cea (current-justification): Renamed from current-justification. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents: 10468
diff changeset
470 (defun current-justification ()
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
471 "How should we justify this line?
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
472 This returns the value of the text-property `justification',
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
473 or the variable `default-justification' if there is no text-property.
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
474 However, it returns nil rather than `none' to mean \"don't justify\"."
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
475 (let ((j (or (get-text-property
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
476 ;; Make sure we're looking at paragraph body.
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
477 (save-excursion (skip-chars-forward " \t")
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
478 (if (and (eobp) (not (bobp)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
479 (1- (point)) (point)))
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
480 'justification)
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
481 default-justification)))
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
482 (if (eq 'none j)
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
483 nil
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
484 j)))
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
485
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
486 (defun set-justification (begin end value &optional whole-par)
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
487 "Set the region's justification style.
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
488 The kind of justification to use is prompted for.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
489 If the mark is not active, this command operates on the current paragraph.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
490 If the mark is active, the region is used. However, if the beginning and end
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
491 of the region are not at paragraph breaks, they are moved to the beginning and
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
492 end of the paragraphs they are in.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
493 If `use-hard-newlines' is true, all hard newlines are taken to be paragraph
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
494 breaks.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
495
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
496 When calling from a program, operates just on region between BEGIN and END,
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
497 unless optional fourth arg WHOLE-PAR is non-nil. In that case bounds are
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
498 extended to include entire paragraphs as in the interactive command."
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
499 (interactive (list (if mark-active (region-beginning) (point))
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
500 (if mark-active (region-end) (point))
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
501 (let ((s (completing-read
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
502 "Set justification to: "
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
503 '(("left") ("right") ("full")
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
504 ("center") ("none"))
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
505 nil t)))
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
506 (if (equal s "") (error ""))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
507 (intern s))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
508 t))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
509 (save-excursion
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
510 (save-restriction
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
511 (if whole-par
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
512 (let ((paragraph-start (if use-hard-newlines "." paragraph-start))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
513 (paragraph-ignore-fill-prefix (if use-hard-newlines t
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
514 paragraph-ignore-fill-prefix)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
515 (goto-char begin)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
516 (while (and (bolp) (not (eobp))) (forward-char 1))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
517 (backward-paragraph)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
518 (setq begin (point))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
519 (goto-char end)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
520 (skip-chars-backward " \t\n" begin)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
521 (forward-paragraph)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
522 (setq end (point))))
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
523
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
524 (narrow-to-region (point-min) end)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
525 (unjustify-region begin (point-max))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
526 (put-text-property begin (point-max) 'justification value)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
527 (fill-region begin (point-max) nil t))))
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
528
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
529 (defun set-justification-none (b e)
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
530 "Disable automatic filling for paragraphs in the region.
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
531 If the mark is not active, this applies to the current paragraph."
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
532 (interactive (list (if mark-active (region-beginning) (point))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
533 (if mark-active (region-end) (point))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
534 (set-justification b e 'none t))
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
535
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
536 (defun set-justification-left (b e)
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
537 "Make paragraphs in the region left-justified.
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
538 This is usually the default, but see the variable `default-justification'.
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
539 If the mark is not active, this applies to the current paragraph."
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
540 (interactive (list (if mark-active (region-beginning) (point))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
541 (if mark-active (region-end) (point))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
542 (set-justification b e 'left t))
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
543
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
544 (defun set-justification-right (b e)
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
545 "Make paragraphs in the region right-justified:
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
546 Flush at the right margin and ragged on the left.
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
547 If the mark is not active, this applies to the current paragraph."
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
548 (interactive (list (if mark-active (region-beginning) (point))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
549 (if mark-active (region-end) (point))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
550 (set-justification b e 'right t))
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
551
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
552 (defun set-justification-full (b e)
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
553 "Make paragraphs in the region fully justified:
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
554 This makes lines flush on both margins by inserting spaces between words.
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
555 If the mark is not active, this applies to the current paragraph."
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
556 (interactive (list (if mark-active (region-beginning) (point))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
557 (if mark-active (region-end) (point))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
558 (set-justification b e 'full t))
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
559
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
560 (defun set-justification-center (b e)
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
561 "Make paragraphs in the region centered.
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
562 If the mark is not active, this applies to the current paragraph."
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
563 (interactive (list (if mark-active (region-beginning) (point))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
564 (if mark-active (region-end) (point))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
565 (set-justification b e 'center t))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
566
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
567 ;; A line has up to six parts:
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
568 ;;
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
569 ;; >>> hello.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
570 ;; [Indent-1][FP][ Indent-2 ][text][trailing whitespace][newline]
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
571 ;;
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
572 ;; "Indent-1" is the left-margin indentation; normally it ends at column
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
573 ;; given by the `current-left-margin' function.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
574 ;; "FP" is the fill-prefix. It can be any string, including whitespace.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
575 ;; "Indent-2" is added to justify a line if the `current-justification' is
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
576 ;; `center' or `right'. In `left' and `full' justification regions, any
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
577 ;; whitespace there is part of the line's text, and should not be changed.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
578 ;; Trailing whitespace is not counted as part of the line length when
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
579 ;; center- or right-justifying.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
580 ;;
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
581 ;; All parts of the line are optional, although the final newline can
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
582 ;; only be missing on the last line of the buffer.
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
583
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
584 (defun justify-current-line (&optional how eop nosqueeze)
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
585 "Do some kind of justification on this line.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
586 Normally does full justification: adds spaces to the line to make it end at
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
587 the column given by `current-fill-column'.
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
588 Optional first argument HOW specifies alternate type of justification:
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
589 it can be `left', `right', `full', `center', or `none'.
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
590 If HOW is t, will justify however the `current-justification' function says to.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
591 If HOW is nil or missing, full justification is done by default.
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
592 Second arg EOP non-nil means that this is the last line of the paragraph, so
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
593 it will not be stretched by full justification.
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
594 Third arg NOSQUEEZE non-nil means to leave interior whitespace unchanged,
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
595 otherwise it is made canonical."
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
596 (interactive)
13473
4492ba9a0757 (fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents: 13172
diff changeset
597 (if (eq t how) (setq how (or (current-justification) 'none))
4492ba9a0757 (fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents: 13172
diff changeset
598 (if (null how) (setq how 'full)
4492ba9a0757 (fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents: 13172
diff changeset
599 (or (memq how '(none left right center))
4492ba9a0757 (fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents: 13172
diff changeset
600 (setq how 'full))))
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
601 (or (memq how '(none left)) ; No action required for these.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
602 (let ((fc (current-fill-column))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
603 (pos (point-marker))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
604 fp-end ; point at end of fill prefix
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
605 beg ; point at beginning of line's text
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
606 end ; point at end of line's text
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
607 indent ; column of `beg'
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
608 endcol ; column of `end'
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
609 ncols) ; new indent point or offset
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
610 (end-of-line)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
611 ;; Check if this is the last line of the paragraph.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
612 (if (and use-hard-newlines (null eop)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
613 (get-text-property (point) 'hard))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
614 (setq eop t))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
615 (skip-chars-backward " \t")
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
616 ;; Quick exit if it appears to be properly justified already
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
617 ;; or there is no text.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
618 (if (or (bolp)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
619 (and (memq how '(full right))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
620 (= (current-column) fc)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
621 nil
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
622 (setq end (point))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
623 (beginning-of-line)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
624 (skip-chars-forward " \t")
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
625 ;; Skip over fill-prefix.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
626 (if (and fill-prefix
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
627 (not (string-equal fill-prefix ""))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
628 (equal fill-prefix
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
629 (buffer-substring
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
630 (point) (min (point-max) (+ (length fill-prefix)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
631 (point))))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
632 (forward-char (length fill-prefix))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
633 (if (and adaptive-fill-mode
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
634 (looking-at adaptive-fill-regexp))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
635 (goto-char (match-end 0))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
636 (setq fp-end (point))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
637 (skip-chars-forward " \t")
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
638 ;; This is beginning of the line's text.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
639 (setq indent (current-column))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
640 (setq beg (point))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
641 (goto-char end)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
642 (setq endcol (current-column))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
643
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
644 ;; HOW can't be null or left--we would have exited already
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
645 (cond ((eq 'right how)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
646 (setq ncols (- fc endcol))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
647 (if (< ncols 0)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
648 ;; Need to remove some indentation
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
649 (delete-region
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
650 (progn (goto-char fp-end)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
651 (if (< (current-column) (+ indent ncols))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
652 (move-to-column (+ indent ncols) t))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
653 (point))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
654 (progn (move-to-column indent) (point)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
655 ;; Need to add some
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
656 (goto-char beg)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
657 (indent-to (+ indent ncols))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
658 ;; If point was at beginning of text, keep it there.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
659 (if (= beg pos)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
660 (move-marker pos (point)))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
661
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
662 ((eq 'center how)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
663 ;; Figure out how much indentation is needed
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
664 (setq ncols (+ (current-left-margin)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
665 (/ (- fc (current-left-margin) ;avail. space
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
666 (- endcol indent)) ;text width
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
667 2)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
668 (if (< ncols indent)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
669 ;; Have too much indentation - remove some
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
670 (delete-region
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
671 (progn (goto-char fp-end)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
672 (if (< (current-column) ncols)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
673 (move-to-column ncols t))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
674 (point))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
675 (progn (move-to-column indent) (point)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
676 ;; Have too little - add some
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
677 (goto-char beg)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
678 (indent-to ncols)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
679 ;; If point was at beginning of text, keep it there.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
680 (if (= beg pos)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
681 (move-marker pos (point)))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
682
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
683 ((eq 'full how)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
684 ;; Insert extra spaces between words to justify line
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
685 (save-restriction
10543
3b896847b849 (justify-current-line): Avoid error comparing fill-prefix
Richard M. Stallman <rms@gnu.org>
parents: 10497
diff changeset
686 (narrow-to-region beg end)
3b896847b849 (justify-current-line): Avoid error comparing fill-prefix
Richard M. Stallman <rms@gnu.org>
parents: 10497
diff changeset
687 (or nosqueeze
3b896847b849 (justify-current-line): Avoid error comparing fill-prefix
Richard M. Stallman <rms@gnu.org>
parents: 10497
diff changeset
688 (canonically-space-region beg end))
3b896847b849 (justify-current-line): Avoid error comparing fill-prefix
Richard M. Stallman <rms@gnu.org>
parents: 10497
diff changeset
689 (goto-char (point-max))
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
690 (setq ncols (- fc endcol))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
691 ;; Ncols is number of additional spaces needed
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
692 (if (> ncols 0)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
693 (if (and (not eop)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
694 (search-backward " " nil t))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
695 (while (> ncols 0)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
696 (let ((nmove (+ 3 (random 3))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
697 (while (> nmove 0)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
698 (or (search-backward " " nil t)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
699 (progn
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
700 (goto-char (point-max))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
701 (search-backward " ")))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
702 (skip-chars-backward " ")
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
703 (setq nmove (1- nmove))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
704 (insert-and-inherit " ")
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
705 (skip-chars-backward " ")
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
706 (setq ncols (1- ncols)))))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
707 (t (error "Unknown justification value"))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
708 (goto-char pos)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
709 (move-marker pos nil)))
2109
73485780a8f9 * simple.el (yank, yank-pop): Always return nil; don't rely on
Jim Blandy <jimb@redhat.com>
parents: 1332
diff changeset
710 nil)
9026
74fd93bc3568 (justify-current-line): Inherit props when inserting spaces.
Richard M. Stallman <rms@gnu.org>
parents: 8363
diff changeset
711
10811
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
712 (defun unjustify-current-line ()
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
713 "Remove justification whitespace from current line.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
714 If the line is centered or right-justified, this function removes any
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
715 indentation past the left margin. If the line is full-jusitified, it removes
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
716 extra spaces between words. It does nothing in other justification modes."
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
717 (let ((justify (current-justification)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
718 (cond ((eq 'left justify) nil)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
719 ((eq nil justify) nil)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
720 ((eq 'full justify) ; full justify: remove extra spaces
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
721 (beginning-of-line-text)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
722 (canonically-space-region
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
723 (point) (save-excursion (end-of-line) (point))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
724 ((memq justify '(center right))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
725 (save-excursion
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
726 (move-to-left-margin nil t)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
727 ;; Position ourselves after any fill-prefix.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
728 (if (and fill-prefix
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
729 (not (string-equal fill-prefix ""))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
730 (equal fill-prefix
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
731 (buffer-substring
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
732 (point) (min (point-max) (+ (length fill-prefix)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
733 (point))))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
734 (forward-char (length fill-prefix)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
735 (delete-region (point) (progn (skip-chars-forward " \t")
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
736 (point))))))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
737
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
738 (defun unjustify-region (&optional begin end)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
739 "Remove justification whitespace from region.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
740 For centered or right-justified regions, this function removes any indentation
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
741 past the left margin from each line. For full-jusitified lines, it removes
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
742 extra spaces between words. It does nothing in other justification modes.
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
743 Arguments BEGIN and END are optional; default is the whole buffer."
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
744 (save-excursion
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
745 (save-restriction
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
746 (if end (narrow-to-region (point-min) end))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
747 (goto-char (or begin (point-min)))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
748 (while (not (eobp))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
749 (unjustify-current-line)
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
750 (forward-line 1)))))
7f9e55cdc349 (set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents: 10636
diff changeset
751
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
752
2520
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
753 (defun fill-nonuniform-paragraphs (min max &optional justifyp mailp)
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
754 "Fill paragraphs within the region, allowing varying indentation within each.
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
755 This command divides the region into \"paragraphs\",
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
756 only at paragraph-separator lines, then fills each paragraph
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
757 using as the fill prefix the smallest indentation of any line
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
758 in the paragraph.
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
759
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
760 When calling from a program, pass range to fill as first two arguments.
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
761
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
762 Optional third and fourth arguments JUSTIFY and MAIL-FLAG:
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
763 JUSTIFY to justify paragraphs (prefix arg),
2520
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
764 MAIL-FLAG for a mail message, i. e. don't fill header lines."
11448
b0a7e8ff84ad (fill-paragraph, fill-region, fill-nonuniform-paragraphs)
Richard M. Stallman <rms@gnu.org>
parents: 11356
diff changeset
765 (interactive (list (region-beginning) (region-end)
b0a7e8ff84ad (fill-paragraph, fill-region, fill-nonuniform-paragraphs)
Richard M. Stallman <rms@gnu.org>
parents: 11356
diff changeset
766 (if current-prefix-arg 'full)))
2520
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
767 (let ((fill-individual-varying-indent t))
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
768 (fill-individual-paragraphs min max justifyp mailp)))
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
769
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
770 (defun fill-individual-paragraphs (min max &optional justify mailp)
2520
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
771 "Fill paragraphs of uniform indentation within the region.
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
772 This command divides the region into \"paragraphs\",
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
773 treating every change in indentation level as a paragraph boundary,
ef643dbb7d40 (fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents: 2412
diff changeset
774 then fills each paragraph using its indentation level as the fill prefix.
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
775
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
776 When calling from a program, pass range to fill as first two arguments.
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
777
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
778 Optional third and fourth arguments JUSTIFY and MAIL-FLAG:
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
779 JUSTIFY to justify paragraphs (prefix arg),
75
a13ef7914930 Initial revision
root <root>
parents:
diff changeset
780 MAIL-FLAG for a mail message, i. e. don't fill header lines."
11448
b0a7e8ff84ad (fill-paragraph, fill-region, fill-nonuniform-paragraphs)
Richard M. Stallman <rms@gnu.org>
parents: 11356
diff changeset
781 (interactive (list (region-beginning) (region-end)
b0a7e8ff84ad (fill-paragraph, fill-region, fill-nonuniform-paragraphs)
Richard M. Stallman <rms@gnu.org>
parents: 11356
diff changeset
782 (if current-prefix-arg 'full)))
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
783 (save-restriction
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
784 (save-excursion
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
785 (goto-char min)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
786 (beginning-of-line)
9706
f5f7d07eece8 (fill-individual-paragraphs): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents: 9217
diff changeset
787 (narrow-to-region (point) max)
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
788 (if mailp
9706
f5f7d07eece8 (fill-individual-paragraphs): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents: 9217
diff changeset
789 (while (and (not (eobp))
13473
4492ba9a0757 (fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents: 13172
diff changeset
790 (or (looking-at "[ \t]*[^ \t\n]+:")
9706
f5f7d07eece8 (fill-individual-paragraphs): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents: 9217
diff changeset
791 (looking-at "[ \t]*$")))
13473
4492ba9a0757 (fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents: 13172
diff changeset
792 (if (looking-at "[ \t]*[^ \t\n]+:")
4992
8a3293abe1ba (fill-individual-paragraphs): Fix skipping headers of yanked message.
Richard M. Stallman <rms@gnu.org>
parents: 4413
diff changeset
793 (search-forward "\n\n" nil 'move)
8a3293abe1ba (fill-individual-paragraphs): Fix skipping headers of yanked message.
Richard M. Stallman <rms@gnu.org>
parents: 4413
diff changeset
794 (forward-line 1))))
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
795 (narrow-to-region (point) max)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
796 ;; Loop over paragraphs.
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
797 (while (progn (skip-chars-forward " \t\n") (not (eobp)))
13502
57a0a9e5399e (fill-region-as-paragraph): Since adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents: 13473
diff changeset
798 (move-to-left-margin)
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
799 (let ((start (point))
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
800 fill-prefix fill-prefix-regexp)
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
801 ;; Find end of paragraph, and compute the smallest fill-prefix
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
802 ;; that fits all the lines in this paragraph.
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
803 (while (progn
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
804 ;; Update the fill-prefix on the first line
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
805 ;; and whenever the prefix good so far is too long.
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
806 (if (not (and fill-prefix
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
807 (looking-at fill-prefix-regexp)))
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
808 (setq fill-prefix
12557
34e9427fe8f5 (canonically-space-region): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 12429
diff changeset
809 (if (and adaptive-fill-mode adaptive-fill-regexp
13502
57a0a9e5399e (fill-region-as-paragraph): Since adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents: 13473
diff changeset
810 (looking-at adaptive-fill-regexp))
57a0a9e5399e (fill-region-as-paragraph): Since adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents: 13473
diff changeset
811 (match-string 0)
57a0a9e5399e (fill-region-as-paragraph): Since adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents: 13473
diff changeset
812 (buffer-substring
57a0a9e5399e (fill-region-as-paragraph): Since adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents: 13473
diff changeset
813 (point)
57a0a9e5399e (fill-region-as-paragraph): Since adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents: 13473
diff changeset
814 (save-excursion (skip-chars-forward " \t")
57a0a9e5399e (fill-region-as-paragraph): Since adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents: 13473
diff changeset
815 (point))))
57a0a9e5399e (fill-region-as-paragraph): Since adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents: 13473
diff changeset
816 fill-prefix-regexp (regexp-quote fill-prefix)))
13548
9be6c740e36f (fill-individual-paragraphs): Advance 1 line in inner loop.
Richard M. Stallman <rms@gnu.org>
parents: 13502
diff changeset
817 (forward-line 1)
9be6c740e36f (fill-individual-paragraphs): Advance 1 line in inner loop.
Richard M. Stallman <rms@gnu.org>
parents: 13502
diff changeset
818 (move-to-left-margin)
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
819 ;; Now stop the loop if end of paragraph.
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
820 (and (not (eobp))
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
821 (if fill-individual-varying-indent
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
822 ;; If this line is a separator line, with or
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
823 ;; without prefix, end the paragraph.
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
824 (and
13548
9be6c740e36f (fill-individual-paragraphs): Advance 1 line in inner loop.
Richard M. Stallman <rms@gnu.org>
parents: 13502
diff changeset
825 (not (looking-at paragraph-separate))
9be6c740e36f (fill-individual-paragraphs): Advance 1 line in inner loop.
Richard M. Stallman <rms@gnu.org>
parents: 13502
diff changeset
826 (save-excursion
9be6c740e36f (fill-individual-paragraphs): Advance 1 line in inner loop.
Richard M. Stallman <rms@gnu.org>
parents: 13502
diff changeset
827 (not (and (looking-at fill-prefix-regexp)
9be6c740e36f (fill-individual-paragraphs): Advance 1 line in inner loop.
Richard M. Stallman <rms@gnu.org>
parents: 13502
diff changeset
828 (progn (forward-char (length fill-prefix))
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
829 (looking-at paragraph-separate))))))
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
830 ;; If this line has more or less indent
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
831 ;; than the fill prefix wants, end the paragraph.
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
832 (and (looking-at fill-prefix-regexp)
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
833 (save-excursion
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
834 (not (progn (forward-char (length fill-prefix))
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
835 (or (looking-at paragraph-separate)
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
836 (looking-at paragraph-start))))))))))
474
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
837 ;; Fill this paragraph, but don't add a newline at the end.
c3bbd755b7da *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 218
diff changeset
838 (let ((had-newline (bolp)))
10468
d0854b6f3216 (set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents: 10423
diff changeset
839 (fill-region-as-paragraph start (point) justify)
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 474
diff changeset
840 (or had-newline (delete-char -1))))))))
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 638
diff changeset
841
732
a8d94735277e *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 729
diff changeset
842 ;;; fill.el ends here