fixed #215 - made Prelude's auto-save optional (and improved it a bit in the process of doing so)

This commit is contained in:
Bozhidar Batsov 2012-12-08 20:59:59 +02:00
parent 257e71b894
commit f66a56a72e

View file

@ -37,6 +37,11 @@
"Emacs Prelude Editor enhancements" "Emacs Prelude Editor enhancements"
:group 'prelude) :group 'prelude)
(defcustom prelude-auto-save t
"Non-nil values enable Prelude's auto save."
:type 'boolean
:group 'prelude)
;; Death to the tabs! However, tabs historically indent to the next ;; Death to the tabs! However, tabs historically indent to the next
;; 8-character offset; specifying anything else will cause *mass* ;; 8-character offset; specifying anything else will cause *mass*
;; confusion, as it will change the appearance of every existing file. ;; confusion, as it will change the appearance of every existing file.
@ -120,18 +125,26 @@
;; automatically save buffers associated with files on buffer switch ;; automatically save buffers associated with files on buffer switch
;; and on windows switch ;; and on windows switch
(defun prelude-auto-save-command ()
(when (and prelude-auto-save
buffer-file-name
(buffer-modified-p (current-buffer)))
(save-buffer)))
(defadvice switch-to-buffer (before save-buffer-now activate) (defadvice switch-to-buffer (before save-buffer-now activate)
(when buffer-file-name (save-buffer))) (prelude-auto-save-command))
(defadvice other-window (before other-window-now activate) (defadvice other-window (before other-window-now activate)
(when buffer-file-name (save-buffer))) (prelude-auto-save-command))
(defadvice windmove-up (before other-window-now activate) (defadvice windmove-up (before other-window-now activate)
(when buffer-file-name (save-buffer))) (prelude-auto-save-command))
(defadvice windmove-down (before other-window-now activate) (defadvice windmove-down (before other-window-now activate)
(when buffer-file-name (save-buffer))) (prelude-auto-save-command))
(defadvice windmove-left (before other-window-now activate) (defadvice windmove-left (before other-window-now activate)
(when buffer-file-name (save-buffer))) (prelude-auto-save-command))
(defadvice windmove-right (before other-window-now activate) (defadvice windmove-right (before other-window-now activate)
(when buffer-file-name (save-buffer))) (prelude-auto-save-command))
(add-hook 'mouse-leave-buffer-hook 'prelude-auto-save-command)
;; show-paren-mode: subtle highlighting of matching parens (global-mode) ;; show-paren-mode: subtle highlighting of matching parens (global-mode)
(show-paren-mode +1) (show-paren-mode +1)