all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* switch-buffer-hook to catch the switch-event?
@ 2013-02-26  0:41 Thorsten Jolitz
  2013-02-26  3:14 ` Stefan Monnier
       [not found] ` <mailman.20875.1361848468.855.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 6+ messages in thread
From: Thorsten Jolitz @ 2013-02-26  0:41 UTC (permalink / raw)
  To: help-gnu-emacs


Hi List, 

I want to revert a buffer everytime it is switched to (it becomes
current-buffer). Searching the web and the manuals for a related emacs
hook, I found out that someone asked the same question before - but with
no 'positive' answer. 

How can I trigger an action everytime a certain buffer gets the focus
(becomes current-buffer)? Is there no hook for 'switch-buffer' or
something similar?

from: http://emacswiki.org/emacs/SwitchingBuffers
,-------------------------------------------------------------------------
|   Question: Is there a way to find out that the user has switched to a
|   buffer, i.e., someting like switch-to-buffer-hook? The manual seems to
|   say no, which is surprising. I would like to set some frame-specific
|   variables according to the buffer which has been selected….
|   JoergVolbers?
|  
|      If you don’t need to know when the switch was made, and you just
|      need to know the current buffer, use function ‘current-buffer’. You
|      might also want to look at variable ‘major-mode’ and the hooks
|      ‘change-major-mode-hook’ and ‘after-change-major-mode-hook’. The
|      last of these is in Emacs 22 only. – DrewAdams
|  
| Thank you for the fast reply, but what I want to do is to catch, so to
| speak, the switch-event [...]
`-------------------------------------------------------------------------


-- 
cheers,
Thorsten





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

* Re: switch-buffer-hook to catch the switch-event?
  2013-02-26  0:41 switch-buffer-hook to catch the switch-event? Thorsten Jolitz
@ 2013-02-26  3:14 ` Stefan Monnier
  2013-02-26  4:23   ` Thorsten Jolitz
       [not found] ` <mailman.20875.1361848468.855.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2013-02-26  3:14 UTC (permalink / raw)
  To: help-gnu-emacs

> How can I trigger an action everytime a certain buffer gets the focus
> (becomes current-buffer)? Is there no hook for 'switch-buffer' or
> something similar?

No, indeed, there isn't.  You can use window-configuration-change-hook
to detect changes within an Emacs frame, but in order to detect focus
changing from/to Emacs to/from other applications you'd additionally
need a focus-hook, but last I checked the corresponding C-level events
are not reliably propagated to Elisp.  Patch welcome.


        Stefan




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

* Re: switch-buffer-hook to catch the switch-event?
  2013-02-26  3:14 ` Stefan Monnier
@ 2013-02-26  4:23   ` Thorsten Jolitz
  2013-02-26  5:11     ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Thorsten Jolitz @ 2013-02-26  4:23 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> How can I trigger an action everytime a certain buffer gets the focus
>> (becomes current-buffer)? Is there no hook for 'switch-buffer' or
>> something similar?
>
> No, indeed, there isn't.  You can use window-configuration-change-hook
> to detect changes within an Emacs frame, but in order to detect focus
> changing from/to Emacs to/from other applications you'd additionally
> need a focus-hook, but last I checked the corresponding C-level events
> are not reliably propagated to Elisp.  Patch welcome.

window-configuration-change-hook is not exactly what I was looking for,
but in the absence of a more straight-forward solution I'll give it a
try. If the only thing that happens is a 'switch-window or
'switch-buffer command - is that considered a
window-configuration-change and triggers the hook?

-- 
cheers,
Thorsten




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

* Re: switch-buffer-hook to catch the switch-event?
  2013-02-26  4:23   ` Thorsten Jolitz
@ 2013-02-26  5:11     ` Stefan Monnier
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2013-02-26  5:11 UTC (permalink / raw)
  To: help-gnu-emacs

> try. If the only thing that happens is a 'switch-window or
> 'switch-buffer command - is that considered a
> window-configuration-change and triggers the hook?

I don't know any `switch-window' command, but for `switch-to-buffer',
the hook is definitely triggered.


        Stefan





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

* Re: switch-buffer-hook to catch the switch-event?
       [not found] ` <mailman.20875.1361848468.855.help-gnu-emacs@gnu.org>
@ 2013-02-26 19:46   ` Sean McAfee
  2013-02-26 23:38     ` Thorsten Jolitz
  0 siblings, 1 reply; 6+ messages in thread
From: Sean McAfee @ 2013-02-26 19:46 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> How can I trigger an action everytime a certain buffer gets the focus
>> (becomes current-buffer)? Is there no hook for 'switch-buffer' or
>> something similar?

> No, indeed, there isn't.

Hmm!  It seems dired-auto-revert-buffer doesn't do what I always assumed
it did.


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

* Re: switch-buffer-hook to catch the switch-event?
  2013-02-26 19:46   ` Sean McAfee
@ 2013-02-26 23:38     ` Thorsten Jolitz
  0 siblings, 0 replies; 6+ messages in thread
From: Thorsten Jolitz @ 2013-02-26 23:38 UTC (permalink / raw)
  To: help-gnu-emacs

Sean McAfee <eefacm@gmail.com> writes:

> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>> How can I trigger an action everytime a certain buffer gets the focus
>>> (becomes current-buffer)? Is there no hook for 'switch-buffer' or
>>> something similar?
>
>> No, indeed, there isn't.
>
> Hmm!  It seems dired-auto-revert-buffer doesn't do what I always assumed
> it did.

But dired-auto-revert-buffer is a defcustom (variable), I wonder how the
switch-to-buffer event is actually tracked? I searched around a bit in
dired.el, but couldn't find an obvious answer.

-- 
cheers,
Thorsten




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

end of thread, other threads:[~2013-02-26 23:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-26  0:41 switch-buffer-hook to catch the switch-event? Thorsten Jolitz
2013-02-26  3:14 ` Stefan Monnier
2013-02-26  4:23   ` Thorsten Jolitz
2013-02-26  5:11     ` Stefan Monnier
     [not found] ` <mailman.20875.1361848468.855.help-gnu-emacs@gnu.org>
2013-02-26 19:46   ` Sean McAfee
2013-02-26 23:38     ` Thorsten Jolitz

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.