;; Using iswitchb for other completion tasks.
;; Kin Cho (kin@neoscale.com) sent the following suggestion to use
-;; iswitchb for other completion tasks.
+;; iswitchb for other completion tasks.
;;
;; (defun my-icompleting-read (prompt choices)
;; "Use iswitch as a completing-read replacement to choose from
;; (delete-minibuffer-contents))
;;
;; (add-hook 'iswitchb-define-mode-map-hook
-;; '(lambda () (define-key
-;; iswitchb-mode-map "\C-o"
+;; '(lambda () (define-key
+;; iswitchb-mode-map "\C-o"
;; 'iswitchb-exclude-nonmatching)))
;; Other lisp packages extend iswitchb behaviour to other tasks. See
(define-key map "\C-m" 'iswitchb-exit-minibuffer)
(setq iswitchb-mode-map map)
(run-hooks 'iswitchb-define-mode-map-hook)))
-
+
;;; MAIN FUNCTION
(defun iswitchb ()
"Switch to buffer matching a substring.
\\[iswitchb-kill-buffer] Kill buffer at head of buffer list."
;;\\[iswitchb-toggle-ignore] Toggle ignoring certain buffers (see \
;;`iswitchb-buffer-ignore')
-
+
(let* ((prompt "iswitch ")
(buf (iswitchb-read-buffer prompt)))
(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
(let (res)
(cond ((not iswitchb-matches)
(run-hooks 'iswitchb-cannot-complete-hook))
-
+
((= 1 (length iswitchb-matches))
;; only one choice, so select it.
(exit-minibuffer))
-
+
(t
;; else there could be some completions
(setq res iswitchb-common-match-string)
ret)
(mapcar
(lambda (x)
-
+
(if do-string
(setq name x) ;We already have the name
(setq name (buffer-name x)))
-
+
(cond
((and (or (and string-format (string-match regexp name))
(and (null string-format)
(string-match (regexp-quote regexp) name)))
-
+
(not (iswitchb-ignore-buffername-p name)))
(setq ret (cons name ret))
)))
(set-window-start win (point-min))
(scroll-other-window))
(set-buffer buf))
-
+
(with-output-to-temp-buffer temp-buf
(if iswitchb-xemacs
-
+
;; XEmacs extents are put on by default, doesn't seem to be
;; any way of switching them off.
(display-completion-list (if iswitchb-matches
(if (and iswitchb-newbuffer
(or
(not iswitchb-prompt-newbuffer)
-
+
(and iswitchb-prompt-newbuffer
(y-or-n-p
(format
(iswitchb-set-common-completion)
;; Insert the match-status information:
- (insert (iswitchb-completions
+ (insert (iswitchb-completions
contents
minibuffer-completion-table
minibuffer-completion-predicate
(defun iswitchb-completions (name candidates predicate require-match)
"Return the string that is displayed after the user's text.
Modified from `icomplete-completions'."
-
+
(let ((comps iswitchb-matches)
; "-determined" - only one candidate
(open-bracket-determined (if require-match "(" "["))
(concat open-bracket-determined
(substring most (length name))
close-bracket-determined))
-
+
;; list all alternatives
open-bracket-prospects
(if most-is-exact
(if (and (boundp 'iswitchb-eoinput)
iswitchb-eoinput)
-
+
(if (> iswitchb-eoinput (point-max))
;; Oops, got rug pulled out from under us - reinit:
(setq iswitchb-eoinput (point-max))
(let ((buffer-undo-list buffer-undo-list )) ; prevent entry
(delete-region iswitchb-eoinput (point-max))))
-
+
;; Reestablish the local variable 'cause minibuffer-setup is weird:
(make-local-variable 'iswitchb-eoinput)
(setq iswitchb-eoinput 1)))