;;; buffer-select.el --- Quick selection of next and previous buffers ;; Copyright (C) 1998, 2001 Stéphane Levant ;; Author: Stéphane Levant ;; Created: Feb 1998 ;; Keywords: convenience ;; Version: 1.1 ;; URL: http://arsunik.free.fr/emacs ;; This file 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 file 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, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; A very usefull way of switching buffer: ;; The functions `buffer-select+' and `buffer-select-' allow you to switch to ;; the next or the previous buffer, excluding the buffers which match ;; `buffer-select-regexp'. The default is to don't see the Emacs buffers ;; which begin and end with a "*". ;; The functions `buffer-all-select+' and `buffer-all-select-' allow you to ;; switch to the next or the previous buffer. ;; The functions `buffer-select-swap' only switch with the previous buffer. ;; This allow to switch between two buffers. ;; ;; INSTALL: put this lines in your .emacs: ;; (autoload 'buffer-select+ "buffer" "" t) ;; (autoload 'buffer-select- "buffer" "" t) ;; (autoload 'buffer-all-select+ "buffer" "" t) ;; (autoload 'buffer-all-select- "buffer" "" t) ;; (autoload 'buffer-select-swap "buffer" "" t) ;; ;; sample keys ;; (global-set-key [M-right] 'buffer-select+) ;; (global-set-key [M-left] 'buffer-select-) ;; (global-set-key [M-S-right] 'buffer-select-all+) ;; (global-set-key [M-S-left] 'buffer-select-all-) ;; (global-set-key [M-] 'buffer-select-all-) ;;; Code: (defvar buffer-select-regexp "^\\( ?\\*.*\\*\\|TAGS\\)" "Regexp which match some buffers which will be ignored by `buffer-select+' and `buffer-select-'.") ;;;###autoload (defun buffer-select-swap () "Switch between two buffers : switch to the previous buffer." (interactive) (let ((l (cdr (buffer-list)))) (while (string-match "\\*Minibuf" (buffer-name (car l))) (setq l (cdr l))) (switch-to-buffer (car l)))) ;;;###autoload (defun buffer-select+() "Switch to the last buffer of the buffer list The buffer which match `buffer-select-regexp' are ignored. Use `buffer-select-all+' to have all buffers." (interactive) (buffer-exclut+ buffer-select-regexp)) ;;;###autoload (defun buffer-select-() "Make the current buffer the last buffer of the buffer list and so, switch to the second buffer of the buffer list. The buffer which match `buffer-select-regexp' are ignored. Use `buffer-select-all+' to have all buffers." (interactive) (buffer-exclut- buffer-select-regexp)) ;;;###autoload (defun buffer-select-all+() "Sélectionne le dernier buffer dans la liste des buffers" (interactive) (buffer-exclut+ "^ \\*Minibuf.*\\*$")) ;;;###autoload (defun buffer-select-all-() "Place le buffer courant en dernière position dans la liste des buffers donc selectionne le deuxième buffer dans la liste des buffers" (interactive) (buffer-exclut- "^ \\*Minibuf.*\\*$")) (defun buffer-exclut+ (regexp) (let ((l (reverse (buffer-list))) (buf (current-buffer))) (while (progn (if l nil (switch-to-buffer buf) (error "No buffer to display")) (switch-to-buffer (car l)) (setq l (cdr l)) (string-match regexp (buffer-name (current-buffer))))))) (defun buffer-exclut- (regexp) (let ((n (length (buffer-list))) (k 0) (buf (current-buffer))) (while (progn (setq k (1+ k)) (if (<= k n) nil (switch-to-buffer buf) (error "No buffer to display")) (bury-buffer) (string-match regexp (buffer-name (current-buffer))))))) ;;; buffer-select.el ends here