annotate lisp/textmodes/fill.el @ 48286:a820dd4741e1

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