annotate lisp/isearchb.el @ 70108:3233d9998115

(comint-previous-input): Don't clobber input line when moving off either end of the input history ring. (comint-delete-input): New function, used by `comint-previous-input' and others. (comint-previous-matching-input): Use `coming-delete-input'. Save the partial input if leaving the edit line. Goto point-max before deleting input to avoid partial input fragments hanging around. (comint-restore-input): New function, used by `comint-previous-input', and bound to "C-c C-j".
author J.D. Smith <jdsmith@as.arizona.edu>
date Tue, 18 Apr 2006 23:48:53 +0000
parents 3bd95f4f2941
children 0245a94c8ed9
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
68651
3bd95f4f2941 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64762
diff changeset
3 ;; Copyright (C) 2004, 2005, 2006 John Wiegley
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>
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
6 ;; Created: 16 Apr 2004
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
7 ;; Version: 1.5
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
8 ;; Keywords: lisp
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
9 ;; 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
10
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
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 ;; GNU Emacs is free software; you can redistribute it and/or modify
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
16 ;; any later version.
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
17
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
18 ;; 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
19 ;; 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
20 ;; 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
21 ;; GNU General Public License for more details.
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
22
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64091
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63420
diff changeset
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63420
diff changeset
26 ;; Boston, MA 02110-1301, USA.
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
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
86 "*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
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
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
93 "*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
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.
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
117 It's purpose is to pass different call arguments to
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))
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
140 (if last-command-char
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
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
143 (char-to-string last-command-char))))
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 ()
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
167 "Function added to post-command-hook to handle the isearchb \"mode\"."
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)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
180 (setq last-command-char nil)
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)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
186 (setq last-command-char nil)
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)
e0a9c86fa070 2004-05-08 John Wiegley <johnw@newartisans.com>
John Wiegley <johnw@newartisans.com>
parents:
diff changeset
190 (setq last-command-char nil)
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
55461
34b5f4f934df Changes from arch/CVS synchronization
Miles Bader <miles@gnu.org>
parents: 55433
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