Mercurial > emacs
annotate lisp/isearchb.el @ 97443:34df0af1cb93
*** empty log message ***
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Wed, 13 Aug 2008 03:12:49 +0000 |
parents | ee5932bf781d |
children | d42aff5ca541 |
rev | line source |
---|---|
55433
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
1 ;;; isearchb --- a marriage between iswitchb and isearch |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
2 |
79721 | 3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
55433
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
4 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
5 ;; Author: John Wiegley <johnw@gnu.org> |
74624 | 6 ;; Maintainer: FSF |
55433
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
7 ;; Created: 16 Apr 2004 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
8 ;; Version: 1.5 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
9 ;; Keywords: lisp |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
10 ;; X-URL: http://www.newartisans.com/johnw/emacs.html |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
11 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
12 ;; This file is part of GNU Emacs. |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
13 |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; GNU Emacs is free software: you can redistribute it and/or modify |
55433
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
15 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
16 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
17 ;; (at your option) any later version. |
55433
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
18 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
19 ;; GNU Emacs is distributed in the hope that it will be useful, |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
22 ;; GNU General Public License for more details. |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
23 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
24 ;; You should have received a copy of the GNU General Public License |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
55433
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
26 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
27 ;;; Commentary: |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
28 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
29 ;; This module allows you to switch to buffers even faster than with |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
30 ;; iswitchb! It is not intended to replace it, however, as it works |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
31 ;; well only with buffers whose names don't typically overlap. You'll |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
32 ;; have to try it first, and see how your mileage varies. |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
33 ;; |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
34 ;; The first way to use isearchb is by holding down a modifier key, in |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
35 ;; which case every letter you type while holding it searches for any |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
36 ;; buffer matching what you're typing (using the same ordering scheme |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
37 ;; employed by iswitchb). To use it this way, add to your .emacs: |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
38 ;; |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
39 ;; (isearchb-set-keybindings 'super) ; s-x s-y s-z now finds "xyz" |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
40 ;; |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
41 ;; The other way is by using a command that puts you into "search" |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
42 ;; mode, just like with isearch. I use C-z for this. The binding in |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
43 ;; my .emacs looks like: |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
44 ;; |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
45 ;; (define-key global-map [(control ?z)] 'isearchb-activate) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
46 ;; |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
47 ;; Now, after pressing C-z (for example), each self-inserting |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
48 ;; character thereafter will search for a buffer containing those |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
49 ;; characters. For instance, typing "C-z xyz" will switch to the |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
50 ;; first buffer containing "xyz". Once you press a non-self-inserting |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
51 ;; character (such as any control key sequence), the search will end. |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
52 ;; |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
53 ;; C-z after C-z toggles between the previously selected buffer and |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
54 ;; the current one. |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
55 ;; |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
56 ;; C-g aborts the search and returns you to your original buffer. |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
57 ;; |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
58 ;; TAB, after typing in a few characters (after C-z), will jump into |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
59 ;; iswitchb, using the prefix you've typed so far. This is handy when |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
60 ;; you realize that isearchb is not powerful enough to find the buffer |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
61 ;; you're looking for. |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
62 ;; |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
63 ;; C-s and C-r move forward and backward in the buffer list. If |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
64 ;; `isearchb-show-completions' is non-nil (the default), the list of |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
65 ;; possible completions is shown in the minibuffer. |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
66 ;; |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
67 ;; If `isearchb-idle-timeout' is set to a number, isearchb will quit |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
68 ;; after that many seconds of idle time. I recommend trying it set to |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
69 ;; one or two seconds. Then, if you switch to a buffer and wait for |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
70 ;; that amount of time, you can start typing without manually exiting |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
71 ;; isearchb. |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
72 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
73 ;; TODO: |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
74 ;; C-z C-z is broken |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
75 ;; killing iswitchb.el and then trying to switch back is broken |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
76 ;; make sure TAB isn't broken |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
77 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
78 (require 'iswitchb) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
79 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
80 (defgroup isearchb nil |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
81 "Switch between buffers using a mechanism like isearch." |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
82 :group 'iswitchb) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
83 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
84 (defcustom isearchb-idle-timeout nil |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
85 "*Number of idle seconds before isearchb turns itself off. |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
86 If nil, don't use a timeout." |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
87 :type '(choice (integer :tag "Seconds") |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
88 (const :tag "Disable" nil)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
89 :group 'isearchb) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
90 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
91 (defcustom isearchb-show-completions t |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
92 "*If non-nil, show possible completions in the minibuffer." |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
93 :type 'boolean |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
94 :group 'isearchb) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
95 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
96 (defvar isearchb-start-buffer nil) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
97 (defvar isearchb-last-buffer nil) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
98 (defvar isearchb-idle-timer nil) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
99 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
100 (defun isearchb-stop (&optional return-to-buffer ignore-command) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
101 "Called by isearchb to terminate a search in progress." |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
102 (remove-hook 'pre-command-hook 'isearchb-follow-char) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
103 (if return-to-buffer |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
104 (switch-to-buffer isearchb-start-buffer) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
105 (setq isearchb-last-buffer isearchb-start-buffer)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
106 (when isearchb-idle-timer |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
107 (cancel-timer isearchb-idle-timer) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
108 (setq isearchb-idle-timer nil)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
109 (if ignore-command |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
110 (setq this-command 'ignore |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
111 last-command 'ignore)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
112 (message nil)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
113 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
114 (defun isearchb-iswitchb () |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
115 "isearchb's custom version of the `iswitchb' command. |
75510
2efde0c63664
(isearchb-iswitchb): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
75352
diff
changeset
|
116 Its purpose is to pass different call arguments to |
55433
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
117 `iswitchb-read-buffer'." |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
118 (interactive) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
119 (let* ((prompt "iswitch ") |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
120 (iswitchb-method 'samewindow) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
121 (buf (iswitchb-read-buffer prompt nil nil iswitchb-text t))) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
122 (if (eq iswitchb-exit 'findfile) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
123 (call-interactively 'find-file) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
124 (when buf |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
125 (if (get-buffer buf) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
126 ;; buffer exists, so view it and then exit |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
127 (iswitchb-visit-buffer buf) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
128 ;; else buffer doesn't exist |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
129 (iswitchb-possible-new-buffer buf)))))) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
130 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
131 (defun isearchb () |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
132 "Switch to buffer matching a substring, based on chars typed." |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
133 (interactive) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
134 (unless (eq last-command 'isearchb) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
135 (setq iswitchb-text nil)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
136 (unless iswitchb-text |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
137 (setq iswitchb-text "") |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
138 (iswitchb-make-buflist nil)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
139 (if last-command-char |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
140 (setq iswitchb-rescan t |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
141 iswitchb-text (concat iswitchb-text |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
142 (char-to-string last-command-char)))) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
143 (iswitchb-set-matches) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
144 (let* ((match (car iswitchb-matches)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
145 (buf (and match (get-buffer match)))) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
146 (if (null buf) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
147 (progn |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
148 (isearchb-stop t) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
149 (isearchb-iswitchb)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
150 (switch-to-buffer buf) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
151 (if isearchb-show-completions |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
152 (message "isearchb: %s%s" iswitchb-text |
63042
925e8bd46083
(isearchb): Don't pass a spurious second argument to `iswitchb-completions'.
Juanma Barranquero <lekktu@gmail.com>
parents:
55461
diff
changeset
|
153 (iswitchb-completions iswitchb-text)) |
55433
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
154 (if (= 1 (length iswitchb-matches)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
155 (message "isearchb: %s (only match)" iswitchb-text) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
156 (message "isearchb: %s" iswitchb-text)))))) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
157 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
158 (defun isearchb-set-keybindings (modifier) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
159 "Setup isearchb on the given MODIFIER." |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
160 (dotimes (i 128) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
161 (if (eq 'self-insert-command |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
162 (lookup-key global-map (vector i))) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
163 (define-key global-map (vector (list modifier i)) 'isearchb)))) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
164 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
165 (defun isearchb-follow-char () |
76566
11d72543a2ba
(isearchb-follow-char): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
75510
diff
changeset
|
166 "Function added to `post-command-hook' to handle the isearchb \"mode\"." |
55433
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
167 (let (keys) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
168 (if (not (and (memq last-command '(isearchb isearchb-activate)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
169 (setq keys (this-command-keys)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
170 (= 1 (length keys)))) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
171 (isearchb-stop) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
172 (cond |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
173 ((or (equal keys "\C-h") (equal keys "\C-?") |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
174 (equal keys [backspace]) (equal keys [delete])) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
175 (setq iswitchb-text |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
176 (substring iswitchb-text 0 (1- (length iswitchb-text)))) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
177 (if (= 0 (length iswitchb-text)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
178 (isearchb-stop t t) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
179 (setq last-command-char nil) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
180 (setq this-command 'isearchb))) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
181 ((or (equal keys "\C-i") (equal keys [tab])) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
182 (setq this-command 'isearchb-iswitchb)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
183 ((equal keys "\C-s") |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
184 (iswitchb-next-match) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
185 (setq last-command-char nil) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
186 (setq this-command 'isearchb)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
187 ((equal keys "\C-r") |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
188 (iswitchb-prev-match) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
189 (setq last-command-char nil) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
190 (setq this-command 'isearchb)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
191 ((equal keys "\C-g") |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
192 (ding) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
193 (isearchb-stop t t)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
194 ((eq (lookup-key global-map keys) 'self-insert-command) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
195 (setq this-command 'isearchb))) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
196 (if (and isearchb-idle-timeout |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
197 (null isearchb-idle-timer)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
198 (setq isearchb-idle-timer |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
199 (run-with-idle-timer isearchb-idle-timeout nil |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
200 'isearchb-stop)))))) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
201 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
202 ;;;###autoload |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
203 (defun isearchb-activate () |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
204 "Active isearchb mode for subsequent alphanumeric keystrokes. |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
205 Executing this command again will terminate the search; or, if |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
206 the search has not yet begun, will toggle to the last buffer |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
207 accessed via isearchb." |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
208 (interactive) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
209 (cond |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
210 ((eq last-command 'isearchb) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
211 (isearchb-stop nil t)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
212 ((eq last-command 'isearchb-activate) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
213 (if isearchb-last-buffer |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
214 (switch-to-buffer isearchb-last-buffer) |
63420
f4efcc094de0
(isearchb-activate): Follow error conventions.
Juanma Barranquero <lekktu@gmail.com>
parents:
63042
diff
changeset
|
215 (error "isearchb: There is no previous buffer to toggle to")) |
55433
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
216 (isearchb-stop nil t)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
217 (t |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
218 (message "isearchb: ") |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
219 (setq iswitchb-text nil |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
220 isearchb-start-buffer (current-buffer)) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
221 (add-hook 'pre-command-hook 'isearchb-follow-char)))) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
222 |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
223 (provide 'isearchb) |
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
224 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79721
diff
changeset
|
225 ;; arch-tag: 9277523f-a624-4aa0-ba10-b89eeb7b6e99 |
55433
e0a9c86fa070
2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff
changeset
|
226 ;;; isearchb.el ends here |