From: Reuben Thomas <rrt@sc3d.org>
To: 6651 <6651@debbugs.gnu.org>
Subject: bug#6651: Better fix
Date: Mon, 26 Jul 2010 19:16:51 +0100 [thread overview]
Message-ID: <AANLkTimhWyN-2d9RuxfgOV09J3Q4Z+RVtWvBdCpAEnoL@mail.gmail.com> (raw)
In-Reply-To: <87oce7lgnz.fsf@mord.config>
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
next prev parent reply other threads:[~2010-07-26 18:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-16 13:06 bug#6651: 23.2; Please allow whitespace fixing to be easily activated without whitespace display Reuben Thomas
2010-07-26 18:16 ` Reuben Thomas [this message]
2010-09-06 14:38 ` Vinicius Jose Latorre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTimhWyN-2d9RuxfgOV09J3Q4Z+RVtWvBdCpAEnoL@mail.gmail.com \
--to=rrt@sc3d.org \
--cc=6651@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).