about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lisp/user-save.el35
1 files changed, 34 insertions, 1 deletions
diff --git a/lisp/user-save.el b/lisp/user-save.el index 01adc22..63fe424 100644 --- a/lisp/user-save.el +++ b/lisp/user-save.el
@@ -8,6 +8,17 @@
8 8
9;;; Code: 9;;; Code:
10 10
11(defgroup user-save nil
12 "Group for `user-save-mode' customizations."
13 :group 'emacs
14 :prefix "user-save-")
15
16(defcustom user-save-hook-into-kill-emacs nil
17 "Add a hook to perform `user-save' to `kill-emacs-hook'.
18This option is only useful is `user-save-mode' is active when
19Emacs is killed."
20 :type 'boolean)
21
11(defvar user-save-hook nil 22(defvar user-save-hook nil
12 "Hook to run when the user, not Emacs, saves the buffer.") 23 "Hook to run when the user, not Emacs, saves the buffer.")
13 24
@@ -34,12 +45,34 @@ ARG is passed directly to `save-buffer'."
34 (save-buffer arg) 45 (save-buffer arg)
35 (message "Saving the buffer...Done.")) 46 (message "Saving the buffer...Done."))
36 47
48(defun user-save-some-buffers (&optional pred)
49 "Save some buffers as though the user saved them.
50This function does not ask the user about each buffer, but PRED
51is used in almost the same way as `save-some-buffers': if it's
52nil or t, it will save all file-visiting modified buffers; if
53it's a zero-argument function, that will be called to determine
54whether the buffer needs to be saved."
55 ;; This could maybe be much better.
56 (interactive "P")
57 (unless pred (setq pred save-some-buffers-default-predicate))
58 (dolist (buf (buffer-list))
59 (with-current-buffer buf
60 (when (and (buffer-modified-p)
61 (buffer-file-name)
62 (or (null pred)
63 (if (functionp pred) (funcall pred) pred)))
64 (user-save-buffer)))))
65
37;;;###autoload 66;;;###autoload
38(define-minor-mode user-save-mode 67(define-minor-mode user-save-mode
39 "Mode to enable an an extra user-save hook." 68 "Mode to enable an an extra user-save hook."
40 :lighter " US" 69 :lighter " US"
41 :global t 70 :global t
42 :keymap 'user-save-mode-map) 71 :keymap 'user-save-mode-map
72 (if user-save-mode
73 (when user-save-hook-into-kill-emacs
74 (add-hook 'kill-emacs-hook #'user-save-some-buffers))
75 (remove-hook 'kill-emacs-hook #'user-save-some-buffers)))
43 76
44(provide 'user-save) 77(provide 'user-save)
45;;; user-save.el ends here 78;;; user-save.el ends here