]> code.delx.au - gnu-emacs/blobdiff - lisp/abbrev.el
Merged in changes from CVS trunk.
[gnu-emacs] / lisp / abbrev.el
index 6a17b747a73005f369b968cc2e211ceed28fc9de..1e3eea0e3590d6735a7219c0d766671ad473265b 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."
@@ -51,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."
@@ -75,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."
@@ -104,7 +115,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 +201,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 +215,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 +232,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 +265,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 +274,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 +310,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 +342,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