Mercurial > emacs
annotate lisp/textmodes/fill.el @ 40486:b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
(fill-indent-according-to-mode): Change default to t.
(fill-context-prefix): Simplify control-flow and use a more
sophisticated merge that unifies both previous checks.
(fill-single-word-nobreak-p, fill-french-nobreak-p): New funs.
(fill-nobreak-predicate): Make it into a defcustom'd hook.
(fill-nobreak-p): New fun.
(fill-region-as-paragraph): Use it.
Handle `fill-indent-according-to-mode' slightly differently.
(fill-individual-paragraphs-prefix): Simplify the control-flow.
(fill-individual-paragraphs-citation): Fix.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 30 Oct 2001 08:08:12 +0000 |
parents | f56c0eb18cac |
children | 9e19d0344da5 |
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 |
24972
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
3 ;; Copyright (C) 1985, 86, 92, 94, 95, 96, 97, 1999 Free Software Foundation, Inc. |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
821
diff
changeset
|
4 |
38697
a19197c6442f
Keyword added and FSF specified as Maintainer.
Pavel Janík <Pavel@Janik.cz>
parents:
38186
diff
changeset
|
5 ;; Maintainer: FSF |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
6 ;; Keywords: wp |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
7 |
75 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; 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
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
75 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
14169 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
75 | 24 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2109
diff
changeset
|
25 ;;; Commentary: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2109
diff
changeset
|
26 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2109
diff
changeset
|
27 ;; 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
|
28 ;; manual. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2109
diff
changeset
|
29 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
30 ;;; Code: |
75 | 31 |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
32 (defcustom fill-individual-varying-indent nil |
638 | 33 "*Controls criterion for a new paragraph in `fill-individual-paragraphs'. |
34 Non-nil means changing indent doesn't end a paragraph. | |
35 That mode can handle paragraphs with extra indentation on the first line, | |
36 but it requires separator lines between paragraphs. | |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
37 A value of nil means that any change in indentation starts a new paragraph." |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
38 :type 'boolean |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
39 :group 'fill) |
5770
92dd602768d2
(sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5291
diff
changeset
|
40 |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
41 (defcustom colon-double-space nil |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
42 "*Non-nil means put two spaces after a colon when filling." |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
43 :type 'boolean |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
44 :group 'fill) |
12752
86c8fb2284de
(fill-region-as-paragraph): Don't find adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents:
12557
diff
changeset
|
45 |
10631
dc245bfecc3b
(fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10543
diff
changeset
|
46 (defvar fill-paragraph-function nil |
13839
d597ac78b00e
(fill-paragraph-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13713
diff
changeset
|
47 "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
|
48 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
|
49 |
17852
a9f18d920c11
(enable-kinsoku): Name changed form do-kinsoku.
Kenichi Handa <handa@m17n.org>
parents:
17664
diff
changeset
|
50 (defvar enable-kinsoku t |
19239
8298b8a6a47d
(enable-kinsoku): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19220
diff
changeset
|
51 "*Non-nil means enable \"kinsoku\" processing on filling paragraph. |
8298b8a6a47d
(enable-kinsoku): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19220
diff
changeset
|
52 Kinsoku processing is designed to prevent certain characters from being |
8298b8a6a47d
(enable-kinsoku): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19220
diff
changeset
|
53 placed at the beginning or end of a line by filling. |
8298b8a6a47d
(enable-kinsoku): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19220
diff
changeset
|
54 See the documentation of `kinsoku' for more information.") |
16998 | 55 |
75 | 56 (defun set-fill-prefix () |
5770
92dd602768d2
(sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5291
diff
changeset
|
57 "Set the fill prefix to the current line up to point. |
218 | 58 Filling expects lines to start with the fill prefix and |
59 reinserts the fill prefix in each resulting line." | |
75 | 60 (interactive) |
35785
e8b7be229b24
(set-fill-prefix): Cancel fill prefix if point
Gerd Moellmann <gerd@gnu.org>
parents:
33441
diff
changeset
|
61 (let ((left-margin-pos (save-excursion (move-to-left-margin) (point)))) |
e8b7be229b24
(set-fill-prefix): Cancel fill prefix if point
Gerd Moellmann <gerd@gnu.org>
parents:
33441
diff
changeset
|
62 (if (> (point) left-margin-pos) |
e8b7be229b24
(set-fill-prefix): Cancel fill prefix if point
Gerd Moellmann <gerd@gnu.org>
parents:
33441
diff
changeset
|
63 (progn |
e8b7be229b24
(set-fill-prefix): Cancel fill prefix if point
Gerd Moellmann <gerd@gnu.org>
parents:
33441
diff
changeset
|
64 (setq fill-prefix (buffer-substring left-margin-pos (point))) |
e8b7be229b24
(set-fill-prefix): Cancel fill prefix if point
Gerd Moellmann <gerd@gnu.org>
parents:
33441
diff
changeset
|
65 (if (equal fill-prefix "") |
e8b7be229b24
(set-fill-prefix): Cancel fill prefix if point
Gerd Moellmann <gerd@gnu.org>
parents:
33441
diff
changeset
|
66 (setq fill-prefix nil))) |
e8b7be229b24
(set-fill-prefix): Cancel fill prefix if point
Gerd Moellmann <gerd@gnu.org>
parents:
33441
diff
changeset
|
67 (setq fill-prefix nil))) |
75 | 68 (if fill-prefix |
69 (message "fill-prefix: \"%s\"" fill-prefix) | |
70 (message "fill-prefix cancelled"))) | |
71 | |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
72 (defcustom adaptive-fill-mode t |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
73 "*Non-nil means determine a paragraph's fill prefix from its text." |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
74 :type 'boolean |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
75 :group 'fill) |
218 | 76 |
32230 | 77 (defcustom adaptive-fill-regexp |
38910
f56c0eb18cac
(adaptive-fill-regexp): Admit tabs as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38697
diff
changeset
|
78 (purecopy "[ \t]*\\([-|#;>*]+[ \t]*\\|(?[0-9]+[.)][ \t]*\\)*") |
218 | 79 "*Regexp to match text at start of line that constitutes indentation. |
18221
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
80 If Adaptive Fill mode is enabled, a prefix matching this pattern |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
81 on the first and second lines of a paragraph is used as the |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
82 standard indentation for the whole paragraph. |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
83 |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
84 If the paragraph has just one line, the indentation is taken from that |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
85 line, but in that case `adaptive-fill-first-line-regexp' also plays |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
86 a role." |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
87 :type 'regexp |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
88 :group 'fill) |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
89 |
19076
457a082715c8
(adaptive-fill-first-line-regexp): Fix regexp.
Richard M. Stallman <rms@gnu.org>
parents:
19010
diff
changeset
|
90 (defcustom adaptive-fill-first-line-regexp "\\`[ \t]*\\'" |
18221
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
91 "*Regexp specifying whether to set fill prefix from a one-line paragraph. |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
92 When a paragraph has just one line, then after `adaptive-fill-regexp' |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
93 finds the prefix at the beginning of the line, if it doesn't |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
94 match this regexp, it is replaced with whitespace. |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
95 |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
96 By default, this regexp matches sequences of just spaces and tabs. |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
97 |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
98 However, we never use a prefix from a one-line paragraph |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
99 if it would act as a paragraph-starter on the second line." |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
100 :type 'regexp |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
101 :group 'fill) |
218 | 102 |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
103 (defcustom adaptive-fill-function nil |
35963
4681ff6664e6
(adaptive-fill-function): Fix :type
Dave Love <fx@gnu.org>
parents:
35785
diff
changeset
|
104 "*Function to call to choose a fill prefix for a paragraph, or nil. |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
105 This function is used when `adaptive-fill-regexp' does not match." |
35963
4681ff6664e6
(adaptive-fill-function): Fix :type
Dave Love <fx@gnu.org>
parents:
35785
diff
changeset
|
106 :type '(choice (const nil) function) |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
107 :group 'fill) |
12752
86c8fb2284de
(fill-region-as-paragraph): Don't find adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents:
12557
diff
changeset
|
108 |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
109 (defvar fill-indent-according-to-mode t |
33365
2c0585b6e6d6
(fill-indent-according-to-mode): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32230
diff
changeset
|
110 "Whether or not filling should try to use the major mode's indentation.") |
2c0585b6e6d6
(fill-indent-according-to-mode): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32230
diff
changeset
|
111 |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
112 (defun current-fill-column () |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
113 "Return the fill-column to use for this line. |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
114 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
|
115 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
|
116 subtracted from `fill-column'. |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
117 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
118 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
|
119 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
|
120 (save-excursion |
12429
d6d785d96455
(current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents:
11448
diff
changeset
|
121 (if fill-column |
d6d785d96455
(current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents:
11448
diff
changeset
|
122 (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
|
123 (here-col 0) |
d6d785d96455
(current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents:
11448
diff
changeset
|
124 (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
|
125 margin fill-col change col) |
32230 | 126 ;; Look separately at each region of line with a different |
127 ;; right-margin. | |
12429
d6d785d96455
(current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents:
11448
diff
changeset
|
128 (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
|
129 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
|
130 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
|
131 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
|
132 (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
|
133 (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
|
134 (< col fill-col))) |
d6d785d96455
(current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents:
11448
diff
changeset
|
135 (setq here change |
d6d785d96455
(current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents:
11448
diff
changeset
|
136 here-col col)) |
d6d785d96455
(current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents:
11448
diff
changeset
|
137 (max here-col fill-col))))) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
138 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
139 (defun canonically-space-region (beg end) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
140 "Remove extra spaces between words in region. |
14621
f989cff391f1
(canonically-space-region): Use insert-before-markers
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
141 Leave one space between words, two at end of sentences or after colons |
23519
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
142 \(depending on values of `sentence-end-double-space', `colon-double-space', |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
143 and `sentence-end-without-period'). |
12557
34e9427fe8f5
(canonically-space-region): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
12429
diff
changeset
|
144 Remove indentation from each line." |
24972
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
145 (interactive "*r") |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
146 (save-excursion |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
147 (goto-char beg) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
148 ;; Nuke tabs; they get screwed up in a fill. |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
149 ;; 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
|
150 ;; 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
|
151 ;; Blame the typist. |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
152 (subst-char-in-region beg end ?\t ?\ ) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
153 (while (and (< (point) end) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
154 (re-search-forward " *" end t)) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
155 (delete-region |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
156 (+ (match-beginning 0) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
157 ;; Determine number of spaces to leave: |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
158 (save-excursion |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
159 (skip-chars-backward " ]})\"'") |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
160 (cond ((and sentence-end-double-space |
23519
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
161 (or (memq (preceding-char) '(?. ?? ?!)) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
162 (and sentence-end-without-period |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
163 (= (char-syntax (preceding-char)) ?w)))) 2) |
12752
86c8fb2284de
(fill-region-as-paragraph): Don't find adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents:
12557
diff
changeset
|
164 ((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
|
165 (= (preceding-char) ?:)) 2) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
166 ((char-equal (preceding-char) ?\n) 0) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
167 (t 1)))) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
168 (match-end 0))) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
169 ;; 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
|
170 ;; loses on split abbrevs ("Mr.\nSmith") |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
171 (goto-char beg) |
25606
7ab723e4a21a
(fill-region-as-paragraph, canonically-space-region):
Richard M. Stallman <rms@gnu.org>
parents:
25127
diff
changeset
|
172 (let ((eol-double-space-re (if colon-double-space |
7ab723e4a21a
(fill-region-as-paragraph, canonically-space-region):
Richard M. Stallman <rms@gnu.org>
parents:
25127
diff
changeset
|
173 "[.?!:][])}\"']*$" |
7ab723e4a21a
(fill-region-as-paragraph, canonically-space-region):
Richard M. Stallman <rms@gnu.org>
parents:
25127
diff
changeset
|
174 "[.?!][])}\"']*$"))) |
7ab723e4a21a
(fill-region-as-paragraph, canonically-space-region):
Richard M. Stallman <rms@gnu.org>
parents:
25127
diff
changeset
|
175 (while (and (< (point) end) |
7ab723e4a21a
(fill-region-as-paragraph, canonically-space-region):
Richard M. Stallman <rms@gnu.org>
parents:
25127
diff
changeset
|
176 (re-search-forward eol-double-space-re end t)) |
14621
f989cff391f1
(canonically-space-region): Use insert-before-markers
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
177 ;; We insert before markers in case a caller such as |
f989cff391f1
(canonically-space-region): Use insert-before-markers
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
178 ;; do-auto-fill has done a save-excursion with point at the end |
f989cff391f1
(canonically-space-region): Use insert-before-markers
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
179 ;; of the line and wants it to stay at the end of the line. |
25606
7ab723e4a21a
(fill-region-as-paragraph, canonically-space-region):
Richard M. Stallman <rms@gnu.org>
parents:
25127
diff
changeset
|
180 (insert-before-markers-and-inherit ? ))))) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
181 |
27287
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
182 (defun fill-common-string-prefix (s1 s2) |
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
183 "Return the longest common prefix of strings S1 and S2, or nil if none." |
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
184 (let ((cmp (compare-strings s1 nil nil s2 nil nil))) |
33365
2c0585b6e6d6
(fill-indent-according-to-mode): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32230
diff
changeset
|
185 (if (eq cmp t) |
27287
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
186 s1 |
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
187 (setq cmp (1- (abs cmp))) |
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
188 (unless (zerop cmp) |
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
189 (substring s1 0 cmp))))) |
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
190 |
13586
292e11b5f9c6
(fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
13578
diff
changeset
|
191 (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
|
192 "Compute a fill prefix from the text between FROM and TO. |
25126
9b5a39995216
(fill-context-prefix): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
25088
diff
changeset
|
193 This uses the variables `adaptive-fill-regexp' and `adaptive-fill-function' |
18221
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
194 and `adaptive-fill-first-line-regexp'. `paragraph-start' also plays a role; |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
195 we reject a prefix based on a one-line paragraph if that prefix would |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
196 act as a paragraph-separator." |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
197 (or first-line-regexp |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
198 (setq first-line-regexp adaptive-fill-first-line-regexp)) |
13473
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
199 (save-excursion |
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
200 (goto-char from) |
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
201 (if (eolp) (forward-line 1)) |
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
202 ;; 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
|
203 (let ((firstline (point)) |
18282
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
204 first-line-prefix |
13586
292e11b5f9c6
(fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
13578
diff
changeset
|
205 ;; Non-nil if we are on the second line. |
18282
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
206 second-line-prefix |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
207 start) |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
208 (move-to-left-margin) |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
209 (setq start (point)) |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
210 (setq first-line-prefix |
36610
0598c5e629d2
(fill-context-prefix): Allow first-line-prefix to match paragraph-start.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36302
diff
changeset
|
211 ;; We don't need to consider `paragraph-start' here since it |
0598c5e629d2
(fill-context-prefix): Allow first-line-prefix to match paragraph-start.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36302
diff
changeset
|
212 ;; will be explicitly checked later on. |
0598c5e629d2
(fill-context-prefix): Allow first-line-prefix to match paragraph-start.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36302
diff
changeset
|
213 ;; Also setting first-line-prefix to nil prevents |
0598c5e629d2
(fill-context-prefix): Allow first-line-prefix to match paragraph-start.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36302
diff
changeset
|
214 ;; second-line-prefix from being used. |
0598c5e629d2
(fill-context-prefix): Allow first-line-prefix to match paragraph-start.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36302
diff
changeset
|
215 (cond ;; ((looking-at paragraph-start) nil) |
18282
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
216 ((and adaptive-fill-regexp (looking-at adaptive-fill-regexp)) |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
217 (match-string-no-properties 0)) |
18282
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
218 (adaptive-fill-function (funcall adaptive-fill-function)))) |
13473
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
219 (forward-line 1) |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
220 (if (< (point) to) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
221 (progn |
18282
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
222 (move-to-left-margin) |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
223 (setq start (point)) |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
224 (setq second-line-prefix |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
225 (cond ((looking-at paragraph-start) nil) ; can it happen ?? -sm |
32230 | 226 ((and adaptive-fill-regexp |
227 (looking-at adaptive-fill-regexp)) | |
18282
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
228 (buffer-substring-no-properties start (match-end 0))) |
32230 | 229 (adaptive-fill-function |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
230 (funcall adaptive-fill-function)))) |
18282
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
231 ;; If we get a fill prefix from the second line, |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
232 ;; make sure it or something compatible is on the first line too. |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
233 (when second-line-prefix |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
234 (unless first-line-prefix (setq first-line-prefix "")) |
27287
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
235 |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
236 (if ;; If the non-whitespace chars match the first line, |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
237 ;; just use it (this subsumes the 2 previous checks). |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
238 ;; Used when first line is `/* ...' and second-line is |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
239 ;; ` * ...'. |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
240 (save-excursion |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
241 (goto-char start) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
242 (looking-at |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
243 (apply 'concat |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
244 (mapcar (lambda (c) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
245 (if (memq c '(?\t ?\ )) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
246 ;; The number of chars might not |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
247 ;; match up if there's a mix of |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
248 ;; tabs and spaces. |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
249 "\\([ \t]*\\|.\\)" |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
250 (regexp-quote (string c)))) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
251 second-line-prefix)))) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
252 second-line-prefix |
27287
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
253 |
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
254 ;; Use the longest common substring of both prefixes, |
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
255 ;; if there is one. |
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
256 (fill-common-string-prefix first-line-prefix |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
257 second-line-prefix)))) |
18282
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
258 ;; If we get a fill prefix from a one-line paragraph, |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
259 ;; maybe change it to whitespace, |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
260 ;; and check that it isn't a paragraph starter. |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
261 (if first-line-prefix |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
262 (let ((result |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
263 ;; If first-line-prefix comes from the first line, |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
264 ;; see if it seems reasonable to use for all lines. |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
265 ;; If not, replace it with whitespace. |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
266 (if (or (and first-line-regexp |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
267 (string-match first-line-regexp |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
268 first-line-prefix)) |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
269 (and comment-start-skip |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
270 (string-match comment-start-skip |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
271 first-line-prefix))) |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
272 first-line-prefix |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
273 (make-string (string-width first-line-prefix) ?\ )))) |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
274 ;; But either way, reject it if it indicates the start |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
275 ;; of a paragraph when text follows it. |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
276 (if (not (eq 0 (string-match paragraph-start |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
277 (concat result "a")))) |
18283 | 278 result))))))) |
13473
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
279 |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
280 (defun fill-single-word-nobreak-p () |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
281 "Don't break a line after the first or before the last word of a sentence." |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
282 (or (looking-at "[ \t]*\\sw+[ \t]*[.?!:][ \t]*$") |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
283 (save-excursion |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
284 (skip-chars-backward " \t") |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
285 (and (/= (skip-syntax-backward "w") 0) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
286 (/= (skip-chars-backward " \t") 0) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
287 (/= (skip-chars-backward ".?!:") 0))))) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
288 |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
289 (defun fill-french-nobreak-p () |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
290 "Return nil if French style allows breaking the line at point. |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
291 This is used in `fill-nobreak-predicate' to prevent breaking lines just |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
292 after an opening paren or just before a closing paren or a punctuation |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
293 mark such as `?' or `:'. It is common in French writing to put a space |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
294 at such places, which would normally allow breaking the line at those |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
295 places." |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
296 (or (looking-at "[ \t]*[])}»?!;:-]") |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
297 (save-excursion |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
298 (skip-chars-backward " \t") |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
299 (unless (bolp) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
300 (backward-char 1) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
301 (or (looking-at "[([{«]") |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
302 ;; Don't cut right after a single-letter word. |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
303 (and (memq (preceding-char) '(?\t ?\ )) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
304 (eq (char-syntax (following-char)) ?w))))))) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
305 |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
306 (defcustom fill-nobreak-predicate nil |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
307 "List of predicates for recognizing places not to break a line. |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
308 The predicates are called with no arguments, with point at the place to |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
309 be tested. If it returns t, fill commands do not break the line there." |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
310 :group 'fill |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
311 :type 'hook |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
312 :options '(fill-french-nobreak-p fill-single-word-nobreak-p)) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
313 |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
314 (defun fill-nobreak-p () |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
315 "Return nil if breaking the line at point is allowed. |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
316 Can be customized with the variable `fill-nobreak-predicate'." |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
317 (unless (bolp) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
318 (or |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
319 ;; Don't break after a period followed by just one space. |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
320 ;; Move back to the previous place to break. |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
321 ;; The reason is that if a period ends up at the end of a |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
322 ;; line, further fills will assume it ends a sentence. |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
323 ;; If we now know it does not end a sentence, avoid putting |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
324 ;; it at the end of the line. |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
325 (and sentence-end-double-space |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
326 (save-excursion |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
327 (skip-chars-backward ". ") |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
328 (looking-at "\\. \\([^ ]\\|$\\)"))) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
329 ;; Another approach to the same problem. |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
330 (save-excursion |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
331 (skip-chars-backward ". ") |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
332 (and (looking-at "\\.") |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
333 (not (looking-at sentence-end)))) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
334 ;; Don't split a line if the rest would look like a new paragraph. |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
335 (unless use-hard-newlines |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
336 (save-excursion |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
337 (skip-chars-forward " \t") (looking-at paragraph-start))) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
338 (run-hook-with-args-until-success 'fill-nobreak-predicate)))) |
21123
e1c817a29b2d
(fill-nobreak-predicate): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
21103
diff
changeset
|
339 |
23519
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
340 ;; Put `fill-find-break-point-function' property to charsets which |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
341 ;; require special functions to find line breaking point. |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
342 (dolist (pair '((katakana-jisx0201 . kinsoku) |
23490
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
343 (chinese-gb2312 . kinsoku) |
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
344 (japanese-jisx0208 . kinsoku) |
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
345 (japanese-jisx0212 . kinsoku) |
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
346 (chinese-big5-1 . kinsoku) |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
347 (chinese-big5-2 . kinsoku))) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
348 (put-charset-property (car pair) 'fill-find-break-point-function (cdr pair))) |
23490
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
349 |
23519
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
350 (defun fill-find-break-point (limit) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
351 "Move point to a proper line breaking position of the current line. |
23490
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
352 Don't move back past the buffer position LIMIT. |
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
353 |
23519
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
354 This function is called when we are going to break the current line |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
355 after or before a non-ascii character. If the charset of the |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
356 character has the property `fill-find-break-point-function', this |
23490
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
357 function calls the property value as a function with one arg LINEBEG. |
23519
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
358 If the charset has no such property, do nothing." |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
359 (let* ((ch (following-char)) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
360 (charset (char-charset ch)) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
361 func) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
362 (if (eq charset 'ascii) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
363 (setq ch (preceding-char) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
364 charset (char-charset ch))) |
29484
59d0015683a5
(fill-find-break-point): Check the validity of charset.
Kenichi Handa <handa@m17n.org>
parents:
28489
diff
changeset
|
365 (if (charsetp charset) |
59d0015683a5
(fill-find-break-point): Check the validity of charset.
Kenichi Handa <handa@m17n.org>
parents:
28489
diff
changeset
|
366 (setq func |
59d0015683a5
(fill-find-break-point): Check the validity of charset.
Kenichi Handa <handa@m17n.org>
parents:
28489
diff
changeset
|
367 (get-charset-property charset 'fill-find-break-point-function))) |
26898
182d67795a5b
(fill-find-break-point): Delete codes for
Kenichi Handa <handa@m17n.org>
parents:
25606
diff
changeset
|
368 (if (and func (fboundp func)) |
182d67795a5b
(fill-find-break-point): Delete codes for
Kenichi Handa <handa@m17n.org>
parents:
25606
diff
changeset
|
369 (funcall func limit)))) |
23490
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
370 |
14621
f989cff391f1
(canonically-space-region): Use insert-before-markers
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
371 (defun fill-region-as-paragraph (from to &optional justify |
f989cff391f1
(canonically-space-region): Use insert-before-markers
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
372 nosqueeze squeeze-after) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
373 "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
|
374 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
|
375 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
|
376 `current-left-margin' and `current-fill-column' functions. |
18664 | 377 \(In most cases, the variable `fill-column' controls the width.) |
13578
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
378 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
|
379 |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
380 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
|
381 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
|
382 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
383 From a program, optional third arg JUSTIFY can specify any type of |
14621
f989cff391f1
(canonically-space-region): Use insert-before-markers
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
384 justification. Fourth arg NOSQUEEZE non-nil means not to make spaces |
14645
875c14f0d0db
(fill-region-as-paragraph): Doc fix.
Erik Naggum <erik@naggum.no>
parents:
14621
diff
changeset
|
385 between words canonical before filling. Fifth arg SQUEEZE-AFTER, if non-nil, |
14621
f989cff391f1
(canonically-space-region): Use insert-before-markers
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
386 means don't canonicalize spaces before that position. |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
387 |
33441
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
388 Return the fill-prefix used for filling. |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
389 |
5770
92dd602768d2
(sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5291
diff
changeset
|
390 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
|
391 space does not end a sentence, so don't break a line there." |
24972
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
392 (interactive (progn |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
393 (barf-if-buffer-read-only) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
394 (list (region-beginning) (region-end) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
395 (if current-prefix-arg 'full)))) |
21150
a9e9f674c9c9
(fill-region-as-paragraph, fill-region): Allow t as legit value of JUSTIFY.
Richard M. Stallman <rms@gnu.org>
parents:
21123
diff
changeset
|
396 (unless (memq justify '(t nil none full center left right)) |
21103
8e12f5209e37
(fill-region): If JUSTIFY is non-nil
Richard M. Stallman <rms@gnu.org>
parents:
20822
diff
changeset
|
397 (setq justify 'full)) |
1332
955ebdb98095
(fill-paragraph): Don't actually change point before
Richard M. Stallman <rms@gnu.org>
parents:
1067
diff
changeset
|
398 ;; 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
|
399 (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
|
400 (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
|
401 |
13578
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
402 ;; Make sure "to" is the endpoint. |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
403 (goto-char (min from to)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
404 (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
|
405 ;; 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
|
406 (skip-chars-forward " \t\n") |
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
407 |
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
408 (let ((from-plus-indent (point)) |
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
409 (oneleft nil)) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
410 |
13578
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
411 (beginning-of-line) |
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
412 (setq from (point)) |
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
413 |
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
414 ;; Delete all but one soft newline at end of region. |
14113
dfbb4ab9bee1
(fill-region-as-paragraph): Check again for reaching
Karl Heuer <kwzh@gnu.org>
parents:
13981
diff
changeset
|
415 ;; And leave TO before that one. |
13578
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
416 (goto-char to) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
417 (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
|
418 (if (and oneleft |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
419 (not (and use-hard-newlines |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
420 (get-text-property (1- (point)) 'hard)))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
421 (delete-backward-char 1) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
422 (backward-char 1) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
423 (setq oneleft t))) |
13578
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
424 (setq to (point)) |
33365
2c0585b6e6d6
(fill-indent-according-to-mode): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32230
diff
changeset
|
425 ;; ;; If there was no newline, and there is text in the paragraph, then |
2c0585b6e6d6
(fill-indent-according-to-mode): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32230
diff
changeset
|
426 ;; ;; create a newline. |
2c0585b6e6d6
(fill-indent-according-to-mode): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32230
diff
changeset
|
427 ;; (if (and (not oneleft) (> to from-plus-indent)) |
2c0585b6e6d6
(fill-indent-according-to-mode): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32230
diff
changeset
|
428 ;; (newline)) |
13578
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
429 (goto-char from-plus-indent)) |
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
430 |
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
431 (if (not (> to (point))) |
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
432 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
|
433 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
434 (or justify (setq justify (current-justification))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
435 |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
436 ;; Never indent-according-to-mode with brain dead "indenting" functions. |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
437 (when (and fill-indent-according-to-mode |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
438 (memq indent-line-function |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
439 '(indent-relative-maybe indent-relative |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
440 indent-to-left-margin))) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
441 (set (make-local-variable 'fill-indent-according-to-mode) nil)) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
442 |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
443 ;; 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
|
444 (let ((fill-prefix fill-prefix)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
445 ;; 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
|
446 (if (and adaptive-fill-mode |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
447 (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
|
448 (setq fill-prefix (fill-context-prefix from to))) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
449 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
450 (save-restriction |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
451 (goto-char from) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
452 (beginning-of-line) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
453 (narrow-to-region (point) to) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
454 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
455 (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
|
456 (progn |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
457 (goto-char from) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
458 (while (not (eobp)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
459 (if (and (not (eolp)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
460 (< (current-indentation) (current-left-margin))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
461 (indent-to-left-margin)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
462 (forward-line 1))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
463 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
464 (if use-hard-newlines |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
465 (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
|
466 ;; 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
|
467 (if (or (memq justify '(right center)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
468 (< (current-indentation) (current-left-margin))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
469 (indent-to-left-margin)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
470 ;; 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
|
471 ;; 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
|
472 (goto-char from) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
473 (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
|
474 (concat "[ \t]*" |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
475 (regexp-quote fill-prefix) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
476 "[ \t]*")))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
477 (and fpre |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
478 (progn |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
479 (if (>= (+ (current-left-margin) (length fill-prefix)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
480 (current-fill-column)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
481 (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
|
482 (goto-char from) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
483 (forward-line 1) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
484 (while (not (eobp)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
485 (if (looking-at fpre) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
486 (delete-region (point) (match-end 0))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
487 (forward-line 1)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
488 (goto-char from) |
14621
f989cff391f1
(canonically-space-region): Use insert-before-markers
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
489 (if (looking-at fpre) |
f989cff391f1
(canonically-space-region): Use insert-before-markers
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
490 (goto-char (match-end 0))) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
491 (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
|
492 ;; 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
|
493 (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
|
494 (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
|
495 (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
|
496 |
7d4805feb413
(fill-region-as-paragraph): Remove fill-prefix first, then remove indentation.
Richard M. Stallman <rms@gnu.org>
parents:
10989
diff
changeset
|
497 ;; 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
|
498 ;; but after any fill prefix on the first line. |
218 | 499 |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
500 ;; 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
|
501 ;; loses on split abbrevs ("Mr.\nSmith") |
25606
7ab723e4a21a
(fill-region-as-paragraph, canonically-space-region):
Richard M. Stallman <rms@gnu.org>
parents:
25127
diff
changeset
|
502 (let ((eol-double-space-re (if colon-double-space |
7ab723e4a21a
(fill-region-as-paragraph, canonically-space-region):
Richard M. Stallman <rms@gnu.org>
parents:
25127
diff
changeset
|
503 "[.?!:][])}\"']*$" |
7ab723e4a21a
(fill-region-as-paragraph, canonically-space-region):
Richard M. Stallman <rms@gnu.org>
parents:
25127
diff
changeset
|
504 "[.?!][])}\"']*$"))) |
7ab723e4a21a
(fill-region-as-paragraph, canonically-space-region):
Richard M. Stallman <rms@gnu.org>
parents:
25127
diff
changeset
|
505 (while (re-search-forward eol-double-space-re nil t) |
7ab723e4a21a
(fill-region-as-paragraph, canonically-space-region):
Richard M. Stallman <rms@gnu.org>
parents:
25127
diff
changeset
|
506 (or (eobp) (insert-and-inherit ?\ )))) |
23519
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
507 |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
508 (goto-char from) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
509 (if enable-multibyte-characters |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
510 ;; Delete unnecessay newlines surrounded by words. The |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
511 ;; character category `|' means that we can break a line |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
512 ;; at the character. And, charset property |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
513 ;; `nospace-between-words' tells how to concatenate |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
514 ;; words. If the value is non-nil, never put spaces |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
515 ;; between words, thus delete a newline between them. |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
516 ;; If the value is nil, delete a newline only when a |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
517 ;; character preceding a newline has text property |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
518 ;; `nospace-between-words'. |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
519 (while (search-forward "\n" nil t) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
520 (let ((prev (char-before (match-beginning 0))) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
521 (next (following-char))) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
522 (if (and (or (aref (char-category-set next) ?|) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
523 (aref (char-category-set prev) ?|)) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
524 (or (get-charset-property (char-charset prev) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
525 'nospace-between-words) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
526 (get-text-property (1- (match-beginning 0)) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
527 'nospace-between-words))) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
528 (delete-char -1))))) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
529 |
16998 | 530 (goto-char from) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
531 (skip-chars-forward " \t") |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
532 ;; Then change all newlines to spaces. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
533 (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
|
534 (if (and nosqueeze (not (eq justify 'full))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
535 nil |
14621
f989cff391f1
(canonically-space-region): Use insert-before-markers
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
536 (canonically-space-region (or squeeze-after (point)) (point-max)) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
537 (goto-char (point-max)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
538 (delete-horizontal-space) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
539 (insert-and-inherit " ")) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
540 (goto-char (point-min)) |
218 | 541 |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
542 ;; This is the actual filling loop. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
543 (let ((prefixcol 0) linebeg) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
544 (while (not (eobp)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
545 (setq linebeg (point)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
546 (move-to-column (1+ (current-fill-column))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
547 (if (eobp) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
548 (or nosqueeze (delete-horizontal-space)) |
16998 | 549 ;; Move back to the point where we can break the line |
550 ;; at. We break the line between word or after/before | |
551 ;; the character which has character category `|'. We | |
552 ;; search space, \c| followed by a character, or \c| | |
553 ;; following a character. If not found, place | |
554 ;; the point at linebeg. | |
555 (if (re-search-backward " \\|\\c|.\\|.\\c|" linebeg 0) | |
556 ;; In case of space, we place the point at next to | |
557 ;; the point where the break occurs acutually, | |
558 ;; because we don't want to change the following | |
559 ;; logic of original Emacs. In case of \c|, the | |
560 ;; point is at the place where the break occurs. | |
561 (forward-char 1)) | |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
562 ;; 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
|
563 ;; 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
|
564 ;; 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
|
565 ;; 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
|
566 ;; 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
|
567 ;; avoid putting it at the end of the line. |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
568 (while (and (> (point) linebeg) (fill-nobreak-p)) |
21123
e1c817a29b2d
(fill-nobreak-predicate): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
21103
diff
changeset
|
569 (if (re-search-backward " \\|\\c|.\\|.\\c|" linebeg 0) |
e1c817a29b2d
(fill-nobreak-predicate): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
21103
diff
changeset
|
570 (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
|
571 ;; If the left margin and fill prefix by themselves |
14840
dfbf6fd50825
(fill-region-as-paragraph): Fix the second check for
Richard M. Stallman <rms@gnu.org>
parents:
14827
diff
changeset
|
572 ;; pass the fill-column. or if they are zero |
dfbf6fd50825
(fill-region-as-paragraph): Fix the second check for
Richard M. Stallman <rms@gnu.org>
parents:
14827
diff
changeset
|
573 ;; but we have no room for even one word, |
16998 | 574 ;; keep at least one word or a character which has |
575 ;; category `|'anyway . | |
13549
f8afa95d197e
(fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents:
13548
diff
changeset
|
576 ;; 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
|
577 (if (if (zerop prefixcol) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
578 (save-excursion |
13578
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
579 (skip-chars-backward " \t" linebeg) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
580 (bolp)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
581 (>= prefixcol (current-column))) |
16998 | 582 ;; Ok, skip at least one word or one \c| character. |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
583 ;; Meanwhile, don't stop at a period followed by one space. |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
584 (let ((fill-nobreak-predicate nil) ;to break sooner. |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
585 (first t)) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
586 (move-to-column prefixcol) |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
587 (while (and (not (eobp)) (or first (fill-nobreak-p))) |
20234
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
588 ;; Find a breakable point while ignoring the |
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
589 ;; following spaces. |
13578
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
590 (skip-chars-forward " \t") |
20234
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
591 (if (looking-at "\\c|") |
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
592 (forward-char 1) |
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
593 (let ((pos (save-excursion |
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
594 (skip-chars-forward "^ \n\t") |
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
595 (point)))) |
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
596 (if (re-search-forward "\\c|" pos t) |
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
597 (forward-char -1) |
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
598 (goto-char pos)))) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
599 (setq first nil))) |
32230 | 600 ;; Normally, move back over the single space between |
601 ;; the words. | |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
602 (skip-chars-backward " \t") |
23490
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
603 |
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
604 (if enable-multibyte-characters |
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
605 ;; If we are going to break the line after or |
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
606 ;; before a non-ascii character, we may have to |
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
607 ;; run a special function for the charset of the |
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
608 ;; character to find the correct break point. |
23519
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
609 (if (not (and (eq (charset-after (1- (point))) 'ascii) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
610 (eq (charset-after (point)) 'ascii))) |
25088
4b9caa006ac3
(fill-region-as-paragraph): Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents:
25061
diff
changeset
|
611 ;; Make sure we take SOMETHING after the |
4b9caa006ac3
(fill-region-as-paragraph): Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents:
25061
diff
changeset
|
612 ;; fill prefix if any. |
4b9caa006ac3
(fill-region-as-paragraph): Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents:
25061
diff
changeset
|
613 (fill-find-break-point |
4b9caa006ac3
(fill-region-as-paragraph): Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents:
25061
diff
changeset
|
614 (save-excursion |
4b9caa006ac3
(fill-region-as-paragraph): Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents:
25061
diff
changeset
|
615 (goto-char linebeg) |
4b9caa006ac3
(fill-region-as-paragraph): Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents:
25061
diff
changeset
|
616 (move-to-column prefixcol) |
4b9caa006ac3
(fill-region-as-paragraph): Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents:
25061
diff
changeset
|
617 (point)))))) |
16998 | 618 |
13549
f8afa95d197e
(fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents:
13548
diff
changeset
|
619 ;; 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
|
620 ;; 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
|
621 ;; 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
|
622 (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
|
623 (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
|
624 (save-excursion |
f8afa95d197e
(fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents:
13548
diff
changeset
|
625 (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
|
626 (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
|
627 (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
|
628 (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
|
629 (< nchars (length fill-prefix)) |
32230 | 630 (string= (buffer-substring (point) |
631 fill-point) | |
632 (substring fill-prefix | |
633 0 nchars))))))) | |
13549
f8afa95d197e
(fill-region-as-paragraph): Handle left margin extending to or past
Richard M. Stallman <rms@gnu.org>
parents:
13548
diff
changeset
|
634 ;; 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
|
635 ;; don't stop at a period followed by just one space. |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
636 (let ((fill-nobreak-predicate nil) ;to break sooner. |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
637 (first t)) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
638 (while (and (not (eobp)) (or first (fill-nobreak-p))) |
20234
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
639 ;; Find a breakable point while ignoring the |
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
640 ;; following spaces. |
13578
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
641 (skip-chars-forward " \t") |
20234
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
642 (if (looking-at "\\c|") |
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
643 (forward-char 1) |
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
644 (let ((pos (save-excursion |
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
645 (skip-chars-forward "^ \n\t") |
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
646 (point)))) |
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
647 (if (re-search-forward "\\c|" pos t) |
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
648 (forward-char -1) |
a21b3ed1915e
(fill-region-as-paragraph): Fix bug of
Kenichi Handa <handa@m17n.org>
parents:
19929
diff
changeset
|
649 (goto-char pos)))) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
650 (setq first nil)))) |
14113
dfbb4ab9bee1
(fill-region-as-paragraph): Check again for reaching
Karl Heuer <kwzh@gnu.org>
parents:
13981
diff
changeset
|
651 ;; Check again to see if we got to the end of the paragraph. |
14840
dfbf6fd50825
(fill-region-as-paragraph): Fix the second check for
Richard M. Stallman <rms@gnu.org>
parents:
14827
diff
changeset
|
652 (if (save-excursion (skip-chars-forward " \t") (eobp)) |
14113
dfbb4ab9bee1
(fill-region-as-paragraph): Check again for reaching
Karl Heuer <kwzh@gnu.org>
parents:
13981
diff
changeset
|
653 (or nosqueeze (delete-horizontal-space)) |
32230 | 654 ;; Replace whitespace here with one newline, then |
655 ;; indent to left margin. | |
14113
dfbb4ab9bee1
(fill-region-as-paragraph): Check again for reaching
Karl Heuer <kwzh@gnu.org>
parents:
13981
diff
changeset
|
656 (skip-chars-backward " \t") |
16998 | 657 (if (and (= (following-char) ?\ ) |
658 (or (aref (char-category-set (preceding-char)) ?|) | |
659 (looking-at "[ \t]+\\c|"))) | |
660 ;; We need one space at end of line so that | |
661 ;; further filling won't delete it. NOTE: We | |
662 ;; intentionally leave this one space to | |
663 ;; distingush the case that user wants to put | |
664 ;; space between \c| characters. | |
665 (forward-char 1)) | |
14113
dfbb4ab9bee1
(fill-region-as-paragraph): Check again for reaching
Karl Heuer <kwzh@gnu.org>
parents:
13981
diff
changeset
|
666 (insert ?\n) |
dfbb4ab9bee1
(fill-region-as-paragraph): Check again for reaching
Karl Heuer <kwzh@gnu.org>
parents:
13981
diff
changeset
|
667 ;; Give newline the properties of the space(s) it replaces |
dfbb4ab9bee1
(fill-region-as-paragraph): Check again for reaching
Karl Heuer <kwzh@gnu.org>
parents:
13981
diff
changeset
|
668 (set-text-properties (1- (point)) (point) |
dfbb4ab9bee1
(fill-region-as-paragraph): Check again for reaching
Karl Heuer <kwzh@gnu.org>
parents:
13981
diff
changeset
|
669 (text-properties-at (point))) |
33365
2c0585b6e6d6
(fill-indent-according-to-mode): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32230
diff
changeset
|
670 (if (or fill-prefix |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
671 (not fill-indent-according-to-mode)) |
33365
2c0585b6e6d6
(fill-indent-according-to-mode): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32230
diff
changeset
|
672 (indent-to-left-margin) |
2c0585b6e6d6
(fill-indent-according-to-mode): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32230
diff
changeset
|
673 (indent-according-to-mode)) |
14113
dfbb4ab9bee1
(fill-region-as-paragraph): Check again for reaching
Karl Heuer <kwzh@gnu.org>
parents:
13981
diff
changeset
|
674 ;; Insert the fill prefix after indentation. |
dfbb4ab9bee1
(fill-region-as-paragraph): Check again for reaching
Karl Heuer <kwzh@gnu.org>
parents:
13981
diff
changeset
|
675 ;; Set prefixcol so whitespace in the prefix won't get lost. |
dfbb4ab9bee1
(fill-region-as-paragraph): Check again for reaching
Karl Heuer <kwzh@gnu.org>
parents:
13981
diff
changeset
|
676 (and fill-prefix (not (equal fill-prefix "")) |
dfbb4ab9bee1
(fill-region-as-paragraph): Check again for reaching
Karl Heuer <kwzh@gnu.org>
parents:
13981
diff
changeset
|
677 (progn |
dfbb4ab9bee1
(fill-region-as-paragraph): Check again for reaching
Karl Heuer <kwzh@gnu.org>
parents:
13981
diff
changeset
|
678 (insert-and-inherit fill-prefix) |
dfbb4ab9bee1
(fill-region-as-paragraph): Check again for reaching
Karl Heuer <kwzh@gnu.org>
parents:
13981
diff
changeset
|
679 (setq prefixcol (current-column)))))) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
680 ;; Justify the line just ended, if desired. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
681 (if justify |
19317
09398d892cf7
(fill-region-as-paragraph):
Richard M. Stallman <rms@gnu.org>
parents:
19239
diff
changeset
|
682 (if (save-excursion (skip-chars-forward " \t") (eobp)) |
09398d892cf7
(fill-region-as-paragraph):
Richard M. Stallman <rms@gnu.org>
parents:
19239
diff
changeset
|
683 (progn |
09398d892cf7
(fill-region-as-paragraph):
Richard M. Stallman <rms@gnu.org>
parents:
19239
diff
changeset
|
684 (delete-horizontal-space) |
09398d892cf7
(fill-region-as-paragraph):
Richard M. Stallman <rms@gnu.org>
parents:
19239
diff
changeset
|
685 (justify-current-line justify t t)) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
686 (forward-line -1) |
11356
4be78e93d1be
(fill-region-as-paragraph): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents:
11282
diff
changeset
|
687 (justify-current-line justify nil t) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
688 (forward-line 1)))))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
689 ;; Leave point after final newline. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
690 (goto-char (point-max))) |
22198
74d1c031f824
(fill-region-as-paragraph):
Richard M. Stallman <rms@gnu.org>
parents:
21727
diff
changeset
|
691 (unless (eobp) |
33441
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
692 (forward-char 1)) |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
693 ;; Return the fill-prefix we used |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
694 fill-prefix))) |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
695 |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
696 (defsubst skip-line-prefix (prefix) |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
697 "If point is inside the string PREFIX at the beginning of line, move past it." |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
698 (when (and prefix |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
699 (< (- (point) (line-beginning-position)) (length prefix)) |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
700 (save-excursion |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
701 (beginning-of-line) |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
702 (looking-at (regexp-quote prefix)))) |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
703 (goto-char (match-end 0)))) |
75 | 704 |
705 (defun fill-paragraph (arg) | |
36302
a2f48aef1741
(fill-region-as-paragraph): Skip spaces backward
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35963
diff
changeset
|
706 "Fill paragraph at or after point. Prefix ARG means justify as well. |
5770
92dd602768d2
(sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5291
diff
changeset
|
707 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
|
708 space does not end a sentence, so don't break a line there. |
18664 | 709 the variable `fill-column' controls the width for filling. |
10631
dc245bfecc3b
(fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10543
diff
changeset
|
710 |
dc245bfecc3b
(fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10543
diff
changeset
|
711 If `fill-paragraph-function' is non-nil, we call it (passing our |
33441
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
712 argument to it), and if it returns non-nil, we simply return its value. |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
713 |
36302
a2f48aef1741
(fill-region-as-paragraph): Skip spaces backward
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35963
diff
changeset
|
714 If `fill-paragraph-function' is nil, return the `fill-prefix' used for filling." |
24972
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
715 (interactive (progn |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
716 (barf-if-buffer-read-only) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
717 (list (if current-prefix-arg 'full)))) |
10631
dc245bfecc3b
(fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10543
diff
changeset
|
718 (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
|
719 (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
|
720 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
|
721 (funcall function arg))) |
22367 | 722 (let ((before (point)) |
33441
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
723 ;; Fill prefix used for filling the paragraph |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
724 fill-pfx |
22367 | 725 ;; If fill-paragraph is called recursively, |
726 ;; don't give fill-paragraph-function a second chance. | |
727 fill-paragraph-function) | |
10631
dc245bfecc3b
(fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10543
diff
changeset
|
728 (save-excursion |
dc245bfecc3b
(fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10543
diff
changeset
|
729 (forward-paragraph) |
dc245bfecc3b
(fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10543
diff
changeset
|
730 (or (bolp) (newline 1)) |
dc245bfecc3b
(fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10543
diff
changeset
|
731 (let ((end (point)) |
dc245bfecc3b
(fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10543
diff
changeset
|
732 (beg (progn (backward-paragraph) (point)))) |
dc245bfecc3b
(fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10543
diff
changeset
|
733 (goto-char before) |
36302
a2f48aef1741
(fill-region-as-paragraph): Skip spaces backward
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35963
diff
changeset
|
734 (setq fill-pfx |
33441
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
735 (if use-hard-newlines |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
736 ;; Can't use fill-region-as-paragraph, since this |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
737 ;; paragraph may still contain hard newlines. See |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
738 ;; fill-region. |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
739 (fill-region beg end arg) |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
740 (fill-region-as-paragraph beg end arg))))) |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
741 ;; See if point ended up inside the fill-prefix, and if so, move |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
742 ;; past it. |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
743 (skip-line-prefix fill-pfx) |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
744 fill-pfx))) |
75 | 745 |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
746 (defun fill-region (from to &optional justify nosqueeze to-eop) |
75 | 747 "Fill each of the paragraphs in the region. |
21103
8e12f5209e37
(fill-region): If JUSTIFY is non-nil
Richard M. Stallman <rms@gnu.org>
parents:
20822
diff
changeset
|
748 A prefix arg means justify as well. |
18664 | 749 Ordinarily the variable `fill-column' controls the width. |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
750 |
21103
8e12f5209e37
(fill-region): If JUSTIFY is non-nil
Richard M. Stallman <rms@gnu.org>
parents:
20822
diff
changeset
|
751 Noninteractively, the third argument JUSTIFY specifies which |
8e12f5209e37
(fill-region): If JUSTIFY is non-nil
Richard M. Stallman <rms@gnu.org>
parents:
20822
diff
changeset
|
752 kind of justification to do: `full', `left', `right', `center', |
21150
a9e9f674c9c9
(fill-region-as-paragraph, fill-region): Allow t as legit value of JUSTIFY.
Richard M. Stallman <rms@gnu.org>
parents:
21123
diff
changeset
|
753 or `none' (equivalent to nil). t means handle each paragraph |
a9e9f674c9c9
(fill-region-as-paragraph, fill-region): Allow t as legit value of JUSTIFY.
Richard M. Stallman <rms@gnu.org>
parents:
21123
diff
changeset
|
754 as specified by its text properties. |
a9e9f674c9c9
(fill-region-as-paragraph, fill-region): Allow t as legit value of JUSTIFY.
Richard M. Stallman <rms@gnu.org>
parents:
21123
diff
changeset
|
755 |
21103
8e12f5209e37
(fill-region): If JUSTIFY is non-nil
Richard M. Stallman <rms@gnu.org>
parents:
20822
diff
changeset
|
756 The fourth arg NOSQUEEZE non-nil means to leave |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
757 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
|
758 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
|
759 hard newline, if `use-hard-newlines' is on). |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
760 |
33441
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
761 Return the fill-prefix used for filling the last paragraph. |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
762 |
5770
92dd602768d2
(sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5291
diff
changeset
|
763 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
|
764 space does not end a sentence, so don't break a line there." |
24972
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
765 (interactive (progn |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
766 (barf-if-buffer-read-only) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
767 (list (region-beginning) (region-end) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
768 (if current-prefix-arg 'full)))) |
21150
a9e9f674c9c9
(fill-region-as-paragraph, fill-region): Allow t as legit value of JUSTIFY.
Richard M. Stallman <rms@gnu.org>
parents:
21123
diff
changeset
|
769 (unless (memq justify '(t nil none full center left right)) |
21103
8e12f5209e37
(fill-region): If JUSTIFY is non-nil
Richard M. Stallman <rms@gnu.org>
parents:
20822
diff
changeset
|
770 (setq justify 'full)) |
33441
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
771 (let (end beg fill-pfx) |
10110
18d52489f138
(fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents:
9706
diff
changeset
|
772 (save-restriction |
18d52489f138
(fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents:
9706
diff
changeset
|
773 (goto-char (max from to)) |
36610
0598c5e629d2
(fill-context-prefix): Allow first-line-prefix to match paragraph-start.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36302
diff
changeset
|
774 (when to-eop |
0598c5e629d2
(fill-context-prefix): Allow first-line-prefix to match paragraph-start.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36302
diff
changeset
|
775 (skip-chars-backward "\n") |
0598c5e629d2
(fill-context-prefix): Allow first-line-prefix to match paragraph-start.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36302
diff
changeset
|
776 (forward-paragraph)) |
10110
18d52489f138
(fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents:
9706
diff
changeset
|
777 (setq end (point)) |
18d52489f138
(fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents:
9706
diff
changeset
|
778 (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
|
779 (beginning-of-line) |
18d52489f138
(fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents:
9706
diff
changeset
|
780 (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
|
781 (while (not (eobp)) |
18d52489f138
(fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents:
9706
diff
changeset
|
782 (let ((initial (point)) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
783 end) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
784 ;; 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
|
785 ;; purposes rather than using paragraph breaks. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
786 (if use-hard-newlines |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
787 (progn |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
788 (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
|
789 'hard t)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
790 (not (= ?\n (char-after end))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
791 (not (= end (point-max)))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
792 (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
|
793 (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
|
794 (goto-char initial)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
795 (forward-paragraph 1) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
796 (setq end (point)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
797 (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
|
798 (if (< (point) beg) |
18d52489f138
(fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents:
9706
diff
changeset
|
799 (goto-char beg)) |
18d52489f138
(fill-region-as-paragraph): If region starts in mid-line,
Richard M. Stallman <rms@gnu.org>
parents:
9706
diff
changeset
|
800 (if (>= (point) initial) |
33441
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
801 (setq fill-pfx |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
802 (fill-region-as-paragraph (point) end justify nosqueeze)) |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
803 (goto-char end)))) |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
804 fill-pfx))) |
75 | 805 |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
806 |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
807 (defcustom default-justification 'left |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
808 "*Method of justifying text not otherwise specified. |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
809 Possible values are `left', `right', `full', `center', or `none'. |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
810 The requested kind of justification is done whenever lines are filled. |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
811 The `justification' text-property can locally override this variable." |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
812 :type '(choice (const left) |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
813 (const right) |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
814 (const full) |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
815 (const center) |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
816 (const none)) |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
817 :group 'fill) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
818 (make-variable-buffer-local 'default-justification) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
819 |
10472
82ff279a4cea
(current-justification): Renamed from current-justification. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
10468
diff
changeset
|
820 (defun current-justification () |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
821 "How should we justify this line? |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
822 This returns the value of the text-property `justification', |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
823 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
|
824 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
|
825 (let ((j (or (get-text-property |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
826 ;; 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
|
827 (save-excursion (skip-chars-forward " \t") |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
828 (if (and (eobp) (not (bobp))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
829 (1- (point)) (point))) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
830 'justification) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
831 default-justification))) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
832 (if (eq 'none j) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
833 nil |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
834 j))) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
835 |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
836 (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
|
837 "Set the region's justification style. |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
838 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
|
839 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
|
840 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
|
841 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
|
842 end of the paragraphs they are in. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
843 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
|
844 breaks. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
845 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
846 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
|
847 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
|
848 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
|
849 (interactive (list (if mark-active (region-beginning) (point)) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
850 (if mark-active (region-end) (point)) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
851 (let ((s (completing-read |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
852 "Set justification to: " |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
853 '(("left") ("right") ("full") |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
854 ("center") ("none")) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
855 nil t))) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
856 (if (equal s "") (error "")) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
857 (intern s)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
858 t)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
859 (save-excursion |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
860 (save-restriction |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
861 (if whole-par |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
862 (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
|
863 (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
|
864 paragraph-ignore-fill-prefix))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
865 (goto-char begin) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
866 (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
|
867 (backward-paragraph) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
868 (setq begin (point)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
869 (goto-char end) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
870 (skip-chars-backward " \t\n" begin) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
871 (forward-paragraph) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
872 (setq end (point)))) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
873 |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
874 (narrow-to-region (point-min) end) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
875 (unjustify-region begin (point-max)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
876 (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
|
877 (fill-region begin (point-max) nil t)))) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
878 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
879 (defun set-justification-none (b e) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
880 "Disable automatic filling for paragraphs in the region. |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
881 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
|
882 (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
|
883 (if mark-active (region-end) (point)))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
884 (set-justification b e 'none t)) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
885 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
886 (defun set-justification-left (b e) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
887 "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
|
888 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
|
889 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
|
890 (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
|
891 (if mark-active (region-end) (point)))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
892 (set-justification b e 'left t)) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
893 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
894 (defun set-justification-right (b e) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
895 "Make paragraphs in the region right-justified: |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
896 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
|
897 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
|
898 (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
|
899 (if mark-active (region-end) (point)))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
900 (set-justification b e 'right t)) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
901 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
902 (defun set-justification-full (b e) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
903 "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
|
904 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
|
905 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
|
906 (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
|
907 (if mark-active (region-end) (point)))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
908 (set-justification b e 'full t)) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
909 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
910 (defun set-justification-center (b e) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
911 "Make paragraphs in the region centered. |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
912 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
|
913 (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
|
914 (if mark-active (region-end) (point)))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
915 (set-justification b e 'center t)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
916 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
917 ;; A line has up to six parts: |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
918 ;; |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
919 ;; >>> hello. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
920 ;; [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
|
921 ;; |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
922 ;; "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
|
923 ;; given by the `current-left-margin' function. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
924 ;; "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
|
925 ;; "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
|
926 ;; `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
|
927 ;; 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
|
928 ;; 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
|
929 ;; center- or right-justifying. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
930 ;; |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
931 ;; 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
|
932 ;; 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
|
933 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
934 (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
|
935 "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
|
936 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
|
937 the column given by `current-fill-column'. |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
938 Optional first argument HOW specifies alternate type of justification: |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
939 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
|
940 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
|
941 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
|
942 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
|
943 it will not be stretched by full justification. |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
944 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
|
945 otherwise it is made canonical." |
24972
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
946 (interactive "*") |
13473
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
947 (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
|
948 (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
|
949 (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
|
950 (setq how 'full)))) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
951 (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
|
952 (let ((fc (current-fill-column)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
953 (pos (point-marker)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
954 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
|
955 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
|
956 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
|
957 indent ; column of `beg' |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
958 endcol ; column of `end' |
21727
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
959 ncols ; new indent point or offset |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
960 (nspaces 0) ; number of spaces between words |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
961 ; in line (not space characters) |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
962 fracspace ; fractional amount of space to be |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
963 ; added between each words |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
964 (curr-fracspace 0) ; current fractional space amount |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
965 count) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
966 (end-of-line) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
967 ;; 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
|
968 (if (and use-hard-newlines (null eop) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
969 (get-text-property (point) 'hard)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
970 (setq eop t)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
971 (skip-chars-backward " \t") |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
972 ;; 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
|
973 ;; or there is no text. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
974 (if (or (bolp) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
975 (and (memq how '(full right)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
976 (= (current-column) fc))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
977 nil |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
978 (setq end (point)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
979 (beginning-of-line) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
980 (skip-chars-forward " \t") |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
981 ;; Skip over fill-prefix. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
982 (if (and fill-prefix |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
983 (not (string-equal fill-prefix "")) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
984 (equal fill-prefix |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
985 (buffer-substring |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
986 (point) (min (point-max) (+ (length fill-prefix) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
987 (point)))))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
988 (forward-char (length fill-prefix)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
989 (if (and adaptive-fill-mode |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
990 (looking-at adaptive-fill-regexp)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
991 (goto-char (match-end 0)))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
992 (setq fp-end (point)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
993 (skip-chars-forward " \t") |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
994 ;; 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
|
995 (setq indent (current-column)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
996 (setq beg (point)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
997 (goto-char end) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
998 (setq endcol (current-column)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
999 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1000 ;; 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
|
1001 (cond ((eq 'right how) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1002 (setq ncols (- fc endcol)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1003 (if (< ncols 0) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1004 ;; Need to remove some indentation |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1005 (delete-region |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1006 (progn (goto-char fp-end) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1007 (if (< (current-column) (+ indent ncols)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1008 (move-to-column (+ indent ncols) t)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1009 (point)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1010 (progn (move-to-column indent) (point))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1011 ;; Need to add some |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1012 (goto-char beg) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1013 (indent-to (+ indent ncols)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1014 ;; 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
|
1015 (if (= beg pos) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1016 (move-marker pos (point))))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1017 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1018 ((eq 'center how) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1019 ;; Figure out how much indentation is needed |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1020 (setq ncols (+ (current-left-margin) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1021 (/ (- fc (current-left-margin) ;avail. space |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1022 (- endcol indent)) ;text width |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1023 2))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1024 (if (< ncols indent) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1025 ;; Have too much indentation - remove some |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1026 (delete-region |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1027 (progn (goto-char fp-end) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1028 (if (< (current-column) ncols) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1029 (move-to-column ncols t)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1030 (point)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1031 (progn (move-to-column indent) (point))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1032 ;; Have too little - add some |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1033 (goto-char beg) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1034 (indent-to ncols) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1035 ;; 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
|
1036 (if (= beg pos) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1037 (move-marker pos (point))))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1038 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1039 ((eq 'full how) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1040 ;; 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
|
1041 (save-restriction |
10543
3b896847b849
(justify-current-line): Avoid error comparing fill-prefix
Richard M. Stallman <rms@gnu.org>
parents:
10497
diff
changeset
|
1042 (narrow-to-region beg end) |
3b896847b849
(justify-current-line): Avoid error comparing fill-prefix
Richard M. Stallman <rms@gnu.org>
parents:
10497
diff
changeset
|
1043 (or nosqueeze |
3b896847b849
(justify-current-line): Avoid error comparing fill-prefix
Richard M. Stallman <rms@gnu.org>
parents:
10497
diff
changeset
|
1044 (canonically-space-region beg end)) |
3b896847b849
(justify-current-line): Avoid error comparing fill-prefix
Richard M. Stallman <rms@gnu.org>
parents:
10497
diff
changeset
|
1045 (goto-char (point-max)) |
21727
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1046 ;; count word spaces in line |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1047 (while (search-backward " " nil t) |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1048 (setq nspaces (1+ nspaces)) |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1049 (skip-chars-backward " ")) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1050 (setq ncols (- fc endcol)) |
21727
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1051 ;; Ncols is number of additional space chars needed |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1052 (if (and (> ncols 0) (> nspaces 0) (not eop)) |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1053 (progn |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1054 (setq curr-fracspace (+ ncols (/ (1+ nspaces) 2)) |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1055 count nspaces) |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1056 (while (> count 0) |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1057 (skip-chars-forward " ") |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1058 (insert-and-inherit |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1059 (make-string (/ curr-fracspace nspaces) ?\ )) |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1060 (search-forward " " nil t) |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1061 (setq count (1- count) |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1062 curr-fracspace |
88afa87063ff
(justify-current-line): Use new algorithm to apportion the spaces to be added.
Richard M. Stallman <rms@gnu.org>
parents:
21150
diff
changeset
|
1063 (+ (% curr-fracspace nspaces) ncols))))))) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1064 (t (error "Unknown justification value")))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1065 (goto-char pos) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1066 (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
|
1067 nil) |
9026
74fd93bc3568
(justify-current-line): Inherit props when inserting spaces.
Richard M. Stallman <rms@gnu.org>
parents:
8363
diff
changeset
|
1068 |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1069 (defun unjustify-current-line () |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1070 "Remove justification whitespace from current line. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1071 If the line is centered or right-justified, this function removes any |
13981
6758b889a7c1
(fill-context-prefix, unjustify-current-line,
Karl Heuer <kwzh@gnu.org>
parents:
13839
diff
changeset
|
1072 indentation past the left margin. If the line is full-justified, it removes |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1073 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
|
1074 (let ((justify (current-justification))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1075 (cond ((eq 'left justify) nil) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1076 ((eq nil justify) nil) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1077 ((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
|
1078 (beginning-of-line-text) |
32230 | 1079 (canonically-space-region (point) (line-end-position))) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1080 ((memq justify '(center right)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1081 (save-excursion |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1082 (move-to-left-margin nil t) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1083 ;; Position ourselves after any fill-prefix. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1084 (if (and fill-prefix |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1085 (not (string-equal fill-prefix "")) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1086 (equal fill-prefix |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1087 (buffer-substring |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1088 (point) (min (point-max) (+ (length fill-prefix) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1089 (point)))))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1090 (forward-char (length fill-prefix))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1091 (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
|
1092 (point)))))))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1093 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1094 (defun unjustify-region (&optional begin end) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1095 "Remove justification whitespace from region. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1096 For centered or right-justified regions, this function removes any indentation |
13981
6758b889a7c1
(fill-context-prefix, unjustify-current-line,
Karl Heuer <kwzh@gnu.org>
parents:
13839
diff
changeset
|
1097 past the left margin from each line. For full-justified lines, it removes |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1098 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
|
1099 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
|
1100 (save-excursion |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1101 (save-restriction |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1102 (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
|
1103 (goto-char (or begin (point-min))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1104 (while (not (eobp)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1105 (unjustify-current-line) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1106 (forward-line 1))))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1107 |
75 | 1108 |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1109 (defun fill-nonuniform-paragraphs (min max &optional justifyp citation-regexp) |
2520
ef643dbb7d40
(fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents:
2412
diff
changeset
|
1110 "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
|
1111 This command divides the region into \"paragraphs\", |
ef643dbb7d40
(fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents:
2412
diff
changeset
|
1112 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
|
1113 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
|
1114 in the paragraph. |
ef643dbb7d40
(fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents:
2412
diff
changeset
|
1115 |
ef643dbb7d40
(fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents:
2412
diff
changeset
|
1116 When calling from a program, pass range to fill as first two arguments. |
638 | 1117 |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1118 Optional third and fourth arguments JUSTIFY and MAIL-FLAG: |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1119 JUSTIFY to justify paragraphs (prefix arg), |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1120 When filling a mail message, pass a regexp for CITATION-REGEXP |
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1121 which will match the prefix of a line which is a citation marker |
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1122 plus whitespace, but no other kind of prefix. |
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1123 Also, if CITATION-REGEXP is non-nil, don't fill header lines." |
24972
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1124 (interactive (progn |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1125 (barf-if-buffer-read-only) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1126 (list (region-beginning) (region-end) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1127 (if current-prefix-arg 'full)))) |
2520
ef643dbb7d40
(fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents:
2412
diff
changeset
|
1128 (let ((fill-individual-varying-indent t)) |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1129 (fill-individual-paragraphs min max justifyp citation-regexp))) |
2520
ef643dbb7d40
(fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents:
2412
diff
changeset
|
1130 |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1131 (defun fill-individual-paragraphs (min max &optional justify citation-regexp) |
2520
ef643dbb7d40
(fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents:
2412
diff
changeset
|
1132 "Fill paragraphs of uniform indentation within the region. |
ef643dbb7d40
(fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents:
2412
diff
changeset
|
1133 This command divides the region into \"paragraphs\", |
19929
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1134 treating every change in indentation level or prefix as a paragraph boundary, |
2520
ef643dbb7d40
(fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents:
2412
diff
changeset
|
1135 then fills each paragraph using its indentation level as the fill prefix. |
638 | 1136 |
19929
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1137 There is one special case where a change in indentation does not start |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1138 a new paragraph. This is for text of this form: |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1139 |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1140 foo> This line with extra indentation starts |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1141 foo> a paragraph that continues on more lines. |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1142 |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1143 These lines are filled together. |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1144 |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1145 When calling from a program, pass the range to fill |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1146 as the first two arguments. |
638 | 1147 |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1148 Optional third and fourth arguments JUSTIFY and MAIL-FLAG: |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1149 JUSTIFY to justify paragraphs (prefix arg), |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1150 When filling a mail message, pass a regexp for CITATION-REGEXP |
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1151 which will match the prefix of a line which is a citation marker |
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1152 plus whitespace, but no other kind of prefix. |
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1153 Also, if CITATION-REGEXP is non-nil, don't fill header lines." |
24972
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1154 (interactive (progn |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1155 (barf-if-buffer-read-only) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1156 (list (region-beginning) (region-end) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1157 (if current-prefix-arg 'full)))) |
474 | 1158 (save-restriction |
1159 (save-excursion | |
1160 (goto-char min) | |
1161 (beginning-of-line) | |
9706
f5f7d07eece8
(fill-individual-paragraphs): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents:
9217
diff
changeset
|
1162 (narrow-to-region (point) max) |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1163 (if citation-regexp |
9706
f5f7d07eece8
(fill-individual-paragraphs): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents:
9217
diff
changeset
|
1164 (while (and (not (eobp)) |
13473
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
1165 (or (looking-at "[ \t]*[^ \t\n]+:") |
9706
f5f7d07eece8
(fill-individual-paragraphs): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents:
9217
diff
changeset
|
1166 (looking-at "[ \t]*$"))) |
13473
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
1167 (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
|
1168 (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
|
1169 (forward-line 1)))) |
474 | 1170 (narrow-to-region (point) max) |
1171 ;; Loop over paragraphs. | |
20263
7808c4885103
(fill-individual-paragraphs): Don't get
Karl Heuer <kwzh@gnu.org>
parents:
20234
diff
changeset
|
1172 (while (let ((here (point))) |
19810
495951c8a761
(fill-individual-paragraphs): Don't include
Richard M. Stallman <rms@gnu.org>
parents:
19419
diff
changeset
|
1173 ;; Skip over all paragraph-separating lines |
495951c8a761
(fill-individual-paragraphs): Don't include
Richard M. Stallman <rms@gnu.org>
parents:
19419
diff
changeset
|
1174 ;; so as to not include them in any paragraph. |
20263
7808c4885103
(fill-individual-paragraphs): Don't get
Karl Heuer <kwzh@gnu.org>
parents:
20234
diff
changeset
|
1175 (while (and (not (eobp)) |
7808c4885103
(fill-individual-paragraphs): Don't get
Karl Heuer <kwzh@gnu.org>
parents:
20234
diff
changeset
|
1176 (progn (move-to-left-margin) |
7808c4885103
(fill-individual-paragraphs): Don't get
Karl Heuer <kwzh@gnu.org>
parents:
20234
diff
changeset
|
1177 (and (not (eobp)) |
7808c4885103
(fill-individual-paragraphs): Don't get
Karl Heuer <kwzh@gnu.org>
parents:
20234
diff
changeset
|
1178 (looking-at paragraph-separate)))) |
19810
495951c8a761
(fill-individual-paragraphs): Don't include
Richard M. Stallman <rms@gnu.org>
parents:
19419
diff
changeset
|
1179 (forward-line 1)) |
495951c8a761
(fill-individual-paragraphs): Don't include
Richard M. Stallman <rms@gnu.org>
parents:
19419
diff
changeset
|
1180 (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
|
1181 (move-to-left-margin) |
474 | 1182 (let ((start (point)) |
1183 fill-prefix fill-prefix-regexp) | |
1184 ;; Find end of paragraph, and compute the smallest fill-prefix | |
1185 ;; that fits all the lines in this paragraph. | |
1186 (while (progn | |
1187 ;; Update the fill-prefix on the first line | |
1188 ;; and whenever the prefix good so far is too long. | |
1189 (if (not (and fill-prefix | |
1190 (looking-at fill-prefix-regexp))) | |
1191 (setq fill-prefix | |
32230 | 1192 (fill-individual-paragraphs-prefix |
1193 citation-regexp) | |
13502
57a0a9e5399e
(fill-region-as-paragraph): Since adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents:
13473
diff
changeset
|
1194 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
|
1195 (forward-line 1) |
15308
9a31b0d0c38a
(fill-individual-paragraphs): Don't get stuck
Richard M. Stallman <rms@gnu.org>
parents:
14840
diff
changeset
|
1196 (if (bolp) |
9a31b0d0c38a
(fill-individual-paragraphs): Don't get stuck
Richard M. Stallman <rms@gnu.org>
parents:
14840
diff
changeset
|
1197 ;; If forward-line went past a newline, |
9a31b0d0c38a
(fill-individual-paragraphs): Don't get stuck
Richard M. Stallman <rms@gnu.org>
parents:
14840
diff
changeset
|
1198 ;; move further to the left margin. |
9a31b0d0c38a
(fill-individual-paragraphs): Don't get stuck
Richard M. Stallman <rms@gnu.org>
parents:
14840
diff
changeset
|
1199 (move-to-left-margin)) |
474 | 1200 ;; Now stop the loop if end of paragraph. |
1201 (and (not (eobp)) | |
638 | 1202 (if fill-individual-varying-indent |
1203 ;; If this line is a separator line, with or | |
1204 ;; without prefix, end the paragraph. | |
1205 (and | |
13548
9be6c740e36f
(fill-individual-paragraphs): Advance 1 line in inner loop.
Richard M. Stallman <rms@gnu.org>
parents:
13502
diff
changeset
|
1206 (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
|
1207 (save-excursion |
9be6c740e36f
(fill-individual-paragraphs): Advance 1 line in inner loop.
Richard M. Stallman <rms@gnu.org>
parents:
13502
diff
changeset
|
1208 (not (and (looking-at fill-prefix-regexp) |
32230 | 1209 (progn (forward-char |
1210 (length fill-prefix)) | |
1211 (looking-at | |
1212 paragraph-separate)))))) | |
638 | 1213 ;; If this line has more or less indent |
1214 ;; than the fill prefix wants, end the paragraph. | |
1215 (and (looking-at fill-prefix-regexp) | |
25127
864a4f79195b
(fill-individual-paragraphs): Calculate new
Karl Heuer <kwzh@gnu.org>
parents:
25126
diff
changeset
|
1216 ;; If fill prefix is shorter than a new |
864a4f79195b
(fill-individual-paragraphs): Calculate new
Karl Heuer <kwzh@gnu.org>
parents:
25126
diff
changeset
|
1217 ;; fill prefix computed here, end paragraph. |
864a4f79195b
(fill-individual-paragraphs): Calculate new
Karl Heuer <kwzh@gnu.org>
parents:
25126
diff
changeset
|
1218 (let ((this-line-fill-prefix |
864a4f79195b
(fill-individual-paragraphs): Calculate new
Karl Heuer <kwzh@gnu.org>
parents:
25126
diff
changeset
|
1219 (fill-individual-paragraphs-prefix |
864a4f79195b
(fill-individual-paragraphs): Calculate new
Karl Heuer <kwzh@gnu.org>
parents:
25126
diff
changeset
|
1220 citation-regexp))) |
864a4f79195b
(fill-individual-paragraphs): Calculate new
Karl Heuer <kwzh@gnu.org>
parents:
25126
diff
changeset
|
1221 (>= (length fill-prefix) |
864a4f79195b
(fill-individual-paragraphs): Calculate new
Karl Heuer <kwzh@gnu.org>
parents:
25126
diff
changeset
|
1222 (length this-line-fill-prefix))) |
638 | 1223 (save-excursion |
32230 | 1224 (not (progn (forward-char |
1225 (length fill-prefix)) | |
19929
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1226 (or (looking-at "[ \t]") |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1227 (looking-at paragraph-separate) |
28489
3fe2e55e31da
(fill-individual-paragraphs): If a no-prefix
Gerd Moellmann <gerd@gnu.org>
parents:
27287
diff
changeset
|
1228 (looking-at paragraph-start))))) |
3fe2e55e31da
(fill-individual-paragraphs): If a no-prefix
Gerd Moellmann <gerd@gnu.org>
parents:
27287
diff
changeset
|
1229 (not (and (equal fill-prefix "") |
3fe2e55e31da
(fill-individual-paragraphs): If a no-prefix
Gerd Moellmann <gerd@gnu.org>
parents:
27287
diff
changeset
|
1230 citation-regexp |
3fe2e55e31da
(fill-individual-paragraphs): If a no-prefix
Gerd Moellmann <gerd@gnu.org>
parents:
27287
diff
changeset
|
1231 (looking-at citation-regexp)))))))) |
474 | 1232 ;; Fill this paragraph, but don't add a newline at the end. |
1233 (let ((had-newline (bolp))) | |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1234 (fill-region-as-paragraph start (point) justify) |
23184
973ac8db2f92
(fill-individual-paragraphs): Before deleting
Karl Heuer <kwzh@gnu.org>
parents:
22748
diff
changeset
|
1235 (if (and (bolp) (not had-newline)) |
973ac8db2f92
(fill-individual-paragraphs): Before deleting
Karl Heuer <kwzh@gnu.org>
parents:
22748
diff
changeset
|
1236 (delete-char -1)))))))) |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1237 (defun fill-individual-paragraphs-prefix (citation-regexp) |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1238 (let* ((adaptive-fill-first-line-regexp ".*") |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1239 (just-one-line-prefix |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1240 ;; Accept any prefix rather than just the ones matched by |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1241 ;; adaptive-fill-first-line-regexp. |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1242 (fill-context-prefix (point) (line-beginning-position 2))) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1243 (two-lines-prefix |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1244 (fill-context-prefix (point) (line-beginning-position 3)))) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1245 (if (not just-one-line-prefix) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1246 (buffer-substring |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1247 (point) (save-excursion (skip-chars-forward " \t") (point))) |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1248 ;; See if the citation part of JUST-ONE-LINE-PREFIX |
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1249 ;; is the same as that of TWO-LINES-PREFIX, |
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1250 ;; except perhaps with longer whitespace. |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1251 (if (and just-one-line-prefix two-lines-prefix |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1252 (let* ((one-line-citation-part |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1253 (fill-individual-paragraphs-citation |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1254 just-one-line-prefix citation-regexp)) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1255 (two-lines-citation-part |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1256 (fill-individual-paragraphs-citation |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1257 two-lines-prefix citation-regexp)) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1258 (adjusted-two-lines-citation-part |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1259 (substring two-lines-citation-part 0 |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1260 (string-match "[ \t]*\\'" |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1261 two-lines-citation-part)))) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1262 (and |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1263 (string-match (concat "\\`" |
32230 | 1264 (regexp-quote |
1265 adjusted-two-lines-citation-part) | |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1266 "[ \t]*\\'") |
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1267 one-line-citation-part) |
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1268 (>= (string-width one-line-citation-part) |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1269 (string-width two-lines-citation-part))))) |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1270 two-lines-prefix |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1271 just-one-line-prefix)))) |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1272 |
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1273 (defun fill-individual-paragraphs-citation (string citation-regexp) |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1274 (if citation-regexp |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1275 (if (string-match citation-regexp string) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1276 (match-string 0 string) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1277 "") |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1278 string)) |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1279 |
732 | 1280 ;;; fill.el ends here |