From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: Hook for "buffer switched" Date: Wed, 15 Dec 2010 10:48:35 -0500 Organization: A noiseless patient Spider Message-ID: References: <44c604d5-d4ca-4914-bc02-40f0fada6f3d@y31g2000vbt.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1292431259 716 80.91.229.12 (15 Dec 2010 16:40:59 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 15 Dec 2010 16:40:59 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 15 17:40:55 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PSuPO-0007tc-M7 for geh-help-gnu-emacs@m.gmane.org; Wed, 15 Dec 2010 17:40:54 +0100 Original-Received: from localhost ([127.0.0.1]:55865 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PSuPO-0006sv-5W for geh-help-gnu-emacs@m.gmane.org; Wed, 15 Dec 2010 11:40:54 -0500 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 42 Injection-Info: mx02.eternal-september.org; posting-host="npc8WwhkFofBeKiRj5F6nA"; logging-data="9768"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//M4s2eJwMFnYJV+awzHHR" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:gezx4oifJXot3N3AUMEWUjX0nKw= sha1:o79KiIrZqsozTIhEAwpjYzeuGqk= Original-Xref: usenet.stanford.edu gnu.emacs.help:183306 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:77552 Archived-At: >> > 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