home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / emacs / 3471 < prev    next >
Encoding:
Text File  |  1992-11-07  |  2.0 KB  |  49 lines

  1. Newsgroups: comp.emacs
  2. Path: sparky!uunet!gatech!news.byu.edu!hamblin.math.byu.edu!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!ftpbox!mothost!merlin.dev.cdx.mot.com!fendahl.dev.cdx.mot.com!mcook
  3. From: mcook@fendahl.dev.cdx.mot.com (Michael Cook)
  4. Subject: Re: anyone got a way to cycle through buffers with a keystroke?
  5. Message-ID: <mcook.720989949@fendahl.dev.cdx.mot.com>
  6. Sender: news@merlin.dev.cdx.mot.com (USENET News System)
  7. Nntp-Posting-Host: fendahl.dev.cdx.mot.com
  8. Organization: Motorola Codex, Canton, Massachusetts
  9. References: <EJH.92Nov4132905@khonshu.colorado.edu>
  10. Date: Thu, 5 Nov 1992 18:59:09 GMT
  11. Lines: 36
  12.  
  13. ejh@khonshu.colorado.edu (Edward J. Hartnett) writes:
  14.  
  15. >Hi. I often have maybe 5 or 10 programs and other files open at once, and
  16. >switch back and forth more or less randomly. It's very annoying that I have
  17. >to tyep out the buffer name I want each time (even with tab completion). Does
  18. >anyone out there have any elisp code that would allow me to cycle through the
  19. >buffers with a keystroke? So I'd hit a key and the buffer would switch to the
  20. >next one, then again and it would go to the next, etc. Then I could just pop
  21. >pop pop on the key until the buffer I wanted came up.  -- Edward
  22.  
  23. Here what I use:
  24.  
  25. (defvar cycle-buffers nil
  26.   "List of buffers we've cycled through so far.")
  27.  
  28. (defun cycle-buffer ()
  29.   "Switch to another buffer."
  30.   (interactive)
  31.   (or (eq last-command this-command)
  32.       (setq cycle-buffers nil))
  33.   (let ((list (buffer-list)))
  34.     (setq cycle-buffers (cons (car list) cycle-buffers))
  35.     (while (or (and list
  36.             (let ((name (buffer-name (car list))))
  37.               (or (string-equal name "")
  38.               (= (aref name 0) ? ))))
  39.            (memq (car list) cycle-buffers))
  40.       (setq list (cdr list)))
  41.     (switch-to-buffer (or (car list)
  42.               (other-buffer)))))
  43.  
  44. Bind it to a key, then each time you press that key, it shows you another
  45. buffer.  If you press any other keys in between, it'll start from the
  46. beginning of the buffer list again.
  47.  
  48. Michael.
  49.