emacs-devel
[Top][All Lists]
Advanced

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

Re: other-buffer advice on kill-buffer


From: Stephen J. Turnbull
Subject: Re: other-buffer advice on kill-buffer
Date: Wed, 03 Aug 2011 16:41:57 +0900

Antoine Levitt writes:
 > 02/08/11 01:03, Jérémy Compostella

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

`other-buffer''s advice will be respected if called as

    Ffuncall(n, intern("other-buffer"), ...)

but not if called as

    Fother_buffer(...)

 > > Is there a restriction on advices for C implemented function ?

No, you can advise functions implemented in C just like any other
function.  The question is whether they are called via their symbol
(ie, with Ffuncall), or via the C-level function.

 > > How the kill-buffer function select the new displayed buffer ? Could I
 > > really modify its behavior and how ?

 > I believe you can't advice a C function (not sure). In any case, advice
 > is generally best left as last resort.

Actually, advice is best used as a first resort.  If it doesn't work
(as here), or if you want to distribute it with Emacs, then you need
to do things more carefully.  Besides the fact that advice for `foo'
will be ignored by C functions that call Ffoo directly, the big
problem with an advice'd function is that it's not standard and
therefore different people will get different results from using the
function.

In this case, that is exactly what Jérémy wants, so no problem!

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

You might also consider using kill-buffer-hook to manipulate the
buffer list, eg by doing a switch-to-prev-buffer there.



reply via email to

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