[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#6651: Better fix
From: |
Reuben Thomas |
Subject: |
bug#6651: Better fix |
Date: |
Mon, 26 Jul 2010 19:16:51 +0100 |
I recently found that my previous suggested workaround for using
whitespace-mode's autocorrection without display is flawed, as it
doesn't deal with local variables. This means that for example one's
settings for tabs vs spaces can be ignored.
Here's a fuller solution, which has two advantages: first, the local
variables now work, and secondly, the workaround of explicitly setting
write-file-functions is no longer needed. Instead, this version of the
workaround disables whitespace-mode display altogether, by simply
redefining whitespace-mode-{on,off}.
It could therefore form the basis of a refactoring that allows display
mode to be separated from correction mode.
Code follows (for .emacs or equivalent):
(require 'whitespace)
;; Versions of whitespace functions that don't turn visualisation on
(defun whitespace-turn-on ()
"Turn on whitespace correction."
;; prepare local hooks
(add-hook 'write-file-functions 'whitespace-write-file-hook nil t)
;; create whitespace local buffer environment
(set (make-local-variable 'whitespace-font-lock-mode) nil)
(set (make-local-variable 'whitespace-font-lock) nil)
(set (make-local-variable 'whitespace-font-lock-keywords) nil)
(set (make-local-variable 'whitespace-display-table) nil)
(set (make-local-variable 'whitespace-display-table-was-local) nil)
(set (make-local-variable 'whitespace-active-style)
(if (listp whitespace-style)
whitespace-style
(list whitespace-style)))
(set (make-local-variable 'whitespace-indent-tabs-mode)
indent-tabs-mode)
(set (make-local-variable 'whitespace-tab-width)
tab-width))
(defun whitespace-turn-off ()
"Turn off whitespace correction."
(remove-hook 'write-file-functions 'whitespace-write-file-hook t))
--
http://rrt.sc3d.org