annotate lisp/isearchb.el @ 107574:2628198e4d2a

*** empty log message ***
author Nick Roberts <nickrob@snap.net.nz>
date Tue, 30 Mar 2010 13:22:34 +1300
parents 1d1d5d9bd884
children 376148b31b5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 101010
diff changeset
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
101010
4efc7ca085ce Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
4 ;; Free Software Foundation, Inc.
55433
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
5
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
6 ;; Author: John Wiegley <johnw@gnu.org>
74624
0245a94c8ed9 No maintainer.
Richard M. Stallman <rms@gnu.org>
parents: 68651
diff changeset
7 ;; Maintainer: FSF
55433
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
8 ;; Created: 16 Apr 2004
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
9 ;; Version: 1.5
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
10 ;; Keywords: lisp
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
11 ;; 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
12
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
13 ;; This file is part of GNU Emacs.
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
14
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
15 ;; 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
16 ;; 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
17 ;; 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
18 ;; (at your option) any later version.
55433
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
19
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
20 ;; 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
21 ;; 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
22 ;; 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
23 ;; GNU General Public License for more details.
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
24
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
25 ;; 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
26 ;; 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
27
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
28 ;;; Commentary:
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
29
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
30 ;; 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
31 ;; 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
32 ;; 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
33 ;; 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
34 ;;
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
35 ;; 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
36 ;; 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
37 ;; 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
38 ;; 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
39 ;;
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
40 ;; (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
41 ;;
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
42 ;; 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
43 ;; 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
44 ;; my .emacs looks like:
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
45 ;;
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
46 ;; (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
47 ;;
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
48 ;; 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
49 ;; 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
50 ;; 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
51 ;; 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
52 ;; 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
53 ;;
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
54 ;; 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
55 ;; the current one.
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
56 ;;
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
57 ;; 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
58 ;;
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
59 ;; 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
60 ;; 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
61 ;; 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
62 ;; you're looking for.
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
63 ;;
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
64 ;; 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
65 ;; `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
66 ;; possible completions is shown in the minibuffer.
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
67 ;;
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
68 ;; 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
69 ;; 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
70 ;; 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
71 ;; 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
72 ;; isearchb.
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
73
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
74 ;; TODO:
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
75 ;; C-z C-z is broken
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
76 ;; 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
77 ;; make sure TAB isn't broken
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
78
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
79 (require 'iswitchb)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
80
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
81 (defgroup isearchb nil
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
82 "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
83 :group 'iswitchb)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
84
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
85 (defcustom isearchb-idle-timeout nil
100171
d42aff5ca541 * align.el:
Lute Kamstra <lute@gnu.org>
parents: 94678
diff changeset
86 "Number of idle seconds before isearchb turns itself off.
55433
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
87 If nil, don't use a timeout."
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
88 :type '(choice (integer :tag "Seconds")
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
89 (const :tag "Disable" nil))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
90 :group 'isearchb)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
91
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
92 (defcustom isearchb-show-completions t
100171
d42aff5ca541 * align.el:
Lute Kamstra <lute@gnu.org>
parents: 94678
diff changeset
93 "If non-nil, show possible completions in the minibuffer."
55433
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
94 :type 'boolean
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
95 :group 'isearchb)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
96
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
97 (defvar isearchb-start-buffer nil)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
98 (defvar isearchb-last-buffer nil)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
99 (defvar isearchb-idle-timer nil)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
100
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
101 (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
102 "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
103 (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
104 (if return-to-buffer
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
105 (switch-to-buffer isearchb-start-buffer)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
106 (setq isearchb-last-buffer isearchb-start-buffer))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
107 (when isearchb-idle-timer
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
108 (cancel-timer isearchb-idle-timer)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
109 (setq isearchb-idle-timer nil))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
110 (if ignore-command
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
111 (setq this-command 'ignore
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
112 last-command 'ignore))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
113 (message nil))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
114
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
115 (defun isearchb-iswitchb ()
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
116 "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
117 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
118 `iswitchb-read-buffer'."
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
119 (interactive)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
120 (let* ((prompt "iswitch ")
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
121 (iswitchb-method 'samewindow)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
122 (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
123 (if (eq iswitchb-exit 'findfile)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
124 (call-interactively 'find-file)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
125 (when buf
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
126 (if (get-buffer buf)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
127 ;; 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
128 (iswitchb-visit-buffer buf)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
129 ;; else buffer doesn't exist
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
130 (iswitchb-possible-new-buffer buf))))))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
131
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
132 (defun isearchb ()
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
133 "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
134 (interactive)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
135 (unless (eq last-command 'isearchb)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
136 (setq iswitchb-text nil))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
137 (unless iswitchb-text
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
138 (setq iswitchb-text "")
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
139 (iswitchb-make-buflist nil))
101010
4efc7ca085ce Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
140 (if last-command-event
55433
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
141 (setq iswitchb-rescan t
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
142 iswitchb-text (concat iswitchb-text
101010
4efc7ca085ce Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
143 (char-to-string last-command-event))))
55433
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
144 (iswitchb-set-matches)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
145 (let* ((match (car iswitchb-matches))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
146 (buf (and match (get-buffer match))))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
147 (if (null buf)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
148 (progn
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
149 (isearchb-stop t)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
150 (isearchb-iswitchb))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
151 (switch-to-buffer buf)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
152 (if isearchb-show-completions
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
153 (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
154 (iswitchb-completions iswitchb-text))
55433
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
155 (if (= 1 (length iswitchb-matches))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
156 (message "isearchb: %s (only match)" iswitchb-text)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
157 (message "isearchb: %s" iswitchb-text))))))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
158
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
159 (defun isearchb-set-keybindings (modifier)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
160 "Setup isearchb on the given MODIFIER."
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
161 (dotimes (i 128)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
162 (if (eq 'self-insert-command
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
163 (lookup-key global-map (vector i)))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
164 (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
165
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
166 (defun isearchb-follow-char ()
76566
11d72543a2ba (isearchb-follow-char): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 75510
diff changeset
167 "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
168 (let (keys)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
169 (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
170 (setq keys (this-command-keys))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
171 (= 1 (length keys))))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
172 (isearchb-stop)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
173 (cond
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
174 ((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
175 (equal keys [backspace]) (equal keys [delete]))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
176 (setq iswitchb-text
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
177 (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
178 (if (= 0 (length iswitchb-text))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
179 (isearchb-stop t t)
101010
4efc7ca085ce Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
180 (setq last-command-event nil)
55433
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
181 (setq this-command 'isearchb)))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
182 ((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
183 (setq this-command 'isearchb-iswitchb))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
184 ((equal keys "\C-s")
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
185 (iswitchb-next-match)
101010
4efc7ca085ce Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
186 (setq last-command-event nil)
55433
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
187 (setq this-command 'isearchb))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
188 ((equal keys "\C-r")
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
189 (iswitchb-prev-match)
101010
4efc7ca085ce Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
190 (setq last-command-event nil)
55433
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
191 (setq this-command 'isearchb))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
192 ((equal keys "\C-g")
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
193 (ding)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
194 (isearchb-stop t t))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
195 ((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
196 (setq this-command 'isearchb)))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
197 (if (and isearchb-idle-timeout
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
198 (null isearchb-idle-timer))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
199 (setq isearchb-idle-timer
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
200 (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
201 'isearchb-stop))))))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
202
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
203 ;;;###autoload
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
204 (defun isearchb-activate ()
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
205 "Active isearchb mode for subsequent alphanumeric keystrokes.
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
206 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
207 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
208 accessed via isearchb."
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
209 (interactive)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
210 (cond
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
211 ((eq last-command 'isearchb)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
212 (isearchb-stop nil t))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
213 ((eq last-command 'isearchb-activate)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
214 (if isearchb-last-buffer
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
215 (switch-to-buffer isearchb-last-buffer)
63420
f4efcc094de0 (isearchb-activate): Follow error conventions.
Juanma Barranquero <lekktu@gmail.com>
parents: 63042
diff changeset
216 (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
217 (isearchb-stop nil t))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
218 (t
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
219 (message "isearchb: ")
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
220 (setq iswitchb-text nil
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
221 isearchb-start-buffer (current-buffer))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
222 (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
223
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
224 (provide 'isearchb)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
225
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 79721
diff changeset
226 ;; 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
227 ;;; isearchb.el ends here