[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: other-buffer advice on kill-buffer

From: Jérémy Compostella
Subject: Re: other-buffer advice on kill-buffer
Date: Tue, 02 Aug 2011 02:06:44 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Antoine Levitt <address@hidden> writes:

> 02/08/11 01:03, Jérémy Compostella
>> All,
>> I'm trying to modify the behavior of the kill-buffer function to fit my
>> needs. I would like to limit the list of eligible buffers used to select
>> the buffer which will be displayed in place of the killed buffer.
>> I have tried to advice the other-buffer function which seems called
>> (Cf. buffer.c) but my advice is never called in this case. Indeed, my
>> other-buffer advice is correctly called on switch-to-buffer call but
>> never on kill-buffer call.
>> So am I missing something ?
>> Is there a restriction on advices for C implemented function ?
>> How the kill-buffer function select the new displayed buffer ? Could I
>> really modify its behavior and how ?
>> Thanks for your help.
>> Jeremy
> Hi Jeremy,
> I believe you can't advice a C function (not sure). In any case, advice
> is generally best left as last resort. What's keeping you from defining
> your own my-kill-buffer that'd call kill-buffer (which would switch to
> the most recent buffer) and then do some buffer switching of your own?
> Also see the docstring of kill-buffer. In particular, the docstring
> tells you than it calls replace-buffer-in-windows, and then the source
> code for replace-buffer-in-windows tells you that it calls
> switch-to-prev-buffer. So if you must advice or redefine an emacs
> function, these two look like better access points.
Thanks I will take a look at it.

> Just out of curiosity, what buffers are you trying to exclude?
I developed an activity manager since I use Emacs as my full desktop
environment (Web, Mail, Jabber, Code with different project at the same

This activity module let me define statically and dynamically
activities. Activities are named and have open/enable/disable handlers to
modify the Emacs behavior in regards of what I like to do under a
particular activity.

It provides functions to switch between activities remembering the
window configuration and now it has the ability to help me to select a
relevant buffer. Actually in some occasion I have several thousands of
buffers for different kind of activities / projects. So I particularly
appreciate this help to select the buffer I want to display by
pre-filtering the buffer list.

Moreover, each visited buffer is automatically associated to the current
activity. So I have a issue when I switch to another activty and call
the kill-buffer function. A buffer of the previous activity is usually
selected in place of the killed buffer and this newly selected buffer is
automatically associated to the current activity which is not the
behavior I wish. I would like the newly selected buffer is selected from
the current activity buffer list.

The activity is written as less intrusive as possible. Yet, for this
issue if I use the kill-buffer function a badly selected buffer will be
associated to the current activity. So, even if I add an advice to
switch to a relevant buffer afterwards I will have to unassociated the
non-relevant buffer. Therefore I don't see another clean way than
modifying the kill-buffer function behavior to prevent this unrelevant
buffer selection issue.

You could take a look at:

Best regards,

Sent from my Emacs

reply via email to

[Prev in Thread] Current Thread [Next in Thread]