;;; Saved through ges-version 0.3.3dev at 2003-03-01 15:10 ;;; ;;; From: Richard Klinda ;;; ;;; Subject: cyclebuffer.el 1.3 -- select buffer by cycling through ;;; ;;; Newsgroups: gnu.emacs.sources ;;; ;;; Date: Sat, 01 Mar 2003 15:02:40 +0100 ;;; ;;; Organization: YOU'D cry too if it happened to YOU!! ;;; --=-=-= ;;; Dear Users, ;;; After 5 years of development, here is cyclebuffer version 1.3 for your ;;; enjoyment. I took over the maintainership of this package from the ;;; original author, Kurt Partridge. If you want to say "whoa this is so ;;; cool and easy to use, thank you for cyclebuffer!" you can reach him at ;;; kepart AT cs DOT washington DOT edu; with problems, wishes and ;;; suggestions please contact me. ;;; --=-=-= ;;; Content-Type: application/emacs-lisp ;;; Content-Disposition: attachment; filename=cyclebuffer.el ;;; Content-Transfer-Encoding: 8bit ;;; Content-Description: cyclebuffer.el 1.3 ;;; cyclebuffer.el --- select buffer by cycling through ;;; Commentary: ;; Description: ;; ------------ ;; Cyclebuffer is yet another way of selecting buffers. Instead of ;; prompting you for a buffer name, cyclebuffer-forward switches to the ;; most recently used buffer, and repeated invocations of ;; cyclebuffer-forward switch to less recently visited buffers. If you ;; accidentally overshoot, calling cyclebuffer-backward goes back. ;; ;; I find this to be the fastest buffer-switching mechanism; it`s like C-x ;; b w/out the return, but it`s not limited to the most recently ;; accessed buffer. Plus you never have to remember buffer names; you ;; just keep cycling until you recognize the buffer you`re searching for. ;; Installation: ;; ------------- ;; Add these lines in your .emacs: ;; (autoload `cyclebuffer-forward "cyclebuffer" "cycle forward" t) ;; (autoload `cyclebuffer-backward "cyclebuffer" "cycle backward" t) ;; (global-set-key "M-N" 'cyclebuffer-forward) ;; (global-set-key "M-P" 'cyclebuffer-backward) ;; ;; If you think you may need cyclebuffer-forward-same-mode and ;; cyclebuffer-backward-same-mode, don't forget to bind them too: ;; (global-set-key "C-M-N" 'cyclebuffer-forward-same-mode) ;; (global-set-key "C-M-P" 'cyclebuffer-backward-same-mode) ;; ;; You may want to adjust the keyboard bindings to avoid conflicts ;; with whatever other packages you`re using... ;; ;; {rklinda} I like to bind cyclebuffer functions to the F keys F11, ;; F12 and C-F11, C-F12. ;; ;; Change History: ;; 18 Feb 98 v1.2 Bug fixes, code simplification. ;; 01 Mar 03 v1.3 New functions (*-same-mode) and new maintainer. ;; ;; Thanks to Henry Harpending for suggestions. ;; ;; Author: Kurt Partridge ;; Maintainer: Richard Klinda (TMDA address) ;; Created: 05 June 1996 ;; Version: $Revision: 1.3 $ ;; URL: http://ignotus.linuxforum.hu/cyclebuffer.el ;; Keywords: switch-to-buffer ;; LCD Archive Entry: ;; cyclebuffer|Richard Klinda|ignotus@my.gnus.org| ;; Select buffers by cycling.| ;; 01-Mar-03|Version 1.3| ;; Copyright (C) 1996 Kurt Partridge ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, 675 Massachusettes Ave, ;; Cambridge, MA 02139, USA. (defvar cyclebuffer-buffer-list nil "List of all buffers; updated every time a new set of cyclebuffer commands are started.") (defvar cyclebuffer-buffer-index nil "Number indicating the index of the buffer in cyclebuffer-buffer-list that is currently being displayed.") (defun cyclebuffer-forward (&optional direction same-major-p) "Like switch-to-buffer, but doesn`t prompt. Repetitive invocations of this function select progressively less recently visited buffers. If same-major-p is T then it will only select buffers that has the same major mode as the starting one." (interactive "P") ;; If starting a new search, a) make sure the current buffer is at top ;; of the list of buffers, and b) set flag to generate a new list (if (not (or (eq `cyclebuffer-forward last-command) (eq `cyclebuffer-backward last-command) (eq `cyclebuffer-forward-same-mode last-command) (eq `cyclebuffer-backward-same-mode last-command))) (progn (setq cyclebuffer-buffer-index nil) (switch-to-buffer (current-buffer)))) ;; Generate new list if necessary (if (not (numberp cyclebuffer-buffer-index)) (let ((major major-mode)) (setq cyclebuffer-buffer-list (if same-major-p (loop for buffer in (buffer-list) when (and (set-buffer buffer) (eq major-mode major)) collect buffer) (buffer-list))) (setq cyclebuffer-buffer-index 0))) ;; Cycle through buffers, skipping any invisible buffers (whose ;; names start with a blank space) (let ((start-buffer (current-buffer)) (chosen-buffer (current-buffer))) (while (or (eq chosen-buffer start-buffer) (char-equal ? (string-to-char (buffer-name chosen-buffer)))) (setq start-buffer nil) (if (or (null direction) (eq direction 1)) (setq cyclebuffer-buffer-index (+ cyclebuffer-buffer-index 1)) (setq cyclebuffer-buffer-index (- cyclebuffer-buffer-index 1))) (setq cyclebuffer-buffer-index (mod cyclebuffer-buffer-index (length cyclebuffer-buffer-list))) (setq chosen-buffer (nth cyclebuffer-buffer-index cyclebuffer-buffer-list))) (switch-to-buffer chosen-buffer))) (defun cyclebuffer-backward (&optional same-major-p) "Like cyclebuffer-forward, but selects progressively more recently visited buffers." (interactive) (cyclebuffer-forward -1 same-major-p)) (defun cyclebuffer-forward-same-mode (&optional direction) "This is a variation of cyclebuffer-forward, it selects buffers with the same major-mode as the starting one." (interactive) (cyclebuffer-forward direction t)) (defun cyclebuffer-backward-same-mode () "Like cyclebuffer-forward-same-mode, but selects progressively more recently visited buffers with the same major-mode as the starting one." (interactive) (cyclebuffer-forward-same-mode -1)) (provide 'cyclebuffer) ;;; --=-=-= ;;; -- ;;; Richard ;;; If you are smart enough to know that you're not smart ;;; enough to be an Engineer, then you're in Business. ;;; --=-=-=--