summary refs log tree commit diff stats
path: root/lisp/user-save.el
diff options
context:
space:
mode:
authorCase Duckworth2022-01-06 15:47:09 -0600
committerCase Duckworth2022-01-06 15:47:20 -0600
commit84139db9a8869b31f831fb154bdc209e06db5ab3 (patch)
tree3e5d7b1efa4c4f59e3e78fcc76c5964d7a8140f6 /lisp/user-save.el
parentAdd +flyspell-correct-buffer (diff)
downloademacs-84139db9a8869b31f831fb154bdc209e06db5ab3.tar.gz
emacs-84139db9a8869b31f831fb154bdc209e06db5ab3.zip
Add user-save-mode
Diffstat (limited to 'lisp/user-save.el')
-rw-r--r--lisp/user-save.el45
1 files changed, 45 insertions, 0 deletions
diff --git a/lisp/user-save.el b/lisp/user-save.el new file mode 100644 index 0000000..01adc22 --- /dev/null +++ b/lisp/user-save.el
@@ -0,0 +1,45 @@
1;;; user-save.el -*- lexical-binding: t; -*-
2
3;; Because `super-save-mode' automatically saves every time we move away from a
4;; buffer, it tends to run a lot of `before-save-hook's that don't need to be
5;; run that often. For that reason, I'm writing a mode where C-x C-s saves
6;; /and/ runs all the "real" before-save-hooks, so that super-save won't
7;; automatically do things like format the buffer all the time.
8
9;;; Code:
10
11(defvar user-save-hook nil
12 "Hook to run when the user, not Emacs, saves the buffer.")
13
14(defvar user-save-mode-map (let ((map (make-sparse-keymap)))
15 (define-key map (kbd "C-x C-s") #'user-save-buffer)
16 map)
17 "Keymap for `user-save-mode'.
18This map shadows the default map for `save-buffer'.")
19
20(defun user-save-buffer (&optional arg)
21 "Save current buffer in visited file if modified.
22This function is precisely the same as `save-buffer', but with
23one modification: it also runs functions in `user-save-hook'.
24This means that if you have some functionality in Emacs to
25automatically save buffers periodically, but have hooks you want
26to automatically run when the buffer saves that are
27computationally expensive or just aren't something you want to
28run all the time, put them in `user-save-hook'.
29
30ARG is passed directly to `save-buffer'."
31 (interactive '(called-interactively))
32 (message "Saving the buffer...")
33 (with-demoted-errors (run-hooks 'user-save-hook))
34 (save-buffer arg)
35 (message "Saving the buffer...Done."))
36
37;;;###autoload
38(define-minor-mode user-save-mode
39 "Mode to enable an an extra user-save hook."
40 :lighter " US"
41 :global t
42 :keymap 'user-save-mode-map)
43
44(provide 'user-save)
45;;; user-save.el ends here