Mercurial > emacs
annotate lisp/textmodes/refill.el @ 34395:2f4a4d355834
(time-stamp-old-format-warn): reorder custom
choices to match documentation string.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Sat, 09 Dec 2000 13:22:51 +0000 |
parents | a65a0f325369 |
children | 64d8d90d180d |
rev | line source |
---|---|
32750 | 1 ;;; refill.el --- `auto-fill' by refilling paragraphs on changes |
2 | |
3 ;; Copyright (C) 2000 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Dave Love <fx@gnu.org> | |
6 ;; Keywords: wp | |
7 | |
8 ;; This program is free software; you can redistribute it and/or modify | |
9 ;; it under the terms of the GNU General Public License as published by | |
10 ;; the Free Software Foundation; either version 2 of the License, or | |
11 ;; (at your option) any later version. | |
12 ;; | |
13 ;; This program is distributed in the hope that it will be useful, | |
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 ;; | |
18 ;; You should have received a copy of the GNU General Public License | |
19 ;; along with this program; if not, write to the | |
20 ;; Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
21 ;; Boston, MA 02111-1307, USA. | |
22 | |
23 ;;; Commentary: | |
24 | |
25 ;; Provides a mode where paragraphs are refilled after changes in them | |
32761
f7e7454c16a0
Fix var names in doc.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32750
diff
changeset
|
26 ;; (using `after-change-functions'). This gives something akin to typical |
32750 | 27 ;; word processor-style filling. We restrict refilling due to |
28 ;; self-insertion to the characters which trigger auto-fill. | |
29 | |
30 ;; It partly satisfies a todo item in enriched.el for some value of | |
31 ;; `without slowing down editing too much'. It doesn't attempt to do | |
32 ;; anything (using `window-size-change-functions'?) about resizing | |
33 ;; windows -- who cares? | |
34 | |
35 ;; This implementation is probably fragile and missing some special | |
36 ;; cases -- not extensively tested. Yanking paragraph breaks, for | |
37 ;; instance, won't DTRT by refilling all the relevant paragraphs. | |
38 | |
39 ;; You could do it a bit more efficiently (and robustly?) with just an | |
40 ;; auto-fill function, but that doesn't cope with changes other than | |
41 ;; through self-insertion. (Using auto-fill and after-change | |
42 ;; functions together didn't seem winning.) This could probably | |
43 ;; benefit from a less-general and faster `fill-paragraph-function', | |
44 ;; ideally as a primitive. | |
45 | |
46 ;; The work is done in a local post-command hook but only if | |
47 ;; `refill-doit' has been set by the after-change function. Using | |
32761
f7e7454c16a0
Fix var names in doc.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32750
diff
changeset
|
48 ;; `post-command-hook' ensures simply that refilling only happens |
32750 | 49 ;; once per command. |
50 | |
51 ;; [Per Abrahamsen's maniac.el does a similar thing, but operates from | |
52 ;; post-command-hook. I don't understand the statement in it that | |
32761
f7e7454c16a0
Fix var names in doc.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32750
diff
changeset
|
53 ;; after-change-functions don't work for this purpose; perhaps there was |
32750 | 54 ;; some Emacs bug at the time. ISTR maniac has problems with |
55 ;; whitespace at the end of paragraphs.] | |
56 | |
57 ;;; Code: | |
58 | |
33660
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
59 (defvar refill-ignorable-overlay nil |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
60 "Portion of the most recently filled paragraph not needing filling. |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
61 This is used to optimize refilling.") |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
62 (make-variable-buffer-local 'refill-ignorable-overlay) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
63 |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
64 (defun refill-adjust-ignorable-overlay (overlay afterp beg end &optional len) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
65 "Adjust OVERLAY to not include the about-to-be-modified region." |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
66 (when (not afterp) |
32750 | 67 (save-excursion |
33660
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
68 (goto-char beg) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
69 (forward-line -1) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
70 (if (<= (point) (overlay-start overlay)) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
71 ;; Just get OVERLAY out of the way |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
72 (move-overlay overlay 1 1) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
73 ;; Make overlay contain only the region |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
74 (move-overlay overlay (overlay-start overlay) (point)))))) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
75 |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
76 (defun refill-fill-paragraph-at (pos &optional arg) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
77 "Like `fill-paragraph' at POS, but don't delete whitespace at paragraph end." |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
78 (let (fill-pfx) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
79 (save-excursion |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
80 (goto-char pos) |
32750 | 81 (forward-paragraph) |
82 (skip-syntax-backward "-") | |
83 (let ((end (point)) | |
33660
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
84 (beg (progn (backward-paragraph) (point))) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
85 (obeg (overlay-start refill-ignorable-overlay)) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
86 (oend (overlay-end refill-ignorable-overlay))) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
87 (goto-char pos) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
88 (if (and (>= beg obeg) (< beg oend)) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
89 ;; Limit filling to the modified tail of the paragraph. |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
90 (let (;; When adaptive-fill-mode is enabled, the filling |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
91 ;; functions will attempt to set the fill prefix from |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
92 ;; the fake paragraph bounds we pass in, so set it |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
93 ;; ourselves first, using the real paragraph bounds. |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
94 (fill-prefix |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
95 (if (and adaptive-fill-mode |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
96 (or (null fill-prefix) (string= fill-prefix ""))) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
97 (fill-context-prefix beg end) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
98 fill-prefix)) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
99 ;; Turn off adaptive-fill-mode temporarily |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
100 (adaptive-fill-mode nil)) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
101 (save-restriction |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
102 (if use-hard-newlines |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
103 (fill-region oend end arg) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
104 (fill-region-as-paragraph oend end arg))) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
105 (setq fill-pfx fill-prefix) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
106 (move-overlay refill-ignorable-overlay obeg (point))) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
107 ;; Fill the whole paragraph |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
108 (setq fill-pfx |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
109 (save-restriction |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
110 (if use-hard-newlines |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
111 (fill-region beg end arg) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
112 (fill-region-as-paragraph beg end arg)))) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
113 (move-overlay refill-ignorable-overlay beg (point))))) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
114 (skip-line-prefix fill-pfx))) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
115 |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
116 (defun refill-fill-paragraph (arg) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
117 "Like `fill-paragraph' but don't delete whitespace at paragraph end." |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
118 (refill-fill-paragraph-at (point) arg)) |
32750 | 119 |
120 (defvar refill-doit nil | |
121 "Non-nil means that `refill-post-command-function' does its processing. | |
32761
f7e7454c16a0
Fix var names in doc.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32750
diff
changeset
|
122 Set by `refill-after-change-function' in `after-change-functions' and |
33660
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
123 unset by `refill-post-command-function' in `post-command-hook', and |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
124 sometimes `refill-pre-command-function' in `pre-command-hook'. This |
32750 | 125 ensures refilling is only done once per command that causes a change, |
126 regardless of the number of after-change calls from commands doing | |
127 complex processing.") | |
128 (make-variable-buffer-local 'refill-doit) | |
129 | |
130 (defun refill-after-change-function (beg end len) | |
131 "Function for `after-change-functions' which just sets `refill-doit'." | |
132 (unless undo-in-progress | |
33660
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
133 (setq refill-doit end))) |
32750 | 134 |
135 (defun refill-post-command-function () | |
136 "Post-command function to do refilling (conditionally)." | |
33660
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
137 (when refill-doit ; there was a change |
32750 | 138 ;; There's probably scope for more special cases here... |
33660
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
139 (if (eq this-command 'self-insert-command) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
140 ;; Treat self-insertion commands specially, since they don't |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
141 ;; always reset `refill-doit' -- for self-insertion commands that |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
142 ;; *don't* cause a refill, we want to leave it turned on so that |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
143 ;; any subsequent non-modification command will cause a refill. |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
144 (when (aref auto-fill-chars (char-before)) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
145 ;; Respond to the same characters as auto-fill (other than |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
146 ;; newline, covered below). |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
147 (refill-fill-paragraph-at refill-doit) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
148 (setq refill-doit nil)) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
149 (cond |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
150 ((or (eq this-command 'quoted-insert) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
151 (eq this-command 'fill-paragraph) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
152 (eq this-command 'fill-region)) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
153 nil) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
154 ((or (eq this-command 'newline) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
155 (eq this-command 'newline-and-indent) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
156 (eq this-command 'open-line)) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
157 ;; Don't zap what was just inserted. |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
158 (save-excursion |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
159 (beginning-of-line) ; for newline-and-indent |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
160 (skip-chars-backward "\n") |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
161 (save-restriction |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
162 (narrow-to-region (point-min) (point)) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
163 (refill-fill-paragraph-at refill-doit))) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
164 (widen) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
165 (save-excursion |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
166 (skip-chars-forward "\n") |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
167 (save-restriction |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
168 (narrow-to-region (line-beginning-position) (point-max)) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
169 (refill-fill-paragraph-at refill-doit)))) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
170 (t |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
171 (refill-fill-paragraph-at refill-doit))) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
172 (setq refill-doit nil)))) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
173 |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
174 (defun refill-pre-command-function () |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
175 "Pre-command function to do refilling (conditionally)." |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
176 (when (and refill-doit (not (eq this-command 'self-insert-command))) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
177 ;; A previous setting of `refill-doit' didn't result in a refill, |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
178 ;; because it was a self-insert-command. Since the next command is |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
179 ;; something else, do the refill now. |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
180 (refill-fill-paragraph-at refill-doit) |
32750 | 181 (setq refill-doit nil))) |
182 | |
32960
0756037b6de5
(refill-late-fill-paragraph-function): New
Dave Love <fx@gnu.org>
parents:
32767
diff
changeset
|
183 (defvar refill-late-fill-paragraph-function nil) |
0756037b6de5
(refill-late-fill-paragraph-function): New
Dave Love <fx@gnu.org>
parents:
32767
diff
changeset
|
184 |
32750 | 185 ;;;###autoload |
186 (define-minor-mode refill-mode | |
187 "Toggle Refill minor mode. | |
188 With prefix arg, turn Refill mode on iff arg is positive. | |
189 | |
190 When Refill mode is on, the current paragraph will be formatted when | |
191 changes are made within it. Self-inserting characters only cause | |
192 refilling if they would cause auto-filling." | |
193 nil " Refill" nil | |
194 ;; This provides the test for recursive paragraph filling. | |
195 (make-local-variable 'fill-paragraph-function) | |
196 (if refill-mode | |
32761
f7e7454c16a0
Fix var names in doc.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32750
diff
changeset
|
197 (progn |
f7e7454c16a0
Fix var names in doc.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32750
diff
changeset
|
198 (add-hook 'after-change-functions 'refill-after-change-function nil t) |
f7e7454c16a0
Fix var names in doc.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32750
diff
changeset
|
199 (add-hook 'post-command-hook 'refill-post-command-function nil t) |
33660
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
200 (add-hook 'pre-command-hook 'refill-pre-command-function nil t) |
32960
0756037b6de5
(refill-late-fill-paragraph-function): New
Dave Love <fx@gnu.org>
parents:
32767
diff
changeset
|
201 (set (make-local-variable 'refill-late-fill-paragraph-function) |
0756037b6de5
(refill-late-fill-paragraph-function): New
Dave Love <fx@gnu.org>
parents:
32767
diff
changeset
|
202 fill-paragraph-function) |
32761
f7e7454c16a0
Fix var names in doc.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32750
diff
changeset
|
203 (set (make-local-variable 'fill-paragraph-function) |
f7e7454c16a0
Fix var names in doc.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32750
diff
changeset
|
204 'refill-fill-paragraph) |
33660
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
205 (setq refill-ignorable-overlay (make-overlay 1 1 nil nil t)) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
206 (overlay-put refill-ignorable-overlay 'modification-hooks |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
207 '(refill-adjust-ignorable-overlay)) |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
208 (overlay-put refill-ignorable-overlay 'insert-behind-hooks |
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
209 '(refill-adjust-ignorable-overlay)) |
32761
f7e7454c16a0
Fix var names in doc.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32750
diff
changeset
|
210 (auto-fill-mode 0)) |
32750 | 211 (remove-hook 'after-change-functions 'refill-after-change-function t) |
212 (remove-hook 'post-command-hook 'refill-post-command-function t) | |
33660
b22657305a2c
(refill-ignorable-overlay): New variable.
Miles Bader <miles@gnu.org>
parents:
32960
diff
changeset
|
213 (delete-overlay refill-ignorable-overlay) |
32960
0756037b6de5
(refill-late-fill-paragraph-function): New
Dave Love <fx@gnu.org>
parents:
32767
diff
changeset
|
214 (setq fill-paragraph-function refill-late-fill-paragraph-function))) |
32750 | 215 |
216 (provide 'refill) | |
217 | |
218 ;;; refill.el ends here |