[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: buffer-list and desktop
From: |
Kevin Rodgers |
Subject: |
Re: buffer-list and desktop |
Date: |
Thu, 11 Nov 2004 11:14:01 -0700 |
User-agent: |
Mozilla Thunderbird 0.9 (X11/20041105) |
David Kastrup wrote:
> Jesper Harder <harder@myrealbox.com> writes:
>>Or if you don't mind requiring cl:
I do mind. :-)
>>(delete-if-not
>> (lambda (buf)
>> (desktop-save-buffer-p (buffer-file-name buf) (buffer-name buf)
>> (buffer-local-value 'major-mode buf)))
>> (buffer-list))
buffer-local-value is not defined in Emacs 21.3. Too bad, because
passing the buffer as an argument should be faster than using
with-current-buffer.
> Still slow because of one bind/unbind per iteration. If you want to
> do it that way, anyway, you could avoid cl by using
>
> (delq nil
> (mapcar
> (lambda (buf)
> (and (desktop-save-buffer-p ...)
> buf))
> (buffer-list)))
>
> with hardly more effort.
Your first idea to just push each buffer that satisifies the predicate
on to a result list is better. And I don't share your aversion to
variable bindings. :-)
So here's what I've come up with. The real problem I see is that the
buffer browsing commands (list-buffers and electric-buffer-list) don't
take the list of buffers as an argument, so you can't write new
desktop-save- versions of those commands that use the result of this
function.
(defun desktop-save-buffer-list ()
"Return the list of buffers that `desktop-save' would save."
(let ((buffer-list '()))
(mapc (lambda (buffer)
(with-current-buffer buffer
(when (desktop-save-buffer-p (buffer-file-name)
(buffer-name)
major-mode)
(setq buffer-list (cons buffer buffer-list)))))
(buffer-list))
(nreverse buffer-list)))
--
Kevin Rodgers