]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/refill.el
texinfo.el addition for bug#2783.
[gnu-emacs] / lisp / textmodes / refill.el
index b5dd64a891a4bcf736dda4c581bec24266421436..474872955b4faafcfc71c9dc6ef5a20be1e5ee33 100644 (file)
@@ -1,16 +1,17 @@
 ;;; refill.el --- `auto-fill' by refilling paragraphs on changes
 
-;; Copyright (C) 2000, 2003  Free Software Foundation, Inc.
+;; Copyright (C) 2000-2011 Free Software Foundation, Inc.
 
 ;; Author: Dave Love <fx@gnu.org>
+;; Maintainer: Miles Bader <miles@gnu.org>
 ;; Keywords: wp
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,9 +19,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -84,6 +83,8 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl))
+
 (defgroup refill nil
   "Refilling paragraphs on changes."
   :group 'fill)
@@ -168,40 +169,36 @@ complex processing.")
   "Post-command function to do refilling (conditionally)."
   (when refill-doit ; there was a change
     ;; There's probably scope for more special cases here...
-    (if (eq this-command 'self-insert-command)
-       ;; Treat self-insertion commands specially, since they don't
-       ;; always reset `refill-doit' -- for self-insertion commands that
-       ;; *don't* cause a refill, we want to leave it turned on so that
-       ;; any subsequent non-modification command will cause a refill.
-       (when (aref auto-fill-chars (char-before))
-         ;; Respond to the same characters as auto-fill (other than
-         ;; newline, covered below).
-         (refill-fill-paragraph-at refill-doit)
-         (setq refill-doit nil))
-      (cond
-       ((or (eq this-command 'quoted-insert)
-           (eq this-command 'fill-paragraph)
-           (eq this-command 'fill-region))
-       nil)
-       ((or (eq this-command 'newline)
-           (eq this-command 'newline-and-indent)
-           (eq this-command 'open-line))
-       ;; Don't zap what was just inserted.
-       (save-excursion
-         (beginning-of-line)           ; for newline-and-indent
-         (skip-chars-backward "\n")
-         (save-restriction
-           (narrow-to-region (point-min) (point))
-           (refill-fill-paragraph-at refill-doit)))
-       (widen)
-       (save-excursion
-         (skip-chars-forward "\n")
-         (save-restriction
-           (narrow-to-region (line-beginning-position) (point-max))
-           (refill-fill-paragraph-at refill-doit))))
-       (t
-       (refill-fill-paragraph-at refill-doit)))
-      (setq refill-doit nil))))
+    (case this-command
+      (self-insert-command
+       ;; Treat self-insertion commands specially, since they don't
+       ;; always reset `refill-doit' -- for self-insertion commands that
+       ;; *don't* cause a refill, we want to leave it turned on so that
+       ;; any subsequent non-modification command will cause a refill.
+       (when (aref auto-fill-chars (char-before))
+        ;; Respond to the same characters as auto-fill (other than
+        ;; newline, covered below).
+        (refill-fill-paragraph-at refill-doit)
+        (setq refill-doit nil)))
+      ((quoted-insert fill-paragraph fill-region) nil)
+      ((newline newline-and-indent open-line indent-new-comment-line
+       reindent-then-newline-and-indent)
+       ;; Don't zap what was just inserted.
+       (save-excursion
+        (beginning-of-line)            ; for newline-and-indent
+        (skip-chars-backward "\n")
+        (save-restriction
+          (narrow-to-region (point-min) (point))
+          (refill-fill-paragraph-at refill-doit)))
+       (widen)
+       (save-excursion
+        (skip-chars-forward "\n")
+        (save-restriction
+          (narrow-to-region (line-beginning-position) (point-max))
+          (refill-fill-paragraph-at refill-doit))))
+      (t
+       (refill-fill-paragraph-at refill-doit)))
+    (setq refill-doit nil)))
 
 (defun refill-pre-command-function ()
   "Pre-command function to do refilling (conditionally)."
@@ -212,31 +209,35 @@ complex processing.")
     (refill-fill-paragraph-at refill-doit)
     (setq refill-doit nil)))
 
-(defvar refill-late-fill-paragraph-function nil)
+(defvar refill-saved-state nil)
 
 ;;;###autoload
 (define-minor-mode refill-mode
   "Toggle Refill minor mode.
-With prefix arg, turn Refill mode on iff arg is positive.
+With prefix arg, turn Refill mode on if arg is positive, otherwise turn it off.
 
 When Refill mode is on, the current paragraph will be formatted when
 changes are made within it.  Self-inserting characters only cause
 refilling if they would cause auto-filling."
-  nil " Refill" '(("\177" . backward-delete-char-untabify))
+  :group 'refill
+  :lighter " Refill"
+  :keymap '(("\177" . backward-delete-char-untabify))
   ;; Remove old state if necessary
   (when refill-ignorable-overlay
     (delete-overlay refill-ignorable-overlay)
     (kill-local-variable 'refill-ignorable-overlay))
-  (when (local-variable-p 'refill-late-fill-paragraph-function)
-    (setq fill-paragraph-function refill-late-fill-paragraph-function)
-    (kill-local-variable 'refill-late-fill-paragraph-function))
+  (when (local-variable-p 'refill-saved-state)
+    (dolist (x refill-saved-state)
+      (set (make-local-variable (car x)) (cdr x)))
+    (kill-local-variable 'refill-saved-state))
   (if refill-mode
       (progn
        (add-hook 'after-change-functions 'refill-after-change-function nil t)
        (add-hook 'post-command-hook 'refill-post-command-function nil t)
        (add-hook 'pre-command-hook 'refill-pre-command-function nil t)
-       (set (make-local-variable 'refill-late-fill-paragraph-function)
-            fill-paragraph-function)
+       (set (make-local-variable 'refill-saved-state)
+            (mapcar (lambda (s) (cons s (symbol-value s)))
+                    '(fill-paragraph-function auto-fill-function)))
        ;; This provides the test for recursive paragraph filling.
        (set (make-local-variable 'fill-paragraph-function)
             'refill-fill-paragraph)