(defun iswitchb-read-buffer (prompt &optional default require-match start matches-set) "Replacement for the built-in `read-buffer'. Return the name of a buffer selected. PROMPT is the prompt to give to the user. DEFAULT if given is the default buffer to be selected, which will go to the front of the list. If REQUIRE-MATCH is non-nil, an existing buffer must be selected. If START is a string, the selection process is started with that string. If MATCHES-SET is non-nil, the buflist is not updated before the selection process begins. Used by isearchb.el." (let ( buf-sel iswitchb-final-text (icomplete-mode nil) ;; prevent icomplete starting up ) (iswitchb-define-mode-map) (setq iswitchb-exit nil) (setq iswitchb-default (if (bufferp default) (buffer-name default) default)) (setq iswitchb-text (or start "")) (unless matches-set (setq iswitchb-rescan t) (iswitchb-make-buflist iswitchb-default) (iswitchb-set-matches)) (let ((minibuffer-local-completion-map iswitchb-mode-map) ;; Record the minibuffer depth that we expect to find once ;; the minibuffer is set up and iswitchb-entryfn-p is called. (iswitchb-minibuf-depth (1+ (minibuffer-depth))) (iswitchb-require-match require-match)) ;; prompt the user for the buffer name (setq iswitchb-final-text (completing-read prompt ;the prompt '(("dummy" . 1)) ;table nil ;predicate nil ;require-match [handled elsewhere] start ;initial-contents 'iswitchb-history))) (if (and (not (eq iswitchb-exit 'usefirst)) (get-buffer iswitchb-final-text)) ;; This happens for example if the buffer was chosen with the mouse. (setq iswitchb-matches (list iswitchb-final-text) iswitchb-virtual-buffers nil)) ;; If no buffer matched, but a virtual buffer was selected, visit ;; that file now and act as though that buffer had been selected. (if (and iswitchb-virtual-buffers (not (iswitchb-existing-buffer-p))) (let ((virt (car iswitchb-virtual-buffers)) (new-buf)) ;; Keep the name of the buffer returned by find-file-noselect, as ;; the buffer 'virt' could be a symlink to a file of a different name. (setq new-buf (buffer-name (find-file-noselect (cdr virt)))) (setq iswitchb-matches (list new-buf) iswitchb-virtual-buffers nil))) ;; Handling the require-match must be done in a better way. (if (and require-match (not (iswitchb-existing-buffer-p))) (error "Must specify valid buffer")) (if (or (eq iswitchb-exit 'takeprompt) (null iswitchb-matches)) (setq buf-sel iswitchb-final-text) ;; else take head of list (setq buf-sel (car iswitchb-matches))) ;; Or possibly choose the default buffer (if (equal iswitchb-final-text "") (setq buf-sel (car iswitchb-matches))) buf-sel))