annotate lisp/textmodes/refill.el @ 33454:782f1528462b

In the entry for config.in from 2000-11-07, change HAVE_MKDIR to HAVE_MKSTEMP.
author Eli Zaretskii <eliz@gnu.org>
date Mon, 13 Nov 2000 16:30:33 +0000
parents 0756037b6de5
children b22657305a2c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32750
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
1 ;;; refill.el --- `auto-fill' by refilling paragraphs on changes
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
2
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 2000 Free Software Foundation, Inc.
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
4
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
5 ;; Author: Dave Love <fx@gnu.org>
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
6 ;; Keywords: wp
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
7
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
8 ;; This program is free software; you can redistribute it and/or modify
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
9 ;; it under the terms of the GNU General Public License as published by
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2 of the License, or
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
11 ;; (at your option) any later version.
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
12 ;;
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
13 ;; This program is distributed in the hope that it will be useful,
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
16 ;; GNU General Public License for more details.
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
17 ;;
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
19 ;; along with this program; if not, write to the
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
20 ;; Free Software Foundation, Inc., 59 Temple Place, Suite 330,
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
21 ;; Boston, MA 02111-1307, USA.
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
22
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
23 ;;; Commentary:
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
24
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
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
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
27 ;; word processor-style filling. We restrict refilling due to
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
28 ;; self-insertion to the characters which trigger auto-fill.
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
29
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
30 ;; It partly satisfies a todo item in enriched.el for some value of
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
31 ;; `without slowing down editing too much'. It doesn't attempt to do
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
32 ;; anything (using `window-size-change-functions'?) about resizing
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
33 ;; windows -- who cares?
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
34
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
35 ;; This implementation is probably fragile and missing some special
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
36 ;; cases -- not extensively tested. Yanking paragraph breaks, for
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
37 ;; instance, won't DTRT by refilling all the relevant paragraphs.
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
38
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
39 ;; You could do it a bit more efficiently (and robustly?) with just an
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
40 ;; auto-fill function, but that doesn't cope with changes other than
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
41 ;; through self-insertion. (Using auto-fill and after-change
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
42 ;; functions together didn't seem winning.) This could probably
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
43 ;; benefit from a less-general and faster `fill-paragraph-function',
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
44 ;; ideally as a primitive.
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
45
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
46 ;; The work is done in a local post-command hook but only if
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
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
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
49 ;; once per command.
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
50
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
51 ;; [Per Abrahamsen's maniac.el does a similar thing, but operates from
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
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
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
54 ;; some Emacs bug at the time. ISTR maniac has problems with
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
55 ;; whitespace at the end of paragraphs.]
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
56
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
57 ;;; Code:
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
58
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
59 (defun refill-fill-paragraph (arg)
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
60 "Like `fill-paragraph' but don't delete whitespace at paragraph end."
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
61 ;; Should probably use a text property indicating previously-filled
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
62 ;; stuff to avoid filling before the point of change.
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
63 (let ((before (point)))
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
64 (save-excursion
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
65 (forward-paragraph)
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
66 (skip-syntax-backward "-")
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
67 (let ((end (point))
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
68 (beg (progn (backward-paragraph) (point))))
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
69 (goto-char before)
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
70 (save-restriction
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
71 (if use-hard-newlines
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
72 (fill-region beg end arg)
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
73 (fill-region-as-paragraph beg end arg)))))))
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
74
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
75 (defvar refill-doit nil
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
76 "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
77 Set by `refill-after-change-function' in `after-change-functions' and
f7e7454c16a0 Fix var names in doc.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32750
diff changeset
78 unset by `refill-post-command-function' in `post-command-hook'. This
32750
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
79 ensures refilling is only done once per command that causes a change,
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
80 regardless of the number of after-change calls from commands doing
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
81 complex processing.")
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
82 (make-variable-buffer-local 'refill-doit)
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
83
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
84 (defun refill-after-change-function (beg end len)
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
85 "Function for `after-change-functions' which just sets `refill-doit'."
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
86 (unless undo-in-progress
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
87 (setq refill-doit t)))
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
88
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
89 (defun refill-post-command-function ()
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
90 "Post-command function to do refilling (conditionally)."
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
91 (when refill-doit ; there was a change
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
92 ;; There's probably scope for more special cases here...
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
93 (cond
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
94 ((eq this-command 'self-insert-command)
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
95 ;; Respond to the same characters as auto-fill (other than
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
96 ;; newline, covered below).
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
97 (if (aref auto-fill-chars (char-before))
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
98 (refill-fill-paragraph nil)))
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
99 ((or (eq this-command 'quoted-insert)
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
100 (eq this-command 'fill-paragraph)
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
101 (eq this-command 'fill-region))
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
102 nil)
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
103 ((or (eq this-command 'newline)
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
104 (eq this-command 'newline-and-indent)
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
105 (eq this-command 'open-line))
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
106 ;; Don't zap what was just inserted.
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
107 (save-excursion
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
108 (beginning-of-line) ; for newline-and-indent
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
109 (skip-chars-backward "\n")
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
110 (save-restriction
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
111 (narrow-to-region (point-min) (point))
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
112 (refill-fill-paragraph nil)))
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
113 (widen)
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
114 (save-excursion
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
115 (skip-chars-forward "\n")
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
116 (save-restriction
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
117 (narrow-to-region (line-beginning-position) (point-max))
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
118 (refill-fill-paragraph nil))))
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
119 (t (refill-fill-paragraph nil)))
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
120 (setq refill-doit nil)))
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
121
32960
0756037b6de5 (refill-late-fill-paragraph-function): New
Dave Love <fx@gnu.org>
parents: 32767
diff changeset
122 (defvar refill-late-fill-paragraph-function nil)
0756037b6de5 (refill-late-fill-paragraph-function): New
Dave Love <fx@gnu.org>
parents: 32767
diff changeset
123
32750
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
124 ;;;###autoload
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
125 (define-minor-mode refill-mode
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
126 "Toggle Refill minor mode.
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
127 With prefix arg, turn Refill mode on iff arg is positive.
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
128
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
129 When Refill mode is on, the current paragraph will be formatted when
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
130 changes are made within it. Self-inserting characters only cause
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
131 refilling if they would cause auto-filling."
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
132 nil " Refill" nil
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
133 ;; This provides the test for recursive paragraph filling.
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
134 (make-local-variable 'fill-paragraph-function)
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
135 (if refill-mode
32761
f7e7454c16a0 Fix var names in doc.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32750
diff changeset
136 (progn
f7e7454c16a0 Fix var names in doc.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32750
diff changeset
137 (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
138 (add-hook 'post-command-hook 'refill-post-command-function nil t)
32960
0756037b6de5 (refill-late-fill-paragraph-function): New
Dave Love <fx@gnu.org>
parents: 32767
diff changeset
139 (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
140 fill-paragraph-function)
32761
f7e7454c16a0 Fix var names in doc.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32750
diff changeset
141 (set (make-local-variable 'fill-paragraph-function)
f7e7454c16a0 Fix var names in doc.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32750
diff changeset
142 'refill-fill-paragraph)
f7e7454c16a0 Fix var names in doc.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32750
diff changeset
143 (auto-fill-mode 0))
32750
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
144 (remove-hook 'after-change-functions 'refill-after-change-function t)
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
145 (remove-hook 'post-command-hook 'refill-post-command-function t)
32960
0756037b6de5 (refill-late-fill-paragraph-function): New
Dave Love <fx@gnu.org>
parents: 32767
diff changeset
146 (setq fill-paragraph-function refill-late-fill-paragraph-function)))
32750
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
147
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
148 (provide 'refill)
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
149
dd36de87245d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
150 ;;; refill.el ends here