183 |
;; Using iswitchb for other completion tasks. |
;; Using iswitchb for other completion tasks. |
184 |
|
|
185 |
;; Kin Cho (kin@neoscale.com) sent the following suggestion to use |
;; Kin Cho (kin@neoscale.com) sent the following suggestion to use |
186 |
;; iswitchb for other completion tasks. |
;; iswitchb for other completion tasks. |
187 |
;; |
;; |
188 |
;; (defun my-icompleting-read (prompt choices) |
;; (defun my-icompleting-read (prompt choices) |
189 |
;; "Use iswitch as a completing-read replacement to choose from |
;; "Use iswitch as a completing-read replacement to choose from |
209 |
;; (delete-minibuffer-contents)) |
;; (delete-minibuffer-contents)) |
210 |
;; |
;; |
211 |
;; (add-hook 'iswitchb-define-mode-map-hook |
;; (add-hook 'iswitchb-define-mode-map-hook |
212 |
;; '(lambda () (define-key |
;; '(lambda () (define-key |
213 |
;; iswitchb-mode-map "\C-o" |
;; iswitchb-mode-map "\C-o" |
214 |
;; 'iswitchb-exclude-nonmatching))) |
;; 'iswitchb-exclude-nonmatching))) |
215 |
|
|
216 |
;; Other lisp packages extend iswitchb behaviour to other tasks. See |
;; Other lisp packages extend iswitchb behaviour to other tasks. See |
518 |
(define-key map "\C-m" 'iswitchb-exit-minibuffer) |
(define-key map "\C-m" 'iswitchb-exit-minibuffer) |
519 |
(setq iswitchb-mode-map map) |
(setq iswitchb-mode-map map) |
520 |
(run-hooks 'iswitchb-define-mode-map-hook))) |
(run-hooks 'iswitchb-define-mode-map-hook))) |
521 |
|
|
522 |
;;; MAIN FUNCTION |
;;; MAIN FUNCTION |
523 |
(defun iswitchb () |
(defun iswitchb () |
524 |
"Switch to buffer matching a substring. |
"Switch to buffer matching a substring. |
547 |
\\[iswitchb-kill-buffer] Kill buffer at head of buffer list." |
\\[iswitchb-kill-buffer] Kill buffer at head of buffer list." |
548 |
;;\\[iswitchb-toggle-ignore] Toggle ignoring certain buffers (see \ |
;;\\[iswitchb-toggle-ignore] Toggle ignoring certain buffers (see \ |
549 |
;;`iswitchb-buffer-ignore') |
;;`iswitchb-buffer-ignore') |
550 |
|
|
551 |
(let* ((prompt "iswitch ") |
(let* ((prompt "iswitch ") |
552 |
(buf (iswitchb-read-buffer prompt))) |
(buf (iswitchb-read-buffer prompt))) |
553 |
|
|
626 |
(setq buf-sel iswitchb-final-text) |
(setq buf-sel iswitchb-final-text) |
627 |
;; else take head of list |
;; else take head of list |
628 |
(setq buf-sel (car iswitchb-matches))) |
(setq buf-sel (car iswitchb-matches))) |
629 |
|
|
630 |
;; Or possibly choose the default buffer |
;; Or possibly choose the default buffer |
631 |
(if (equal iswitchb-final-text "") |
(if (equal iswitchb-final-text "") |
632 |
(setq buf-sel |
(setq buf-sel |
661 |
(let (res) |
(let (res) |
662 |
(cond ((not iswitchb-matches) |
(cond ((not iswitchb-matches) |
663 |
(run-hooks 'iswitchb-cannot-complete-hook)) |
(run-hooks 'iswitchb-cannot-complete-hook)) |
664 |
|
|
665 |
((= 1 (length iswitchb-matches)) |
((= 1 (length iswitchb-matches)) |
666 |
;; only one choice, so select it. |
;; only one choice, so select it. |
667 |
(exit-minibuffer)) |
(exit-minibuffer)) |
668 |
|
|
669 |
(t |
(t |
670 |
;; else there could be some completions |
;; else there could be some completions |
671 |
(setq res iswitchb-common-match-string) |
(setq res iswitchb-common-match-string) |
847 |
ret) |
ret) |
848 |
(mapcar |
(mapcar |
849 |
(lambda (x) |
(lambda (x) |
850 |
|
|
851 |
(if do-string |
(if do-string |
852 |
(setq name x) ;We already have the name |
(setq name x) ;We already have the name |
853 |
(setq name (buffer-name x))) |
(setq name (buffer-name x))) |
854 |
|
|
855 |
(cond |
(cond |
856 |
((and (or (and string-format (string-match regexp name)) |
((and (or (and string-format (string-match regexp name)) |
857 |
(and (null string-format) |
(and (null string-format) |
858 |
(string-match (regexp-quote regexp) name))) |
(string-match (regexp-quote regexp) name))) |
859 |
|
|
860 |
(not (iswitchb-ignore-buffername-p name))) |
(not (iswitchb-ignore-buffername-p name))) |
861 |
(setq ret (cons name ret)) |
(setq ret (cons name ret)) |
862 |
))) |
))) |
954 |
(set-window-start win (point-min)) |
(set-window-start win (point-min)) |
955 |
(scroll-other-window)) |
(scroll-other-window)) |
956 |
(set-buffer buf)) |
(set-buffer buf)) |
957 |
|
|
958 |
(with-output-to-temp-buffer temp-buf |
(with-output-to-temp-buffer temp-buf |
959 |
(if iswitchb-xemacs |
(if iswitchb-xemacs |
960 |
|
|
961 |
;; XEmacs extents are put on by default, doesn't seem to be |
;; XEmacs extents are put on by default, doesn't seem to be |
962 |
;; any way of switching them off. |
;; any way of switching them off. |
963 |
(display-completion-list (if iswitchb-matches |
(display-completion-list (if iswitchb-matches |
1043 |
(if (and iswitchb-newbuffer |
(if (and iswitchb-newbuffer |
1044 |
(or |
(or |
1045 |
(not iswitchb-prompt-newbuffer) |
(not iswitchb-prompt-newbuffer) |
1046 |
|
|
1047 |
(and iswitchb-prompt-newbuffer |
(and iswitchb-prompt-newbuffer |
1048 |
(y-or-n-p |
(y-or-n-p |
1049 |
(format |
(format |
1187 |
(iswitchb-set-common-completion) |
(iswitchb-set-common-completion) |
1188 |
|
|
1189 |
;; Insert the match-status information: |
;; Insert the match-status information: |
1190 |
(insert (iswitchb-completions |
(insert (iswitchb-completions |
1191 |
contents |
contents |
1192 |
minibuffer-completion-table |
minibuffer-completion-table |
1193 |
minibuffer-completion-predicate |
minibuffer-completion-predicate |
1196 |
(defun iswitchb-completions (name candidates predicate require-match) |
(defun iswitchb-completions (name candidates predicate require-match) |
1197 |
"Return the string that is displayed after the user's text. |
"Return the string that is displayed after the user's text. |
1198 |
Modified from `icomplete-completions'." |
Modified from `icomplete-completions'." |
1199 |
|
|
1200 |
(let ((comps iswitchb-matches) |
(let ((comps iswitchb-matches) |
1201 |
; "-determined" - only one candidate |
; "-determined" - only one candidate |
1202 |
(open-bracket-determined (if require-match "(" "[")) |
(open-bracket-determined (if require-match "(" "[")) |
1260 |
|
|
1261 |
;; put in common completion item -- what you get by |
;; put in common completion item -- what you get by |
1262 |
;; pressing tab |
;; pressing tab |
1263 |
(if (> (length iswitchb-common-match-string) (length name)) |
(if (and (stringp iswitchb-common-match-string) |
1264 |
|
(> (length iswitchb-common-match-string) (length name))) |
1265 |
(concat open-bracket-determined |
(concat open-bracket-determined |
1266 |
(substring iswitchb-common-match-string |
(substring iswitchb-common-match-string |
1267 |
(length name)) |
(length name)) |
1273 |
(concat open-bracket-determined |
(concat open-bracket-determined |
1274 |
(substring most (length name)) |
(substring most (length name)) |
1275 |
close-bracket-determined)) |
close-bracket-determined)) |
1276 |
|
|
1277 |
;; list all alternatives |
;; list all alternatives |
1278 |
open-bracket-prospects |
open-bracket-prospects |
1279 |
(if most-is-exact |
(if most-is-exact |
1304 |
|
|
1305 |
(if (and (boundp 'iswitchb-eoinput) |
(if (and (boundp 'iswitchb-eoinput) |
1306 |
iswitchb-eoinput) |
iswitchb-eoinput) |
1307 |
|
|
1308 |
(if (> iswitchb-eoinput (point-max)) |
(if (> iswitchb-eoinput (point-max)) |
1309 |
;; Oops, got rug pulled out from under us - reinit: |
;; Oops, got rug pulled out from under us - reinit: |
1310 |
(setq iswitchb-eoinput (point-max)) |
(setq iswitchb-eoinput (point-max)) |
1311 |
(let ((buffer-undo-list buffer-undo-list )) ; prevent entry |
(let ((buffer-undo-list buffer-undo-list )) ; prevent entry |
1312 |
(delete-region iswitchb-eoinput (point-max)))) |
(delete-region iswitchb-eoinput (point-max)))) |
1313 |
|
|
1314 |
;; Reestablish the local variable 'cause minibuffer-setup is weird: |
;; Reestablish the local variable 'cause minibuffer-setup is weird: |
1315 |
(make-local-variable 'iswitchb-eoinput) |
(make-local-variable 'iswitchb-eoinput) |
1316 |
(setq iswitchb-eoinput 1))) |
(setq iswitchb-eoinput 1))) |