[comp.emacs] How can I select the next buffer?

wmesard@oracle.com (Wayne Mesard) (10/12/90)

david@WUBIOS.WUSTL.EDU (David J. Camp) writes:
>I am looking for a command in emacs to easily alternate from one
>buffer to the next.  For example, if I am editing ~/.login and
>~/.cshrc, I may want to toggle between them without reentering 
>the filename.  This seesm like an reasonable thing to do, but I
>cannot find it in the documentation.  Thanks,  -David-

I wrote a function which does just that.  It was inspired by the
Control-Meta-L command from Symbolics' Zmacs editor.  You, of course,
can bind it to anything you like.

(global-set-key "\e\C-l" 'select-previous-buffer)

(defun select-previous-buffer (nth)
  "Like the useful parts of Zmacs' command of the same name.
With no arg it toggles between the two topmost buffers.  With an arg,
goes to the Nth buffer down on the stack, er, ring."
  (interactive "p")
  (let ((buf (current-buffer)))
    (while (not (zerop nth))
      (setq nth (1- nth))
      (setq buf (other-buffer buf))
      )
    (switch-to-buffer buf)
    ))

jlange@oracle.com (Jim Lange) (10/13/90)

The command bury-buffer will switch to the next buffer.  Just assign this to
a key sequence (I assign it to the SELECT key of a vt220).  This is much faster
than switch-to-buffer, even when you have to cycle through a few buffers to 
get to the one you want.

A few months ago someone posted lisp routines to support cycling both forward
and backward and someone else posted routines to toggle between the current and
last accessed buffer.

Jim Lange
Oracle Corporation