Function: iswitchb-read-buffer

iswitchb-read-buffer is a byte-compiled function defined in iswitchb.el.gz.

Signature

(iswitchb-read-buffer PROMPT &optional DEFAULT REQUIRE-MATCH PREDICATE START MATCHES-SET)

Documentation

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.

Probably introduced at or before Emacs version 20.3.

Source Code

;; Defined in /usr/src/emacs/lisp/obsolete/iswitchb.el.gz
(defun iswitchb-read-buffer (prompt &optional default require-match
				    _predicate 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."
  ;; The map is generated every time so that it can inherit new
  ;; functions.
  (let ((map (copy-keymap minibuffer-local-map))
	buf-sel iswitchb-final-text
	icomplete-mode)  ; prevent icomplete starting up
    (define-key map "?" #'iswitchb-completion-help)
    (define-key map "\C-s" #'iswitchb-next-match)
    (define-key map "\C-r" #'iswitchb-prev-match)
    (define-key map "\t" #'iswitchb-complete)
    (define-key map "\C-j" #'iswitchb-select-buffer-text)
    (define-key map "\C-t" #'iswitchb-toggle-regexp)
    (define-key map "\C-x\C-f" #'iswitchb-find-file)
    (define-key map "\C-n" #'iswitchb-toggle-ignore)
    (define-key map "\C-c" #'iswitchb-toggle-case)
    (define-key map "\C-k" #'iswitchb-kill-buffer)
    (define-key map "\C-m" #'iswitchb-exit-minibuffer)
    (setq iswitchb-mode-map map)
    (run-hooks 'iswitchb-define-mode-map-hook)

    (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))