* buffer-list and desktop
@ 2004-11-10 12:13 Matthias
2004-11-10 19:30 ` Kevin Rodgers
0 siblings, 1 reply; 8+ messages in thread
From: Matthias @ 2004-11-10 12:13 UTC (permalink / raw)
Hi,
Is there a ready-made command, or package to list buffers that will be
saved by desktop.el?
Thank you for your attention.
--
Matthias
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: buffer-list and desktop
2004-11-10 12:13 buffer-list and desktop Matthias
@ 2004-11-10 19:30 ` Kevin Rodgers
2004-11-10 22:06 ` Kevin Rodgers
0 siblings, 1 reply; 8+ messages in thread
From: Kevin Rodgers @ 2004-11-10 19:30 UTC (permalink / raw)
Matthias wrote:
> Is there a ready-made command, or package to list buffers that will be
> saved by desktop.el?
Here's a start:
(defun desktop-list-buffers ()
"Return the list of buffers that `desktop-save' would save."
(nreverse
(apply 'nconc
(mapcar (lambda (buffer)
(save-excursion
(set-buffer buffer)
(if (desktop-save-buffer-p (buffer-file-name)
(buffer-name)
major-mode)
(list buffer))))
(buffer-list)))))
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: buffer-list and desktop
2004-11-10 19:30 ` Kevin Rodgers
@ 2004-11-10 22:06 ` Kevin Rodgers
2004-11-10 22:18 ` David Kastrup
2004-11-10 22:35 ` Jesper Harder
0 siblings, 2 replies; 8+ messages in thread
From: Kevin Rodgers @ 2004-11-10 22:06 UTC (permalink / raw)
Kevin Rodgers wrote:
> Here's a start:
Gotta get used to using with-current-buffer:
(defun desktop-list-buffers ()
"Return the list of buffers that `desktop-save' would save."
(nreverse
(apply 'nconc
(mapcar (lambda (buffer)
(with-current-buffer buffer
(if (desktop-save-buffer-p (buffer-file-name)
(buffer-name)
major-mode)
(list buffer))))
(buffer-list)))))
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: buffer-list and desktop
2004-11-10 22:06 ` Kevin Rodgers
@ 2004-11-10 22:18 ` David Kastrup
2004-11-10 22:35 ` Jesper Harder
1 sibling, 0 replies; 8+ messages in thread
From: David Kastrup @ 2004-11-10 22:18 UTC (permalink / raw)
Kevin Rodgers <ihs_4664@yahoo.com> writes:
> Kevin Rodgers wrote:
> > Here's a start:
>
> Gotta get used to using with-current-buffer:
>
> (defun desktop-list-buffers ()
> "Return the list of buffers that `desktop-save' would save."
> (nreverse
> (apply 'nconc
> (mapcar (lambda (buffer)
> (with-current-buffer buffer
> (if (desktop-save-buffer-p (buffer-file-name)
> (buffer-name)
> major-mode)
> (list buffer))))
> (buffer-list)))))
Actually, you are trying too hard to be smart: the code is rather
inefficient. You'll get by better with
(defun desktop-list-buffers ()
"..."
(let ((lst))
(dolist (buffer (buffer-list) lst)
(with-current-buffer buffer
(when (desktop-save-buffer-p ...)
(push buffer lst))))))
This only has two variable bindings (lst and the list for dolist), and
none in the loop.
In contrast, your version binds and unbinds buffer fresh for every
iteration, and it needs a (slow) call to apply/nconc with a large
number of arguments.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: buffer-list and desktop
2004-11-10 22:06 ` Kevin Rodgers
2004-11-10 22:18 ` David Kastrup
@ 2004-11-10 22:35 ` Jesper Harder
2004-11-10 22:48 ` David Kastrup
1 sibling, 1 reply; 8+ messages in thread
From: Jesper Harder @ 2004-11-10 22:35 UTC (permalink / raw)
Kevin Rodgers <ihs_4664@yahoo.com> writes:
> Gotta get used to using with-current-buffer:
>
> (defun desktop-list-buffers ()
> "Return the list of buffers that `desktop-save' would save."
> (nreverse
> (apply 'nconc
> (mapcar (lambda (buffer)
> (with-current-buffer buffer
> (if (desktop-save-buffer-p (buffer-file-name)
> (buffer-name)
> major-mode)
> (list buffer))))
> (buffer-list)))))
Or if you don't mind requiring cl:
(delete-if-not
(lambda (buf)
(desktop-save-buffer-p (buffer-file-name buf) (buffer-name buf)
(buffer-local-value 'major-mode buf)))
(buffer-list))
--
Jesper Harder <http://purl.org/harder/>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: buffer-list and desktop
2004-11-10 22:35 ` Jesper Harder
@ 2004-11-10 22:48 ` David Kastrup
2004-11-11 18:14 ` Kevin Rodgers
0 siblings, 1 reply; 8+ messages in thread
From: David Kastrup @ 2004-11-10 22:48 UTC (permalink / raw)
Jesper Harder <harder@myrealbox.com> writes:
> Kevin Rodgers <ihs_4664@yahoo.com> writes:
>
>> Gotta get used to using with-current-buffer:
>>
>> (defun desktop-list-buffers ()
>> "Return the list of buffers that `desktop-save' would save."
>> (nreverse
>> (apply 'nconc
>> (mapcar (lambda (buffer)
>> (with-current-buffer buffer
>> (if (desktop-save-buffer-p (buffer-file-name)
>> (buffer-name)
>> major-mode)
>> (list buffer))))
>> (buffer-list)))))
>
> Or if you don't mind requiring cl:
>
> (delete-if-not
> (lambda (buf)
> (desktop-save-buffer-p (buffer-file-name buf) (buffer-name buf)
> (buffer-local-value 'major-mode buf)))
> (buffer-list))
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.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: buffer-list and desktop
2004-11-10 22:48 ` David Kastrup
@ 2004-11-11 18:14 ` Kevin Rodgers
2004-11-12 5:05 ` Matthias
0 siblings, 1 reply; 8+ messages in thread
From: Kevin Rodgers @ 2004-11-11 18:14 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: buffer-list and desktop
2004-11-11 18:14 ` Kevin Rodgers
@ 2004-11-12 5:05 ` Matthias
0 siblings, 0 replies; 8+ messages in thread
From: Matthias @ 2004-11-12 5:05 UTC (permalink / raw)
Kevin Rodgers <ihs_4664@yahoo.com> wrote:
> (...) 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.
Exactly! May be one should change `list-buffers' so that it accept a
second optional argument, a list of buffers!!
Thank you very much Kevin, David and Jesper.
--
Matthias
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2004-11-12 5:05 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-10 12:13 buffer-list and desktop Matthias
2004-11-10 19:30 ` Kevin Rodgers
2004-11-10 22:06 ` Kevin Rodgers
2004-11-10 22:18 ` David Kastrup
2004-11-10 22:35 ` Jesper Harder
2004-11-10 22:48 ` David Kastrup
2004-11-11 18:14 ` Kevin Rodgers
2004-11-12 5:05 ` Matthias
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.