Also inhibit user-save-mode with predicates
This commit is contained in:
parent
340c8583cc
commit
8edc3aa615
|
@ -29,10 +29,16 @@ This option is only useful is `user-save-mode' is active when
|
|||
Emacs is killed."
|
||||
:type 'boolean)
|
||||
|
||||
(defcustom user-save-inhibit '(special-mode)
|
||||
(defcustom user-save-inhibit-modes '(special-mode)
|
||||
"List of modes to inhibit `user-save-mode' from activation in."
|
||||
:type '(repeat symbol))
|
||||
|
||||
(defcustom user-save-inhibit-predicates '(user-save-non-file-buffer-p)
|
||||
"List of predicates to inhibit `user-save-mode' from activation.
|
||||
Each predicate will be called with no arguments, and if it
|
||||
returns t, will inhibit `user-save-mode' from activating."
|
||||
:type '(repeat function))
|
||||
|
||||
(defvar user-save-hook nil
|
||||
"Hook to run when the user, not Emacs, saves the buffer.")
|
||||
|
||||
|
@ -49,6 +55,12 @@ This does /not/ also save the buffer."
|
|||
(with-demoted-errors "User-save-hook error: %S"
|
||||
(run-hooks 'user-save-hook)))
|
||||
|
||||
(defun user-save-non-file-buffer-p (&optional buffer-or-name)
|
||||
"Return whether BUFFER-OR-NAME is a non-file buffer.
|
||||
BUFFER-OR-NAME, if omitted, defaults to the current buffer."
|
||||
(with-current-buffer (or buffer-or-name (current-buffer))
|
||||
(not (buffer-file-name))))
|
||||
|
||||
(defun user-save-buffer (&optional arg)
|
||||
"Save current buffer in visited file if modified.
|
||||
This function is precisely the same as `save-buffer', but with
|
||||
|
@ -99,9 +111,11 @@ whether the buffer needs to be saved."
|
|||
(defun user-save-mode-in-some-buffers ()
|
||||
"Enable `user-save-mode', but only in some buffers.
|
||||
The mode will not be enabled in buffers derived from modes in
|
||||
`user-save-inhibit', or in the minibuffer."
|
||||
(unless (or (cl-some #'derived-mode-p user-save-inhibit)
|
||||
(minibufferp))
|
||||
`user-save-inhibit-modes', those for which
|
||||
`user-save-inhibit-predicates' return t, or in the minibuffer."
|
||||
(unless (or (minibufferp)
|
||||
(cl-some #'derived-mode-p user-save-inhibit-modes)
|
||||
(run-hook-with-args-until-failure 'user-save-inhibit-predicates))
|
||||
(user-save-mode +1)))
|
||||
|
||||
;;;###autoload
|
||||
|
|
Loading…
Reference in New Issue