Mercurial > emacs
annotate lisp/textmodes/fill.el @ 110383:e1094870ea06
ftfont.c (ftfont_check_otf): Fix previous change.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 17 Sep 2010 13:57:58 +0900 |
parents | 280c8ae2476d |
children | 56b71cddc9c5 |
rev | line source |
---|---|
105144
5be976c84fc7
Convert to utf-8 encoding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102881
diff
changeset
|
1 ;;; fill.el --- fill commands for Emacs -*- coding: utf-8 -*- |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
638
diff
changeset
|
2 |
63380
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
3 ;; Copyright (C) 1985, 1986, 1992, 1994, 1995, 1996, 1997, 1999, 2001, 2002, |
106815 | 4 ;; 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
821
diff
changeset
|
5 |
38697
a19197c6442f
Keyword added and FSF specified as Maintainer.
Pavel Janík <Pavel@Janik.cz>
parents:
38186
diff
changeset
|
6 ;; Maintainer: FSF |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
7 ;; Keywords: wp |
110015
280c8ae2476d
Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents:
109614
diff
changeset
|
8 ;; Package: emacs |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
732
diff
changeset
|
9 |
75 | 10 ;; This file is part of GNU Emacs. |
11 | |
94670
f4a69fedbd46
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94004
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
75 | 13 ;; it under the terms of the GNU General Public License as published by |
94670
f4a69fedbd46
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94004
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
f4a69fedbd46
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94004
diff
changeset
|
15 ;; (at your option) any later version. |
75 | 16 |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
94670
f4a69fedbd46
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94004
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
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 |
54311
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
32 (defgroup fill nil |
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
33 "Indenting and filling text." |
54549 | 34 :link '(custom-manual "(emacs)Filling") |
54311
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
35 :group 'editing) |
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
36 |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
37 (defcustom fill-individual-varying-indent nil |
96497
885e5368ecb2
Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents:
94670
diff
changeset
|
38 "Controls criterion for a new paragraph in `fill-individual-paragraphs'. |
638 | 39 Non-nil means changing indent doesn't end a paragraph. |
40 That mode can handle paragraphs with extra indentation on the first line, | |
41 but it requires separator lines between paragraphs. | |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
42 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
|
43 :type 'boolean |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
44 :group 'fill) |
5770
92dd602768d2
(sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5291
diff
changeset
|
45 |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
46 (defcustom colon-double-space nil |
96497
885e5368ecb2
Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents:
94670
diff
changeset
|
47 "Non-nil means put two spaces after a colon when filling." |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
48 :type 'boolean |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
49 :group 'fill) |
92948
73a01bf5cb80
* faces.el (xw-defined-colors):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
92360
diff
changeset
|
50 (put 'colon-double-space 'safe-local-variable 'booleanp) |
12752
86c8fb2284de
(fill-region-as-paragraph): Don't find adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents:
12557
diff
changeset
|
51 |
10631
dc245bfecc3b
(fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10543
diff
changeset
|
52 (defvar fill-paragraph-function nil |
13839
d597ac78b00e
(fill-paragraph-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13713
diff
changeset
|
53 "Mode-specific function to fill a paragraph, or nil if there is none. |
75474
cf580adfa498
(fill-paragraph-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
75347
diff
changeset
|
54 If the function returns nil, then `fill-paragraph' does its normal work. |
94004
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
55 A value of t means explicitly \"do nothing special\". |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
56 Note: This only affects `fill-paragraph' and not `fill-region' |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
57 nor `auto-fill-mode', so it is often better to use some other hook, |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
58 such as `fill-forward-paragraph-function'.") |
10631
dc245bfecc3b
(fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10543
diff
changeset
|
59 |
48126
92c696f8509e
(fill-paragraph-handle-comment): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48095
diff
changeset
|
60 (defvar fill-paragraph-handle-comment t |
54311
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
61 "Non-nil means paragraph filling will try to pay attention to comments.") |
48126
92c696f8509e
(fill-paragraph-handle-comment): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48095
diff
changeset
|
62 |
54311
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
63 (defcustom enable-kinsoku t |
96497
885e5368ecb2
Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents:
94670
diff
changeset
|
64 "Non-nil means enable \"kinsoku\" processing on filling paragraphs. |
19239
8298b8a6a47d
(enable-kinsoku): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19220
diff
changeset
|
65 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
|
66 placed at the beginning or end of a line by filling. |
54311
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
67 See the documentation of `kinsoku' for more information." |
62531
c905fcf5e3d9
Specify missing group (and type, if simple) in defcustom.
Juanma Barranquero <lekktu@gmail.com>
parents:
61155
diff
changeset
|
68 :type 'boolean |
c905fcf5e3d9
Specify missing group (and type, if simple) in defcustom.
Juanma Barranquero <lekktu@gmail.com>
parents:
61155
diff
changeset
|
69 :group 'fill) |
16998 | 70 |
75 | 71 (defun set-fill-prefix () |
5770
92dd602768d2
(sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5291
diff
changeset
|
72 "Set the fill prefix to the current line up to point. |
218 | 73 Filling expects lines to start with the fill prefix and |
74 reinserts the fill prefix in each resulting line." | |
75 | 75 (interactive) |
35785
e8b7be229b24
(set-fill-prefix): Cancel fill prefix if point
Gerd Moellmann <gerd@gnu.org>
parents:
33441
diff
changeset
|
76 (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
|
77 (if (> (point) left-margin-pos) |
e8b7be229b24
(set-fill-prefix): Cancel fill prefix if point
Gerd Moellmann <gerd@gnu.org>
parents:
33441
diff
changeset
|
78 (progn |
e8b7be229b24
(set-fill-prefix): Cancel fill prefix if point
Gerd Moellmann <gerd@gnu.org>
parents:
33441
diff
changeset
|
79 (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
|
80 (if (equal fill-prefix "") |
e8b7be229b24
(set-fill-prefix): Cancel fill prefix if point
Gerd Moellmann <gerd@gnu.org>
parents:
33441
diff
changeset
|
81 (setq fill-prefix nil))) |
e8b7be229b24
(set-fill-prefix): Cancel fill prefix if point
Gerd Moellmann <gerd@gnu.org>
parents:
33441
diff
changeset
|
82 (setq fill-prefix nil))) |
75 | 83 (if fill-prefix |
84 (message "fill-prefix: \"%s\"" fill-prefix) | |
85 (message "fill-prefix cancelled"))) | |
86 | |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
87 (defcustom adaptive-fill-mode t |
96497
885e5368ecb2
Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents:
94670
diff
changeset
|
88 "Non-nil means determine a paragraph's fill prefix from its text." |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
89 :type 'boolean |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
90 :group 'fill) |
218 | 91 |
32230 | 92 (defcustom adaptive-fill-regexp |
44491
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
93 ;; Added `!' for doxygen comments starting with `//!' or `/*!'. |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
94 ;; Added `%' for TeX comments. |
72722
8c5e09c8076c
(adaptive-fill-regexp): Don't match `(1)' or `1.'
Richard M. Stallman <rms@gnu.org>
parents:
72683
diff
changeset
|
95 ;; RMS: deleted the code to match `1.' and `(1)'. |
105870
26baacb565b0
* textmodes/tex-mode.el (tex-alt-dvi-print-command)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105144
diff
changeset
|
96 (purecopy "[ \t]*\\([-!|#%;>*·•‣⁃◦]+[ \t]*\\)*") |
96497
885e5368ecb2
Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents:
94670
diff
changeset
|
97 "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
|
98 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
|
99 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
|
100 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
|
101 |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
102 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
|
103 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
|
104 a role." |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
105 :type 'regexp |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
106 :group 'fill) |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
107 |
105870
26baacb565b0
* textmodes/tex-mode.el (tex-alt-dvi-print-command)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105144
diff
changeset
|
108 (defcustom adaptive-fill-first-line-regexp (purecopy "\\`[ \t]*\\'") |
96497
885e5368ecb2
Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents:
94670
diff
changeset
|
109 "Regexp specifying whether to set fill prefix from a one-line paragraph. |
18221
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
110 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
|
111 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
|
112 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
|
113 |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
114 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
|
115 |
5ab53c383b5c
(fill-context-prefix): If we get a prefix from the
Richard M. Stallman <rms@gnu.org>
parents:
17852
diff
changeset
|
116 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
|
117 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
|
118 :type 'regexp |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
119 :group 'fill) |
218 | 120 |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
121 (defcustom adaptive-fill-function nil |
79138
d5f52eab5fd5
(fill-individual-paragraphs): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
78225
diff
changeset
|
122 "Function to call to choose a fill prefix for a paragraph, or nil. |
d5f52eab5fd5
(fill-individual-paragraphs): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
78225
diff
changeset
|
123 A nil value means the function has not determined the fill prefix." |
35963
4681ff6664e6
(adaptive-fill-function): Fix :type
Dave Love <fx@gnu.org>
parents:
35785
diff
changeset
|
124 :type '(choice (const nil) function) |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
125 :group 'fill) |
12752
86c8fb2284de
(fill-region-as-paragraph): Don't find adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents:
12557
diff
changeset
|
126 |
41517
f0a204c61f81
(fill-indent-according-to-mode): Default to nil.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
41303
diff
changeset
|
127 (defvar fill-indent-according-to-mode nil ;Screws up CC-mode's filling tricks. |
33365
2c0585b6e6d6
(fill-indent-according-to-mode): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32230
diff
changeset
|
128 "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
|
129 |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
130 (defun current-fill-column () |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
131 "Return the fill-column to use for this line. |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
132 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
|
133 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
|
134 subtracted from `fill-column'. |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
135 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
136 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
|
137 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
|
138 (save-excursion |
12429
d6d785d96455
(current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents:
11448
diff
changeset
|
139 (if fill-column |
d6d785d96455
(current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents:
11448
diff
changeset
|
140 (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
|
141 (here-col 0) |
d6d785d96455
(current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents:
11448
diff
changeset
|
142 (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
|
143 margin fill-col change col) |
32230 | 144 ;; Look separately at each region of line with a different |
145 ;; right-margin. | |
12429
d6d785d96455
(current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents:
11448
diff
changeset
|
146 (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
|
147 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
|
148 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
|
149 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
|
150 (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
|
151 (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
|
152 (< col fill-col))) |
d6d785d96455
(current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents:
11448
diff
changeset
|
153 (setq here change |
d6d785d96455
(current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents:
11448
diff
changeset
|
154 here-col col)) |
d6d785d96455
(current-fill-column): If fill-column is nil, return nil.
Richard M. Stallman <rms@gnu.org>
parents:
11448
diff
changeset
|
155 (max here-col fill-col))))) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
156 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
157 (defun canonically-space-region (beg end) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
158 "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
|
159 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
|
160 \(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
|
161 and `sentence-end-without-period'). |
12557
34e9427fe8f5
(canonically-space-region): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
12429
diff
changeset
|
162 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
|
163 (interactive "*r") |
77808
c97a9221b6b8
(canonically-space-region): Make the second arg
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
77515
diff
changeset
|
164 ;; Ideally, we'd want to scan the text from the end, so that changes to |
c97a9221b6b8
(canonically-space-region): Make the second arg
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
77515
diff
changeset
|
165 ;; text don't affect the boundary, but the regexp we match against does |
c97a9221b6b8
(canonically-space-region): Make the second arg
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
77515
diff
changeset
|
166 ;; not match as eagerly when matching backward, so we instead use |
c97a9221b6b8
(canonically-space-region): Make the second arg
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
77515
diff
changeset
|
167 ;; a marker. |
c97a9221b6b8
(canonically-space-region): Make the second arg
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
77515
diff
changeset
|
168 (unless (markerp end) (setq end (copy-marker end t))) |
54978
8ecfbf14a036
(canonically-space-region, fill-nobreak-p, fill-delete-newlines):
Juri Linkov <juri@jurta.org>
parents:
54701
diff
changeset
|
169 (let ((end-spc-re (concat "\\(" (sentence-end) "\\) *\\| +"))) |
44504
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
170 (save-excursion |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
171 (goto-char beg) |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
172 ;; Nuke tabs; they get screwed up in a fill. |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
173 ;; This is quick, but loses when a tab follows the end of a sentence. |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
174 ;; Actually, it is difficult to tell that from "Mr.\tSmith". |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
175 ;; Blame the typist. |
64853
a045a3e5b467
(fill-nonuniform-paragraphs): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents:
64751
diff
changeset
|
176 (subst-char-in-region beg end ?\t ?\s) |
25606
7ab723e4a21a
(fill-region-as-paragraph, canonically-space-region):
Richard M. Stallman <rms@gnu.org>
parents:
25127
diff
changeset
|
177 (while (and (< (point) end) |
44504
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
178 (re-search-forward end-spc-re end t)) |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
179 (delete-region |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
180 (cond |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
181 ;; `sentence-end' matched and did not match all spaces. |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
182 ;; I.e. it only matched the number of spaces it needs: drop the rest. |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
183 ((and (match-end 1) (> (match-end 0) (match-end 1))) (match-end 1)) |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
184 ;; `sentence-end' matched but with nothing left. Either that means |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
185 ;; nothing should be removed, or it means it's the "old-style" |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
186 ;; sentence-end which matches all it can. Keep only 2 spaces. |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
187 ;; We probably don't even need to check `sentence-end-double-space'. |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
188 ((match-end 1) |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
189 (min (match-end 0) |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
190 (+ (if sentence-end-double-space 2 1) |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
191 (save-excursion (goto-char (match-end 0)) |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
192 (skip-chars-backward " ") |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
193 (point))))) |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
194 (t ;; It's not an end of sentence. |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
195 (+ (match-beginning 0) |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
196 ;; Determine number of spaces to leave: |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
197 (save-excursion |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
198 (skip-chars-backward " ]})\"'") |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
199 (cond ((and sentence-end-double-space |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
200 (or (memq (preceding-char) '(?. ?? ?!)) |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
201 (and sentence-end-without-period |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
202 (= (char-syntax (preceding-char)) ?w)))) 2) |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
203 ((and colon-double-space |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
204 (= (preceding-char) ?:)) 2) |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
205 ((char-equal (preceding-char) ?\n) 0) |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
206 (t 1)))))) |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
207 (match-end 0)))))) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
208 |
27287
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
209 (defun fill-common-string-prefix (s1 s2) |
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
210 "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
|
211 (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
|
212 (if (eq cmp t) |
27287
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
213 s1 |
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
214 (setq cmp (1- (abs cmp))) |
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
215 (unless (zerop cmp) |
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
216 (substring s1 0 cmp))))) |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
217 |
63380
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
218 (defun fill-match-adaptive-prefix () |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
219 (let ((str (or |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
220 (and adaptive-fill-function (funcall adaptive-fill-function)) |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
221 (and adaptive-fill-regexp (looking-at adaptive-fill-regexp) |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
222 (match-string-no-properties 0))))) |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
223 (if (>= (+ (current-left-margin) (length str)) (current-fill-column)) |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
224 ;; Death to insanely long prefixes. |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
225 nil |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
226 str))) |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
227 |
13586
292e11b5f9c6
(fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
13578
diff
changeset
|
228 (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
|
229 "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
|
230 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
|
231 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
|
232 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
|
233 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
|
234 (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
|
235 (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
|
236 (save-excursion |
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
237 (goto-char from) |
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
238 (if (eolp) (forward-line 1)) |
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
239 ;; Move to the second line unless there is just one. |
40668
56aa9e5dc60c
(fill-context-prefix): Fix braino.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40633
diff
changeset
|
240 (move-to-left-margin) |
63380
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
241 (let (first-line-prefix |
13586
292e11b5f9c6
(fill-context-prefix): New arg first-line-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
13578
diff
changeset
|
242 ;; Non-nil if we are on the second line. |
63380
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
243 second-line-prefix) |
18282
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
244 (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
|
245 ;; 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
|
246 ;; 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
|
247 ;; 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
|
248 ;; second-line-prefix from being used. |
63380
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
249 ;; ((looking-at paragraph-start) nil) |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
250 (fill-match-adaptive-prefix)) |
13473
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
251 (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
|
252 (if (< (point) to) |
63380
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
253 (progn |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
254 (move-to-left-margin) |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
255 (setq second-line-prefix |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
256 (cond ((looking-at paragraph-start) nil) ;Can it happen? -Stef |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
257 (t (fill-match-adaptive-prefix)))) |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
258 ;; If we get a fill prefix from the second line, |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
259 ;; make sure it or something compatible is on the first line too. |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
260 (when second-line-prefix |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
261 (unless first-line-prefix (setq first-line-prefix "")) |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
262 ;; If the non-whitespace chars match the first line, |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
263 ;; just use it (this subsumes the 2 checks used previously). |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
264 ;; Used when first line is `/* ...' and second-line is |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
265 ;; ` * ...'. |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
266 (let ((tmp second-line-prefix) |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
267 (re "\\`")) |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
268 (while (string-match "\\`[ \t]*\\([^ \t]+\\)" tmp) |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
269 (setq re (concat re ".*" (regexp-quote (match-string 1 tmp)))) |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
270 (setq tmp (substring tmp (match-end 0)))) |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
271 ;; (assert (string-match "\\`[ \t]*\\'" tmp)) |
27287
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
272 |
63380
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
273 (if (string-match re first-line-prefix) |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
274 second-line-prefix |
27287
523c67808ff4
(fill-common-string-prefix): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
26898
diff
changeset
|
275 |
63380
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
276 ;; Use the longest common substring of both prefixes, |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
277 ;; if there is one. |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
278 (fill-common-string-prefix first-line-prefix |
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
279 second-line-prefix))))) |
18282
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
280 ;; 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
|
281 ;; maybe change it to whitespace, |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
282 ;; 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
|
283 (if first-line-prefix |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
284 (let ((result |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
285 ;; 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
|
286 ;; 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
|
287 ;; 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
|
288 (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
|
289 (string-match first-line-regexp |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
290 first-line-prefix)) |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
291 (and comment-start-skip |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
292 (string-match comment-start-skip |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
293 first-line-prefix))) |
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
294 first-line-prefix |
64853
a045a3e5b467
(fill-nonuniform-paragraphs): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents:
64751
diff
changeset
|
295 (make-string (string-width first-line-prefix) ?\s)))) |
18282
363bd42657e1
(fill-context-prefix): Fix criteria for first line,
Richard M. Stallman <rms@gnu.org>
parents:
18229
diff
changeset
|
296 ;; 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
|
297 ;; 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
|
298 (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
|
299 (concat result "a")))) |
18283 | 300 result))))))) |
13473
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
301 |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
302 (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
|
303 "Don't break a line after the first or before the last word of a sentence." |
72683
e37026af049b
(fill-single-word-nobreak-p): Allow breaking before
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71736
diff
changeset
|
304 ;; Actually, allow breaking before the last word of a sentence, so long as |
e37026af049b
(fill-single-word-nobreak-p): Allow breaking before
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71736
diff
changeset
|
305 ;; it's not the last word of the paragraph. |
e37026af049b
(fill-single-word-nobreak-p): Allow breaking before
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71736
diff
changeset
|
306 (or (looking-at (concat "[ \t]*\\sw+" "\\(?:" (sentence-end) "\\)[ \t]*$")) |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
307 (save-excursion |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
308 (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
|
309 (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
|
310 (/= (skip-chars-backward " \t") 0) |
67916
26c863f15f72
(fill-single-word-nobreak-p): Use `sentence-end'.
Juri Linkov <juri@jurta.org>
parents:
66280
diff
changeset
|
311 (/= (skip-chars-backward ".?!:") 0) |
26c863f15f72
(fill-single-word-nobreak-p): Use `sentence-end'.
Juri Linkov <juri@jurta.org>
parents:
66280
diff
changeset
|
312 (looking-at (sentence-end)))))) |
40486
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-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
|
315 "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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 places." |
105144
5be976c84fc7
Convert to utf-8 encoding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102881
diff
changeset
|
321 (or (looking-at "[ \t]*[])}»?!;:-]") |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
322 (save-excursion |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
323 (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
|
324 (unless (bolp) |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
325 (backward-char 1) |
105144
5be976c84fc7
Convert to utf-8 encoding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102881
diff
changeset
|
326 (or (looking-at "[([{«]") |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
327 ;; Don't cut right after a single-letter word. |
64853
a045a3e5b467
(fill-nonuniform-paragraphs): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents:
64751
diff
changeset
|
328 (and (memq (preceding-char) '(?\t ?\s)) |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
329 (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
|
330 |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
331 (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
|
332 "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
|
333 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
|
334 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
|
335 :group 'fill |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
336 :type 'hook |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
337 :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
|
338 |
48286
a820dd4741e1
(fill-nobreak-invisible): New var.
Kim F. Storm <storm@cua.dk>
parents:
48208
diff
changeset
|
339 (defcustom fill-nobreak-invisible nil |
54311
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
340 "Non-nil means that fill commands do not break lines in invisible text." |
48286
a820dd4741e1
(fill-nobreak-invisible): New var.
Kim F. Storm <storm@cua.dk>
parents:
48208
diff
changeset
|
341 :type 'boolean |
a820dd4741e1
(fill-nobreak-invisible): New var.
Kim F. Storm <storm@cua.dk>
parents:
48208
diff
changeset
|
342 :group 'fill) |
a820dd4741e1
(fill-nobreak-invisible): New var.
Kim F. Storm <storm@cua.dk>
parents:
48208
diff
changeset
|
343 |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
344 (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
|
345 "Return nil if breaking the line at point is allowed. |
48286
a820dd4741e1
(fill-nobreak-invisible): New var.
Kim F. Storm <storm@cua.dk>
parents:
48208
diff
changeset
|
346 Can be customized with the variables `fill-nobreak-predicate' |
a820dd4741e1
(fill-nobreak-invisible): New var.
Kim F. Storm <storm@cua.dk>
parents:
48208
diff
changeset
|
347 and `fill-nobreak-invisible'." |
a820dd4741e1
(fill-nobreak-invisible): New var.
Kim F. Storm <storm@cua.dk>
parents:
48208
diff
changeset
|
348 (or |
85683
2b92bd846058
(fill-nobreak-p): Replace obsolete alias
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85498
diff
changeset
|
349 (and fill-nobreak-invisible (invisible-p (point))) |
48286
a820dd4741e1
(fill-nobreak-invisible): New var.
Kim F. Storm <storm@cua.dk>
parents:
48208
diff
changeset
|
350 (unless (bolp) |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
351 (or |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
352 ;; 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
|
353 ;; 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
|
354 ;; 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
|
355 ;; 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
|
356 ;; If we now know it does not end a sentence, avoid putting |
44491
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
357 ;; 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
|
358 (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
|
359 (save-excursion |
66280
843776c843bf
(fill-nobreak-p): Fix first two rules to skip backward only
Juri Linkov <juri@jurta.org>
parents:
64853
diff
changeset
|
360 (skip-chars-backward " ") |
843776c843bf
(fill-nobreak-p): Fix first two rules to skip backward only
Juri Linkov <juri@jurta.org>
parents:
64853
diff
changeset
|
361 (and (eq (preceding-char) ?.) |
843776c843bf
(fill-nobreak-p): Fix first two rules to skip backward only
Juri Linkov <juri@jurta.org>
parents:
64853
diff
changeset
|
362 (looking-at " \\([^ ]\\|$\\)")))) |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
363 ;; 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
|
364 (save-excursion |
66280
843776c843bf
(fill-nobreak-p): Fix first two rules to skip backward only
Juri Linkov <juri@jurta.org>
parents:
64853
diff
changeset
|
365 (skip-chars-backward " ") |
843776c843bf
(fill-nobreak-p): Fix first two rules to skip backward only
Juri Linkov <juri@jurta.org>
parents:
64853
diff
changeset
|
366 (and (eq (preceding-char) ?.) |
843776c843bf
(fill-nobreak-p): Fix first two rules to skip backward only
Juri Linkov <juri@jurta.org>
parents:
64853
diff
changeset
|
367 (not (progn (forward-char -1) (looking-at (sentence-end)))))) |
40486
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
368 ;; 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
|
369 (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
|
370 (save-excursion |
56489
fb549e5bb99c
(fill-comment-paragraph): Handle indent-tabs-mode.
Richard M. Stallman <rms@gnu.org>
parents:
54978
diff
changeset
|
371 (skip-chars-forward " \t") |
fb549e5bb99c
(fill-comment-paragraph): Handle indent-tabs-mode.
Richard M. Stallman <rms@gnu.org>
parents:
54978
diff
changeset
|
372 ;; If this break point is at the end of the line, |
fb549e5bb99c
(fill-comment-paragraph): Handle indent-tabs-mode.
Richard M. Stallman <rms@gnu.org>
parents:
54978
diff
changeset
|
373 ;; which can occur for auto-fill, don't consider the newline |
fb549e5bb99c
(fill-comment-paragraph): Handle indent-tabs-mode.
Richard M. Stallman <rms@gnu.org>
parents:
54978
diff
changeset
|
374 ;; which follows as a reason to return t. |
fb549e5bb99c
(fill-comment-paragraph): Handle indent-tabs-mode.
Richard M. Stallman <rms@gnu.org>
parents:
54978
diff
changeset
|
375 (and (not (eolp)) |
fb549e5bb99c
(fill-comment-paragraph): Handle indent-tabs-mode.
Richard M. Stallman <rms@gnu.org>
parents:
54978
diff
changeset
|
376 (looking-at paragraph-start)))) |
48286
a820dd4741e1
(fill-nobreak-invisible): New var.
Kim F. Storm <storm@cua.dk>
parents:
48208
diff
changeset
|
377 (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
|
378 |
90633
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
379 (defvar fill-find-break-point-function-table (make-char-table nil) |
90625
81b116fa69ab
Don't use charset property
Kenichi Handa <handa@m17n.org>
parents:
90601
diff
changeset
|
380 "Char-table of special functions to find line breaking point.") |
23490
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
381 |
90633
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
382 (defvar fill-nospace-between-words-table (make-char-table nil) |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
383 "Char-table of characters that don't use space between words.") |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
384 |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
385 (progn |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
386 ;; Register `kinsoku' for scripts HAN, KANA, BOPOMPFO, and CJK-MISS. |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
387 ;; Also tell that they don't use space between words. |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
388 (map-char-table |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
389 #'(lambda (key val) |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
390 (when (memq val '(han kana bopomofo cjk-misc)) |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
391 (set-char-table-range fill-find-break-point-function-table |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
392 key 'kinsoku) |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
393 (set-char-table-range fill-nospace-between-words-table |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
394 key t))) |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
395 char-script-table) |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
396 ;; Do the same thing also for full width characters and half |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
397 ;; width kana variants. |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
398 (set-char-table-range fill-find-break-point-function-table |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
399 '(#xFF01 . #xFFE6) 'kinsoku) |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
400 (set-char-table-range fill-nospace-between-words-table |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
401 '(#xFF01 . #xFFE6) 'kinsoku)) |
23490
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
402 |
23519
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
403 (defun fill-find-break-point (limit) |
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
404 "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
|
405 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
|
406 |
23519
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
407 This function is called when we are going to break the current line |
54311
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
408 after or before a non-ASCII character. If the charset of the |
23519
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
409 character has the property `fill-find-break-point-function', this |
79627
d8528753376d
(fill-find-break-point): Fix doc-string typo.
Martin Rudalics <rudalics@gmx.at>
parents:
79138
diff
changeset
|
410 function calls the property value as a function with one arg LIMIT. |
23519
78085d485d73
(sentence-end-without-period): New variable.
Kenichi Handa <handa@m17n.org>
parents:
23490
diff
changeset
|
411 If the charset has no such property, do nothing." |
90625
81b116fa69ab
Don't use charset property
Kenichi Handa <handa@m17n.org>
parents:
90601
diff
changeset
|
412 (let ((func (or |
81b116fa69ab
Don't use charset property
Kenichi Handa <handa@m17n.org>
parents:
90601
diff
changeset
|
413 (aref fill-find-break-point-function-table (following-char)) |
81b116fa69ab
Don't use charset property
Kenichi Handa <handa@m17n.org>
parents:
90601
diff
changeset
|
414 (aref fill-find-break-point-function-table (preceding-char))))) |
26898
182d67795a5b
(fill-find-break-point): Delete codes for
Kenichi Handa <handa@m17n.org>
parents:
25606
diff
changeset
|
415 (if (and func (fboundp func)) |
182d67795a5b
(fill-find-break-point): Delete codes for
Kenichi Handa <handa@m17n.org>
parents:
25606
diff
changeset
|
416 (funcall func limit)))) |
23490
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
417 |
41303
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
418 (defun fill-delete-prefix (from to prefix) |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
419 "Delete the fill prefix from every line except the first. |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
420 The first line may not even have a fill prefix. |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
421 Point is moved to just past the fill prefix on the first line." |
44491
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
422 (let ((fpre (if (and prefix (not (string-match "\\`[ \t]*\\'" prefix))) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
423 (concat "[ \t]*\\(" |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
424 (replace-regexp-in-string |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
425 "[ \t]+" "[ \t]*" |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
426 (regexp-quote prefix)) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
427 "\\)?[ \t]*") |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
428 "[ \t]*"))) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
429 (goto-char from) |
71678
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
430 ;; Why signal an error here? The problem needs to be caught elsewhere. |
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
431 ;; (if (>= (+ (current-left-margin) (length prefix)) |
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
432 ;; (current-fill-column)) |
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
433 ;; (error "fill-prefix too long for specified width")) |
44491
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
434 (forward-line 1) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
435 (while (< (point) to) |
41303
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
436 (if (looking-at fpre) |
71678
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
437 (delete-region (point) (match-end 0))) |
44491
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
438 (forward-line 1)) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
439 (goto-char from) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
440 (if (looking-at fpre) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
441 (goto-char (match-end 0))) |
71678
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
442 (point))) |
41303
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
443 |
50757
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
444 ;; The `fill-space' property carries the string with which a newline |
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
445 ;; should be replaced when unbreaking a line (in fill-delete-newlines). |
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
446 ;; It is added to newline characters by fill-newline when the default |
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
447 ;; behavior of fill-delete-newlines is not what we want. |
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
448 (add-to-list 'text-property-default-nonsticky '(fill-space . t)) |
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
449 |
41303
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
450 (defun fill-delete-newlines (from to justify nosqueeze squeeze-after) |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
451 (goto-char from) |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
452 ;; Make sure sentences ending at end of line get an extra space. |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
453 ;; loses on split abbrevs ("Mr.\nSmith") |
44491
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
454 (let ((eol-double-space-re |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
455 (cond |
54978
8ecfbf14a036
(canonically-space-region, fill-nobreak-p, fill-delete-newlines):
Juri Linkov <juri@jurta.org>
parents:
54701
diff
changeset
|
456 ((not colon-double-space) (concat (sentence-end) "$")) |
44491
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
457 ;; Try to add the : inside the `sentence-end' regexp. |
54978
8ecfbf14a036
(canonically-space-region, fill-nobreak-p, fill-delete-newlines):
Juri Linkov <juri@jurta.org>
parents:
54701
diff
changeset
|
458 ((string-match "\\[[^][]*\\(\\.\\)[^][]*\\]" (sentence-end)) |
8ecfbf14a036
(canonically-space-region, fill-nobreak-p, fill-delete-newlines):
Juri Linkov <juri@jurta.org>
parents:
54701
diff
changeset
|
459 (concat (replace-match ".:" nil nil (sentence-end) 1) "$")) |
44491
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
460 ;; Can't find the right spot to insert the colon. |
53723
31efc669b404
(fill-delete-newlines): Don't add a space if a
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
461 (t "[.?!:][])}\"']*$"))) |
31efc669b404
(fill-delete-newlines): Don't add a space if a
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
462 (sentence-end-without-space-list |
31efc669b404
(fill-delete-newlines): Don't add a space if a
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
463 (string-to-list sentence-end-without-space))) |
41303
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
464 (while (re-search-forward eol-double-space-re to t) |
64853
a045a3e5b467
(fill-nonuniform-paragraphs): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents:
64751
diff
changeset
|
465 (or (>= (point) to) (memq (char-before) '(?\t ?\s)) |
54311
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
466 (memq (char-after (match-beginning 0)) |
53723
31efc669b404
(fill-delete-newlines): Don't add a space if a
Kenichi Handa <handa@m17n.org>
parents:
52401
diff
changeset
|
467 sentence-end-without-space-list) |
64853
a045a3e5b467
(fill-nonuniform-paragraphs): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents:
64751
diff
changeset
|
468 (insert-and-inherit ?\s)))) |
41303
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
469 |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
470 (goto-char from) |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
471 (if enable-multibyte-characters |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
472 ;; Delete unnecessay newlines surrounded by words. The |
90633
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
473 ;; character category `|' means that we can break a line at the |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
474 ;; character. And, char-table |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
475 ;; `fill-nospace-between-words-table' tells how to concatenate |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
476 ;; words. If a character has non-nil value in the table, never |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
477 ;; put spaces between words, thus delete a newline between them. |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
478 ;; Otherwise, delete a newline only when a character preceding a |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
479 ;; newline has non-nil value in that table. |
41303
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
480 (while (search-forward "\n" to t) |
50757
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
481 (if (get-text-property (match-beginning 0) 'fill-space) |
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
482 (replace-match (get-text-property (match-beginning 0) 'fill-space)) |
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
483 (let ((prev (char-before (match-beginning 0))) |
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
484 (next (following-char))) |
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
485 (if (and (or (aref (char-category-set next) ?|) |
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
486 (aref (char-category-set prev) ?|)) |
90633
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
487 (or (aref fill-nospace-between-words-table next) |
6408dbfc7b6a
(fill-find-break-point-function-table): Don't
Kenichi Handa <handa@m17n.org>
parents:
90625
diff
changeset
|
488 (aref fill-nospace-between-words-table prev))) |
50757
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
489 (delete-char -1)))))) |
41303
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
490 |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
491 (goto-char from) |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
492 (skip-chars-forward " \t") |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
493 ;; Then change all newlines to spaces. |
64853
a045a3e5b467
(fill-nonuniform-paragraphs): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents:
64751
diff
changeset
|
494 (subst-char-in-region from to ?\n ?\s) |
41303
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
495 (if (and nosqueeze (not (eq justify 'full))) |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
496 nil |
50437
1a4038cf9a79
(fill-delete-newlines): Remove trailing whitespace.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50411
diff
changeset
|
497 (canonically-space-region (or squeeze-after (point)) to) |
1a4038cf9a79
(fill-delete-newlines): Remove trailing whitespace.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50411
diff
changeset
|
498 ;; Remove trailing whitespace. |
1a4038cf9a79
(fill-delete-newlines): Remove trailing whitespace.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50411
diff
changeset
|
499 ;; Maybe canonically-space-region should do that. |
50443
dff98b69fed2
(fill-delete-newlines): Don't delete past TO.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50438
diff
changeset
|
500 (goto-char to) (delete-char (- (skip-chars-backward " \t")))) |
41303
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
501 (goto-char from)) |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
502 |
44491
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
503 (defun fill-move-to-break-point (linebeg) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
504 "Move to the position where the line should be broken. |
44504
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
505 The break position will be always after LINEBEG and generally before point." |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
506 ;; If the fill column is before linebeg, move to linebeg. |
483f757c5f72
(canonically-space-region): Obey sentence-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44491
diff
changeset
|
507 (if (> linebeg (point)) (goto-char linebeg)) |
44491
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
508 ;; Move back to the point where we can break the line |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
509 ;; at. We break the line between word or after/before |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
510 ;; the character which has character category `|'. We |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
511 ;; search space, \c| followed by a character, or \c| |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
512 ;; following a character. If not found, place |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
513 ;; the point at linebeg. |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
514 (while |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
515 (when (re-search-backward "[ \t]\\|\\c|.\\|.\\c|" linebeg 0) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
516 ;; In case of space, we place the point at next to |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
517 ;; the point where the break occurs actually, |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
518 ;; because we don't want to change the following |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
519 ;; logic of original Emacs. In case of \c|, the |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
520 ;; point is at the place where the break occurs. |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
521 (forward-char 1) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
522 (when (fill-nobreak-p) (skip-chars-backward " \t" linebeg)))) |
48095
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
523 |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
524 ;; Move back over the single space between the words. |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
525 (skip-chars-backward " \t") |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
526 |
44491
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
527 ;; If the left margin and fill prefix by themselves |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
528 ;; pass the fill-column. or if they are zero |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
529 ;; but we have no room for even one word, |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
530 ;; keep at least one word or a character which has |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
531 ;; category `|' anyway. |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
532 (if (>= linebeg (point)) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
533 ;; Ok, skip at least one word or one \c| character. |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
534 ;; Meanwhile, don't stop at a period followed by one space. |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
535 (let ((to (line-end-position)) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
536 (first t)) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
537 (goto-char linebeg) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
538 (while (and (< (point) to) (or first (fill-nobreak-p))) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
539 ;; Find a breakable point while ignoring the |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
540 ;; following spaces. |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
541 (skip-chars-forward " \t") |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
542 (if (looking-at "\\c|") |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
543 (forward-char 1) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
544 (let ((pos (save-excursion |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
545 (skip-chars-forward "^ \n\t") |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
546 (point)))) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
547 (if (re-search-forward "\\c|" pos t) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
548 (forward-char -1) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
549 (goto-char pos)))) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
550 (setq first nil))) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
551 |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
552 (if enable-multibyte-characters |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
553 ;; If we are going to break the line after or |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
554 ;; before a non-ascii character, we may have to |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
555 ;; run a special function for the charset of the |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
556 ;; character to find the correct break point. |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
557 (if (not (and (eq (charset-after (1- (point))) 'ascii) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
558 (eq (charset-after (point)) 'ascii))) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
559 ;; Make sure we take SOMETHING after the fill prefix if any. |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
560 (fill-find-break-point linebeg))))) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
561 |
61155
801f886872c5
(fill-text-properties-at): New function.
Kenichi Handa <handa@m17n.org>
parents:
60561
diff
changeset
|
562 ;; Like text-properties-at but don't include `composition' property. |
801f886872c5
(fill-text-properties-at): New function.
Kenichi Handa <handa@m17n.org>
parents:
60561
diff
changeset
|
563 (defun fill-text-properties-at (pos) |
801f886872c5
(fill-text-properties-at): New function.
Kenichi Handa <handa@m17n.org>
parents:
60561
diff
changeset
|
564 (let ((l (text-properties-at pos)) |
801f886872c5
(fill-text-properties-at): New function.
Kenichi Handa <handa@m17n.org>
parents:
60561
diff
changeset
|
565 prop-list) |
801f886872c5
(fill-text-properties-at): New function.
Kenichi Handa <handa@m17n.org>
parents:
60561
diff
changeset
|
566 (while l |
801f886872c5
(fill-text-properties-at): New function.
Kenichi Handa <handa@m17n.org>
parents:
60561
diff
changeset
|
567 (unless (eq (car l) 'composition) |
801f886872c5
(fill-text-properties-at): New function.
Kenichi Handa <handa@m17n.org>
parents:
60561
diff
changeset
|
568 (setq prop-list |
801f886872c5
(fill-text-properties-at): New function.
Kenichi Handa <handa@m17n.org>
parents:
60561
diff
changeset
|
569 (cons (car l) (cons (cadr l) prop-list)))) |
801f886872c5
(fill-text-properties-at): New function.
Kenichi Handa <handa@m17n.org>
parents:
60561
diff
changeset
|
570 (setq l (cddr l))) |
801f886872c5
(fill-text-properties-at): New function.
Kenichi Handa <handa@m17n.org>
parents:
60561
diff
changeset
|
571 prop-list)) |
801f886872c5
(fill-text-properties-at): New function.
Kenichi Handa <handa@m17n.org>
parents:
60561
diff
changeset
|
572 |
44491
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
573 (defun fill-newline () |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
574 ;; Replace whitespace here with one newline, then |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
575 ;; indent to left margin. |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
576 (skip-chars-backward " \t") |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
577 (insert ?\n) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
578 ;; Give newline the properties of the space(s) it replaces |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
579 (set-text-properties (1- (point)) (point) |
61155
801f886872c5
(fill-text-properties-at): New function.
Kenichi Handa <handa@m17n.org>
parents:
60561
diff
changeset
|
580 (fill-text-properties-at (point))) |
50757
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
581 (and (looking-at "\\( [ \t]*\\)\\(\\c|\\)?") |
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
582 (or (aref (char-category-set (or (char-before (1- (point))) ?\000)) ?|) |
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
583 (match-end 2)) |
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
584 ;; When refilling later on, this newline would normally not be replaced |
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
585 ;; by a space, so we need to mark it specially to re-install the space |
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
586 ;; when we unfill. |
89533dc3e837
(text-property-default-nonsticky): Add fill-space.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50659
diff
changeset
|
587 (put-text-property (1- (point)) (point) 'fill-space (match-string 1))) |
48286
a820dd4741e1
(fill-nobreak-invisible): New var.
Kim F. Storm <storm@cua.dk>
parents:
48208
diff
changeset
|
588 ;; If we don't want breaks in invisible text, don't insert |
a820dd4741e1
(fill-nobreak-invisible): New var.
Kim F. Storm <storm@cua.dk>
parents:
48208
diff
changeset
|
589 ;; an invisible newline. |
a820dd4741e1
(fill-nobreak-invisible): New var.
Kim F. Storm <storm@cua.dk>
parents:
48208
diff
changeset
|
590 (if fill-nobreak-invisible |
a820dd4741e1
(fill-nobreak-invisible): New var.
Kim F. Storm <storm@cua.dk>
parents:
48208
diff
changeset
|
591 (remove-text-properties (1- (point)) (point) |
a820dd4741e1
(fill-nobreak-invisible): New var.
Kim F. Storm <storm@cua.dk>
parents:
48208
diff
changeset
|
592 '(invisible t))) |
44491
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
593 (if (or fill-prefix |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
594 (not fill-indent-according-to-mode)) |
48621
2cf7301b2f52
(fill-indent-to-left-margin): New function.
Richard M. Stallman <rms@gnu.org>
parents:
48286
diff
changeset
|
595 (fill-indent-to-left-margin) |
44491
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
596 (indent-according-to-mode)) |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
597 ;; Insert the fill prefix after indentation. |
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
598 (and fill-prefix (not (equal fill-prefix "")) |
50411
62a57aa6353a
(fill-newline): Don't leave markers before the prefix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50409
diff
changeset
|
599 ;; Markers that were after the whitespace are now at point: insert |
62a57aa6353a
(fill-newline): Don't leave markers before the prefix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50409
diff
changeset
|
600 ;; before them so they don't get stuck before the prefix. |
62a57aa6353a
(fill-newline): Don't leave markers before the prefix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50409
diff
changeset
|
601 (insert-before-markers-and-inherit fill-prefix))) |
44491
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
602 |
48621
2cf7301b2f52
(fill-indent-to-left-margin): New function.
Richard M. Stallman <rms@gnu.org>
parents:
48286
diff
changeset
|
603 (defun fill-indent-to-left-margin () |
2cf7301b2f52
(fill-indent-to-left-margin): New function.
Richard M. Stallman <rms@gnu.org>
parents:
48286
diff
changeset
|
604 "Indent current line to the column given by `current-left-margin'." |
2cf7301b2f52
(fill-indent-to-left-margin): New function.
Richard M. Stallman <rms@gnu.org>
parents:
48286
diff
changeset
|
605 (let ((beg (point))) |
2cf7301b2f52
(fill-indent-to-left-margin): New function.
Richard M. Stallman <rms@gnu.org>
parents:
48286
diff
changeset
|
606 (indent-line-to (current-left-margin)) |
2cf7301b2f52
(fill-indent-to-left-margin): New function.
Richard M. Stallman <rms@gnu.org>
parents:
48286
diff
changeset
|
607 (put-text-property beg (point) 'face 'default))) |
2cf7301b2f52
(fill-indent-to-left-margin): New function.
Richard M. Stallman <rms@gnu.org>
parents:
48286
diff
changeset
|
608 |
14621
f989cff391f1
(canonically-space-region): Use insert-before-markers
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
609 (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
|
610 nosqueeze squeeze-after) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
611 "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
|
612 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
|
613 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
|
614 `current-left-margin' and `current-fill-column' functions. |
18664 | 615 \(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
|
616 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
|
617 |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
618 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
|
619 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
|
620 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
621 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
|
622 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
|
623 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
|
624 means don't canonicalize spaces before that position. |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
625 |
48095
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
626 Return the `fill-prefix' used for filling. |
33441
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
627 |
5770
92dd602768d2
(sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5291
diff
changeset
|
628 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
|
629 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
|
630 (interactive (progn |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
631 (barf-if-buffer-read-only) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
632 (list (region-beginning) (region-end) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
633 (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
|
634 (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
|
635 (setq justify 'full)) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
636 |
13578
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
637 ;; Make sure "to" is the endpoint. |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
638 (goto-char (min from to)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
639 (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
|
640 ;; 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
|
641 (skip-chars-forward " \t\n") |
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
642 |
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
643 (let ((from-plus-indent (point)) |
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
644 (oneleft nil)) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
645 |
71736
125374685aec
(fill-region-as-paragraph): Refine last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71678
diff
changeset
|
646 (beginning-of-line) |
71678
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
647 ;; We used to round up to whole line, but that prevents us from |
71736
125374685aec
(fill-region-as-paragraph): Refine last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71678
diff
changeset
|
648 ;; correctly handling filling of mixed code-and-comment where we do want |
125374685aec
(fill-region-as-paragraph): Refine last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71678
diff
changeset
|
649 ;; to fill the comment but not the code. So only use (point) if it's |
125374685aec
(fill-region-as-paragraph): Refine last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71678
diff
changeset
|
650 ;; further than `from', which means that `from' is followed by some |
125374685aec
(fill-region-as-paragraph): Refine last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71678
diff
changeset
|
651 ;; number of empty lines. |
125374685aec
(fill-region-as-paragraph): Refine last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71678
diff
changeset
|
652 (setq from (max (point) from)) |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
653 |
13578
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
654 ;; 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
|
655 ;; 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
|
656 (goto-char to) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
657 (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
|
658 (if (and oneleft |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
659 (not (and use-hard-newlines |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
660 (get-text-property (1- (point)) 'hard)))) |
108765
d835100c3e8b
Replace Lisp calls to delete-backward-char by delete-char.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108662
diff
changeset
|
661 (delete-char -1) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
662 (backward-char 1) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
663 (setq oneleft t))) |
41303
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
664 (setq to (copy-marker (point) t)) |
33365
2c0585b6e6d6
(fill-indent-according-to-mode): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32230
diff
changeset
|
665 ;; ;; 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
|
666 ;; ;; create a newline. |
2c0585b6e6d6
(fill-indent-according-to-mode): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32230
diff
changeset
|
667 ;; (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
|
668 ;; (newline)) |
13578
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
669 (goto-char from-plus-indent)) |
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
670 |
85697e02a482
(fill-region-as-paragraph): Remove redundant "setq from".
Richard M. Stallman <rms@gnu.org>
parents:
13549
diff
changeset
|
671 (if (not (> to (point))) |
44491
d85112eaf2d2
(adaptive-fill-regexp): Add ! and %.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44478
diff
changeset
|
672 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
|
673 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
674 (or justify (setq justify (current-justification))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
675 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
676 ;; 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
|
677 (let ((fill-prefix fill-prefix)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
678 ;; Figure out how this paragraph is indented, if desired. |
41303
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
679 (when (and adaptive-fill-mode |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
680 (or (null fill-prefix) (string= fill-prefix ""))) |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
681 (setq fill-prefix (fill-context-prefix from to)) |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
682 ;; Ignore a white-space only fill-prefix |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
683 ;; if we indent-according-to-mode. |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
684 (when (and fill-prefix fill-indent-according-to-mode |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
685 (string-match "\\`[ \t]*\\'" fill-prefix)) |
ada5571dc737
(fill-delete-prefix, fill-delete-newlines):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
40668
diff
changeset
|
686 (setq fill-prefix nil))) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
687 |
50408
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
688 (goto-char from) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
689 (beginning-of-line) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
690 |
50408
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
691 (if (not justify) ; filling disabled: just check indentation |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
692 (progn |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
693 (goto-char from) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
694 (while (< (point) to) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
695 (if (and (not (eolp)) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
696 (< (current-indentation) (current-left-margin))) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
697 (fill-indent-to-left-margin)) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
698 (forward-line 1))) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
699 |
50408
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
700 (if use-hard-newlines |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
701 (remove-list-of-text-properties from to '(hard))) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
702 ;; Make sure first line is indented (at least) to left margin... |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
703 (if (or (memq justify '(right center)) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
704 (< (current-indentation) (current-left-margin))) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
705 (fill-indent-to-left-margin)) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
706 ;; Delete the fill-prefix from every line. |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
707 (fill-delete-prefix from to fill-prefix) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
708 (setq from (point)) |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
709 |
50408
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
710 ;; FROM, and point, are now before the text to fill, |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
711 ;; but after any fill prefix on the first line. |
218 | 712 |
50408
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
713 (fill-delete-newlines from to justify nosqueeze squeeze-after) |
218 | 714 |
50408
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
715 ;; This is the actual filling loop. |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
716 (goto-char from) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
717 (let (linebeg) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
718 (while (< (point) to) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
719 (setq linebeg (point)) |
50659
f20dbbe44da9
(fill-region-as-paragraph): Fix "last line goes to fill-column+1" problem.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50443
diff
changeset
|
720 (move-to-column (current-fill-column)) |
50408
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
721 (if (when (< (point) to) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
722 ;; Find the position where we'll break the line. |
50659
f20dbbe44da9
(fill-region-as-paragraph): Fix "last line goes to fill-column+1" problem.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50443
diff
changeset
|
723 (forward-char 1) ;Use an immediately following space, if any. |
50408
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
724 (fill-move-to-break-point linebeg) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
725 ;; Check again to see if we got to the end of |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
726 ;; the paragraph. |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
727 (skip-chars-forward " \t") |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
728 (< (point) to)) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
729 ;; Found a place to cut. |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
730 (progn |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
731 (fill-newline) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
732 (when justify |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
733 ;; Justify the line just ended, if desired. |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
734 (save-excursion |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
735 (forward-line -1) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
736 (justify-current-line justify nil t)))) |
23490
dc320f6914fe
Setup `fill-find-break-point-function'
Kenichi Handa <handa@m17n.org>
parents:
23351
diff
changeset
|
737 |
50408
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
738 (goto-char to) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
739 ;; Justify this last line, if desired. |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
740 (if justify (justify-current-line justify t t)))))) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
741 ;; Leave point after final newline. |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
742 (goto-char to) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
743 (unless (eobp) (forward-char 1)) |
33441
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
744 ;; Return the fill-prefix we used |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
745 fill-prefix))) |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
746 |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
747 (defsubst skip-line-prefix (prefix) |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
748 "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
|
749 (when (and prefix |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
750 (< (- (point) (line-beginning-position)) (length prefix)) |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
751 (save-excursion |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
752 (beginning-of-line) |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
753 (looking-at (regexp-quote prefix)))) |
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
754 (goto-char (match-end 0)))) |
75 | 755 |
73778
7e762349b1c3
(fill-minibuffer-function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
72722
diff
changeset
|
756 (defun fill-minibuffer-function (arg) |
7e762349b1c3
(fill-minibuffer-function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
72722
diff
changeset
|
757 "Fill a paragraph in the minibuffer, ignoring the prompt." |
75185
de505aec360d
(fill-region): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
75133
diff
changeset
|
758 (save-restriction |
73778
7e762349b1c3
(fill-minibuffer-function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
72722
diff
changeset
|
759 (narrow-to-region (minibuffer-prompt-end) (point-max)) |
7e762349b1c3
(fill-minibuffer-function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
72722
diff
changeset
|
760 (fill-paragraph arg))) |
7e762349b1c3
(fill-minibuffer-function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
72722
diff
changeset
|
761 |
94004
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
762 (defvar fill-forward-paragraph-function 'forward-paragraph |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
763 "Function to move over paragraphs used by the filling code. |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
764 It is called with a single argument specifying the number of paragraphs to move. |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
765 Just like `forward-paragraph', it should return the number of paragraphs |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
766 left to move.") |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
767 |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
768 (defun fill-forward-paragraph (arg) |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
769 (funcall fill-forward-paragraph-function arg)) |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
770 |
85375
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
771 (defun fill-paragraph (&optional justify region) |
77515 | 772 "Fill paragraph at or after point. |
773 | |
85375
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
774 If JUSTIFY is non-nil (interactively, with prefix argument), justify as well. |
5770
92dd602768d2
(sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5291
diff
changeset
|
775 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
|
776 space does not end a sentence, so don't break a line there. |
96497
885e5368ecb2
Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents:
94670
diff
changeset
|
777 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
|
778 |
dc245bfecc3b
(fill-paragraph-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10543
diff
changeset
|
779 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
|
780 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
|
781 |
85375
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
782 If `fill-paragraph-function' is nil, return the `fill-prefix' used for filling. |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
783 |
102881
1bdb6d2477f5
* textmodes/fill.el (fill-paragraph): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
100908
diff
changeset
|
784 The REGION argument is non-nil if called interactively; in that |
1bdb6d2477f5
* textmodes/fill.el (fill-paragraph): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
100908
diff
changeset
|
785 case, if Transient Mark mode is enabled and the mark is active, |
1bdb6d2477f5
* textmodes/fill.el (fill-paragraph): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
100908
diff
changeset
|
786 call `fill-region' to fill each of the paragraphs in the active |
1bdb6d2477f5
* textmodes/fill.el (fill-paragraph): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
100908
diff
changeset
|
787 region, instead of just filling the current paragraph." |
24972
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
788 (interactive (progn |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
789 (barf-if-buffer-read-only) |
85375
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
790 (list (if current-prefix-arg 'full) t))) |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
791 (or |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
792 ;; 1. Fill the region if it is active when called interactively. |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
793 (and region transient-mark-mode mark-active |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
794 (not (eq (region-beginning) (region-end))) |
85498
707687ae3f04
(fill-paragraph): When the region is active, don't try other `or' branches
Juri Linkov <juri@jurta.org>
parents:
85403
diff
changeset
|
795 (or (fill-region (region-beginning) (region-end) justify) t)) |
85375
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
796 ;; 2. Try fill-paragraph-function. |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
797 (and (not (eq fill-paragraph-function t)) |
94004
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
798 (or fill-paragraph-function |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
799 (and (minibufferp (current-buffer)) |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
800 (= 1 (point-min)))) |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
801 (let ((function (or fill-paragraph-function |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
802 ;; In the minibuffer, don't count the width |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
803 ;; of the prompt. |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
804 'fill-minibuffer-function)) |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
805 ;; If fill-paragraph-function is set, it probably takes care |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
806 ;; of comments and stuff. If not, it will have to set |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
807 ;; fill-paragraph-handle-comment back to t explicitly or |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
808 ;; return nil. |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
809 (fill-paragraph-handle-comment nil) |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
810 (fill-paragraph-function t)) |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
811 (funcall function justify))) |
85375
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
812 ;; 3. Try our syntax-aware filling code. |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
813 (and fill-paragraph-handle-comment |
94004
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
814 ;; Our code only handles \n-terminated comments right now. |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
815 comment-start (equal comment-end "") |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
816 (let ((fill-paragraph-handle-comment nil)) |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
817 (fill-comment-paragraph justify))) |
85375
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
818 ;; 4. If it all fails, default to the good ol' text paragraph filling. |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
819 (let ((before (point)) |
94004
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
820 (paragraph-start paragraph-start) |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
821 ;; Fill prefix used for filling the paragraph. |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
822 fill-pfx) |
85375
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
823 ;; Try to prevent code sections and comment sections from being |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
824 ;; filled together. |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
825 (when (and fill-paragraph-handle-comment comment-start-skip) |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
826 (setq paragraph-start |
94004
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
827 (concat paragraph-start "\\|[ \t]*\\(?:" |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
828 comment-start-skip "\\)"))) |
85375
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
829 (save-excursion |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
830 ;; To make sure the return value of forward-paragraph is meaningful, |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
831 ;; we have to start from the beginning of line, otherwise skipping |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
832 ;; past the last few chars of a paragraph-separator would count as |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
833 ;; a paragraph (and not skipping any chars at EOB would not count |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
834 ;; as a paragraph even if it is). |
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
835 (move-to-left-margin) |
94004
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
836 (if (not (zerop (fill-forward-paragraph 1))) |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
837 ;; There's no paragraph at or after point: give up. |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
838 (setq fill-pfx "") |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
839 (let ((end (point)) |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
840 (beg (progn (fill-forward-paragraph -1) (point)))) |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
841 (goto-char before) |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
842 (setq fill-pfx |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
843 (if use-hard-newlines |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
844 ;; Can't use fill-region-as-paragraph, since this |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
845 ;; paragraph may still contain hard newlines. See |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
846 ;; fill-region. |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
847 (fill-region beg end justify) |
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
848 (fill-region-as-paragraph beg end justify)))))) |
85375
8f6c4eb58cdb
(fill-paragraph-or-region): Remove function at the request of RMS.
Juri Linkov <juri@jurta.org>
parents:
85069
diff
changeset
|
849 fill-pfx))) |
75 | 850 |
87125
781744830529
Remove directory part from filenames in function declarations.
Glenn Morris <rgm@gnu.org>
parents:
86243
diff
changeset
|
851 (declare-function comment-search-forward "newcomment" (limit &optional noerror)) |
781744830529
Remove directory part from filenames in function declarations.
Glenn Morris <rgm@gnu.org>
parents:
86243
diff
changeset
|
852 (declare-function comment-string-strip "newcomment" (str beforep afterp)) |
86243
4d615a83cee2
* progmodes/idlw-help.el: Require browse-url unconditionally, it
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85683
diff
changeset
|
853 |
75 | 854 |
48126
92c696f8509e
(fill-paragraph-handle-comment): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48095
diff
changeset
|
855 (defun fill-comment-paragraph (&optional justify) |
92c696f8509e
(fill-paragraph-handle-comment): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48095
diff
changeset
|
856 "Fill current comment. |
92c696f8509e
(fill-paragraph-handle-comment): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48095
diff
changeset
|
857 If we're not in a comment, just return nil so that the caller |
48208
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
858 can take care of filling. JUSTIFY is used as in `fill-paragraph'." |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
859 (comment-normalize-vars) |
71678
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
860 (let (has-code-and-comment ; Non-nil if it contains code and a comment. |
48208
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
861 comin comstart) |
48126
92c696f8509e
(fill-paragraph-handle-comment): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48095
diff
changeset
|
862 ;; Figure out what kind of comment we are looking at. |
92c696f8509e
(fill-paragraph-handle-comment): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48095
diff
changeset
|
863 (save-excursion |
92c696f8509e
(fill-paragraph-handle-comment): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48095
diff
changeset
|
864 (beginning-of-line) |
48208
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
865 (when (setq comstart (comment-search-forward (line-end-position) t)) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
866 (setq comin (point)) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
867 (goto-char comstart) (skip-chars-backward " \t") |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
868 (setq has-code-and-comment (not (bolp))))) |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
869 |
80237
d2d9530e9b45
(fill-comment-paragraph): Don't try to do comment-paragraph filling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79719
diff
changeset
|
870 (if (not (and comstart |
d2d9530e9b45
(fill-comment-paragraph): Don't try to do comment-paragraph filling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79719
diff
changeset
|
871 ;; Make sure the comment-start mark we found is accepted by |
d2d9530e9b45
(fill-comment-paragraph): Don't try to do comment-paragraph filling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79719
diff
changeset
|
872 ;; comment-start-skip. If not, all bets are off, and |
d2d9530e9b45
(fill-comment-paragraph): Don't try to do comment-paragraph filling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79719
diff
changeset
|
873 ;; we'd better not mess with it. |
d2d9530e9b45
(fill-comment-paragraph): Don't try to do comment-paragraph filling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79719
diff
changeset
|
874 (string-match comment-start-skip |
d2d9530e9b45
(fill-comment-paragraph): Don't try to do comment-paragraph filling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79719
diff
changeset
|
875 (buffer-substring comstart comin)))) |
d2d9530e9b45
(fill-comment-paragraph): Don't try to do comment-paragraph filling
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79719
diff
changeset
|
876 |
48126
92c696f8509e
(fill-paragraph-handle-comment): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48095
diff
changeset
|
877 ;; Return nil, so the normal filling will take place. |
92c696f8509e
(fill-paragraph-handle-comment): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48095
diff
changeset
|
878 nil |
92c696f8509e
(fill-paragraph-handle-comment): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48095
diff
changeset
|
879 |
92c696f8509e
(fill-paragraph-handle-comment): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48095
diff
changeset
|
880 ;; Narrow to include only the comment, and then fill the region. |
48208
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
881 (let* ((fill-prefix fill-prefix) |
52023
ba56926bf332
(fill-comment-paragraph): Construct a regexp
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50757
diff
changeset
|
882 (commark |
ba56926bf332
(fill-comment-paragraph): Construct a regexp
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50757
diff
changeset
|
883 (comment-string-strip (buffer-substring comstart comin) nil t)) |
ba56926bf332
(fill-comment-paragraph): Construct a regexp
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
50757
diff
changeset
|
884 (comment-re |
75133
827cbf161c8f
(fill-comment-paragraph): Improve comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
74962
diff
changeset
|
885 ;; A regexp more specialized than comment-start-skip, that only |
827cbf161c8f
(fill-comment-paragraph): Improve comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
74962
diff
changeset
|
886 ;; matches the current commark rather than any valid commark. |
75185
de505aec360d
(fill-region): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
75133
diff
changeset
|
887 ;; |
75133
827cbf161c8f
(fill-comment-paragraph): Improve comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
74962
diff
changeset
|
888 ;; The specialized regexp only works for "normal" comment |
827cbf161c8f
(fill-comment-paragraph): Improve comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
74962
diff
changeset
|
889 ;; syntax, not for Texinfo's "@c" (which can't be immediately |
827cbf161c8f
(fill-comment-paragraph): Improve comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
74962
diff
changeset
|
890 ;; followed by word-chars) or Fortran's "C" (which needs to be |
827cbf161c8f
(fill-comment-paragraph): Improve comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
74962
diff
changeset
|
891 ;; at bol), so check that comment-start-skip indeed allows the |
827cbf161c8f
(fill-comment-paragraph): Improve comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
74962
diff
changeset
|
892 ;; commark to appear in the middle of the line and followed by |
827cbf161c8f
(fill-comment-paragraph): Improve comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
74962
diff
changeset
|
893 ;; word chars. The choice of "\0" and "a" is mostly arbitrary. |
827cbf161c8f
(fill-comment-paragraph): Improve comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
74962
diff
changeset
|
894 (if (string-match comment-start-skip (concat "\0" commark "a")) |
827cbf161c8f
(fill-comment-paragraph): Improve comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
74962
diff
changeset
|
895 (concat "[ \t]*" (regexp-quote commark) |
827cbf161c8f
(fill-comment-paragraph): Improve comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
74962
diff
changeset
|
896 ;; Make sure we only match comments that |
827cbf161c8f
(fill-comment-paragraph): Improve comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
74962
diff
changeset
|
897 ;; use the exact same comment marker. |
827cbf161c8f
(fill-comment-paragraph): Improve comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
74962
diff
changeset
|
898 "[^" (substring commark -1) "]") |
827cbf161c8f
(fill-comment-paragraph): Improve comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
74962
diff
changeset
|
899 (concat "[ \t]*\\(?:" comment-start-skip "\\)"))) |
827cbf161c8f
(fill-comment-paragraph): Improve comment.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
74962
diff
changeset
|
900 (comment-fill-prefix ; Compute a fill prefix. |
48208
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
901 (save-excursion |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
902 (goto-char comstart) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
903 (if has-code-and-comment |
54701
1abda8ef8f22
(fill-comment-paragraph): Obey indent-tabs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54549
diff
changeset
|
904 (concat |
1abda8ef8f22
(fill-comment-paragraph): Obey indent-tabs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54549
diff
changeset
|
905 (if (not indent-tabs-mode) |
64853
a045a3e5b467
(fill-nonuniform-paragraphs): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents:
64751
diff
changeset
|
906 (make-string (current-column) ?\s) |
54701
1abda8ef8f22
(fill-comment-paragraph): Obey indent-tabs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54549
diff
changeset
|
907 (concat |
1abda8ef8f22
(fill-comment-paragraph): Obey indent-tabs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54549
diff
changeset
|
908 (make-string (/ (current-column) tab-width) ?\t) |
64853
a045a3e5b467
(fill-nonuniform-paragraphs): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents:
64751
diff
changeset
|
909 (make-string (% (current-column) tab-width) ?\s))) |
54701
1abda8ef8f22
(fill-comment-paragraph): Obey indent-tabs-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54549
diff
changeset
|
910 (buffer-substring (point) comin)) |
48208
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
911 (buffer-substring (line-beginning-position) comin)))) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
912 beg end) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
913 (save-excursion |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
914 (save-restriction |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
915 (beginning-of-line) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
916 (narrow-to-region |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
917 ;; Find the first line we should include in the region to fill. |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
918 (if has-code-and-comment |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
919 (line-beginning-position) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
920 (save-excursion |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
921 (while (and (zerop (forward-line -1)) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
922 (looking-at comment-re))) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
923 ;; We may have gone too far. Go forward again. |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
924 (line-beginning-position |
54252
bd2c8b015291
(fill-comment-paragraph): Be more careful when
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54247
diff
changeset
|
925 (if (progn |
bd2c8b015291
(fill-comment-paragraph): Be more careful when
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54247
diff
changeset
|
926 (goto-char |
bd2c8b015291
(fill-comment-paragraph): Be more careful when
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54247
diff
changeset
|
927 (or (comment-search-forward (line-end-position) t) |
bd2c8b015291
(fill-comment-paragraph): Be more careful when
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54247
diff
changeset
|
928 (point))) |
bd2c8b015291
(fill-comment-paragraph): Be more careful when
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54247
diff
changeset
|
929 (looking-at comment-re)) |
71678
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
930 (progn (setq comstart (point)) 1) |
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
931 (progn (setq comstart (point)) 2))))) |
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
932 ;; Find the beginning of the first line past the region to fill. |
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
933 (save-excursion |
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
934 (while (progn (forward-line 1) |
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
935 (looking-at comment-re))) |
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
936 (point))) |
48208
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
937 ;; Obey paragraph starters and boundaries within comments. |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
938 (let* ((paragraph-separate |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
939 ;; Use the default values since they correspond to |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
940 ;; the values to use for plain text. |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
941 (concat paragraph-separate "\\|[ \t]*\\(?:" |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
942 comment-start-skip "\\)\\(?:" |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
943 (default-value 'paragraph-separate) "\\)")) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
944 (paragraph-start |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
945 (concat paragraph-start "\\|[ \t]*\\(?:" |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
946 comment-start-skip "\\)\\(?:" |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
947 (default-value 'paragraph-start) "\\)")) |
71678
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
948 ;; We used to rely on fill-prefix to break paragraph at |
54311
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
949 ;; comment-starter changes, but it did not work for the |
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
950 ;; first line (mixed comment&code). |
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
951 ;; We now use comment-re instead to "manually" make sure |
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
952 ;; we treat comment-marker changes as paragraph boundaries. |
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
953 ;; (paragraph-ignore-fill-prefix nil) |
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
954 ;; (fill-prefix comment-fill-prefix) |
48208
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
955 (after-line (if has-code-and-comment |
50408
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
956 (line-beginning-position 2)))) |
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
957 (setq end (progn (forward-paragraph) (point))) |
48208
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
958 ;; If this comment starts on a line with code, |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
959 ;; include that line in the filling. |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
960 (setq beg (progn (backward-paragraph) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
961 (if (eq (point) after-line) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
962 (forward-line -1)) |
50408
329ac267f1fc
(fill-region-as-paragraph): Remove obsolete `save-restriction'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
49599
diff
changeset
|
963 (point))))) |
48126
92c696f8509e
(fill-paragraph-handle-comment): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48095
diff
changeset
|
964 |
48208
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
965 ;; Find the fill-prefix to use. |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
966 (cond |
71678
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
967 (fill-prefix) ; Use the user-provided fill prefix. |
48208
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
968 ((and adaptive-fill-mode ; Try adaptive fill mode. |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
969 (setq fill-prefix (fill-context-prefix beg end)) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
970 (string-match comment-start-skip fill-prefix))) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
971 (t |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
972 (setq fill-prefix comment-fill-prefix))) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
973 |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
974 ;; Don't fill with narrowing. |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
975 (or |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
976 (fill-region-as-paragraph |
71678
dd05f4dc5c56
(fill-delete-prefix): Don't ignore excessively long prefixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
70269
diff
changeset
|
977 (max comstart beg) end justify nil |
48208
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
978 ;; Don't canonicalize spaces within the code just before |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
979 ;; the comment. |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
980 (save-excursion |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
981 (goto-char beg) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
982 (if (looking-at fill-prefix) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
983 nil |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
984 (re-search-forward comment-start-skip)))) |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
985 ;; Make sure we don't return nil. |
0cdc12c2cf68
(fill-paragraph): Consider a comment-start as
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48126
diff
changeset
|
986 t)))))) |
48126
92c696f8509e
(fill-paragraph-handle-comment): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
48095
diff
changeset
|
987 |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
988 (defun fill-region (from to &optional justify nosqueeze to-eop) |
75 | 989 "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
|
990 A prefix arg means justify as well. |
18664 | 991 Ordinarily the variable `fill-column' controls the width. |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
992 |
21103
8e12f5209e37
(fill-region): If JUSTIFY is non-nil
Richard M. Stallman <rms@gnu.org>
parents:
20822
diff
changeset
|
993 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
|
994 kind of justification to do: `full', `left', `right', `center', |
75185
de505aec360d
(fill-region): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
75133
diff
changeset
|
995 or `none' (equivalent to nil). A value of t means handle each |
de505aec360d
(fill-region): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
75133
diff
changeset
|
996 paragraph as specified by its text properties. |
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
|
997 |
75185
de505aec360d
(fill-region): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
75133
diff
changeset
|
998 The fourth arg NOSQUEEZE non-nil means to leave whitespace other |
de505aec360d
(fill-region): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
75133
diff
changeset
|
999 than line breaks untouched, and fifth arg TO-EOP non-nil means |
de505aec360d
(fill-region): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
75133
diff
changeset
|
1000 to keep filling to the end of the paragraph (or next hard newline, |
de505aec360d
(fill-region): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
75133
diff
changeset
|
1001 if variable `use-hard-newlines' is on). |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1002 |
33441
b938b9d018a3
(skip-line-prefix): New function.
Miles Bader <miles@gnu.org>
parents:
33365
diff
changeset
|
1003 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
|
1004 |
5770
92dd602768d2
(sentence-end-double-space): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5291
diff
changeset
|
1005 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
|
1006 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
|
1007 (interactive (progn |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1008 (barf-if-buffer-read-only) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1009 (list (region-beginning) (region-end) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1010 (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
|
1011 (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
|
1012 (setq justify 'full)) |
48095
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1013 (let (max beg fill-pfx) |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1014 (goto-char (max from to)) |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1015 (when to-eop |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1016 (skip-chars-backward "\n") |
94004
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
1017 (fill-forward-paragraph 1)) |
48095
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1018 (setq max (copy-marker (point) t)) |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1019 (goto-char (setq beg (min from to))) |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1020 (beginning-of-line) |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1021 (while (< (point) max) |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1022 (let ((initial (point)) |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1023 end) |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1024 ;; If using hard newlines, break at every one for filling |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1025 ;; purposes rather than using paragraph breaks. |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1026 (if use-hard-newlines |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1027 (progn |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1028 (while (and (setq end (text-property-any (point) max |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1029 'hard t)) |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1030 (not (= ?\n (char-after end))) |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1031 (not (>= end max))) |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1032 (goto-char (1+ end))) |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1033 (setq end (if end (min max (1+ end)) max)) |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1034 (goto-char initial)) |
94004
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
1035 (fill-forward-paragraph 1) |
48095
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1036 (setq end (min max (point))) |
94004
0ab0b9641d80
(fill-forward-paragraph-function): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92948
diff
changeset
|
1037 (fill-forward-paragraph -1)) |
48095
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1038 (if (< (point) beg) |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1039 (goto-char beg)) |
108662
30ebb77362b6
* textmodes/fill.el (fill-region): Don't fill past the end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106815
diff
changeset
|
1040 (if (and (>= (point) initial) (< (point) end)) |
48095
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1041 (setq fill-pfx |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1042 (fill-region-as-paragraph (point) end justify nosqueeze)) |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1043 (goto-char end)))) |
cce15dd3ec16
(fill-move-to-break-point): Skip white space
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
47779
diff
changeset
|
1044 fill-pfx)) |
75 | 1045 |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1046 |
17664
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
1047 (defcustom default-justification 'left |
96497
885e5368ecb2
Typos, doc fixes, etc.
Juanma Barranquero <lekktu@gmail.com>
parents:
94670
diff
changeset
|
1048 "Method of justifying text not otherwise specified. |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1049 Possible values are `left', `right', `full', `center', or `none'. |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1050 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
|
1051 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
|
1052 :type '(choice (const left) |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
1053 (const right) |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
1054 (const full) |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
1055 (const center) |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
1056 (const none)) |
d8cb277f0ce8
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
16998
diff
changeset
|
1057 :group 'fill) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1058 (make-variable-buffer-local 'default-justification) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1059 |
10472
82ff279a4cea
(current-justification): Renamed from current-justification. Callers changed.
Richard M. Stallman <rms@gnu.org>
parents:
10468
diff
changeset
|
1060 (defun current-justification () |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1061 "How should we justify this line? |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1062 This returns the value of the text-property `justification', |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1063 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
|
1064 However, it returns nil rather than `none' to mean \"don't justify\"." |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1065 (let ((j (or (get-text-property |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1066 ;; Make sure we're looking at paragraph body. |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1067 (save-excursion (skip-chars-forward " \t") |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1068 (if (and (eobp) (not (bobp))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1069 (1- (point)) (point))) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1070 'justification) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1071 default-justification))) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1072 (if (eq 'none j) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1073 nil |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1074 j))) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1075 |
41849
82810216f9a4
(set-justification): Rename arg VALUE to STYLE.
Richard M. Stallman <rms@gnu.org>
parents:
41800
diff
changeset
|
1076 (defun set-justification (begin end style &optional whole-par) |
82810216f9a4
(set-justification): Rename arg VALUE to STYLE.
Richard M. Stallman <rms@gnu.org>
parents:
41800
diff
changeset
|
1077 "Set the region's justification style to STYLE. |
82810216f9a4
(set-justification): Rename arg VALUE to STYLE.
Richard M. Stallman <rms@gnu.org>
parents:
41800
diff
changeset
|
1078 This commands prompts for the kind of justification to use. |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1079 If the mark is not active, this command operates on the current paragraph. |
41849
82810216f9a4
(set-justification): Rename arg VALUE to STYLE.
Richard M. Stallman <rms@gnu.org>
parents:
41800
diff
changeset
|
1080 If the mark is active, it operates on the region. However, if the |
82810216f9a4
(set-justification): Rename arg VALUE to STYLE.
Richard M. Stallman <rms@gnu.org>
parents:
41800
diff
changeset
|
1081 beginning and end of the region are not at paragraph breaks, they are |
82810216f9a4
(set-justification): Rename arg VALUE to STYLE.
Richard M. Stallman <rms@gnu.org>
parents:
41800
diff
changeset
|
1082 moved to the beginning and end \(respectively) of the paragraphs they |
82810216f9a4
(set-justification): Rename arg VALUE to STYLE.
Richard M. Stallman <rms@gnu.org>
parents:
41800
diff
changeset
|
1083 are in. |
82810216f9a4
(set-justification): Rename arg VALUE to STYLE.
Richard M. Stallman <rms@gnu.org>
parents:
41800
diff
changeset
|
1084 |
54311
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
1085 If variable `use-hard-newlines' is true, all hard newlines are |
c8366dca5cf2
(fill) <defgroup>: Move from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54252
diff
changeset
|
1086 taken to be paragraph breaks. |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1087 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1088 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
|
1089 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
|
1090 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
|
1091 (interactive (list (if mark-active (region-beginning) (point)) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1092 (if mark-active (region-end) (point)) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1093 (let ((s (completing-read |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1094 "Set justification to: " |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1095 '(("left") ("right") ("full") |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1096 ("center") ("none")) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1097 nil t))) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1098 (if (equal s "") (error "")) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1099 (intern s)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1100 t)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1101 (save-excursion |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1102 (save-restriction |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1103 (if whole-par |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1104 (let ((paragraph-start (if use-hard-newlines "." paragraph-start)) |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1105 (paragraph-ignore-fill-prefix (if use-hard-newlines t |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1106 paragraph-ignore-fill-prefix))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1107 (goto-char begin) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1108 (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
|
1109 (backward-paragraph) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1110 (setq begin (point)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1111 (goto-char end) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1112 (skip-chars-backward " \t\n" begin) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1113 (forward-paragraph) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1114 (setq end (point)))) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1115 |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1116 (narrow-to-region (point-min) end) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1117 (unjustify-region begin (point-max)) |
41849
82810216f9a4
(set-justification): Rename arg VALUE to STYLE.
Richard M. Stallman <rms@gnu.org>
parents:
41800
diff
changeset
|
1118 (put-text-property begin (point-max) 'justification style) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1119 (fill-region begin (point-max) nil t)))) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1120 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1121 (defun set-justification-none (b e) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1122 "Disable automatic filling for paragraphs in the region. |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1123 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
|
1124 (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
|
1125 (if mark-active (region-end) (point)))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1126 (set-justification b e 'none t)) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1127 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1128 (defun set-justification-left (b e) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1129 "Make paragraphs in the region left-justified. |
41849
82810216f9a4
(set-justification): Rename arg VALUE to STYLE.
Richard M. Stallman <rms@gnu.org>
parents:
41800
diff
changeset
|
1130 This means they are flush at the left margin and ragged on the right. |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1131 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
|
1132 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
|
1133 (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
|
1134 (if mark-active (region-end) (point)))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1135 (set-justification b e 'left t)) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1136 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1137 (defun set-justification-right (b e) |
41800 | 1138 "Make paragraphs in the region right-justified. |
41849
82810216f9a4
(set-justification): Rename arg VALUE to STYLE.
Richard M. Stallman <rms@gnu.org>
parents:
41800
diff
changeset
|
1139 This means they are flush at the right margin and ragged on the left. |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1140 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
|
1141 (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
|
1142 (if mark-active (region-end) (point)))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1143 (set-justification b e 'right t)) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1144 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1145 (defun set-justification-full (b e) |
41800 | 1146 "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
|
1147 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
|
1148 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
|
1149 (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
|
1150 (if mark-active (region-end) (point)))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1151 (set-justification b e 'full t)) |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1152 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1153 (defun set-justification-center (b e) |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1154 "Make paragraphs in the region centered. |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1155 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
|
1156 (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
|
1157 (if mark-active (region-end) (point)))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1158 (set-justification b e 'center t)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1159 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1160 ;; A line has up to six parts: |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1161 ;; |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1162 ;; >>> hello. |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1163 ;; [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
|
1164 ;; |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1165 ;; "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
|
1166 ;; given by the `current-left-margin' function. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1167 ;; "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
|
1168 ;; "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
|
1169 ;; `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
|
1170 ;; 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
|
1171 ;; 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
|
1172 ;; center- or right-justifying. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1173 ;; |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1174 ;; All parts of the line are optional, although the final newline can |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1175 ;; 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
|
1176 |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1177 (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
|
1178 "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
|
1179 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
|
1180 the column given by `current-fill-column'. |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1181 Optional first argument HOW specifies alternate type of justification: |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1182 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
|
1183 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
|
1184 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
|
1185 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
|
1186 it will not be stretched by full justification. |
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1187 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
|
1188 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
|
1189 (interactive "*") |
13473
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
1190 (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
|
1191 (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
|
1192 (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
|
1193 (setq how 'full)))) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1194 (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
|
1195 (let ((fc (current-fill-column)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1196 (pos (point-marker)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1197 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
|
1198 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
|
1199 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
|
1200 indent ; column of `beg' |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1201 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
|
1202 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
|
1203 (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
|
1204 ; 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
|
1205 (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
|
1206 count) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1207 (end-of-line) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1208 ;; Check if this is the last line of the paragraph. |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1209 (if (and use-hard-newlines (null eop) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1210 (get-text-property (point) 'hard)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1211 (setq eop t)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1212 (skip-chars-backward " \t") |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1213 ;; 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
|
1214 ;; or there is no text. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1215 (if (or (bolp) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1216 (and (memq how '(full right)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1217 (= (current-column) fc))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1218 nil |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1219 (setq end (point)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1220 (beginning-of-line) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1221 (skip-chars-forward " \t") |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1222 ;; Skip over fill-prefix. |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1223 (if (and fill-prefix |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1224 (not (string-equal fill-prefix "")) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1225 (equal fill-prefix |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1226 (buffer-substring |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1227 (point) (min (point-max) (+ (length fill-prefix) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1228 (point)))))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1229 (forward-char (length fill-prefix)) |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1230 (if (and adaptive-fill-mode |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1231 (looking-at adaptive-fill-regexp)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1232 (goto-char (match-end 0)))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1233 (setq fp-end (point)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1234 (skip-chars-forward " \t") |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1235 ;; 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
|
1236 (setq indent (current-column)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1237 (setq beg (point)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1238 (goto-char end) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1239 (setq endcol (current-column)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1240 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1241 ;; HOW can't be null or left--we would have exited already |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1242 (cond ((eq 'right how) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1243 (setq ncols (- fc endcol)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1244 (if (< ncols 0) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1245 ;; Need to remove some indentation |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1246 (delete-region |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1247 (progn (goto-char fp-end) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1248 (if (< (current-column) (+ indent ncols)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1249 (move-to-column (+ indent ncols) t)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1250 (point)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1251 (progn (move-to-column indent) (point))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1252 ;; Need to add some |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1253 (goto-char beg) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1254 (indent-to (+ indent ncols)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1255 ;; If point was at beginning of text, keep it there. |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1256 (if (= beg pos) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1257 (move-marker pos (point))))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1258 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1259 ((eq 'center how) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1260 ;; Figure out how much indentation is needed |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1261 (setq ncols (+ (current-left-margin) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1262 (/ (- fc (current-left-margin) ;avail. space |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1263 (- endcol indent)) ;text width |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1264 2))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1265 (if (< ncols indent) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1266 ;; Have too much indentation - remove some |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1267 (delete-region |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1268 (progn (goto-char fp-end) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1269 (if (< (current-column) ncols) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1270 (move-to-column ncols t)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1271 (point)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1272 (progn (move-to-column indent) (point))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1273 ;; Have too little - add some |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1274 (goto-char beg) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1275 (indent-to ncols) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1276 ;; 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
|
1277 (if (= beg pos) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1278 (move-marker pos (point))))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1279 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1280 ((eq 'full how) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1281 ;; 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
|
1282 (save-restriction |
10543
3b896847b849
(justify-current-line): Avoid error comparing fill-prefix
Richard M. Stallman <rms@gnu.org>
parents:
10497
diff
changeset
|
1283 (narrow-to-region beg end) |
3b896847b849
(justify-current-line): Avoid error comparing fill-prefix
Richard M. Stallman <rms@gnu.org>
parents:
10497
diff
changeset
|
1284 (or nosqueeze |
3b896847b849
(justify-current-line): Avoid error comparing fill-prefix
Richard M. Stallman <rms@gnu.org>
parents:
10497
diff
changeset
|
1285 (canonically-space-region beg end)) |
3b896847b849
(justify-current-line): Avoid error comparing fill-prefix
Richard M. Stallman <rms@gnu.org>
parents:
10497
diff
changeset
|
1286 (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
|
1287 ;; 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
|
1288 (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
|
1289 (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
|
1290 (skip-chars-backward " ")) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1291 (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
|
1292 ;; Ncols is number of additional space chars needed |
109614
e20f769083f9
* lisp/textmodes/fill.el (justify-current-line): Don't add 1 to nspaces
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108765
diff
changeset
|
1293 (when (and (> ncols 0) (> nspaces 0) (not eop)) |
e20f769083f9
* lisp/textmodes/fill.el (justify-current-line): Don't add 1 to nspaces
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108765
diff
changeset
|
1294 (setq curr-fracspace (+ ncols (/ nspaces 2)) |
e20f769083f9
* lisp/textmodes/fill.el (justify-current-line): Don't add 1 to nspaces
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108765
diff
changeset
|
1295 count nspaces) |
e20f769083f9
* lisp/textmodes/fill.el (justify-current-line): Don't add 1 to nspaces
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108765
diff
changeset
|
1296 (while (> count 0) |
e20f769083f9
* lisp/textmodes/fill.el (justify-current-line): Don't add 1 to nspaces
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108765
diff
changeset
|
1297 (skip-chars-forward " ") |
e20f769083f9
* lisp/textmodes/fill.el (justify-current-line): Don't add 1 to nspaces
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108765
diff
changeset
|
1298 (insert-char ?\s (/ curr-fracspace nspaces) t) |
e20f769083f9
* lisp/textmodes/fill.el (justify-current-line): Don't add 1 to nspaces
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108765
diff
changeset
|
1299 (search-forward " " nil t) |
e20f769083f9
* lisp/textmodes/fill.el (justify-current-line): Don't add 1 to nspaces
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108765
diff
changeset
|
1300 (setq count (1- count) |
e20f769083f9
* lisp/textmodes/fill.el (justify-current-line): Don't add 1 to nspaces
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108765
diff
changeset
|
1301 curr-fracspace |
e20f769083f9
* lisp/textmodes/fill.el (justify-current-line): Don't add 1 to nspaces
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108765
diff
changeset
|
1302 (+ (% curr-fracspace nspaces) ncols)))))) |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1303 (t (error "Unknown justification value")))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1304 (goto-char pos) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1305 (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
|
1306 nil) |
9026
74fd93bc3568
(justify-current-line): Inherit props when inserting spaces.
Richard M. Stallman <rms@gnu.org>
parents:
8363
diff
changeset
|
1307 |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1308 (defun unjustify-current-line () |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1309 "Remove justification whitespace from current line. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1310 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
|
1311 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
|
1312 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
|
1313 (let ((justify (current-justification))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1314 (cond ((eq 'left justify) nil) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1315 ((eq nil justify) nil) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1316 ((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
|
1317 (beginning-of-line-text) |
32230 | 1318 (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
|
1319 ((memq justify '(center right)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1320 (save-excursion |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1321 (move-to-left-margin nil t) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1322 ;; Position ourselves after any fill-prefix. |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1323 (if (and fill-prefix |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1324 (not (string-equal fill-prefix "")) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1325 (equal fill-prefix |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1326 (buffer-substring |
10811
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1327 (point) (min (point-max) (+ (length fill-prefix) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1328 (point)))))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1329 (forward-char (length fill-prefix))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1330 (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
|
1331 (point)))))))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1332 |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1333 (defun unjustify-region (&optional begin end) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1334 "Remove justification whitespace from region. |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1335 For centered or right-justified regions, this function removes any indentation |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1336 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
|
1337 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
|
1338 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
|
1339 (save-excursion |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1340 (save-restriction |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1341 (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
|
1342 (goto-char (or begin (point-min))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1343 (while (not (eobp)) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1344 (unjustify-current-line) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1345 (forward-line 1))))) |
7f9e55cdc349
(set-fill-prefix): start from left-margin.
Boris Goldowsky <boris@gnu.org>
parents:
10636
diff
changeset
|
1346 |
75 | 1347 |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1348 (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
|
1349 "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
|
1350 This command divides the region into \"paragraphs\", |
ef643dbb7d40
(fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents:
2412
diff
changeset
|
1351 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
|
1352 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
|
1353 in the paragraph. |
ef643dbb7d40
(fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents:
2412
diff
changeset
|
1354 |
ef643dbb7d40
(fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents:
2412
diff
changeset
|
1355 When calling from a program, pass range to fill as first two arguments. |
638 | 1356 |
64853
a045a3e5b467
(fill-nonuniform-paragraphs): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents:
64751
diff
changeset
|
1357 Optional third and fourth arguments JUSTIFYP and CITATION-REGEXP: |
a045a3e5b467
(fill-nonuniform-paragraphs): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents:
64751
diff
changeset
|
1358 JUSTIFYP to justify paragraphs (prefix arg). |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1359 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
|
1360 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
|
1361 plus whitespace, but no other kind of prefix. |
47269
dd5bcff29f6a
(fill-nonuniform-paragraphs, fill-individual-paragraphs): Fix spacing.
Juanma Barranquero <lekktu@gmail.com>
parents:
44955
diff
changeset
|
1362 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
|
1363 (interactive (progn |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1364 (barf-if-buffer-read-only) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1365 (list (region-beginning) (region-end) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1366 (if current-prefix-arg 'full)))) |
2520
ef643dbb7d40
(fill-nonuniform-paragraphs): New command.
Richard M. Stallman <rms@gnu.org>
parents:
2412
diff
changeset
|
1367 (let ((fill-individual-varying-indent t)) |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1368 (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
|
1369 |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1370 (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
|
1371 "Fill paragraphs of uniform indentation within the region. |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1372 This command divides the region into \"paragraphs\", |
19929
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1373 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
|
1374 then fills each paragraph using its indentation level as the fill prefix. |
638 | 1375 |
19929
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1376 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
|
1377 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
|
1378 |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1379 foo> This line with extra indentation starts |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1380 foo> a paragraph that continues on more lines. |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1381 |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1382 These lines are filled together. |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1383 |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1384 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
|
1385 as the first two arguments. |
638 | 1386 |
79138
d5f52eab5fd5
(fill-individual-paragraphs): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
78225
diff
changeset
|
1387 Optional third and fourth arguments JUSTIFY and CITATION-REGEXP: |
d5f52eab5fd5
(fill-individual-paragraphs): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
78225
diff
changeset
|
1388 JUSTIFY to justify paragraphs (prefix arg). |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1389 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
|
1390 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
|
1391 plus whitespace, but no other kind of prefix. |
47269
dd5bcff29f6a
(fill-nonuniform-paragraphs, fill-individual-paragraphs): Fix spacing.
Juanma Barranquero <lekktu@gmail.com>
parents:
44955
diff
changeset
|
1392 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
|
1393 (interactive (progn |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1394 (barf-if-buffer-read-only) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1395 (list (region-beginning) (region-end) |
ff8ffbbc63e8
(canonically-space-region, justify-current-line): Add * to interactive
Dave Love <fx@gnu.org>
parents:
24473
diff
changeset
|
1396 (if current-prefix-arg 'full)))) |
474 | 1397 (save-restriction |
1398 (save-excursion | |
1399 (goto-char min) | |
1400 (beginning-of-line) | |
9706
f5f7d07eece8
(fill-individual-paragraphs): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents:
9217
diff
changeset
|
1401 (narrow-to-region (point) max) |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1402 (if citation-regexp |
9706
f5f7d07eece8
(fill-individual-paragraphs): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents:
9217
diff
changeset
|
1403 (while (and (not (eobp)) |
13473
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
1404 (or (looking-at "[ \t]*[^ \t\n]+:") |
9706
f5f7d07eece8
(fill-individual-paragraphs): Avoid infinite loop
Richard M. Stallman <rms@gnu.org>
parents:
9217
diff
changeset
|
1405 (looking-at "[ \t]*$"))) |
13473
4492ba9a0757
(fill-region-as-paragraph): Use fill-context-prefix.
Richard M. Stallman <rms@gnu.org>
parents:
13172
diff
changeset
|
1406 (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
|
1407 (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
|
1408 (forward-line 1)))) |
474 | 1409 (narrow-to-region (point) max) |
1410 ;; Loop over paragraphs. | |
63380
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
1411 (while (progn |
19810
495951c8a761
(fill-individual-paragraphs): Don't include
Richard M. Stallman <rms@gnu.org>
parents:
19419
diff
changeset
|
1412 ;; Skip over all paragraph-separating lines |
495951c8a761
(fill-individual-paragraphs): Don't include
Richard M. Stallman <rms@gnu.org>
parents:
19419
diff
changeset
|
1413 ;; 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
|
1414 (while (and (not (eobp)) |
7808c4885103
(fill-individual-paragraphs): Don't get
Karl Heuer <kwzh@gnu.org>
parents:
20234
diff
changeset
|
1415 (progn (move-to-left-margin) |
7808c4885103
(fill-individual-paragraphs): Don't get
Karl Heuer <kwzh@gnu.org>
parents:
20234
diff
changeset
|
1416 (and (not (eobp)) |
7808c4885103
(fill-individual-paragraphs): Don't get
Karl Heuer <kwzh@gnu.org>
parents:
20234
diff
changeset
|
1417 (looking-at paragraph-separate)))) |
19810
495951c8a761
(fill-individual-paragraphs): Don't include
Richard M. Stallman <rms@gnu.org>
parents:
19419
diff
changeset
|
1418 (forward-line 1)) |
495951c8a761
(fill-individual-paragraphs): Don't include
Richard M. Stallman <rms@gnu.org>
parents:
19419
diff
changeset
|
1419 (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
|
1420 (move-to-left-margin) |
474 | 1421 (let ((start (point)) |
1422 fill-prefix fill-prefix-regexp) | |
1423 ;; Find end of paragraph, and compute the smallest fill-prefix | |
1424 ;; that fits all the lines in this paragraph. | |
1425 (while (progn | |
1426 ;; Update the fill-prefix on the first line | |
1427 ;; and whenever the prefix good so far is too long. | |
1428 (if (not (and fill-prefix | |
1429 (looking-at fill-prefix-regexp))) | |
1430 (setq fill-prefix | |
32230 | 1431 (fill-individual-paragraphs-prefix |
1432 citation-regexp) | |
13502
57a0a9e5399e
(fill-region-as-paragraph): Since adaptive-fill-regexp
Richard M. Stallman <rms@gnu.org>
parents:
13473
diff
changeset
|
1433 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
|
1434 (forward-line 1) |
15308
9a31b0d0c38a
(fill-individual-paragraphs): Don't get stuck
Richard M. Stallman <rms@gnu.org>
parents:
14840
diff
changeset
|
1435 (if (bolp) |
9a31b0d0c38a
(fill-individual-paragraphs): Don't get stuck
Richard M. Stallman <rms@gnu.org>
parents:
14840
diff
changeset
|
1436 ;; 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
|
1437 ;; move further to the left margin. |
9a31b0d0c38a
(fill-individual-paragraphs): Don't get stuck
Richard M. Stallman <rms@gnu.org>
parents:
14840
diff
changeset
|
1438 (move-to-left-margin)) |
474 | 1439 ;; Now stop the loop if end of paragraph. |
1440 (and (not (eobp)) | |
638 | 1441 (if fill-individual-varying-indent |
1442 ;; If this line is a separator line, with or | |
1443 ;; without prefix, end the paragraph. | |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1444 (and |
13548
9be6c740e36f
(fill-individual-paragraphs): Advance 1 line in inner loop.
Richard M. Stallman <rms@gnu.org>
parents:
13502
diff
changeset
|
1445 (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
|
1446 (save-excursion |
9be6c740e36f
(fill-individual-paragraphs): Advance 1 line in inner loop.
Richard M. Stallman <rms@gnu.org>
parents:
13502
diff
changeset
|
1447 (not (and (looking-at fill-prefix-regexp) |
32230 | 1448 (progn (forward-char |
1449 (length fill-prefix)) | |
1450 (looking-at | |
1451 paragraph-separate)))))) | |
638 | 1452 ;; If this line has more or less indent |
1453 ;; than the fill prefix wants, end the paragraph. | |
1454 (and (looking-at fill-prefix-regexp) | |
25127
864a4f79195b
(fill-individual-paragraphs): Calculate new
Karl Heuer <kwzh@gnu.org>
parents:
25126
diff
changeset
|
1455 ;; If fill prefix is shorter than a new |
864a4f79195b
(fill-individual-paragraphs): Calculate new
Karl Heuer <kwzh@gnu.org>
parents:
25126
diff
changeset
|
1456 ;; fill prefix computed here, end paragraph. |
864a4f79195b
(fill-individual-paragraphs): Calculate new
Karl Heuer <kwzh@gnu.org>
parents:
25126
diff
changeset
|
1457 (let ((this-line-fill-prefix |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1458 (fill-individual-paragraphs-prefix |
25127
864a4f79195b
(fill-individual-paragraphs): Calculate new
Karl Heuer <kwzh@gnu.org>
parents:
25126
diff
changeset
|
1459 citation-regexp))) |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
49315
diff
changeset
|
1460 (>= (length fill-prefix) |
25127
864a4f79195b
(fill-individual-paragraphs): Calculate new
Karl Heuer <kwzh@gnu.org>
parents:
25126
diff
changeset
|
1461 (length this-line-fill-prefix))) |
638 | 1462 (save-excursion |
32230 | 1463 (not (progn (forward-char |
1464 (length fill-prefix)) | |
19929
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1465 (or (looking-at "[ \t]") |
0ccbd9bdcd8f
(canonically-space-region): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19810
diff
changeset
|
1466 (looking-at paragraph-separate) |
28489
3fe2e55e31da
(fill-individual-paragraphs): If a no-prefix
Gerd Moellmann <gerd@gnu.org>
parents:
27287
diff
changeset
|
1467 (looking-at paragraph-start))))) |
3fe2e55e31da
(fill-individual-paragraphs): If a no-prefix
Gerd Moellmann <gerd@gnu.org>
parents:
27287
diff
changeset
|
1468 (not (and (equal fill-prefix "") |
3fe2e55e31da
(fill-individual-paragraphs): If a no-prefix
Gerd Moellmann <gerd@gnu.org>
parents:
27287
diff
changeset
|
1469 citation-regexp |
3fe2e55e31da
(fill-individual-paragraphs): If a no-prefix
Gerd Moellmann <gerd@gnu.org>
parents:
27287
diff
changeset
|
1470 (looking-at citation-regexp)))))))) |
474 | 1471 ;; Fill this paragraph, but don't add a newline at the end. |
1472 (let ((had-newline (bolp))) | |
10468
d0854b6f3216
(set-justification): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10423
diff
changeset
|
1473 (fill-region-as-paragraph start (point) justify) |
23184
973ac8db2f92
(fill-individual-paragraphs): Before deleting
Karl Heuer <kwzh@gnu.org>
parents:
22748
diff
changeset
|
1474 (if (and (bolp) (not had-newline)) |
973ac8db2f92
(fill-individual-paragraphs): Before deleting
Karl Heuer <kwzh@gnu.org>
parents:
22748
diff
changeset
|
1475 (delete-char -1)))))))) |
85400
62d330e3a0a8
(fill-individual-paragraphs): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
85375
diff
changeset
|
1476 |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1477 (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
|
1478 (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
|
1479 (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
|
1480 ;; 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
|
1481 ;; 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
|
1482 (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
|
1483 (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
|
1484 (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
|
1485 (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
|
1486 (buffer-substring |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1487 (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
|
1488 ;; 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
|
1489 ;; 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
|
1490 ;; 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
|
1491 (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
|
1492 (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
|
1493 (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
|
1494 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
|
1495 (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
|
1496 (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
|
1497 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
|
1498 (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
|
1499 (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
|
1500 (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
|
1501 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
|
1502 (and |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1503 (string-match (concat "\\`" |
32230 | 1504 (regexp-quote |
1505 adjusted-two-lines-citation-part) | |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1506 "[ \t]*\\'") |
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1507 one-line-citation-part) |
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1508 (>= (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
|
1509 (string-width two-lines-citation-part))))) |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1510 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
|
1511 just-one-line-prefix)))) |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1512 |
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1513 (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
|
1514 (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
|
1515 (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
|
1516 (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
|
1517 "") |
b5f06f88b686
(sentence-end-double-space, sentence-end-without-period): Move to paragraphs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38910
diff
changeset
|
1518 string)) |
22748
8d234814a5a6
(fill-individual-paragraphs-prefix): New
Richard M. Stallman <rms@gnu.org>
parents:
22728
diff
changeset
|
1519 |
63380
10ceeb0364c5
(fill-match-adaptive-prefix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63315
diff
changeset
|
1520 ;; arch-tag: 727ad455-1161-4fa9-8df5-0f74b179216d |
732 | 1521 ;;; fill.el ends here |