diff options
Diffstat (limited to 'lisp/abbrev.el')
-rw-r--r-- | lisp/abbrev.el | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/lisp/abbrev.el b/lisp/abbrev.el index b7216f5d633..e875d77faae 100644 --- a/lisp/abbrev.el +++ b/lisp/abbrev.el @@ -68,13 +68,11 @@ be replaced by its expansion." (define-obsolete-variable-alias 'edit-abbrevs-map 'edit-abbrevs-mode-map "24.4") -(defvar edit-abbrevs-mode-map - (let ((map (make-sparse-keymap))) - (define-key map "\C-x\C-s" 'abbrev-edit-save-buffer) - (define-key map "\C-x\C-w" 'abbrev-edit-save-to-file) - (define-key map "\C-c\C-c" 'edit-abbrevs-redefine) - map) - "Keymap used in `edit-abbrevs'.") +(defvar-keymap edit-abbrevs-mode-map + :doc "Keymap used in `edit-abbrevs'." + "C-x C-s" #'abbrev-edit-save-buffer + "C-x C-w" #'abbrev-edit-save-to-file + "C-c C-c" #'edit-abbrevs-redefine) (defun kill-all-abbrevs () "Undefine all defined abbrevs." @@ -176,7 +174,7 @@ that may be omitted (it is usually omitted)." (defun edit-abbrevs-redefine () "Redefine abbrevs according to current buffer contents." - (interactive) + (interactive nil edit-abbrevs-mode) (save-restriction (widen) (define-abbrevs t) @@ -279,7 +277,8 @@ abbrevs have been saved." (list (read-file-name "Save abbrevs to file: " (file-name-directory (expand-file-name abbrev-file-name)) - abbrev-file-name))) + abbrev-file-name)) + edit-abbrevs-mode) (edit-abbrevs-redefine) (write-abbrev-file file t)) @@ -287,7 +286,7 @@ abbrevs have been saved." "Save all the user-level abbrev definitions in current buffer. The saved abbrevs are written to the file specified by `abbrev-file-name'." - (interactive) + (interactive nil edit-abbrevs-mode) (abbrev-edit-save-to-file abbrev-file-name)) @@ -491,7 +490,8 @@ PROPS is a list of properties." (defun abbrev-table-p (object) "Return non-nil if OBJECT is an abbrev table." (and (obarrayp object) - (numberp (abbrev-table-get object :abbrev-table-modiff)))) + (numberp (ignore-error 'wrong-type-argument + (abbrev-table-get object :abbrev-table-modiff))))) (defun abbrev-table-empty-p (object &optional ignore-system) "Return nil if there are no abbrev symbols in OBJECT. @@ -604,7 +604,8 @@ PROPS is a property list. The following properties are special: An obsolete but still supported calling form is: -\(define-abbrev TABLE ABBREV EXPANSION &optional HOOK COUNT SYSTEM)." +\(define-abbrev TABLE NAME EXPANSION &optional HOOK COUNT SYSTEM)." + (declare (indent defun)) (when (and (consp props) (or (null (car props)) (numberp (car props)))) ;; Old-style calling convention. (setq props `(:count ,(car props) @@ -1164,7 +1165,7 @@ Properties with special meaning: - `:enable-function' can be set to a function of no arguments which returns non-nil if and only if the abbrevs in this table should be used for this instance of `expand-abbrev'." - (declare (doc-string 3)) + (declare (doc-string 3) (indent defun)) ;; We used to manually add the docstring, but we also want to record this ;; location as the definition of the variable (in load-history), so we may ;; as well just use `defvar'. @@ -1212,7 +1213,30 @@ SORTFUN is passed to `sort' to change the default ordering." (define-derived-mode edit-abbrevs-mode fundamental-mode "Edit-Abbrevs" "Major mode for editing the list of abbrev definitions. This mode is for editing abbrevs in a buffer prepared by `edit-abbrevs', -which see.") +which see." + :interactive nil) + +(defun abbrev--possibly-save (query &optional arg) + ;; Query mode. + (if (eq query 'query) + (and save-abbrevs abbrevs-changed) + ;; Maybe save abbrevs, and record whether we either saved them or + ;; asked to. + (and save-abbrevs + abbrevs-changed + (progn + (if (or arg + (eq save-abbrevs 'silently) + (y-or-n-p (format "Save abbrevs in %s? " abbrev-file-name))) + (progn + (write-abbrev-file nil) + nil) + ;; Don't keep bothering user if they say no. + (setq abbrevs-changed nil) + ;; Inhibit message in `save-some-buffers'. + t))))) + +(add-hook 'save-some-buffers-functions #'abbrev--possibly-save) (provide 'abbrev) |