diff options
| author | Eli Zaretskii | 2005-06-04 19:10:07 +0000 |
|---|---|---|
| committer | Eli Zaretskii | 2005-06-04 19:10:07 +0000 |
| commit | b21688f0cadd5fdfd051a3197918c54b0c75bd9e (patch) | |
| tree | 1389195420957ef386fa4aa44013d4a8d7718aca | |
| parent | a6b017c9a4802e1cebccb286f8b1f41d670287d7 (diff) | |
| download | emacs-b21688f0cadd5fdfd051a3197918c54b0c75bd9e.tar.gz emacs-b21688f0cadd5fdfd051a3197918c54b0c75bd9e.zip | |
(iswitchb-single-match-face)
(iswitchb-current-match-face, iswitchb-virtual-matches-face)
(iswitchb-invalid-regexp-face): New faces.
(iswitchb-completions): Use them.
(iswitchb-use-faces): Renamed from iswitchb-use-fonts, which is
now marked as an obsolete alias.
(iswitchb-read-buffer): Remove check for bound font variables.
(iswitchb-invalid-regexp): New free variable.
(iswitchb-get-matched-buffers): Catch invalid-regexp errors and
set iswitchb-invalid-regexp.
(iswitchb, iswitchb-complete, iswitchb-completions): Deal with invalid regexps.
(iswitchb-completions): Add check for complete match when entering a regexp.
(iswitchb-completions): Remove require-match argument.
(iswitchb-exhibit): Fix caller.
(iswitchb-common-match-inserted): New variable.
(iswitchb-complete, iswitchb-completion-help): Use it.
| -rw-r--r-- | lisp/iswitchb.el | 146 |
1 files changed, 93 insertions, 53 deletions
diff --git a/lisp/iswitchb.el b/lisp/iswitchb.el index 5c01e77aabb..2943be851a0 100644 --- a/lisp/iswitchb.el +++ b/lisp/iswitchb.el | |||
| @@ -1,6 +1,6 @@ | |||
| 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 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Stephen Eglen <stephen@gnu.org> | 5 | ;; Author: Stephen Eglen <stephen@gnu.org> |
| 6 | ;; Maintainer: Stephen Eglen <stephen@gnu.org> | 6 | ;; Maintainer: Stephen Eglen <stephen@gnu.org> |
| @@ -165,11 +165,10 @@ | |||
| 165 | 165 | ||
| 166 | ;; Font-Lock | 166 | ;; Font-Lock |
| 167 | 167 | ||
| 168 | ;; If you have font-lock loaded, the first matching buffer is | 168 | ;; font-lock is used to highlight the first matching buffer. To |
| 169 | ;; highlighted. To switch this off, set (setq iswitchb-use-fonts nil) | 169 | ;; 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 | 170 | ;; the matching buffer name was suggested by Carsten Dominik |
| 171 | ;; this is too harsh, let me know. Colouring of the matching buffer | 171 | ;; (dominik@strw.leidenuniv.nl) |
| 172 | ;; name was suggested by Carsten Dominik (dominik@strw.leidenuniv.nl) | ||
| 173 | 172 | ||
| 174 | ;; Replacement for read-buffer | 173 | ;; Replacement for read-buffer |
| 175 | 174 | ||
| @@ -230,16 +229,10 @@ | |||
| 230 | 229 | ||
| 231 | ;; Regexp matching | 230 | ;; Regexp matching |
| 232 | 231 | ||
| 233 | ;; There is limited provision for regexp matching within iswitchb, | 232 | ;; There is provision for regexp matching within iswitchb, enabled |
| 234 | ;; enabled through `iswitchb-regexp'. This allows you to type `c$' | 233 | ;; through `iswitchb-regexp'. This allows you to type `c$' for |
| 235 | ;; for example and see all buffer names ending in `c'. This facility | 234 | ;; example and see all buffer names ending in `c'. No completion |
| 236 | ;; is quite limited though in two respects. First, you can't | 235 | ;; 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 | 236 | ||
| 244 | ;;; TODO | 237 | ;;; TODO |
| 245 | 238 | ||
| @@ -256,6 +249,8 @@ | |||
| 256 | (fboundp 'last))) | 249 | (fboundp 'last))) |
| 257 | (require 'cl)) | 250 | (require 'cl)) |
| 258 | 251 | ||
| 252 | (require 'font-lock) | ||
| 253 | |||
| 259 | ;; Set up the custom library. | 254 | ;; Set up the custom library. |
| 260 | ;; taken from http://www.dina.kvl.dk/~abraham/custom/ | 255 | ;; taken from http://www.dina.kvl.dk/~abraham/custom/ |
| 261 | (eval-and-compile | 256 | (eval-and-compile |
| @@ -377,10 +372,11 @@ See also `iswitchb-newbuffer'." | |||
| 377 | :type 'boolean | 372 | :type 'boolean |
| 378 | :group 'iswitchb) | 373 | :group 'iswitchb) |
| 379 | 374 | ||
| 380 | (defcustom iswitchb-use-fonts t | 375 | (defcustom iswitchb-use-faces t |
| 381 | "*Non-nil means use font-lock fonts for showing first match." | 376 | "*Non-nil means use font-lock fonts for showing first match." |
| 382 | :type 'boolean | 377 | :type 'boolean |
| 383 | :group 'iswitchb) | 378 | :group 'iswitchb) |
| 379 | (define-obsolete-variable-alias 'iswitchb-use-fonts 'iswitchb-use-faces "22.1") | ||
| 384 | 380 | ||
| 385 | (defcustom iswitchb-use-frame-buffer-list nil | 381 | (defcustom iswitchb-use-frame-buffer-list nil |
| 386 | "*Non-nil means use the currently selected frame's buffer list." | 382 | "*Non-nil means use the currently selected frame's buffer list." |
| @@ -408,6 +404,35 @@ iswitchb is running." | |||
| 408 | :type 'hook | 404 | :type 'hook |
| 409 | :group 'iswitchb) | 405 | :group 'iswitchb) |
| 410 | 406 | ||
| 407 | (defface iswitchb-single-match-face | ||
| 408 | '((t | ||
| 409 | (:inherit font-lock-comment-face))) | ||
| 410 | "Iswitchb face for single matching buffer name." | ||
| 411 | :version "22.1" | ||
| 412 | :group 'iswitchb) | ||
| 413 | |||
| 414 | (defface iswitchb-current-match-face | ||
| 415 | '((t | ||
| 416 | (:inherit font-lock-function-name-face))) | ||
| 417 | "Iswitchb face for current matching buffer name." | ||
| 418 | :version "22.1" | ||
| 419 | :group 'iswitchb) | ||
| 420 | |||
| 421 | (defface iswitchb-virtual-matches-face | ||
| 422 | '((t | ||
| 423 | (:inherit font-lock-builtin-face))) | ||
| 424 | "Iswitchb face for matching virtual buffer names. | ||
| 425 | See also `iswitchb-use-virtual-buffers'." | ||
| 426 | :version "22.1" | ||
| 427 | :group 'iswitchb) | ||
| 428 | |||
| 429 | (defface iswitchb-invalid-regexp-face | ||
| 430 | '((t | ||
| 431 | (:inherit font-lock-warning-face))) | ||
| 432 | "Iswitchb face for indicating invalid regexp. " | ||
| 433 | :version "22.1" | ||
| 434 | :group 'iswitchb) | ||
| 435 | |||
| 411 | ;; Do we need the variable iswitchb-use-mycompletion? | 436 | ;; Do we need the variable iswitchb-use-mycompletion? |
| 412 | 437 | ||
| 413 | ;;; Internal Variables | 438 | ;;; Internal Variables |
| @@ -507,6 +532,11 @@ selected.") | |||
| 507 | (defvar iswitchb-minibuf-depth nil | 532 | (defvar iswitchb-minibuf-depth nil |
| 508 | "Value we expect to be returned by `minibuffer-depth' in the minibuffer.") | 533 | "Value we expect to be returned by `minibuffer-depth' in the minibuffer.") |
| 509 | 534 | ||
| 535 | (defvar iswitchb-common-match-inserted nil | ||
| 536 | "Non-nil if we have just inserted a common match in the minibuffer.") | ||
| 537 | |||
| 538 | (defvar iswitchb-invalid-regexp) | ||
| 539 | |||
| 510 | ;;; FUNCTIONS | 540 | ;;; FUNCTIONS |
| 511 | 541 | ||
| 512 | ;;; ISWITCHB KEYMAP | 542 | ;;; ISWITCHB KEYMAP |
| @@ -564,6 +594,7 @@ in a separate window. | |||
| 564 | ;;`iswitchb-buffer-ignore') | 594 | ;;`iswitchb-buffer-ignore') |
| 565 | 595 | ||
| 566 | (let* ((prompt "iswitch ") | 596 | (let* ((prompt "iswitch ") |
| 597 | iswitchb-invalid-regexp | ||
| 567 | (buf (iswitchb-read-buffer prompt))) | 598 | (buf (iswitchb-read-buffer prompt))) |
| 568 | 599 | ||
| 569 | ;;(message "chosen text %s" iswitchb-final-text) | 600 | ;;(message "chosen text %s" iswitchb-final-text) |
| @@ -572,7 +603,8 @@ in a separate window. | |||
| 572 | 603 | ||
| 573 | (cond ( (eq iswitchb-exit 'findfile) | 604 | (cond ( (eq iswitchb-exit 'findfile) |
| 574 | (call-interactively 'find-file)) | 605 | (call-interactively 'find-file)) |
| 575 | 606 | (iswitchb-invalid-regexp | |
| 607 | (message "Won't make invalid regexp named buffer")) | ||
| 576 | (t | 608 | (t |
| 577 | ;; View the buffer | 609 | ;; View the buffer |
| 578 | ;;(message "go to buf %s" buf) | 610 | ;;(message "go to buf %s" buf) |
| @@ -602,10 +634,7 @@ the selection process begins. Used by isearchb.el." | |||
| 602 | buf-sel | 634 | buf-sel |
| 603 | iswitchb-final-text | 635 | iswitchb-final-text |
| 604 | (icomplete-mode nil) ;; prevent icomplete starting up | 636 | (icomplete-mode nil) ;; prevent icomplete starting up |
| 605 | ;; can only use fonts if they have been bound. | 637 | ) |
| 606 | (iswitchb-use-fonts (and iswitchb-use-fonts | ||
| 607 | (boundp 'font-lock-comment-face) | ||
| 608 | (boundp 'font-lock-function-name-face)))) | ||
| 609 | 638 | ||
| 610 | (iswitchb-define-mode-map) | 639 | (iswitchb-define-mode-map) |
| 611 | (setq iswitchb-exit nil) | 640 | (setq iswitchb-exit nil) |
| @@ -691,7 +720,9 @@ The result is stored in `iswitchb-common-match-string'." | |||
| 691 | (let (res) | 720 | (let (res) |
| 692 | (cond ((not iswitchb-matches) | 721 | (cond ((not iswitchb-matches) |
| 693 | (run-hooks 'iswitchb-cannot-complete-hook)) | 722 | (run-hooks 'iswitchb-cannot-complete-hook)) |
| 694 | 723 | (iswitchb-invalid-regexp | |
| 724 | ;; Do nothing | ||
| 725 | ) | ||
| 695 | ((= 1 (length iswitchb-matches)) | 726 | ((= 1 (length iswitchb-matches)) |
| 696 | ;; only one choice, so select it. | 727 | ;; only one choice, so select it. |
| 697 | (exit-minibuffer)) | 728 | (exit-minibuffer)) |
| @@ -703,7 +734,8 @@ The result is stored in `iswitchb-common-match-string'." | |||
| 703 | (not (equal res iswitchb-text))) | 734 | (not (equal res iswitchb-text))) |
| 704 | ;; found something to complete, so put it in the minibuffer. | 735 | ;; found something to complete, so put it in the minibuffer. |
| 705 | (progn | 736 | (progn |
| 706 | (setq iswitchb-rescan nil) | 737 | (setq iswitchb-rescan nil |
| 738 | iswitchb-common-match-inserted t) | ||
| 707 | (delete-region (minibuffer-prompt-end) (point)) | 739 | (delete-region (minibuffer-prompt-end) (point)) |
| 708 | (insert res)) | 740 | (insert res)) |
| 709 | ;; else nothing to complete | 741 | ;; else nothing to complete |
| @@ -889,6 +921,7 @@ BUFFER-LIST can be list of buffers or list of strings." | |||
| 889 | (do-string (stringp (car list))) | 921 | (do-string (stringp (car list))) |
| 890 | name | 922 | name |
| 891 | ret) | 923 | ret) |
| 924 | (setq iswitchb-invalid-regexp nil) | ||
| 892 | (catch 'invalid-regexp | 925 | (catch 'invalid-regexp |
| 893 | (mapcar | 926 | (mapcar |
| 894 | (lambda (x) | 927 | (lambda (x) |
| @@ -898,17 +931,15 @@ BUFFER-LIST can be list of buffers or list of strings." | |||
| 898 | (setq name (buffer-name x))) | 931 | (setq name (buffer-name x))) |
| 899 | 932 | ||
| 900 | (cond | 933 | (cond |
| 901 | ((and (or (and string-format | 934 | ((and (if (not string-format) |
| 902 | (condition-case error | 935 | (string-match (regexp-quote regexp) name) |
| 903 | (string-match regexp name) | 936 | (condition-case error |
| 904 | (invalid-regexp | 937 | (string-match regexp name) |
| 905 | (throw 'invalid-regexp (setq ret (cdr error)))))) | 938 | (invalid-regexp |
| 906 | (and (null string-format) | 939 | (setq iswitchb-invalid-regexp t) |
| 907 | (string-match (regexp-quote regexp) name))) | 940 | (throw 'invalid-regexp (setq ret (cdr error)))))) |
| 908 | |||
| 909 | (not (iswitchb-ignore-buffername-p name))) | 941 | (not (iswitchb-ignore-buffername-p name))) |
| 910 | (setq ret (cons name ret)) | 942 | (setq ret (cons name ret))))) |
| 911 | ))) | ||
| 912 | list)) | 943 | list)) |
| 913 | ret)) | 944 | ret)) |
| 914 | 945 | ||
| @@ -994,7 +1025,8 @@ Return the modified list with the last element prepended to it." | |||
| 994 | (temp-buf "*Completions*") | 1025 | (temp-buf "*Completions*") |
| 995 | (win)) | 1026 | (win)) |
| 996 | 1027 | ||
| 997 | (if (eq last-command this-command) | 1028 | (if (and (eq last-command this-command) |
| 1029 | (not iswitchb-common-match-inserted)) | ||
| 998 | ;; scroll buffer | 1030 | ;; scroll buffer |
| 999 | (progn | 1031 | (progn |
| 1000 | (set-buffer temp-buf) | 1032 | (set-buffer temp-buf) |
| @@ -1021,8 +1053,8 @@ Return the modified list with the last element prepended to it." | |||
| 1021 | (fundamental-mode)) | 1053 | (fundamental-mode)) |
| 1022 | (display-completion-list (if iswitchb-matches | 1054 | (display-completion-list (if iswitchb-matches |
| 1023 | iswitchb-matches | 1055 | iswitchb-matches |
| 1024 | iswitchb-buflist)) | 1056 | iswitchb-buflist)))) |
| 1025 | ))))) | 1057 | (setq iswitchb-common-match-inserted nil)))) |
| 1026 | 1058 | ||
| 1027 | ;;; KILL CURRENT BUFFER | 1059 | ;;; KILL CURRENT BUFFER |
| 1028 | 1060 | ||
| @@ -1232,8 +1264,7 @@ Copied from `icomplete-exhibit' with two changes: | |||
| 1232 | 1264 | ||
| 1233 | ;; Insert the match-status information: | 1265 | ;; Insert the match-status information: |
| 1234 | (insert (iswitchb-completions | 1266 | (insert (iswitchb-completions |
| 1235 | contents | 1267 | contents)))))) |
| 1236 | (not minibuffer-completion-confirm))))))) | ||
| 1237 | 1268 | ||
| 1238 | (eval-when-compile | 1269 | (eval-when-compile |
| 1239 | (defvar most-len) | 1270 | (defvar most-len) |
| @@ -1248,27 +1279,29 @@ Copied from `icomplete-exhibit' with two changes: | |||
| 1248 | (setq most-is-exact t)) | 1279 | (setq most-is-exact t)) |
| 1249 | (substring com most-len))) | 1280 | (substring com most-len))) |
| 1250 | 1281 | ||
| 1251 | (defun iswitchb-completions (name require-match) | 1282 | (defun iswitchb-completions (name) |
| 1252 | "Return the string that is displayed after the user's text. | 1283 | "Return the string that is displayed after the user's text. |
| 1253 | Modified from `icomplete-completions'." | 1284 | Modified from `icomplete-completions'." |
| 1254 | 1285 | ||
| 1255 | (let ((comps iswitchb-matches) | 1286 | (let ((comps iswitchb-matches) |
| 1256 | ; "-determined" - only one candidate | 1287 | ; "-determined" - only one candidate |
| 1257 | (open-bracket-determined (if require-match "(" "[")) | 1288 | (open-bracket-determined "[") |
| 1258 | (close-bracket-determined (if require-match ")" "]")) | 1289 | (close-bracket-determined "]") |
| 1259 | ;"-prospects" - more than one candidate | 1290 | ;"-prospects" - more than one candidate |
| 1260 | (open-bracket-prospects "{") | 1291 | (open-bracket-prospects "{") |
| 1261 | (close-bracket-prospects "}") | 1292 | (close-bracket-prospects "}") |
| 1262 | first) | 1293 | first) |
| 1263 | 1294 | ||
| 1264 | (if (and iswitchb-use-fonts comps) | 1295 | (if (and iswitchb-use-faces comps) |
| 1265 | (progn | 1296 | (progn |
| 1266 | (setq first (car comps)) | 1297 | (setq first (car comps)) |
| 1267 | (setq first (format "%s" first)) | 1298 | (setq first (format "%s" first)) |
| 1268 | (put-text-property 0 (length first) 'face | 1299 | (put-text-property 0 (length first) 'face |
| 1269 | (if (= (length comps) 1) | 1300 | (if (= (length comps) 1) |
| 1270 | 'font-lock-comment-face | 1301 | (if iswitchb-invalid-regexp |
| 1271 | 'font-lock-function-name-face) | 1302 | 'iswitchb-invalid-regexp-face |
| 1303 | 'iswitchb-single-match-face) | ||
| 1304 | 'iswitchb-current-match-face) | ||
| 1272 | first) | 1305 | first) |
| 1273 | (setq comps (cons first (cdr comps))))) | 1306 | (setq comps (cons first (cdr comps))))) |
| 1274 | 1307 | ||
| @@ -1297,7 +1330,7 @@ Modified from `icomplete-completions'." | |||
| 1297 | (let ((comp comps)) | 1330 | (let ((comp comps)) |
| 1298 | (while comp | 1331 | (while comp |
| 1299 | (put-text-property 0 (length (car comp)) | 1332 | (put-text-property 0 (length (car comp)) |
| 1300 | 'face 'font-lock-builtin-face | 1333 | 'face 'iswitchb-virtual-matches-face |
| 1301 | (car comp)) | 1334 | (car comp)) |
| 1302 | (setq comp (cdr comp)))))) | 1335 | (setq comp (cdr comp)))))) |
| 1303 | 1336 | ||
| @@ -1305,16 +1338,23 @@ Modified from `icomplete-completions'." | |||
| 1305 | open-bracket-determined | 1338 | open-bracket-determined |
| 1306 | close-bracket-determined)) | 1339 | close-bracket-determined)) |
| 1307 | 1340 | ||
| 1308 | ((null (cdr comps)) ;one match | 1341 | (iswitchb-invalid-regexp |
| 1309 | (concat (if (and (> (length (car comps)) | 1342 | (concat " " (car comps))) |
| 1310 | (length name))) | 1343 | ((null (cdr comps)) ;one match |
| 1311 | (concat open-bracket-determined | 1344 | (concat |
| 1345 | (if (if (not iswitchb-regexp) | ||
| 1346 | (= (length name) | ||
| 1347 | (length (car comps))) | ||
| 1348 | (string-match name (car comps)) | ||
| 1349 | (string-equal (match-string 0 (car comps)) | ||
| 1350 | (car comps))) | ||
| 1351 | "" | ||
| 1352 | (concat open-bracket-determined | ||
| 1312 | ;; when there is one match, show the | 1353 | ;; when there is one match, show the |
| 1313 | ;; matching buffer name in full | 1354 | ;; matching buffer name in full |
| 1314 | (car comps) | 1355 | (car comps) |
| 1315 | close-bracket-determined) | 1356 | close-bracket-determined)) |
| 1316 | "") | 1357 | (if (not iswitchb-use-faces) " [Matched]"))) |
| 1317 | (if (not iswitchb-use-fonts) " [Matched]"))) | ||
| 1318 | (t ;multiple matches | 1358 | (t ;multiple matches |
| 1319 | (if (and iswitchb-max-to-show | 1359 | (if (and iswitchb-max-to-show |
| 1320 | (> (length comps) iswitchb-max-to-show)) | 1360 | (> (length comps) iswitchb-max-to-show)) |