[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Elisp beginner's question
From: |
Tassilo Horn |
Subject: |
Re: Elisp beginner's question |
Date: |
Thu, 18 Sep 2008 16:16:59 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
Uwe Siart <usenet@siart.de> writes:
Hi Uwe,
> ;; --------------------------------------------
> (defun toggle-show-trailing-whitespace ()
> "Toggle highlighting of trailing whitespace."
> (interactive)
> (if show-trailing-whitespace
> (setq show-trailing-whitespace nil)
> (setq show-trailing-whitespace t)))
> ;; --------------------------------------------
>
> And - well - it works somehow, I don't see any misbehaviour so far.
> But I'd appreciate some experts' advice whether this approach is ok or
> whether it should be done differently.
Your function is ok, but this one is shorter. ;-)
--8<---------------cut here---------------start------------->8---
(defun toggle-show-trailing-whitespace ()
"Toggle highlighting of trailing whitespace."
(interactive)
(setq show-trailing-whitespace (not show-trailing-whitespace)))
--8<---------------cut here---------------end--------------->8---
But I'd say most of the time you want to set this variable on a per-mode
basis and not on a per-buffer basis, right? In that case you'd set the
variable in the mode's hook like this:
--8<---------------cut here---------------start------------->8---
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(setq show-trailing-whitespace)))
--8<---------------cut here---------------end--------------->8---
Hope that helps,
Tassilo
--
Chuck Norris can skeletize a cow in two minutes.