Re: Elisp beginner's question
  Home FAQ Contact Sign in
gnu.emacs.help only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: Elisp beginner's question         

Group: gnu.emacs.help · Group Profile
Author: Tassilo Horn
Date: Sep 18, 2008 07:16

Uwe Siart 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.
no comments
diggit! del.icio.us! reddit!