emacs-devel
[Top][All Lists]
Advanced

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

Re: Buffer listing in multiple frames/ttys


From: Károly Lőrentey
Subject: Re: Buffer listing in multiple frames/ttys
Date: Tue, 06 Dec 2005 13:44:53 +0100
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.52 (gnu/linux)

Richard Stallman <address@hidden> writes:
> bury-buffer is the only way to put a buffer at the end of the buffer
> list.  next-buffer must call bury-buffer in order to do that.

OK.

I note that `bury-buffer' removes the buffer from the frame-local
buffer lists of all frames, not just the selected one.  This is an
unwanted side-effect in this case, as we want the effects of
`next-buffer' to remain frame-local.  I propose to add an optional
parameter to `bury-buffer' to support this.

>     Now, I like these definitions as it makes more sense for me to keep
>     the buffer cycle frame-local, but they do have one disadvantage: the
>     `next-buffer'/`prev-buffer' cycle will not usually contain all
>     buffers---just those that were displayed in the current frame.
>
> As far as I can see, buffers that have never been displayed in this
> frame WILL be included.  other-buffer will find them, and prev-buffer
> will find them via the call to buffer-list.

In my quoted message, the definition of next buffer appends the old
buffer to the end of the frame-local buffer list.  Therefore, the
frame-local list will be recycled continously, and subsequent
`next-buffer' calls are prevented from reaching any buffers in the
global buffer list.

I appended to the end of this message enhanced versions of
`next-buffer' and `prev-buffer' that eliminate this problem by
maintaining a new auxiliary frame-local buffer list, called
`previous-buffer-list'.  `next-buffer' prepends the old buffer to this
list, and `prev-buffer' searches this list first; otherwise the two
functions behave as in CVS.

> However, I see that these functions do not find buffers that are
> currently displayed in some window.  I think that these commands
> should disregard whether the buffer is visible elsewhere.  That means
> passing t for the 2nd arg to other-buffer, and removing some code in
> prev-buffer.

I applied that change to these new versions.  I also agree with Juri's
suggestion to rename `prev-buffer' to `previous-buffer', for
consistency with the rest of Emacs.

(defun next-buffer ()
  "Switch to the next buffer in cyclic order."
  (interactive)
  (let ((buffer (current-buffer))
        (pbl (frame-parameter nil 'previous-buffer-list)))
    (switch-to-buffer (other-buffer buffer t))
    (bury-buffer buffer)
    (set-frame-parameter nil 'previous-buffer-list
                         (cons buffer (delq buffer pbl)))))

(defun prev-buffer ()
  "Switch to the previous buffer in cyclic order."
  (interactive)
  (let ((search-list
         #'(lambda (list)
             "Search LIST for a valid buffer to display."
             (let (found buffer)
               (while (and (not found) (list))
                 (setq buffer (car list))
                 (if (and (buffer-live-p buffer)
                          (not (string-match "\\` " (buffer-name buffer))))
                     (setq found buffer)
                   (setq list (cdr list))))
               list))))
    (let ((prev (funcall search-list (frame-parameter nil 
'previous-buffer-list))))
      (set-frame-parameter nil 'previous-buffer-list (cdr prev))
      (switch-to-buffer
       (or (car prev)
           (car (funcall search-list (nreverse (buffer-list)))))))))

-- 
Károly

Attachment: pgpuTbBXWzA5w.pgp
Description: PGP signature


reply via email to

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