aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/iswitchb.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/iswitchb.el')
-rw-r--r--lisp/iswitchb.el172
1 files changed, 101 insertions, 71 deletions
diff --git a/lisp/iswitchb.el b/lisp/iswitchb.el
index 52915c46950..d705faf9708 100644
--- a/lisp/iswitchb.el
+++ b/lisp/iswitchb.el
@@ -1,6 +1,7 @@
1;;; iswitchb.el --- switch between buffers using substrings 1;;; iswitchb.el --- switch between buffers using substrings
2 2
3;; Copyright (C) 1996, 1997, 2000, 2001, 2003 Free Software Foundation, Inc. 3;; Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005
4;; Free Software Foundation, Inc.
4 5
5;; Author: Stephen Eglen <stephen@gnu.org> 6;; Author: Stephen Eglen <stephen@gnu.org>
6;; Maintainer: Stephen Eglen <stephen@gnu.org> 7;; Maintainer: Stephen Eglen <stephen@gnu.org>
@@ -165,11 +166,10 @@
165 166
166;; Font-Lock 167;; Font-Lock
167 168
168;; If you have font-lock loaded, the first matching buffer is 169;; font-lock is used to highlight the first matching buffer. To
169;; highlighted. To switch this off, set (setq iswitchb-use-fonts nil) 170;; switch this off, set (setq iswitchb-use-faces nil). Colouring of
170;; I don't use font-lock that much, so I've hardcoded the faces. If 171;; the matching buffer name was suggested by Carsten Dominik
171;; this is too harsh, let me know. Colouring of the matching buffer 172;; (dominik@strw.leidenuniv.nl)
172;; name was suggested by Carsten Dominik (dominik@strw.leidenuniv.nl)
173 173
174;; Replacement for read-buffer 174;; Replacement for read-buffer
175 175
@@ -230,16 +230,10 @@
230 230
231;; Regexp matching 231;; Regexp matching
232 232
233;; There is limited provision for regexp matching within iswitchb, 233;; There is provision for regexp matching within iswitchb, enabled
234;; enabled through `iswitchb-regexp'. This allows you to type `c$' 234;; through `iswitchb-regexp'. This allows you to type `c$' for
235;; for example and see all buffer names ending in `c'. This facility 235;; example and see all buffer names ending in `c'. No completion
236;; is quite limited though in two respects. First, you can't 236;; mechanism is currently offered when regexp searching.
237;; currently type in expressions like `[0-9]' directly -- you have to
238;; type them in when iswitchb-regexp is nil and then toggle on the
239;; regexp functionality. Likewise, don't enter an expression
240;; containing `\' in regexp mode. If you try, iswitchb gets confused,
241;; so just hit C-g and try again. Secondly, no completion mechanism
242;; is currently offered when regexp searching.
243 237
244;;; TODO 238;;; TODO
245 239
@@ -256,6 +250,8 @@
256 (fboundp 'last))) 250 (fboundp 'last)))
257 (require 'cl)) 251 (require 'cl))
258 252
253(require 'font-lock)
254
259;; Set up the custom library. 255;; Set up the custom library.
260;; taken from http://www.dina.kvl.dk/~abraham/custom/ 256;; taken from http://www.dina.kvl.dk/~abraham/custom/
261(eval-and-compile 257(eval-and-compile
@@ -377,10 +373,11 @@ See also `iswitchb-newbuffer'."
377 :type 'boolean 373 :type 'boolean
378 :group 'iswitchb) 374 :group 'iswitchb)
379 375
380(defcustom iswitchb-use-fonts t 376(defcustom iswitchb-use-faces t
381 "*Non-nil means use font-lock fonts for showing first match." 377 "*Non-nil means use font-lock fonts for showing first match."
382 :type 'boolean 378 :type 'boolean
383 :group 'iswitchb) 379 :group 'iswitchb)
380(define-obsolete-variable-alias 'iswitchb-use-fonts 'iswitchb-use-faces "22.1")
384 381
385(defcustom iswitchb-use-frame-buffer-list nil 382(defcustom iswitchb-use-frame-buffer-list nil
386 "*Non-nil means use the currently selected frame's buffer list." 383 "*Non-nil means use the currently selected frame's buffer list."
@@ -408,6 +405,35 @@ iswitchb is running."
408 :type 'hook 405 :type 'hook
409 :group 'iswitchb) 406 :group 'iswitchb)
410 407
408(defface iswitchb-single-match
409 '((t
410 (:inherit font-lock-comment-face)))
411 "Iswitchb face for single matching buffer name."
412 :version "22.1"
413 :group 'iswitchb)
414
415(defface iswitchb-current-match
416 '((t
417 (:inherit font-lock-function-name-face)))
418 "Iswitchb face for current matching buffer name."
419 :version "22.1"
420 :group 'iswitchb)
421
422(defface iswitchb-virtual-matches
423 '((t
424 (:inherit font-lock-builtin-face)))
425 "Iswitchb face for matching virtual buffer names.
426See also `iswitchb-use-virtual-buffers'."
427 :version "22.1"
428 :group 'iswitchb)
429
430(defface iswitchb-invalid-regexp
431 '((t
432 (:inherit font-lock-warning-face)))
433 "Iswitchb face for indicating invalid regexp. "
434 :version "22.1"
435 :group 'iswitchb)
436
411;; Do we need the variable iswitchb-use-mycompletion? 437;; Do we need the variable iswitchb-use-mycompletion?
412 438
413;;; Internal Variables 439;;; Internal Variables
@@ -507,6 +533,11 @@ selected.")
507(defvar iswitchb-minibuf-depth nil 533(defvar iswitchb-minibuf-depth nil
508 "Value we expect to be returned by `minibuffer-depth' in the minibuffer.") 534 "Value we expect to be returned by `minibuffer-depth' in the minibuffer.")
509 535
536(defvar iswitchb-common-match-inserted nil
537 "Non-nil if we have just inserted a common match in the minibuffer.")
538
539(defvar iswitchb-invalid-regexp)
540
510;;; FUNCTIONS 541;;; FUNCTIONS
511 542
512;;; ISWITCHB KEYMAP 543;;; ISWITCHB KEYMAP
@@ -564,6 +595,7 @@ in a separate window.
564 ;;`iswitchb-buffer-ignore') 595 ;;`iswitchb-buffer-ignore')
565 596
566 (let* ((prompt "iswitch ") 597 (let* ((prompt "iswitch ")
598 iswitchb-invalid-regexp
567 (buf (iswitchb-read-buffer prompt))) 599 (buf (iswitchb-read-buffer prompt)))
568 600
569 ;;(message "chosen text %s" iswitchb-final-text) 601 ;;(message "chosen text %s" iswitchb-final-text)
@@ -572,7 +604,8 @@ in a separate window.
572 604
573 (cond ( (eq iswitchb-exit 'findfile) 605 (cond ( (eq iswitchb-exit 'findfile)
574 (call-interactively 'find-file)) 606 (call-interactively 'find-file))
575 607 (iswitchb-invalid-regexp
608 (message "Won't make invalid regexp named buffer"))
576 (t 609 (t
577 ;; View the buffer 610 ;; View the buffer
578 ;;(message "go to buf %s" buf) 611 ;;(message "go to buf %s" buf)
@@ -602,10 +635,7 @@ the selection process begins. Used by isearchb.el."
602 buf-sel 635 buf-sel
603 iswitchb-final-text 636 iswitchb-final-text
604 (icomplete-mode nil) ;; prevent icomplete starting up 637 (icomplete-mode nil) ;; prevent icomplete starting up
605 ;; can only use fonts if they have been bound. 638 )
606 (iswitchb-use-fonts (and iswitchb-use-fonts
607 (boundp 'font-lock-comment-face)
608 (boundp 'font-lock-function-name-face))))
609 639
610 (iswitchb-define-mode-map) 640 (iswitchb-define-mode-map)
611 (setq iswitchb-exit nil) 641 (setq iswitchb-exit nil)
@@ -691,7 +721,9 @@ The result is stored in `iswitchb-common-match-string'."
691 (let (res) 721 (let (res)
692 (cond ((not iswitchb-matches) 722 (cond ((not iswitchb-matches)
693 (run-hooks 'iswitchb-cannot-complete-hook)) 723 (run-hooks 'iswitchb-cannot-complete-hook))
694 724 (iswitchb-invalid-regexp
725 ;; Do nothing
726 )
695 ((= 1 (length iswitchb-matches)) 727 ((= 1 (length iswitchb-matches))
696 ;; only one choice, so select it. 728 ;; only one choice, so select it.
697 (exit-minibuffer)) 729 (exit-minibuffer))
@@ -703,7 +735,8 @@ The result is stored in `iswitchb-common-match-string'."
703 (not (equal res iswitchb-text))) 735 (not (equal res iswitchb-text)))
704 ;; found something to complete, so put it in the minibuffer. 736 ;; found something to complete, so put it in the minibuffer.
705 (progn 737 (progn
706 (setq iswitchb-rescan nil) 738 (setq iswitchb-rescan nil
739 iswitchb-common-match-inserted t)
707 (delete-region (minibuffer-prompt-end) (point)) 740 (delete-region (minibuffer-prompt-end) (point))
708 (insert res)) 741 (insert res))
709 ;; else nothing to complete 742 ;; else nothing to complete
@@ -839,10 +872,8 @@ it is put to the start of the list."
839 872
840(defun iswitchb-to-end (lst) 873(defun iswitchb-to-end (lst)
841 "Move the elements from LST to the end of `iswitchb-temp-buflist'." 874 "Move the elements from LST to the end of `iswitchb-temp-buflist'."
842 (mapcar 875 (dolist (elem lst)
843 (lambda (elem) 876 (setq iswitchb-temp-buflist (delq elem iswitchb-temp-buflist)))
844 (setq iswitchb-temp-buflist (delq elem iswitchb-temp-buflist)))
845 lst)
846 (setq iswitchb-temp-buflist (nconc iswitchb-temp-buflist lst))) 877 (setq iswitchb-temp-buflist (nconc iswitchb-temp-buflist lst)))
847 878
848(defun iswitchb-get-buffers-in-frames (&optional current) 879(defun iswitchb-get-buffers-in-frames (&optional current)
@@ -883,29 +914,19 @@ current frame, rather than all frames, regardless of value of
883 "Return buffers matching REGEXP. 914 "Return buffers matching REGEXP.
884If STRING-FORMAT is nil, consider REGEXP as just a string. 915If STRING-FORMAT is nil, consider REGEXP as just a string.
885BUFFER-LIST can be list of buffers or list of strings." 916BUFFER-LIST can be list of buffers or list of strings."
886 (let* ((case-fold-search (iswitchb-case)) 917 (let* ((case-fold-search (iswitchb-case))
887 ;; need reverse since we are building up list backwards 918 name ret)
888 (list (reverse buffer-list)) 919 (if (null string-format) (setq regexp (regexp-quote regexp)))
889 (do-string (stringp (car list))) 920 (setq iswitchb-invalid-regexp nil)
890 name 921 (condition-case error
891 ret) 922 (dolist (x buffer-list (nreverse ret))
892 (mapcar 923 (setq name (if (stringp x) x (buffer-name x)))
893 (lambda (x) 924 (when (and (string-match regexp name)
894 925 (not (iswitchb-ignore-buffername-p name)))
895 (if do-string 926 (push name ret)))
896 (setq name x) ;We already have the name 927 (invalid-regexp
897 (setq name (buffer-name x))) 928 (setq iswitchb-invalid-regexp t)
898 929 (cdr error)))))
899 (cond
900 ((and (or (and string-format (string-match regexp name))
901 (and (null string-format)
902 (string-match (regexp-quote regexp) name)))
903
904 (not (iswitchb-ignore-buffername-p name)))
905 (setq ret (cons name ret))
906 )))
907 list)
908 ret))
909 930
910(defun iswitchb-ignore-buffername-p (bufname) 931(defun iswitchb-ignore-buffername-p (bufname)
911 "Return t if the buffer BUFNAME should be ignored." 932 "Return t if the buffer BUFNAME should be ignored."
@@ -989,7 +1010,8 @@ Return the modified list with the last element prepended to it."
989 (temp-buf "*Completions*") 1010 (temp-buf "*Completions*")
990 (win)) 1011 (win))
991 1012
992 (if (eq last-command this-command) 1013 (if (and (eq last-command this-command)
1014 (not iswitchb-common-match-inserted))
993 ;; scroll buffer 1015 ;; scroll buffer
994 (progn 1016 (progn
995 (set-buffer temp-buf) 1017 (set-buffer temp-buf)
@@ -1016,8 +1038,8 @@ Return the modified list with the last element prepended to it."
1016 (fundamental-mode)) 1038 (fundamental-mode))
1017 (display-completion-list (if iswitchb-matches 1039 (display-completion-list (if iswitchb-matches
1018 iswitchb-matches 1040 iswitchb-matches
1019 iswitchb-buflist)) 1041 iswitchb-buflist))))
1020 ))))) 1042 (setq iswitchb-common-match-inserted nil))))
1021 1043
1022;;; KILL CURRENT BUFFER 1044;;; KILL CURRENT BUFFER
1023 1045
@@ -1227,8 +1249,7 @@ Copied from `icomplete-exhibit' with two changes:
1227 1249
1228 ;; Insert the match-status information: 1250 ;; Insert the match-status information:
1229 (insert (iswitchb-completions 1251 (insert (iswitchb-completions
1230 contents 1252 contents))))))
1231 (not minibuffer-completion-confirm)))))))
1232 1253
1233(eval-when-compile 1254(eval-when-compile
1234 (defvar most-len) 1255 (defvar most-len)
@@ -1243,27 +1264,29 @@ Copied from `icomplete-exhibit' with two changes:
1243 (setq most-is-exact t)) 1264 (setq most-is-exact t))
1244 (substring com most-len))) 1265 (substring com most-len)))
1245 1266
1246(defun iswitchb-completions (name require-match) 1267(defun iswitchb-completions (name)
1247 "Return the string that is displayed after the user's text. 1268 "Return the string that is displayed after the user's text.
1248Modified from `icomplete-completions'." 1269Modified from `icomplete-completions'."
1249 1270
1250 (let ((comps iswitchb-matches) 1271 (let ((comps iswitchb-matches)
1251 ; "-determined" - only one candidate 1272 ; "-determined" - only one candidate
1252 (open-bracket-determined (if require-match "(" "[")) 1273 (open-bracket-determined "[")
1253 (close-bracket-determined (if require-match ")" "]")) 1274 (close-bracket-determined "]")
1254 ;"-prospects" - more than one candidate 1275 ;"-prospects" - more than one candidate
1255 (open-bracket-prospects "{") 1276 (open-bracket-prospects "{")
1256 (close-bracket-prospects "}") 1277 (close-bracket-prospects "}")
1257 first) 1278 first)
1258 1279
1259 (if (and iswitchb-use-fonts comps) 1280 (if (and iswitchb-use-faces comps)
1260 (progn 1281 (progn
1261 (setq first (car comps)) 1282 (setq first (car comps))
1262 (setq first (format "%s" first)) 1283 (setq first (format "%s" first))
1263 (put-text-property 0 (length first) 'face 1284 (put-text-property 0 (length first) 'face
1264 (if (= (length comps) 1) 1285 (if (= (length comps) 1)
1265 'font-lock-comment-face 1286 (if iswitchb-invalid-regexp
1266 'font-lock-function-name-face) 1287 'iswitchb-invalid-regexp
1288 'iswitchb-single-match)
1289 'iswitchb-current-match)
1267 first) 1290 first)
1268 (setq comps (cons first (cdr comps))))) 1291 (setq comps (cons first (cdr comps)))))
1269 1292
@@ -1292,7 +1315,7 @@ Modified from `icomplete-completions'."
1292 (let ((comp comps)) 1315 (let ((comp comps))
1293 (while comp 1316 (while comp
1294 (put-text-property 0 (length (car comp)) 1317 (put-text-property 0 (length (car comp))
1295 'face 'font-lock-builtin-face 1318 'face 'iswitchb-virtual-matches
1296 (car comp)) 1319 (car comp))
1297 (setq comp (cdr comp)))))) 1320 (setq comp (cdr comp))))))
1298 1321
@@ -1300,16 +1323,23 @@ Modified from `icomplete-completions'."
1300 open-bracket-determined 1323 open-bracket-determined
1301 close-bracket-determined)) 1324 close-bracket-determined))
1302 1325
1303 ((null (cdr comps)) ;one match 1326 (iswitchb-invalid-regexp
1304 (concat (if (and (> (length (car comps)) 1327 (concat " " (car comps)))
1305 (length name))) 1328 ((null (cdr comps)) ;one match
1306 (concat open-bracket-determined 1329 (concat
1330 (if (if (not iswitchb-regexp)
1331 (= (length name)
1332 (length (car comps)))
1333 (string-match name (car comps))
1334 (string-equal (match-string 0 (car comps))
1335 (car comps)))
1336 ""
1337 (concat open-bracket-determined
1307 ;; when there is one match, show the 1338 ;; when there is one match, show the
1308 ;; matching buffer name in full 1339 ;; matching buffer name in full
1309 (car comps) 1340 (car comps)
1310 close-bracket-determined) 1341 close-bracket-determined))
1311 "") 1342 (if (not iswitchb-use-faces) " [Matched]")))
1312 (if (not iswitchb-use-fonts) " [Matched]")))
1313 (t ;multiple matches 1343 (t ;multiple matches
1314 (if (and iswitchb-max-to-show 1344 (if (and iswitchb-max-to-show
1315 (> (length comps) iswitchb-max-to-show)) 1345 (> (length comps) iswitchb-max-to-show))
@@ -1431,5 +1461,5 @@ This mode enables switching between buffers using substrings. See
1431 1461
1432(provide 'iswitchb) 1462(provide 'iswitchb)
1433 1463
1434;;; arch-tag: d74198ae-753f-44f2-b34f-0c515398d90a 1464;; arch-tag: d74198ae-753f-44f2-b34f-0c515398d90a
1435;;; iswitchb.el ends here 1465;;; iswitchb.el ends here