summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2014-11-08 00:50:39 -0500
committerKyle Meyer <kyle@kyleam.com>2014-11-08 00:50:39 -0500
commitad80f4b4896b13d23b488146af4e4df6354191a7 (patch)
tree9ff6663588df4e43219d3e0d7985bd808fa755dd
parent3fd00921d8e93f902f3b8070f544d09892a098c9 (diff)
downloademacs.d-ad80f4b4896b13d23b488146af4e4df6354191a7.tar.gz
Move cleanup-buffer code
-rw-r--r--lisp/init-editing.el23
1 files changed, 23 insertions, 0 deletions
diff --git a/lisp/init-editing.el b/lisp/init-editing.el
index bf2e3e5..bd85d50 100644
--- a/lisp/init-editing.el
+++ b/lisp/init-editing.el
@@ -142,6 +142,29 @@ and '<<<' mark the bounds of the narrowed region.
(define-key km/editing-map "p" 'mc/mark-previous-like-this)
(define-key km/editing-map "a" 'mc/mark-all-like-this)
+;; Buffer-specific prevention modified from
+;; http://stackoverflow.com/questions/14913398/
+;; in-emacs-how-do-i-save-without-running-save-hooks.
+(defvar km/prevent-cleanup nil
+ "If set, `km/cleanup-buffer' does not perform clean up on save.")
+
+(defun km/toggle-prevent-cleanup ()
+ "Toggle state of `km/prevent-cleanup'"
+ (interactive)
+ (if km/prevent-cleanup
+ (message "Allowing cleanup on save ")
+ (message "Preventing cleanup on save"))
+ (set (make-local-variable 'km/prevent-cleanup) (not km/prevent-cleanup)))
+
+(defun km/cleanup-buffer ()
+ (interactive)
+ (unless km/prevent-cleanup
+ (unless (equal major-mode 'makefile-gmake-mode)
+ (untabify (point-min) (point-max)))
+ (delete-trailing-whitespace)
+ (set-buffer-file-coding-system 'utf-8)))
+(add-hook 'before-save-hook 'km/cleanup-buffer)
+
(define-key km/editing-map "t" 'km/toggle-prevent-cleanup)
(global-set-key (kbd "C-;") 'er/expand-region)