comparison lisp/textmodes/refill.el @ 90084:befae6bafecb

Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-6 Merge from emacs--cvs-trunk--0 Patches applied: * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-48 - miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-51 Update from CVS
author Miles Bader <miles@gnu.org>
date Mon, 24 Jan 2005 22:34:31 +0000
parents 68c22ea6027c 73def390d890
children 02f1dbc4a199
comparison
equal deleted inserted replaced
90083:2b2f720892ae 90084:befae6bafecb
1 ;;; refill.el --- `auto-fill' by refilling paragraphs on changes 1 ;;; refill.el --- `auto-fill' by refilling paragraphs on changes
2 2
3 ;; Copyright (C) 2000, 2003 Free Software Foundation, Inc. 3 ;; Copyright (C) 2000, 2003, 2005 Free Software Foundation, Inc.
4 4
5 ;; Author: Dave Love <fx@gnu.org> 5 ;; Author: Dave Love <fx@gnu.org>
6 ;; Maintainer: Miles Bader <miles@gnu.org> 6 ;; Maintainer: Miles Bader <miles@gnu.org>
7 ;; Keywords: wp 7 ;; Keywords: wp
8 8
82 ;; Foo bar blablabla asdgf 82 ;; Foo bar blablabla asdgf
83 ;; ><asdfas dfasdfasd asd 83 ;; ><asdfas dfasdfasd asd
84 ;; asdfa sdfasd sdf 84 ;; asdfa sdfasd sdf
85 85
86 ;;; Code: 86 ;;; Code:
87
88 (eval-when-compile (require 'cl))
87 89
88 (defgroup refill nil 90 (defgroup refill nil
89 "Refilling paragraphs on changes." 91 "Refilling paragraphs on changes."
90 :group 'fill) 92 :group 'fill)
91 93
167 169
168 (defun refill-post-command-function () 170 (defun refill-post-command-function ()
169 "Post-command function to do refilling (conditionally)." 171 "Post-command function to do refilling (conditionally)."
170 (when refill-doit ; there was a change 172 (when refill-doit ; there was a change
171 ;; There's probably scope for more special cases here... 173 ;; There's probably scope for more special cases here...
172 (if (eq this-command 'self-insert-command) 174 (case this-command
173 ;; Treat self-insertion commands specially, since they don't 175 (self-insert-command
174 ;; always reset `refill-doit' -- for self-insertion commands that 176 ;; Treat self-insertion commands specially, since they don't
175 ;; *don't* cause a refill, we want to leave it turned on so that 177 ;; always reset `refill-doit' -- for self-insertion commands that
176 ;; any subsequent non-modification command will cause a refill. 178 ;; *don't* cause a refill, we want to leave it turned on so that
177 (when (aref auto-fill-chars (char-before)) 179 ;; any subsequent non-modification command will cause a refill.
178 ;; Respond to the same characters as auto-fill (other than 180 (when (aref auto-fill-chars (char-before))
179 ;; newline, covered below). 181 ;; Respond to the same characters as auto-fill (other than
180 (refill-fill-paragraph-at refill-doit) 182 ;; newline, covered below).
181 (setq refill-doit nil)) 183 (refill-fill-paragraph-at refill-doit)
182 (cond 184 (setq refill-doit nil)))
183 ((or (eq this-command 'quoted-insert) 185 ((quoted-insert fill-paragraph fill-region) nil)
184 (eq this-command 'fill-paragraph) 186 ((newline newline-and-indent open-line indent-new-comment-line
185 (eq this-command 'fill-region)) 187 reindent-then-newline-and-indent)
186 nil) 188 ;; Don't zap what was just inserted.
187 ((or (eq this-command 'newline) 189 (save-excursion
188 (eq this-command 'newline-and-indent) 190 (beginning-of-line) ; for newline-and-indent
189 (eq this-command 'open-line)) 191 (skip-chars-backward "\n")
190 ;; Don't zap what was just inserted. 192 (save-restriction
191 (save-excursion 193 (narrow-to-region (point-min) (point))
192 (beginning-of-line) ; for newline-and-indent 194 (refill-fill-paragraph-at refill-doit)))
193 (skip-chars-backward "\n") 195 (widen)
194 (save-restriction 196 (save-excursion
195 (narrow-to-region (point-min) (point)) 197 (skip-chars-forward "\n")
196 (refill-fill-paragraph-at refill-doit))) 198 (save-restriction
197 (widen) 199 (narrow-to-region (line-beginning-position) (point-max))
198 (save-excursion 200 (refill-fill-paragraph-at refill-doit))))
199 (skip-chars-forward "\n") 201 (t
200 (save-restriction 202 (refill-fill-paragraph-at refill-doit)))
201 (narrow-to-region (line-beginning-position) (point-max)) 203 (setq refill-doit nil)))
202 (refill-fill-paragraph-at refill-doit))))
203 (t
204 (refill-fill-paragraph-at refill-doit)))
205 (setq refill-doit nil))))
206 204
207 (defun refill-pre-command-function () 205 (defun refill-pre-command-function ()
208 "Pre-command function to do refilling (conditionally)." 206 "Pre-command function to do refilling (conditionally)."
209 (when (and refill-doit (not (eq this-command 'self-insert-command))) 207 (when (and refill-doit (not (eq this-command 'self-insert-command)))
210 ;; A previous setting of `refill-doit' didn't result in a refill, 208 ;; A previous setting of `refill-doit' didn't result in a refill,
211 ;; because it was a self-insert-command. Since the next command is 209 ;; because it was a self-insert-command. Since the next command is
212 ;; something else, do the refill now. 210 ;; something else, do the refill now.
213 (refill-fill-paragraph-at refill-doit) 211 (refill-fill-paragraph-at refill-doit)
214 (setq refill-doit nil))) 212 (setq refill-doit nil)))
215 213
216 (defvar refill-late-fill-paragraph-function nil) 214 (defvar refill-saved-state nil)
217 215
218 ;;;###autoload 216 ;;;###autoload
219 (define-minor-mode refill-mode 217 (define-minor-mode refill-mode
220 "Toggle Refill minor mode. 218 "Toggle Refill minor mode.
221 With prefix arg, turn Refill mode on iff arg is positive. 219 With prefix arg, turn Refill mode on iff arg is positive.
226 nil " Refill" '(("\177" . backward-delete-char-untabify)) 224 nil " Refill" '(("\177" . backward-delete-char-untabify))
227 ;; Remove old state if necessary 225 ;; Remove old state if necessary
228 (when refill-ignorable-overlay 226 (when refill-ignorable-overlay
229 (delete-overlay refill-ignorable-overlay) 227 (delete-overlay refill-ignorable-overlay)
230 (kill-local-variable 'refill-ignorable-overlay)) 228 (kill-local-variable 'refill-ignorable-overlay))
231 (when (local-variable-p 'refill-late-fill-paragraph-function) 229 (when (local-variable-p 'refill-saved-state)
232 (setq fill-paragraph-function refill-late-fill-paragraph-function) 230 (dolist (x refill-saved-state)
233 (kill-local-variable 'refill-late-fill-paragraph-function)) 231 (set (make-local-variable (car x)) (cdr x)))
232 (kill-local-variable 'refill-saved-state))
234 (if refill-mode 233 (if refill-mode
235 (progn 234 (progn
236 (add-hook 'after-change-functions 'refill-after-change-function nil t) 235 (add-hook 'after-change-functions 'refill-after-change-function nil t)
237 (add-hook 'post-command-hook 'refill-post-command-function nil t) 236 (add-hook 'post-command-hook 'refill-post-command-function nil t)
238 (add-hook 'pre-command-hook 'refill-pre-command-function nil t) 237 (add-hook 'pre-command-hook 'refill-pre-command-function nil t)
239 (set (make-local-variable 'refill-late-fill-paragraph-function) 238 (set (make-local-variable 'refill-saved-state)
240 fill-paragraph-function) 239 (mapcar (lambda (s) (cons s (symbol-value s)))
240 '(fill-paragraph-function auto-fill-function)))
241 ;; This provides the test for recursive paragraph filling. 241 ;; This provides the test for recursive paragraph filling.
242 (set (make-local-variable 'fill-paragraph-function) 242 (set (make-local-variable 'fill-paragraph-function)
243 'refill-fill-paragraph) 243 'refill-fill-paragraph)
244 ;; When using justification, doing DEL on 2 spaces should remove 244 ;; When using justification, doing DEL on 2 spaces should remove
245 ;; both, otherwise, the subsequent refill will undo the DEL. 245 ;; both, otherwise, the subsequent refill will undo the DEL.
255 (remove-hook 'post-command-hook 'refill-post-command-function t) 255 (remove-hook 'post-command-hook 'refill-post-command-function t)
256 (kill-local-variable 'backward-delete-char-untabify-method))) 256 (kill-local-variable 'backward-delete-char-untabify-method)))
257 257
258 (provide 'refill) 258 (provide 'refill)
259 259
260 ;;; arch-tag: 2c4ce9e8-1daa-4a3b-b6f8-fd6ac5bf6138 260 ;; arch-tag: 2c4ce9e8-1daa-4a3b-b6f8-fd6ac5bf6138
261 ;;; refill.el ends here 261 ;;; refill.el ends here