unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Buffer switching hook
@ 2013-04-27 12:50 Miguel Guedes
  2013-04-27 13:26 ` Pascal J. Bourguignon
  0 siblings, 1 reply; 3+ messages in thread
From: Miguel Guedes @ 2013-04-27 12:50 UTC (permalink / raw)
  To: help-gnu-emacs

Hello List,

I am writing a minor mode and as part of the requirements I need the 
minor-mode to be aware of when the user switches to a different buffer; 
something akin to `find-file-hook' but for buffers.

What is the best strategy to implement such a mechanism? I haven't really 
looked into `pre-command-hook' as I'd rather just use a hook, if one is 
available.

Miguel


PS: I've only just started learning (e)LISP so apologies if this is a 
straightforward question.



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

* Re: Buffer switching hook
  2013-04-27 12:50 Buffer switching hook Miguel Guedes
@ 2013-04-27 13:26 ` Pascal J. Bourguignon
  2013-04-29  8:48   ` Miguel Guedes
  0 siblings, 1 reply; 3+ messages in thread
From: Pascal J. Bourguignon @ 2013-04-27 13:26 UTC (permalink / raw)
  To: help-gnu-emacs

Miguel Guedes <miguel.a.guedes@gmail.com> writes:

> Hello List,
>
> I am writing a minor mode and as part of the requirements I need the 
> minor-mode to be aware of when the user switches to a different buffer; 
> something akin to `find-file-hook' but for buffers.

Your problem is probably ill-defined.

What do you mean by "user switches to a different buffer"?

There's a switch-to-buffer command, that you could advice, but it
probably is not all that you mean.

For example, the user could change the selected window or/and the
selected frame, and thus the current buffer, without switching to a
different buffer in any window.


> What is the best strategy to implement such a mechanism? I haven't really 
> looked into `pre-command-hook' as I'd rather just use a hook, if one is 
> available.

or post-command-hook.  But since those hooks are run for each command,
including each character insertion, they must be very light.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


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

* Re: Buffer switching hook
  2013-04-27 13:26 ` Pascal J. Bourguignon
@ 2013-04-29  8:48   ` Miguel Guedes
  0 siblings, 0 replies; 3+ messages in thread
From: Miguel Guedes @ 2013-04-29  8:48 UTC (permalink / raw)
  To: help-gnu-emacs

On Sat, 27 Apr 2013 15:26:25 +0200, Pascal J. Bourguignon wrote:

> 
> There's a switch-to-buffer command, that you could advice, but it
> probably is not all that you mean.
> 
> For example, the user could change the selected window or/and the
> selected frame, and thus the current buffer, without switching to a
> different buffer in any window.

Apologies for my poor semantics. I thought my statement implied window/
frame switching because the active buffer may change (or not, i.e. same 
buffer in more than one window/frame.)

> 
> or post-command-hook.  But since those hooks are run for each command,
> including each character insertion, they must be very light.

Was hoping for an easier way of achieving this (such as a hook) but (pre/
post)-command-hook will do.

Many thanks for the help, Pascal.



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

end of thread, other threads:[~2013-04-29  8:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-27 12:50 Buffer switching hook Miguel Guedes
2013-04-27 13:26 ` Pascal J. Bourguignon
2013-04-29  8:48   ` Miguel Guedes

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