summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--init.el5
-rw-r--r--lisp/user-save.el45
2 files changed, 49 insertions, 1 deletions
diff --git a/init.el b/init.el index 67528fd..5bf4dee 100644 --- a/init.el +++ b/init.el
@@ -104,6 +104,9 @@
104(setup (:require reading) 104(setup (:require reading)
105 (:global "C-c C-r" #'reading-mode)) 105 (:global "C-c C-r" #'reading-mode))
106 106
107(setup (:require user-save)
108 (user-save-mode +1))
109
107(setup +key 110(setup +key
108 (+ensure-after-init #'+key-global-mode)) 111 (+ensure-after-init #'+key-global-mode))
109 112
@@ -450,7 +453,7 @@
450 "C-c C-l" #'+org-insert-link-dwim 453 "C-c C-l" #'+org-insert-link-dwim
451 "C-c C-n" #'+org-next-heading-widen 454 "C-c C-n" #'+org-next-heading-widen
452 "C-c C-p" #'+org-previous-heading-widen) 455 "C-c C-p" #'+org-previous-heading-widen)
453 (:local-hook before-save-hook #'+org-before-save@prettify-buffer) 456 (:local-hook user-save-hook #'+org-before-save@prettify-buffer)
454 (advice-add #'org-delete-backward-char :override #'+org-delete-backward-char) 457 (advice-add #'org-delete-backward-char :override #'+org-delete-backward-char)
455 (with-eval-after-load 'org 458 (with-eval-after-load 'org
456 (org-clock-persistence-insinuate) 459 (org-clock-persistence-insinuate)
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