[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fix to buff-sel.el
From: |
David Kreil |
Subject: |
Fix to buff-sel.el |
Date: |
Mon, 12 Apr 2004 19:24:46 +0100 |
Hi,
I am not sure whether there is anyone maintaining the buff-sel library now,
considering that the last trace of a contactable person is dated 1992 and that
I cannot find an obvious source of the file in the first place. Please let me
know, however, if there is!
I have found buff-sel.el most useful in the past but noticed that it has
become broken in newer emacs versions. Please find a fixed buff-sel that works
with modern emacs versions below.
With best regards,
David.
; Newsgroups: gnu.emacs.sources
; Path: hal.com!decwrl!uunet!brunix!doorknob!rsw
; From: address@hidden (Bob Weiner)
; Subject: buf-sel.el - Minibuffer buffer selection and killing with
completion.
; Organization: Brown U.
; Date: Wed, 25 Mar 1992 20:36:51 GMT
;
;; LCD Archive Entry:
;; buf-sel|Tomn Horsley|address@hidden|
;; Interactive buffer-list in the minibuffer.|
;; 92-03-25||~/misc/buf-sel.el.Z|
;;
;; =====================================================================
;; usenet: address@hidden USMail: Tom Horsley
;; compuserve: 76505,364 511 Kingbird Circle
;; genie: T.HORSLEY Delray Beach, FL 33444
;; ======================== Aging: Just say no! ========================
;;
;; This file provides an interactive buffer-list capability.
;; When the function select-buffer is invoked, the minibuffer
;; prompts you for another buffer to select. The default is the second
;; buffer on the buffer-list. Also, all the keys that are normally
;; bound to next-line and previous-line are bound to functions that
;; navigate through the buffer list. Any keys bound to kill-buffer
;; are rebound to a function that will kill the buffer currently
;; named in the minibuffer, then move to the next buffer on the list.
;; This is a faster means of selecting another buffer than buffer-menu
;; is, but with most of the power.
;;
;; Bob Weiner, Motorola, Inc., 4/5/89
;; Added 'select-buffer-other-window' command bound to {C-x4b}
;; usually.
;;
;; Bob Weiner, Motorola, Inc., 10/3/91
;; Eliminated inefficient recursion for computing buffer list.
;; This eliminated error of passing max-lisp-eval-depth when working
;; with many buffers.
;; Added completion to 'select-buffer' so it works like standard
;; 'switch-to-buffer' function.
;;
;; We have gotten to where we use this technique for several of the
;; packages we have written where something prompts for input, each
;; command keeps its own history list so you can quickly cycle through
;; the previous input to just that command.
;;
;; It is very handy to rebind the keys where next line is, so you can
;; continue to use any cursor keys.
;;
;; (autoload 'select-buffer "buff-sel" nil t)
;; (global-set-key "\C-xb" 'select-buffer)
;; (global-set-key "\C-x4b" 'select-buffer-other-window)
;;
;; Modifications:
;; --------------
;; Modified on: 2 April 1992
;; Modified by: Uffe Kjaerulff <<EMAIL: PROTECTED>>
;; Description: Prompt changed from "Switch to buffer: " to
;; "Switch to buffer: (default <next buffer>) " and
;; initial input changed from "<next buffer>" to "".
;; In this way 'select-buffer' differs from the
;; standard 'switch-to-buffer' only by providing the
;; interactive buffer-list capability described above.
;; The fix eliminates the need to delete the initial input
;; before typing (the prefix of) the name of a buffer.
;; (Typically, you don't want to use the 'next-line'/
;; 'previous-line' keys to obtain a buffer name if it's
;; to be found far down the buffer list.)
;;
;; Modified on: 8 May 1995
;; Modified by: Jerry Quinn <<EMAIL: PROTECTED>>
;; Description: Changed default next buffer from 2nd on list to the output
;; of other-buffer. If more than one window was displayed,
;; every change of buffer would default to the other one already
;; shown.
;;
;; Modified on: 1 Feb 1997
;; Modified by: Jerry Quinn <<EMAIL: PROTECTED>>
;; Description: Above change sometimes caused the first buffer-select-prev to
;; offer the default choice. Fixed means of computing
;; buffer-select-list-index.
;;
;; Modified on: 12 Apr 2004
;; Modified by: D P Kreil, address@hidden
;; Description: erase-buffer conflicts with modern minibuffer prompt display
;; as a read-only field. Changed to delete-field.
;;
(defvar buffer-select-list-index 0 "Index into buffer-list")
(defvar buffer-select-local-list nil "Local copy of buffer-list")
(defvar buffer-select-minibuffer-map
(copy-keymap minibuffer-local-completion-map)
"This is a copy of the minibuffer completion keymap with all the keys that
were bound to next-line now bound to buffer-select-next and all the keys
that were bound to previous-line now bound to buffer-select-prev.")
(mapcar
(function
(lambda (keyseq)
(define-key buffer-select-minibuffer-map keyseq 'buffer-select-prev)))
(where-is-internal 'previous-line nil nil))
(mapcar
(function
(lambda (keyseq)
(define-key buffer-select-minibuffer-map keyseq 'buffer-select-next)))
(where-is-internal 'next-line nil nil))
(mapcar
(function
(lambda (keyseq)
(define-key buffer-select-minibuffer-map keyseq 'buffer-select-kill-buf)))
(where-is-internal 'kill-buffer nil nil))
(defun make-buffer-list (buffer-list)
"Returns names from BUFFER-LIST excluding those beginning with a space."
(delq nil (mapcar '(lambda (b)
(if (= (aref (buffer-name b) 0) ? ) nil b))
buffer-list)))
(defun select-buffer (&optional other-window)
"Interactively select or kill buffer using the minibuffer.
Optional argument OTHER-WINDOW non-nil means display buffer in another window.
The default buffer is the second one in the buffer-list. Other buffers can
selected either explicitly, or by using buffer-select-next and
buffer-select-prev. Keys normally bound to next-line are bound to
buffer-select-next, those normally bound to previous-line are bound to
buffer-select-prev, and those normally bound to kill-buffer are bound to
buffer-select-kill-buf."
(interactive)
(setq buffer-select-local-list (make-buffer-list (buffer-list)))
(let ((save-minibuffer-map minibuffer-local-completion-map)
(default-buffer (buffer-name (other-buffer)))
inpt)
(setq inpt
(unwind-protect
(progn
(setq minibuffer-local-completion-map
buffer-select-minibuffer-map
;; count-windows was used, but didn't work right
buffer-select-list-index
(1- (length (memq (other-buffer)
(reverse buffer-select-local-list)))))
(completing-read (concat
"Switch to buffer"
(if other-window " in other window")
": (default " default-buffer ") ")
(mapcar '(lambda (buf)
(list (buffer-name buf)))
buffer-select-local-list)
nil nil nil)
)
(setq minibuffer-local-completion-map save-minibuffer-map)
))
(if (string-equal inpt "")
(setq inpt default-buffer))
(if other-window
(switch-to-buffer-other-window inpt)
(switch-to-buffer inpt))
))
(defun select-buffer-other-window ()
"See documentation for 'select-buffer'."
(interactive)
(select-buffer t))
(defun buffer-select-next ()
"Move to the next buffer on the buffer-list."
(interactive)
; (erase-buffer) ; bad: also tries to delete read-only Prompt field
(delete-field)
(setq buffer-select-list-index (1+ buffer-select-list-index))
(if (>= buffer-select-list-index (length buffer-select-local-list))
(setq buffer-select-list-index 0)
)
(insert (buffer-name (nth buffer-select-list-index
buffer-select-local-list)))
)
(defun buffer-select-prev ()
"Move to the previous buffer on the buffer-list."
(interactive)
; (erase-buffer) ; bad: also tries to delete read-only Prompt field
(delete-field)
(setq buffer-select-list-index (1- buffer-select-list-index))
(if (< buffer-select-list-index 0)
(setq buffer-select-list-index (1- (length buffer-select-local-list)))
)
(insert (buffer-name
(nth buffer-select-list-index buffer-select-local-list)))
)
(defun buffer-select-kill-buf ()
"Kill the buffer currently appearing in the minibuffer, then move to
the next buffer on the buffer-list."
(interactive)
(let
(
(mbuf (current-buffer)) ;; Save the minibuffer because
;; kill-buffer selects a buffer
(kbuf (nth buffer-select-list-index buffer-select-local-list))
)
(message "Killing buffer %s." (buffer-name kbuf))
(kill-buffer kbuf)
(set-buffer mbuf)
)
;; Rebuild the buffer list, so that the killed buffer doesn't appear
;; in it. Under certain circumstances, the buffer might not have
;; gone away, such as killing "*scratch*" when it is the last buffer.
(setq buffer-select-local-list (make-buffer-list (buffer-list)))
;; Fix buffer-select-list-index, in case it went off the end of
;; the list (in either direction, just to be absolutely safe).
(if (< buffer-select-list-index 0)
(setq buffer-select-list-index (1- (length buffer-select-local-list)))
)
(if (>= buffer-select-list-index (length buffer-select-local-list))
(setq buffer-select-list-index 0)
)
(erase-buffer)
(insert (buffer-name
(nth buffer-select-list-index buffer-select-local-list)))
)
;; end of file buff-sel.el
------------------------------------------------------------------------
Dr David Philip Kreil ("`-''-/").___..--''"`-._
Research Fellow `6_ 6 ) `-. ( ).`-.__.`)
University of Cambridge (_Y_.)' ._ ) `._ `. ``-..-'
++44 1223 764107, fax 333992 _..`--'_..-_/ /--'_.' ,'
www.inference.phy.cam.ac.uk/dpk20 (il),-'' (li),' ((!.-'
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Fix to buff-sel.el,
David Kreil <=