]> code.delx.au - gnu-emacs/blobdiff - lisp/abbrev.el
(write-abbrev-file): Don't hardcode point-min == 1.
[gnu-emacs] / lisp / abbrev.el
index 7e60541aaf0ddf08282571a58fee193cd810982f..a73c8e0fe8d9aeb7edba1bca50ff944b8eb6eef4 100644 (file)
@@ -2,6 +2,7 @@
 
 ;; Copyright (C) 1985, 1986, 1987, 1992 Free Software Foundation, Inc.
 
+;; Maintainer: FSF
 ;; Keywords: abbrev convenience
 
 ;; This file is part of GNU Emacs.
@@ -27,7 +28,7 @@
 
 ;;; Code:
 
-(defcustom only-global-abbrevs nil 
+(defcustom only-global-abbrevs nil
   "*t means user plans to use global abbrevs only.
 This makes the commands that normally define mode-specific abbrevs
 define global abbrevs instead."
@@ -50,7 +51,6 @@ and be replaced by its expansion."
   "Toggle abbrev mode.
 Non-nil means automatically expand abbrevs as they are inserted.
 
-This variable automatically becomes buffer-local when set in any fashion.
 Changing it with \\[customize] sets the default value.
 Use the command `abbrev-mode' to enable or disable Abbrev mode in the current
 buffer."
@@ -74,6 +74,18 @@ buffer."
       (clear-abbrev-table (symbol-value (car tables)))
       (setq tables (cdr tables)))))
 
+(defun copy-abbrev-table (table)
+  "Make a new abbrev-table with the same abbrevs as TABLE."
+  (let ((new-table (make-abbrev-table)))
+    (mapatoms
+     (lambda (symbol)
+       (define-abbrev new-table
+        (symbol-name symbol)
+        (symbol-value symbol)
+        (symbol-function symbol)))
+     table)
+    new-table))
+
 (defun insert-abbrevs ()
   "Insert after point a description of all defined abbrevs.
 Mark is set after the inserted text."
@@ -86,23 +98,37 @@ Mark is set after the inserted text."
        (setq tables (cdr tables))))
     (point))))
 
-(defun list-abbrevs ()
-  "Display a list of all defined abbrevs."
-  (interactive)
-  (display-buffer (prepare-abbrev-list-buffer)))
-
-(defun prepare-abbrev-list-buffer ()
+(defun list-abbrevs (&optional local)
+  "Display a list of defined abbrevs.
+If LOCAL is non-nil, interactively when invoked with a
+prefix arg, display only local, i.e. mode-specific, abbrevs.
+Otherwise display all abbrevs."
+  (interactive "P")
+  (display-buffer (prepare-abbrev-list-buffer local)))
+
+(defun abbrev-table-name (table)
+  "Value is the name of abbrev table TABLE."
+  (let ((tables abbrev-table-name-list)
+       found)
+    (while (and (not found) tables)
+      (when (eq (symbol-value (car tables)) table)
+       (setq found (car tables)))
+      (setq tables (cdr tables)))
+    found))
+
+(defun prepare-abbrev-list-buffer (&optional local)
   (save-excursion
-    (set-buffer (get-buffer-create "*Abbrevs*"))
-    (erase-buffer)
-    (let ((tables abbrev-table-name-list))
-      (while tables
-       (insert-abbrev-table-description (car tables) t)
-       (setq tables (cdr tables))))
-    (goto-char (point-min))
-    (set-buffer-modified-p nil)
-    (edit-abbrevs-mode))
-  (get-buffer-create "*Abbrevs*"))
+    (let ((table local-abbrev-table))
+      (set-buffer (get-buffer-create "*Abbrevs*"))
+      (erase-buffer)
+      (if local
+         (insert-abbrev-table-description (abbrev-table-name table) t)
+       (dolist (table abbrev-table-name-list)
+         (insert-abbrev-table-description table t)))
+      (goto-char (point-min))
+      (set-buffer-modified-p nil)
+      (edit-abbrevs-mode)
+      (current-buffer))))
 
 (defun edit-abbrevs-mode ()
   "Major mode for editing the list of abbrev definitions.
@@ -161,17 +187,17 @@ the ones defined from the buffer now."
   "Read abbrev definitions from file written with `write-abbrev-file'.
 Optional argument FILE is the name of the file to read;
 it defaults to the value of `abbrev-file-name'.
-Optional second argument QUIETLY non-nil means don't print anything."
+Optional second argument QUIETLY non-nil means don't display a message."
   (interactive "fRead abbrev file: ")
   (load (if (and file (> (length file) 0)) file abbrev-file-name)
        nil quietly)
-  (setq save-abbrevs t abbrevs-changed nil))
+  (setq abbrevs-changed nil))
 
 (defun quietly-read-abbrev-file (&optional file)
   "Read abbrev definitions from file written with write-abbrev-file.
 Optional argument FILE is the name of the file to read;
 it defaults to the value of `abbrev-file-name'.
-Does not print anything."
+Does not display any message."
   ;(interactive "fRead abbrev file: ")
   (read-abbrev-file file t))
 
@@ -193,7 +219,7 @@ The argument FILE is the file name to write."
      (while tables
        (insert-abbrev-table-description (car tables) nil)
        (setq tables (cdr tables))))
-   (write-region 1 (point-max) file)
+   (write-region (point-min) (point-max) file)
    (erase-buffer)))
 \f
 (defun add-mode-abbrev (arg)
@@ -240,7 +266,7 @@ Don't use this function in a Lisp program; use `define-abbrev' instead."
            (y-or-n-p (format "%s expands to \"%s\"; redefine? "
                              name (abbrev-expansion name table))))
        (define-abbrev table (downcase name) exp))))
-       
+
 (defun inverse-add-mode-abbrev (arg)
   "Define last word before point as a mode-specific abbrev.
 With prefix argument N, defines the Nth word before point.
@@ -249,7 +275,7 @@ Expands the abbreviation after defining it."
   (interactive "p")
   (inverse-add-abbrev
    (if only-global-abbrevs
-       global-abbrev-table 
+       global-abbrev-table
      (or local-abbrev-table
         (error "No per-mode abbrev table")))
    "Mode" arg))