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

more...

gnu.emacs.help Profile…
 Up
Elisp beginner's question         


Author: Uwe Siart
Date: Sep 18, 2008 00:16

Dear all,

the value of the buffer local variable 'show-trailing-whitespace'
determines highlighting of trailing whitespace. This variable can be
customized. However, I could not find an interactive function to toggle
highlighting of trailing whitespace in a particular buffer. Therefore my
attempt to provide such a function is as follows:

;; --------------------------------------------
(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.

Thank you.
Show full article (0.86Kb)
4 Comments
Re: Elisp beginner's question         


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. ;-)
Show full article (1.42Kb)
no comments
Re: Elisp beginner's question         


Author: Uwe Siart
Date: Sep 18, 2008 07:41

Tassilo Horn member.fsf.org> writes:
> [suggestions for alternative solutions]

Thank you for your comments, Tassilo. And yes, setting it on a per-mode
basis will also be useful for me.

--
Uwe
no comments
Re: Elisp beginner's question         


Author: Joe Casadonte
Date: Sep 18, 2008 09:36

On 18 Sep 2008, Uwe Siart wrote:
> 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.

Looks OK to me. For purely aesthetic reasons you could rewrite it
like this:

(defun toggle-show-trailing-whitespace ()
"Toggle highlighting of trailing whitespace."
(interactive)
(setq show-trailing-whitespace (not show-trailing-whitespace)))

But I don't know that that buys you anything useful.

--
Regards,

joe
Joe Casadonte
jcasadonte@northbound-train.com
Show full article (1.16Kb)
no comments
Re: Elisp beginner's question         


Author: Uwe Siart
Date: Sep 18, 2008 10:08

"Joe Casadonte" northbound-train.com> writes:
> (defun toggle-show-trailing-whitespace ()
> "Toggle highlighting of trailing whitespace."
> (interactive)
> (setq show-trailing-whitespace (not show-trailing-whitespace)))
>
> But I don't know that that buys you anything useful.

It is instructive to me. Your (and Tassilo's) version is a lot more
elegant.

--
Uwe
no comments