all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Disabling show-wspace for a specific mode or buffer
@ 2012-06-27 18:27 Valera Rozuvan
  2012-06-27 20:01 ` Alp Aker
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Valera Rozuvan @ 2012-06-27 18:27 UTC (permalink / raw)
  To: help-gnu-emacs

Hi!

I am using the package show-wspace (
http://www.emacswiki.org/emacs/show-wspace.el ) to visually show
trailing whitespace and tab characters in all my files. I achieve this
by adding the following line to the ~/.emacs file:

(add-to-list 'load-path "~/.emacs.d/") ;; show-wspace.el can be found here
(require 'show-wspace)

(add-hook 'font-lock-mode-hook 'show-ws-highlight-tabs)
(add-hook 'font-lock-mode-hook 'show-ws-highlight-trailing-whitespace)

My problem is that in 99% of buffers I want this behavior, but
sometimes I don't. For example, when I run the command M-x w3m to
browse the web, I don't want to see trailing whitespace highlighted.
Can anyone suggest a solution for this problem?

Regards,
Valera Rozuvan



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

* Re: Disabling show-wspace for a specific mode or buffer
  2012-06-27 18:27 Disabling show-wspace for a specific mode or buffer Valera Rozuvan
@ 2012-06-27 20:01 ` Alp Aker
  2012-06-27 20:10   ` Valera Rozuvan
  2012-06-27 20:27 ` Drew Adams
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Alp Aker @ 2012-06-27 20:01 UTC (permalink / raw)
  To: Valera Rozuvan; +Cc: help-gnu-emacs

> I am using the package show-wspace
>
> (add-hook 'font-lock-mode-hook 'show-ws-highlight-tabs)
> (add-hook 'font-lock-mode-hook 'show-ws-highlight-trailing-whitespace)
>
> My problem is that in 99% of buffers I want this behavior, but
> sometimes I don't.
>
> Can anyone suggest a solution for this problem?

Does this work?  (Untested.)

(add-hook 'w3m-mode-hook 'show-ws-dont-highlight-trailing-whitespace)
(add-hook 'w3m-mode-hook 'show-ws-dont-highlight-tabs)



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

* Re: Disabling show-wspace for a specific mode or buffer
  2012-06-27 20:01 ` Alp Aker
@ 2012-06-27 20:10   ` Valera Rozuvan
  2012-06-27 20:31     ` Alp Aker
  0 siblings, 1 reply; 12+ messages in thread
From: Valera Rozuvan @ 2012-06-27 20:10 UTC (permalink / raw)
  To: Alp Aker; +Cc: help-gnu-emacs

On Wed, Jun 27, 2012 at 11:01 PM, Alp Aker <alptekin.aker@gmail.com> wrote:
> Does this work?  (Untested.)
>
> (add-hook 'w3m-mode-hook 'show-ws-dont-highlight-trailing-whitespace)
> (add-hook 'w3m-mode-hook 'show-ws-dont-highlight-tabs)

Hi Alp,

I added your add-hook statements, restarted emacs, but when I open w3m
they appear to have no effect. Also when I run the command

M-x show-ws-dont-highlight-trailing-whitespace

Nothing happens, and "[No match]" is inserted at the end of the mini buffer.

Thanks,
Valera Rozuvan



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

* RE: Disabling show-wspace for a specific mode or buffer
  2012-06-27 18:27 Disabling show-wspace for a specific mode or buffer Valera Rozuvan
  2012-06-27 20:01 ` Alp Aker
@ 2012-06-27 20:27 ` Drew Adams
       [not found] ` <mailman.3588.1340828845.855.help-gnu-emacs@gnu.org>
  2012-06-28  2:11 ` John Wiegley
  3 siblings, 0 replies; 12+ messages in thread
From: Drew Adams @ 2012-06-27 20:27 UTC (permalink / raw)
  To: 'Valera Rozuvan', help-gnu-emacs

> I am using the package show-wspace (
> http://www.emacswiki.org/emacs/show-wspace.el ) to visually show
> trailing whitespace and tab characters in all my files. I achieve this
> by adding the following line to the ~/.emacs file:
> 
> (add-to-list 'load-path "~/.emacs.d/") ;; show-wspace.el can 
> be found here
> (require 'show-wspace)
> 
> (add-hook 'font-lock-mode-hook 'show-ws-highlight-tabs)
> (add-hook 'font-lock-mode-hook 'show-ws-highlight-trailing-whitespace)
> 
> My problem is that in 99% of buffers I want this behavior, but
> sometimes I don't. For example, when I run the command M-x w3m to
> browse the web, I don't want to see trailing whitespace highlighted.
> Can anyone suggest a solution for this problem?

Sorry, but there is no simple way to do that.  But you can do it in this
roundabout way (ugly!):

(add-hook 'change-major-mode-hook
          (lambda ()
            (add-hook 'font-lock-mode-hook
                      'show-ws-highlight-trailing-whitespace)))

(add-hook 'after-change-major-mode-hook
          (lambda ()
            (when (eq major-mode 'THE-MODE)
              (remove-hook 'font-lock-mode-hook
                           'show-ws-highlight-trailing-whitespace)
              (show-ws-dont-highlight-trailing-whitespace)))
          'append)

where THE-MODE is the mode of the buffer where you do not want the highlighting.

It's an old library - the code should probably be rewritten to define a minor
mode (and a globalized version of it).




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

* Re: Disabling show-wspace for a specific mode or buffer
  2012-06-27 20:10   ` Valera Rozuvan
@ 2012-06-27 20:31     ` Alp Aker
  2012-06-27 20:41       ` Alp Aker
  0 siblings, 1 reply; 12+ messages in thread
From: Alp Aker @ 2012-06-27 20:31 UTC (permalink / raw)
  To: Valera Rozuvan; +Cc: help-gnu-emacs

> I added your add-hook statements, restarted emacs, but when I open w3m
> they appear to have no effect.

Did you add them to your .emacs *after* you load w3?  You could also
try this (it's overkill, but might work):

(add-hook 'w3m-fontify-before-hook
'show-ws-dont-highlight-trailing-whitespace)

Again, this is untested, as w3m breaks my setup, so I'm just looking
at the sources.

> Also when I run the command
>
> M-x show-ws-dont-highlight-trailing-whitespace
>
> Nothing happens, and "[No match]" is inserted at the end of the mini buffer.

Correct:  show-ws-dont-highlight-trailing-whitespace is not an
interactive command, so you can't invoke it that way.  You could
redefine it by placing the following in your .emacs (after you load
show-wspace):

(defun show-ws-dont-highlight-trailing-whitespace ()
  "Don't highlight whitespace characters at line ends."
  (interactive)
  (when (fboundp 'font-lock-remove-keywords)
    (font-lock-remove-keywords
     nil '(("[\240\040\t]+$" (0 'show-ws-trailing-whitespace t)))))
  (when (called-interactively-p 'any)
    (font-lock-fontify-buffer)))

and then it can be invoked via

  M-x show-ws-dont-highlight-trailing-whitespace



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

* Re: Disabling show-wspace for a specific mode or buffer
  2012-06-27 20:31     ` Alp Aker
@ 2012-06-27 20:41       ` Alp Aker
  2012-06-27 20:56         ` Valera Rozuvan
  0 siblings, 1 reply; 12+ messages in thread
From: Alp Aker @ 2012-06-27 20:41 UTC (permalink / raw)
  To: Valera Rozuvan; +Cc: help-gnu-emacs

On Wed, Jun 27, 2012 at 4:31 PM, Alp Aker <alptekin.aker@gmail.com> wrote:

> Did you add them to your .emacs *after* you load w3?

Actually, that's not important.  But try Drew's suggestion, or my
other suggestion.



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

* Re: Disabling show-wspace for a specific mode or buffer
  2012-06-27 20:41       ` Alp Aker
@ 2012-06-27 20:56         ` Valera Rozuvan
  2012-06-27 21:16           ` Drew Adams
  0 siblings, 1 reply; 12+ messages in thread
From: Valera Rozuvan @ 2012-06-27 20:56 UTC (permalink / raw)
  To: Alp Aker, drew.adams; +Cc: help-gnu-emacs

> Actually, that's not important.  But try Drew's suggestion, or my
> other suggestion.

Thanks for your replies! I have modified your suggestions, and came up
with the following:

(defun show-ws-dont-highlight-trailing-whitespace ()
    "Don't highlight whitespace characters at line ends."
    (interactive)
    (when (fboundp 'font-lock-remove-keywords)
        (font-lock-remove-keywords
            nil '(("[\240\040\t]+$" (0 'show-ws-trailing-whitespace t)))))
    (when (called-interactively-p 'any)
        (font-lock-fontify-buffer)))

(defun show-ws-highlight-trailing-whitespace ()
    "Highlight whitespace characters at line ends."
    (interactive)
    (font-lock-add-keywords
        nil '(("[\240\040\t]+$" (0 'show-ws-trailing-whitespace t))))
    (when (called-interactively-p 'any)
        (font-lock-fontify-buffer)))

(global-set-key (kbd "<f11>") 'show-ws-dont-highlight-trailing-whitespace)
(global-set-key (kbd "<f12>") 'show-ws-highlight-trailing-whitespace)

Now when I press F11 - the highlighting is turned off (F12 turns it
back on). I believe that this approach is the best for me because I
don't have to hard code into ~/.emacs the modes for which I want to
disable the highlighting functionality.

Thanks,
Valera Rozuvan



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

* RE: Disabling show-wspace for a specific mode or buffer
  2012-06-27 20:56         ` Valera Rozuvan
@ 2012-06-27 21:16           ` Drew Adams
  2012-06-27 21:45             ` Valera Rozuvan
  0 siblings, 1 reply; 12+ messages in thread
From: Drew Adams @ 2012-06-27 21:16 UTC (permalink / raw)
  To: 'Valera Rozuvan', 'Alp Aker'; +Cc: help-gnu-emacs

> (global-set-key (kbd "<f11>") 
> 'show-ws-dont-highlight-trailing-whitespace)
> (global-set-key (kbd "<f12>") 'show-ws-highlight-trailing-whitespace)
> 
> Now when I press F11 - the highlighting is turned off (F12 turns it
> back on). I believe that this approach is the best for me because I
> don't have to hard code into ~/.emacs the modes for which I want to
> disable the highlighting functionality.

I thought you wanted to leave it off for specific modes (you mentioned w3m),
which is what my suggestion does.

If instead you just want to hit a key to turn it on/off, all you need to do is
bind `show-ws-toggle-show-trailing-whitespace' to a (single) key - that's what
it's for:

(global-set-key (kbd "<f11>")
                'show-ws-toggle-show-trailing-whitespace)




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

* Re: Disabling show-wspace for a specific mode or buffer
  2012-06-27 21:16           ` Drew Adams
@ 2012-06-27 21:45             ` Valera Rozuvan
  2012-06-27 22:12               ` Drew Adams
  0 siblings, 1 reply; 12+ messages in thread
From: Valera Rozuvan @ 2012-06-27 21:45 UTC (permalink / raw)
  To: Drew Adams; +Cc: Alp Aker, help-gnu-emacs

> I thought you wanted to leave it off for specific modes (you mentioned w3m),
> which is what my suggestion does.

I am just experimenting - and for now looking for the best possible solutions.

> If instead you just want to hit a key to turn it on/off, all you need to do is
> bind `show-ws-toggle-show-trailing-whitespace' to a (single) key - that's what
> it's for:
>
> (global-set-key (kbd "<f11>")
>                'show-ws-toggle-show-trailing-whitespace)

Thanks for the suggestion. But the command
show-ws-toggle-show-trailing-whitespace initially assumes that the
highlighting is OFF. I, on the other hand, from the start turn ON the
highlighting everywhere with the command:

(add-hook 'font-lock-mode-hook 'show-ws-highlight-trailing-whitespace)

So, with your suggestion, I have to press F11 twice to actually tun
OFF highlighting. And also I am not sure if
show-ws-toggle-show-trailing-whitespace works just with the buffer, or
if it is a global toggle.

Regards,
Valera Rozuvan



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

* RE: Disabling show-wspace for a specific mode or buffer
  2012-06-27 21:45             ` Valera Rozuvan
@ 2012-06-27 22:12               ` Drew Adams
  0 siblings, 0 replies; 12+ messages in thread
From: Drew Adams @ 2012-06-27 22:12 UTC (permalink / raw)
  To: 'Valera Rozuvan'; +Cc: 'Alp Aker', help-gnu-emacs

> Thanks for the suggestion. But the command
> show-ws-toggle-show-trailing-whitespace initially assumes that the
> highlighting is OFF.

No, it doesn't assume on or off.  It just toggles whatever the state is.

> I, on the other hand, from the start turn ON the
> highlighting everywhere with the command:
> (add-hook 'font-lock-mode-hook 'show-ws-highlight-trailing-whitespace)
> So, with your suggestion, I have to press F11 twice to actually tun
> OFF highlighting. 

So add this: (setq show-ws-highlight-trailing-whitespace-p t)

> And also I am not sure if
> show-ws-toggle-show-trailing-whitespace works just with the buffer, or
> if it is a global toggle.

It is global.  For that your commands are better for what you want.




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

* Re: Disabling show-wspace for a specific mode or buffer
       [not found] ` <mailman.3588.1340828845.855.help-gnu-emacs@gnu.org>
@ 2012-06-27 22:23   ` Michael Heerdegen
  0 siblings, 0 replies; 12+ messages in thread
From: Michael Heerdegen @ 2012-06-27 22:23 UTC (permalink / raw)
  To: help-gnu-emacs

"Drew Adams" <drew.adams@oracle.com> writes:

> > (add-hook 'font-lock-mode-hook 'show-ws-highlight-tabs)
> > (add-hook 'font-lock-mode-hook 'show-ws-highlight-trailing-whitespace)
> > 
> > My problem is that in 99% of buffers I want this behavior, but
> > sometimes I don't. For example, when I run the command M-x w3m to
> > browse the web, I don't want to see trailing whitespace highlighted.
> > Can anyone suggest a solution for this problem?
>
> Sorry, but there is no simple way to do that.  But you can do it in this
> roundabout way (ugly!):
>
> (add-hook 'change-major-mode-hook
>           (lambda ()
>             (add-hook 'font-lock-mode-hook
>                       'show-ws-highlight-trailing-whitespace)))
>
> (add-hook 'after-change-major-mode-hook
>           (lambda ()
>             (when (eq major-mode 'THE-MODE)
>               (remove-hook 'font-lock-mode-hook
>                            'show-ws-highlight-trailing-whitespace)
>               (show-ws-dont-highlight-trailing-whitespace)))
>           'append)

Maybe an alternative approach would be to add the highlighting functions
to the text-mode-hook:

(add-hook 'text-mode-hook 'show-ws-highlight-tabs)
(add-hook 'text-mode-hook 'show-ws-highlight-trailing-whitespace)

Since most editing modes run `text-mode-hook', and other modes don't,
maybe this way you can get along with less exceptions?  Just an idea.


Michael.



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

* Re: Disabling show-wspace for a specific mode or buffer
  2012-06-27 18:27 Disabling show-wspace for a specific mode or buffer Valera Rozuvan
                   ` (2 preceding siblings ...)
       [not found] ` <mailman.3588.1340828845.855.help-gnu-emacs@gnu.org>
@ 2012-06-28  2:11 ` John Wiegley
  3 siblings, 0 replies; 12+ messages in thread
From: John Wiegley @ 2012-06-28  2:11 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Valera Rozuvan <valera.rozuvan@gmail.com> writes:

> I am using the package show-wspace (
> http://www.emacswiki.org/emacs/show-wspace.el ) to visually show
> trailing whitespace and tab characters in all my files.

FWIW- M-x whitespace-mode does this exact same thing, is highly configurable,
can even cleanup whitespace issues, and comes with Emacs 24.

John



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

end of thread, other threads:[~2012-06-28  2:11 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-27 18:27 Disabling show-wspace for a specific mode or buffer Valera Rozuvan
2012-06-27 20:01 ` Alp Aker
2012-06-27 20:10   ` Valera Rozuvan
2012-06-27 20:31     ` Alp Aker
2012-06-27 20:41       ` Alp Aker
2012-06-27 20:56         ` Valera Rozuvan
2012-06-27 21:16           ` Drew Adams
2012-06-27 21:45             ` Valera Rozuvan
2012-06-27 22:12               ` Drew Adams
2012-06-27 20:27 ` Drew Adams
     [not found] ` <mailman.3588.1340828845.855.help-gnu-emacs@gnu.org>
2012-06-27 22:23   ` Michael Heerdegen
2012-06-28  2:11 ` John Wiegley

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.