all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: Hook for "buffer switched"
Date: Wed, 15 Dec 2010 10:48:35 -0500	[thread overview]
Message-ID: <jwvd3p311r4.fsf-monnier+gnu.emacs.help@gnu.org> (raw)
In-Reply-To: 44c604d5-d4ca-4914-bc02-40f0fada6f3d@y31g2000vbt.googlegroups.com

>> > Is there any hook that is run when a buffer is switched?
>> I think generally the answer is "no", tho this question is ill-formed:
>> it's not clear what you mean by switching buffer: do you mean "change
>> the currently active buffer" (i.e. what is done by `set-buffer'), or
>> "change the buffer displayed in the current window", or "select
>> a different window showing a different buffer", or ...
> I would like to be able to handle the "change
> the currently active buffer" case.

You do realize that this can happen a thousand times within a single
command, right?  A lot of code does things like

  (with-current-buffer some-other-buf
    get-some-info-from-there)

which results in 2 changes of active buffer (once to some-other-buf and
another time to return to the previous buffer)?

It will also happen without any user action whenever Emacs receives
output from an "inferior process" (e.g. in *grep* or in *shell*, ...).
And it might do such a back&forth switch for every char received.

>> > If not, why not?
>> Maybe because to a large extent it's an ill-defined problem and once
>> they try to define it better, people seem to end up deciding they don't
>> really need to solve it any more?
> Or maybe because they are not able to solve it reliably.  For
> instance, I'd like Viper state to be global instead of buffer-local.
> For this to work, I would have to know whenever the current active
> buffer changes and switch Viper state when needed.  Or I could just
> prefer always switching to Normal state whenever I switch buffer.

[ I don't know Viper enough to understand what you intend to do, so
  take the following with a grain of salt. ]
Then I think you don't really care about the active buffer (in the sense
of set-buffer), but only about "the buffer in the selected window when
Emacs is waiting for user input".  So you can probably get what you want
via a post-command-hook that compares the current (window-buffer
(selected-window)) with the previous one.


        Stefan


  parent reply	other threads:[~2010-12-15 15:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1.1292332531.794.help-gnu-emacs@gnu.org>
2010-12-15  5:07 ` Hook for "buffer switched" Stefan Monnier
2010-12-15  9:02   ` Elena
2010-12-15 10:22     ` Deniz Dogan
2010-12-15 10:33       ` egarrulo
2010-12-15 10:49         ` Deniz Dogan
2010-12-15 15:40       ` Peter Dyballa
2010-12-15 15:48     ` Stefan Monnier [this message]
2010-12-14 13:14 Deniz Dogan
2010-12-14 13:18 ` Leo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvd3p311r4.fsf-monnier+gnu.emacs.help@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.