summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/user-save.el24
1 files changed, 19 insertions, 5 deletions
diff --git a/lisp/user-save.el b/lisp/user-save.el index 15e61a0..1c04c9d 100644 --- a/lisp/user-save.el +++ b/lisp/user-save.el
@@ -29,10 +29,16 @@ This option is only useful is `user-save-mode' is active when
29Emacs is killed." 29Emacs is killed."
30 :type 'boolean) 30 :type 'boolean)
31 31
32(defcustom user-save-inhibit '(special-mode) 32(defcustom user-save-inhibit-modes '(special-mode)
33 "List of modes to inhibit `user-save-mode' from activation in." 33 "List of modes to inhibit `user-save-mode' from activation in."
34 :type '(repeat symbol)) 34 :type '(repeat symbol))
35 35
36(defcustom user-save-inhibit-predicates '(user-save-non-file-buffer-p)
37 "List of predicates to inhibit `user-save-mode' from activation.
38Each predicate will be called with no arguments, and if it
39returns t, will inhibit `user-save-mode' from activating."
40 :type '(repeat function))
41
36(defvar user-save-hook nil 42(defvar user-save-hook nil
37 "Hook to run when the user, not Emacs, saves the buffer.") 43 "Hook to run when the user, not Emacs, saves the buffer.")
38 44
@@ -47,7 +53,13 @@ This map shadows the default map for `save-buffer'.")
47 "Run the hooks in `user-save-hook'. 53 "Run the hooks in `user-save-hook'.
48This does /not/ also save the buffer." 54This does /not/ also save the buffer."
49 (with-demoted-errors "User-save-hook error: %S" 55 (with-demoted-errors "User-save-hook error: %S"
50 (run-hooks 'user-save-hook))) 56 (run-hooks 'user-save-hook)))
57
58(defun user-save-non-file-buffer-p (&optional buffer-or-name)
59 "Return whether BUFFER-OR-NAME is a non-file buffer.
60BUFFER-OR-NAME, if omitted, defaults to the current buffer."
61 (with-current-buffer (or buffer-or-name (current-buffer))
62 (not (buffer-file-name))))
51 63
52(defun user-save-buffer (&optional arg) 64(defun user-save-buffer (&optional arg)
53 "Save current buffer in visited file if modified. 65 "Save current buffer in visited file if modified.
@@ -99,9 +111,11 @@ whether the buffer needs to be saved."
99(defun user-save-mode-in-some-buffers () 111(defun user-save-mode-in-some-buffers ()
100 "Enable `user-save-mode', but only in some buffers. 112 "Enable `user-save-mode', but only in some buffers.
101The mode will not be enabled in buffers derived from modes in 113The mode will not be enabled in buffers derived from modes in
102`user-save-inhibit', or in the minibuffer." 114`user-save-inhibit-modes', those for which
103 (unless (or (cl-some #'derived-mode-p user-save-inhibit) 115`user-save-inhibit-predicates' return t, or in the minibuffer."
104 (minibufferp)) 116 (unless (or (minibufferp)
117 (cl-some #'derived-mode-p user-save-inhibit-modes)
118 (run-hook-with-args-until-failure 'user-save-inhibit-predicates))
105 (user-save-mode +1))) 119 (user-save-mode +1)))
106 120
107;;;###autoload 121;;;###autoload