From 5f4f111cd367266fd9df656d409f0b0fe9cf9836 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 22 Jan 2015 23:05:36 -0500 Subject: Use whitespace-mode as cleanup indicator - Activate global whitespace-mode. When not allowing the buffer to be cleaned up, use more annoying whitespace indicators. - Use whitespace-cleanup as cleanup function. Except for trailing whitespace, this should cover what km/cleanup-buffer was doing and more. --- lisp/init-editing.el | 25 ++++++++++++++++++------- lisp/init-general.el | 1 - 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'lisp') diff --git a/lisp/init-editing.el b/lisp/init-editing.el index a8f37ae..ea1efac 100644 --- a/lisp/init-editing.el +++ b/lisp/init-editing.el @@ -158,23 +158,34 @@ and '<<<' mark the bounds of the narrowed region. ;; 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 +(defvar-local km/prevent-cleanup nil "If set, `km/cleanup-buffer' does not perform clean up on save.") +(setq whitespace-style '(face trailing indentation)) +(global-whitespace-mode 1) + (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))) + (progn + (message "Allowing cleanup on save") + (kill-local-variable 'whitespace-style) + (global-whitespace-mode 0) + (global-whitespace-mode 1)) + (message "Preventing cleanup on save") + (setq-local whitespace-style + '(face trailing indentation + tab-mark space-mark newline-mark)) + (global-whitespace-mode 0) + (global-whitespace-mode 1)) + (setq km/prevent-cleanup (not km/prevent-cleanup))) (defun km/cleanup-buffer () (interactive) (unless km/prevent-cleanup - (unless indent-tabs-mode - (untabify (point-min) (point-max))) - (delete-trailing-whitespace))) + (whitespace-cleanup))) + (add-hook 'before-save-hook 'km/cleanup-buffer) (define-key km/editing-map "t" 'km/toggle-prevent-cleanup) diff --git a/lisp/init-general.el b/lisp/init-general.el index f5f28f7..adc9df3 100644 --- a/lisp/init-general.el +++ b/lisp/init-general.el @@ -1,7 +1,6 @@ (setq echo-keystrokes 0.1 use-dialog-box nil visible-bell t - whitespace-style '(spaces tabs newline space-mark tab-mark newline-mark) tramp-default-method "ssh" enable-recursive-minibuffers t) -- cgit v1.2.3