From 9e5bce94e18a933e44efa39dfdac1bde5442e9f0 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Mon, 11 Nov 2013 15:51:53 -0500 Subject: Toggle variable for save hook clean up Useful for making changes to files from other people's projects --- init/km-func.el | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/init/km-func.el b/init/km-func.el index bf98552..e41bfcb 100644 --- a/init/km-func.el +++ b/init/km-func.el @@ -1,12 +1,27 @@ ;; http://whattheemacsd.com/ ;; whitespace cleanup +;; 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) + (let ((state t)) + (when km/prevent-cleanup + (setq state nil)) + (set (make-local-variable 'km/prevent-cleanup) state))) + (defun km/cleanup-buffer () (interactive) - (unless (equal major-mode 'makefile-gmake-mode) - (untabify (point-min) (point-max))) - (delete-trailing-whitespace) - (set-buffer-file-coding-system 'utf-8)) + (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) (defun km/rename-current-buffer-file () -- cgit v1.2.3