*** empty log message ***
[bpt/emacs.git] / lisp / abbrev.el
index 6a17b74..3be0014 100644 (file)
@@ -28,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."
@@ -37,9 +37,9 @@ define global abbrevs instead."
   :group 'convenience)
 
 (defun abbrev-mode (&optional arg)
-  "Toggle abbrev mode.
+  "Toggle Abbrev mode in the current buffer.
 With argument ARG, turn abbrev mode on iff ARG is positive.
-In abbrev mode, inserting an abbreviation causes it to expand
+In Abbrev mode, inserting an abbreviation causes it to expand
 and be replaced by its expansion."
   (interactive "P")
   (setq abbrev-mode
@@ -48,19 +48,19 @@ and be replaced by its expansion."
   (force-mode-line-update))
 
 (defcustom abbrev-mode nil
-  "Toggle abbrev mode.
+  "Enable or disable Abbrev mode.
 Non-nil means automatically expand abbrevs as they are inserted.
 
-This variable automatically becomes buffer-local when set in any fashion.
+Setting this variable with `setq' changes it for the current buffer.
 Changing it with \\[customize] sets the default value.
-Use the command `abbrev-mode' to enable or disable Abbrev mode in the current
-buffer."
+Interactively, use the command `abbrev-mode'
+to enable or disable Abbrev mode in the current buffer."
   :type 'boolean
   :group 'abbrev-mode)
 
 \f
 (defvar edit-abbrevs-map nil
-  "Keymap used in edit-abbrevs.")
+  "Keymap used in `edit-abbrevs'.")
 (if edit-abbrevs-map
     nil
   (setq edit-abbrevs-map (make-sparse-keymap))
@@ -75,6 +75,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."
@@ -104,7 +116,7 @@ Otherwise display all abbrevs."
        (setq found (car tables)))
       (setq tables (cdr tables)))
     found))
-    
+
 (defun prepare-abbrev-list-buffer (&optional local)
   (save-excursion
     (let ((table local-abbrev-table))
@@ -190,10 +202,13 @@ Does not display any message."
   ;(interactive "fRead abbrev file: ")
   (read-abbrev-file file t))
 
-(defun write-abbrev-file (file)
-  "Write all abbrev definitions to a file of Lisp code.
+(defun write-abbrev-file (&optional file)
+  "Write all user-level abbrev definitions to a file of Lisp code.
+This does not include system abbrevs; it includes only the abbrev tables
+listed in listed in `abbrev-table-name-list'.
 The file written can be loaded in another session to define the same abbrevs.
-The argument FILE is the file name to write."
+The argument FILE is the file name to write.  If omitted or nil, the file
+specified in `abbrev-file-name' is used."
   (interactive
    (list
     (read-file-name "Write abbrev file: "
@@ -201,15 +216,11 @@ The argument FILE is the file name to write."
                    abbrev-file-name)))
   (or (and file (> (length file) 0))
       (setq file abbrev-file-name))
-  (save-excursion
-   (set-buffer (get-buffer-create " write-abbrev-file"))
-   (erase-buffer)
-   (let ((tables abbrev-table-name-list))
-     (while tables
-       (insert-abbrev-table-description (car tables) nil)
-       (setq tables (cdr tables))))
-   (write-region 1 (point-max) file)
-   (erase-buffer)))
+  (let ((coding-system-for-write 'emacs-mule))
+    (with-temp-file file
+      (insert ";;-*-coding: emacs-mule;-*-\n")
+      (dolist (table abbrev-table-name-list)
+       (insert-abbrev-table-description table nil)))))
 \f
 (defun add-mode-abbrev (arg)
   "Define mode-specific abbrev for last word(s) before point.
@@ -222,7 +233,7 @@ Don't use this function in a Lisp program; use `define-abbrev' instead."
   (interactive "p")
   (add-abbrev
    (if only-global-abbrevs
-       global-abbrev-table 
+       global-abbrev-table
      (or local-abbrev-table
         (error "No per-mode abbrev table")))
    "Mode" arg))
@@ -255,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.
@@ -264,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))
@@ -300,7 +311,11 @@ Expands the abbreviation after defining it."
   "Mark current point as the beginning of an abbrev.
 Abbrev to be expanded starts here rather than at beginning of word.
 This way, you can expand an abbrev with a prefix: insert the prefix,
-use this command, then insert the abbrev."
+use this command, then insert the abbrev.  This command inserts a
+temporary hyphen after the prefix \(until the intended abbrev
+expansion occurs).
+If the prefix is itself an abbrev, this command expands it, unless
+ARG is non-nil.  Interactively, ARG is the prefix argument."
   (interactive "P")
   (or arg (expand-abbrev))
   (setq abbrev-start-location (point-marker)
@@ -328,4 +343,5 @@ If called from a Lisp program, arguments are START END &optional NOQUERY."
            (if (or noquery (y-or-n-p (format "Expand `%s'? " string)))
                (expand-abbrev)))))))
 
+;;; arch-tag: dbd6f3ae-dfe3-40ba-b00f-f9e3ff960df5
 ;;; abbrev.el ends here