Skip to content

Commit

Permalink
Replace Prelude's auto-save functionality with super-save
Browse files Browse the repository at this point in the history
Prelude's auto-save logic was extracted in the super-save packaged
and polished a bit there.
  • Loading branch information
bbatsov authored and Caleb Epstein committed Sep 4, 2019
1 parent ad967f3 commit ac65443
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 27 deletions.
29 changes: 2 additions & 27 deletions core/prelude-editor.el
Original file line number Diff line number Diff line change
Expand Up @@ -149,33 +149,8 @@

;; automatically save buffers associated with files on buffer switch
;; and on windows switch
(defun prelude-auto-save-command ()
"Save the current buffer if `prelude-auto-save' is not nil."
(when (and prelude-auto-save
buffer-file-name
(buffer-modified-p (current-buffer))
(file-writable-p buffer-file-name))
(save-buffer)))

(defmacro advise-commands (advice-name commands class &rest body)
"Apply advice named ADVICE-NAME to multiple COMMANDS.
The body of the advice is in BODY."
`(progn
,@(mapcar (lambda (command)
`(defadvice ,command (,class ,(intern (concat (symbol-name command) "-" advice-name)) activate)
,@body))
commands)))

;; advise all window switching functions
(advise-commands "auto-save"
(switch-to-buffer other-window windmove-up windmove-down windmove-left windmove-right)
before
(prelude-auto-save-command))

(add-hook 'mouse-leave-buffer-hook 'prelude-auto-save-command)

(add-hook 'focus-out-hook 'prelude-auto-save-command)
(require 'super-save)
(super-save-mode +1)

(defadvice set-buffer-major-mode (after set-major-mode activate compile)
"Set buffer major mode according to `auto-mode-alist'."
Expand Down
1 change: 1 addition & 0 deletions core/prelude-packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
operate-on-number
smartparens
smartrep
super-save
undo-tree
volatile-highlights
which-key
Expand Down

0 comments on commit ac65443

Please sign in to comment.