tags:

views:

39

answers:

2

I'm trying to write a plugin that calls a function (icalendar-import-file) which has the nasty side effect of opening between 1 and 3 buffers every time it is called, and sometimes I want to call it a whole bunch of times.

I can't even find a function that will list buffers without popping up a new buffer, which is a little frustrating.

As far as I can tell that defun (ical...) doesn't return anything useful, so the two obvious solutions to me are to either: (1) set a variable to a list of buffers before I run the function, and then sweep through the buffers that exist after the function exits and delete the new ones, (something like save-excursion, but for buffers) or (2) somehow suppress the creation. It looks like ical... is pretty heavily dependent on this, though, so I'm not sure that that's feasible.

+3  A: 

Are you looking for the function :

buffer-list is a built-in function in `C source code'.

(buffer-list &optional FRAME)

Return a list of all existing live buffers. If the optional arg FRAME is a frame, we return the buffer list in the proper order for that frame: the buffers in FRAME's `buffer-list' frame parameter come first, followed by the rest of the buffers.

Chmouel Boudjnah
Oh jeez. Yeah. I spent too many hours trying to figure out how to deal with list-buffers... Thanks!
quodlibetor
A: 

If you know which function is creating the unwanted buffers, and understand what effect removing them will have, you could always advise them (using after advice) to remove the unwanted buffer right at the source of the problem. I think this is safer than simply removing any new buffer once a function has finished.

Joe Casadonte
I considered that, but the buffer names are dynamic, and not provided by import-icalendar. Also, I'm pretty sure that defadvice works universally in emacs, right? I don't want to seriously modify an internal function just because it's inconvenient for me. The buffer-list sweep works well enough for me, I think, for as long as emacs remains single-threaded. Because nothing between when I create the list and when i delete extra buffers outside processes.
quodlibetor