unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Elisp beginner's question
@ 2008-09-18  7:16 Uwe Siart
  2008-09-18 14:16 ` Tassilo Horn
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Uwe Siart @ 2008-09-18  7:16 UTC (permalink / raw)
  To: help-gnu-emacs

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.

-- 
Uwe


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Elisp beginner's question
  2008-09-18  7:16 Elisp beginner's question Uwe Siart
@ 2008-09-18 14:16 ` Tassilo Horn
       [not found] ` <mailman.19466.1221747573.18990.help-gnu-emacs@gnu.org>
  2008-09-18 16:36 ` Joe Casadonte
  2 siblings, 0 replies; 5+ messages in thread
From: Tassilo Horn @ 2008-09-18 14:16 UTC (permalink / raw)
  To: help-gnu-emacs

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. 





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Elisp beginner's question
       [not found] ` <mailman.19466.1221747573.18990.help-gnu-emacs@gnu.org>
@ 2008-09-18 14:41   ` Uwe Siart
  0 siblings, 0 replies; 5+ messages in thread
From: Uwe Siart @ 2008-09-18 14:41 UTC (permalink / raw)
  To: help-gnu-emacs

Tassilo Horn <tassilo@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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Elisp beginner's question
  2008-09-18  7:16 Elisp beginner's question Uwe Siart
  2008-09-18 14:16 ` Tassilo Horn
       [not found] ` <mailman.19466.1221747573.18990.help-gnu-emacs@gnu.org>
@ 2008-09-18 16:36 ` Joe Casadonte
  2008-09-18 17:08   ` Uwe Siart
  2 siblings, 1 reply; 5+ messages in thread
From: Joe Casadonte @ 2008-09-18 16:36 UTC (permalink / raw)
  To: help-gnu-emacs

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

------------------------------------------------------------------------------
         Llama Fresh Farms => http://www.northbound-train.com
    Ramblings of a Gay Man => http://www.northbound-train.com/ramblings
               Emacs Stuff => http://www.northbound-train.com/emacs.html
          Music CD Trading => http://www.northbound-train.com/cdr.html
------------------------------------------------------------------------------
                       Live Free, that's the message!
------------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Elisp beginner's question
  2008-09-18 16:36 ` Joe Casadonte
@ 2008-09-18 17:08   ` Uwe Siart
  0 siblings, 0 replies; 5+ messages in thread
From: Uwe Siart @ 2008-09-18 17:08 UTC (permalink / raw)
  To: help-gnu-emacs

"Joe Casadonte" <jcasadonte@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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-09-18 17:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-18  7:16 Elisp beginner's question Uwe Siart
2008-09-18 14:16 ` Tassilo Horn
     [not found] ` <mailman.19466.1221747573.18990.help-gnu-emacs@gnu.org>
2008-09-18 14:41   ` Uwe Siart
2008-09-18 16:36 ` Joe Casadonte
2008-09-18 17:08   ` Uwe Siart

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).