* Confusion about first-change-hook
@ 2012-12-18 19:59 David Engster
2012-12-18 20:43 ` Stefan Monnier
2012-12-18 21:01 ` Jambunathan K
0 siblings, 2 replies; 6+ messages in thread
From: David Engster @ 2012-12-18 19:59 UTC (permalink / raw)
To: emacs-devel
I wanted to do something very simple: Activate whitespace-mode only when
I start editing a buffer. So I looked into the manual and found
`first-change-hook', which seemed exactly what I wanted.
However, I soon saw that whitespace-mode got immediately activated in my
C++ buffers. The reason is that changing a text property apparently
already counts as "changing the buffer". Is this really the desired
behavior? If so, what else is there to achieve the above? Should I file
a wishlist-bug for something like 'buffer-modified-hook'?
-David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Confusion about first-change-hook
2012-12-18 19:59 Confusion about first-change-hook David Engster
@ 2012-12-18 20:43 ` Stefan Monnier
2012-12-18 21:00 ` David Engster
2012-12-18 21:01 ` Jambunathan K
1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2012-12-18 20:43 UTC (permalink / raw)
To: emacs-devel
> However, I soon saw that whitespace-mode got immediately activated in my
> C++ buffers. The reason is that changing a text property apparently
> already counts as "changing the buffer". Is this really the desired
> behavior? If so, what else is there to achieve the above? Should I file
> a wishlist-bug for something like 'buffer-modified-hook'?
I think the bug is in the major mode that sets the text-property without
proper protection (e.g. with-silent-modifications).
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Confusion about first-change-hook
2012-12-18 20:43 ` Stefan Monnier
@ 2012-12-18 21:00 ` David Engster
2012-12-19 1:01 ` Stefan Monnier
0 siblings, 1 reply; 6+ messages in thread
From: David Engster @ 2012-12-18 21:00 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
Stefan Monnier writes:
>> However, I soon saw that whitespace-mode got immediately activated in my
>> C++ buffers. The reason is that changing a text property apparently
>> already counts as "changing the buffer". Is this really the desired
>> behavior? If so, what else is there to achieve the above? Should I file
>> a wishlist-bug for something like 'buffer-modified-hook'?
>
> I think the bug is in the major mode that sets the text-property without
> proper protection (e.g. with-silent-modifications).
Oh. I didn't know that putting text properties on an unmodified buffer
should be protected like that. I guess I will have to look at some of my
own packages...
Anyway, thanks for the pointer. I'll see to it that I file a bug for
cc-mode.
-David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Confusion about first-change-hook
2012-12-18 21:00 ` David Engster
@ 2012-12-19 1:01 ` Stefan Monnier
0 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2012-12-19 1:01 UTC (permalink / raw)
To: emacs-devel
> Oh. I didn't know that putting text properties on an unmodified buffer
> should be protected like that. I guess I will have to look at some of my
> own packages...
Many packages do part of what with-silent-modifications does, such as
save buffer-modified-p and restore it afterwards, but that is only
sufficient in some cases (as seen in your particular case).
`with-silent-modifications' takes care of several more potential
problems.
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Confusion about first-change-hook
2012-12-18 19:59 Confusion about first-change-hook David Engster
2012-12-18 20:43 ` Stefan Monnier
@ 2012-12-18 21:01 ` Jambunathan K
2012-12-18 21:09 ` David Engster
1 sibling, 1 reply; 6+ messages in thread
From: Jambunathan K @ 2012-12-18 21:01 UTC (permalink / raw)
To: emacs-devel
David Engster <deng@randomsample.de> writes:
> I wanted to do something very simple: Activate whitespace-mode only when
> I start editing a buffer. So I looked into the manual and found
> `first-change-hook', which seemed exactly what I wanted.
This seems to work:
(add-hook 'c++-mode-hook
(lambda nil
(add-hook 'before-change-functions 'activate-whitespace-mode
nil 'local)))
(defun activate-whitespace-mode (beg end)
(whitespace-mode 1)
(remove-hook 'before-change-functions
'activate-whitespace-mode 'local))
>
> However, I soon saw that whitespace-mode got immediately activated in my
> C++ buffers. The reason is that changing a text property apparently
> already counts as "changing the buffer". Is this really the desired
> behavior? If so, what else is there to achieve the above? Should I file
> a wishlist-bug for something like 'buffer-modified-hook'?
>
> -David
>
>
--
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Confusion about first-change-hook
2012-12-18 21:01 ` Jambunathan K
@ 2012-12-18 21:09 ` David Engster
0 siblings, 0 replies; 6+ messages in thread
From: David Engster @ 2012-12-18 21:09 UTC (permalink / raw)
To: Jambunathan K; +Cc: emacs-devel
Jambunathan K. writes:
> David Engster <deng@randomsample.de> writes:
>
>> I wanted to do something very simple: Activate whitespace-mode only when
>> I start editing a buffer. So I looked into the manual and found
>> `first-change-hook', which seemed exactly what I wanted.
>
> This seems to work:
>
> (add-hook 'c++-mode-hook
> (lambda nil
> (add-hook 'before-change-functions 'activate-whitespace-mode
> nil 'local)))
>
> (defun activate-whitespace-mode (beg end)
> (whitespace-mode 1)
> (remove-hook 'before-change-functions
> 'activate-whitespace-mode 'local))
Thank you. This works nicely.
-David
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-12-19 1:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-18 19:59 Confusion about first-change-hook David Engster
2012-12-18 20:43 ` Stefan Monnier
2012-12-18 21:00 ` David Engster
2012-12-19 1:01 ` Stefan Monnier
2012-12-18 21:01 ` Jambunathan K
2012-12-18 21:09 ` David Engster
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.