;;; iswitchb-narrow.el --- narrow the iswitch buffer to subsets ;; Author: Mark Triggs ;; 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: ;; Causes iswitchb's TAB to cycle through sets of buffers matching predicates ;; in ISWITCHB-NARROW-PREDICATES. ;; ;; Just bind ISWITCHB-WITH-NARROWING to a key with a form like: ;; ;; (define-key global-map (kbd "C-x b") 'iswitchb-with-narrowing) ;; ;; And add predicates to ISWITCHB-NARROW-PREDICATES. Each predicate should be ;; a function that takes a buffer and returns non-nil if that buffer should be ;; included in the narrowed buffer list. ;;; Code: (defvar iswitchb-narrow-predicates (list (lambda (b) (eq (buffer-mode this-buffer) (buffer-mode (get-buffer b))))) "Each time TAB is pressed when running iswitchb-with-narrowing, the next predicate in this list is used to filter the buffer list. Each predicate should be a function of one argument that returns non-nil if the function should be included in the listing") (defvar iswitchb-narrow-predicate-idx 0 "An index into ISWITCHB-NARROW-PREDICATES. Intended for internal use.") (defun iswitchb-with-narrowing () "Run an iswitchb-buffer with support for narrowing. Each time TAB is pressed, the list of buffers will be filtered using the next predicate in ISWITCHB-NARROW-PREDICATES." (interactive) (let ((this-buffer (current-buffer))) (let ((iswitchb-minibuffer-setup-hook (cons (lambda () (define-key iswitchb-mode-map "\t" 'iswitchb-narrow-next)) iswitchb-minibuffer-setup-hook))) (setq iswitchb-narrow-predicate-idx -1) (iswitchb-buffer)))) (defun iswitchb-narrow-next () "Narrow the iswitch buffer using the next predicate in ISWITCHB-NARROW-PREDICATES" (interactive) (incf iswitchb-narrow-predicate-idx) (let* ((next-predicate (cond ((= iswitchb-narrow-predicate-idx (length iswitchb-narrow-predicates)) (setq iswitchb-narrow-predicate-idx -1) 'identity) (t (nth iswitchb-narrow-predicate-idx iswitchb-narrow-predicates)))) (iswitchb-make-buflist-hook (cons (lambda () (setq iswitchb-temp-buflist (remove-if-not next-predicate iswitchb-temp-buflist))) iswitchb-make-buflist-hook)) (iswitchb-rescan t)) (iswitchb-make-buflist nil) (setq iswitchb-buflist (delq nil iswitchb-buflist)) (iswitchb-set-matches))) (provide 'iswitchb-narrow) ;;; iswitchb-narrow.el ends here