Mercurial > emacs
annotate lisp/iswitchb.el @ 18797:e9aa787f0154
(quail-translate-key): Fix previous change.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 15 Jul 1997 08:24:47 +0000 |
parents | 61751ba33c8f |
children | fff55212f6a7 |
rev | line source |
---|---|
17617 | 1 ;;; iswitchb.el --- switch between buffers using substrings |
17616 | 2 |
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Stephen Eglen <stephene@cogs.susx.ac.uk> | |
6 ;; Maintainer: Stephen Eglen <stephene@cogs.susx.ac.uk> | |
7 ;; Keywords: extensions | |
8 ;; location: http://www.cogs.susx.ac.uk/users/stephene/emacs | |
9 | |
17617 | 10 ;; This file is part of GNU Emacs. |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
17616 | 13 ;; it under the terms of the GNU General Public License as published by |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17617 | 17 ;; GNU Emacs is distributed in the hope that it will be useful, |
17616 | 18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
26 | |
27 ;;; Installation: | |
28 | |
29 ;; To get the functions in this package bound to keys, do | |
30 ;; (iswitchb-default-keybindings) | |
31 | |
32 ;;; Commentary: | |
33 | |
34 ;; As you type in a substring, the list of buffers currently matching | |
35 ;; the substring are displayed as you type. The list is ordered so | |
36 ;; that the most recent buffers visited come at the start of the list. | |
37 ;; The buffer at the start of the list will be the one visited when | |
38 ;; you press return. By typing more of the substring, the list is | |
39 ;; narrowed down so that gradually the buffer you want will be at the | |
40 ;; top of the list. Alternatively, you can use C-s an C-r to rotate | |
41 ;; buffer names in the list until the one you want is at the top of | |
42 ;; the list. Completion is also available so that you can see what is | |
43 ;; common to all of the matching buffers as you type. | |
44 | |
45 ;; This code is similar to a couple of other packages. Michael R Cook | |
46 ;; <mcook@cognex.com wrote a similar buffer switching package, but | |
47 ;; does exact matching rather than substring matching on buffer names. | |
48 ;; I also modified a couple of functions from icomplete.el to provide | |
49 ;; the completion feedback in the minibuffer. | |
50 | |
51 ;;; Example | |
52 | |
53 ;;If I have two buffers called "123456" and "123", with "123456" the | |
54 ;;most recent, when I use iswitchb, I first of all get presented with | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
55 ;;the list of all the buffers |
17616 | 56 ;; |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
57 ;; iswitch {123456,123} |
17616 | 58 ;; |
59 ;; If I then press 2: | |
60 ;; iswitch 2[3]{123456,123} | |
61 ;; | |
62 ;; The list in {} are the matching buffers, most recent first (buffers | |
63 ;; visible in the current frame are put at the end of the list by | |
64 ;; default). At any time I can select the item at the head of the | |
65 ;; list by pressing RET. I can also bring the put the first element | |
66 ;; at the end of the list by pressing C-s, or put the last element at | |
67 ;; the head of the list by pressing C-r. The item in [] indicates | |
68 ;; what can be added to my input by pressing TAB. In this case, I | |
69 ;; will get "3" added to my input. So, press TAB: | |
70 ;; iswitch 23{123456,123} | |
71 ;; | |
72 ;; At this point, I still have two matching buffers. | |
73 ;; If I want the first buffer in the list, I simply press RET. If I | |
74 ;; wanted the second in the list, I could press C-s to move it to the | |
75 ;; top of the list and then RET to select it. | |
76 ;; | |
77 ;;However, If I type 4, I only have one match left: | |
78 ;; iswitch 234[123456] [Matched] | |
79 ;; | |
80 ;;Since there is only one matching buffer left, it is given in [] and we | |
81 ;;see the text [Matched] afterwards. I can now press TAB or RET to go | |
82 ;;to that buffer. | |
83 ;; | |
84 ;; If however, I now type "a": | |
85 ;; iswitch 234a [No match] | |
86 ;; There are no matching buffers. If I press RET or TAB, I can be | |
87 ;; prompted to create a new buffer called "234a". | |
88 ;; | |
89 ;; Of course, where this function comes in really useful is when you | |
90 ;; can specify the buffer using only a few keystrokes. In the above | |
91 ;; example, the quickest way to get to the "123456" buffer would be | |
92 ;; just to type 4 and then RET (assuming there isnt any newer buffer | |
93 ;; with 4 in its name). | |
94 | |
95 ;; To see a full list of all matching buffers in a separate buffer, | |
96 ;; hit ? or press TAB when there are no further completions to the | |
97 ;; substring. | |
98 | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
99 ;; The buffer at the head of the list can be killed by pressing C-k. |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
100 ;; If the buffer needs saving, you will be queried before the buffer |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
101 ;; is killed. |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
102 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
103 ;; If you find that the file you are after is not in a buffer, you can |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
104 ;; press C-x C-f to immediately drop into find-file. |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
105 |
17616 | 106 ;; |
107 ;; See the doc string of iswitchb for full keybindings and features. | |
108 ;; (describe-function 'iswitchb) | |
109 | |
110 ;;; Customisation | |
111 | |
112 ;; See the User Variables section below for easy ways to change the | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
113 ;; functionality of the program. These are accessible using the |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
114 ;; custom package. |
17616 | 115 ;; To modify the keybindings, use the hook provided. For example: |
116 ;;(add-hook 'iswitchb-define-mode-map-hook | |
117 ;; 'iswitchb-my-keys) | |
118 ;; | |
119 ;;(defun iswitchb-my-keys () | |
120 ;; "Add my keybings for iswitchb." | |
121 ;; (define-key iswitchb-mode-map " " 'iswitchb-next-match) | |
122 ;; ) | |
123 ;; | |
124 ;; Seeing all the matching buffers. | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
125 ;; |
17616 | 126 ;; If you have many matching buffers, they may not all fit onto one |
127 ;; line of the minibuffer. In this case, you should use rsz-mini | |
128 ;; (resize-minibuffer-mode). You can also limit iswitchb so that it | |
129 ;; only shows a certain number of lines -- see the documentation for | |
130 ;; `iswitchb-minibuffer-setup-hook'. | |
131 | |
132 | |
133 ;; Changing the list of buffers. | |
134 | |
135 ;; By default, the list of current buffers is most recent first, | |
136 ;; oldest last, with the exception that the buffers visible in the | |
137 ;; current frame are put at the end of the list. A hook exists to | |
138 ;; allow other functions to order the list. For example, if you add: | |
139 ;; | |
140 ;; (add-hook 'iswitchb-make-buflist-hook 'iswitchb-summaries-to-end) | |
141 ;; | |
142 ;; then all buffers matching "Summary" are moved to the end of the | |
143 ;; list. (I find this handy for keeping the INBOX Summary and so on | |
144 ;; out of the way.) It also moves buffers matching "output\*$" to the | |
145 ;; end of the list (these are created by AUC TeX when compiling.) | |
146 ;; Other functions could be made available which alter the list of | |
147 ;; matching buffers (either deleting or rearranging elements.) | |
148 | |
149 ;; Font-Lock | |
150 | |
151 ;; If you have font-lock loaded, the first matching buffer is | |
152 ;; highlighted. To switch this off, set (setq iswitchb-use-fonts nil) | |
153 ;; I don't use font-lock that much, so I've hardcoded the faces. If | |
154 ;; this is too harsh, let me know. Colouring of the matching buffer | |
155 ;; name was suggested by Carsten Dominik (dominik@strw.leidenuniv.nl) | |
156 | |
157 ;;; Comparison with iswitch-buffer | |
158 | |
159 ;; This package is a rewrite of iswitch-buffer, using the minibuffer | |
160 ;; rather than the echo area. The advantages of using the minibuffer | |
161 ;; are several: | |
162 ;; o minibuffer has more powerful editing facilities | |
163 ;; o doesnt interfere with other packages that use the echo area | |
164 ;; o *Messages* buffer doesnt get filled up with all of the messages that | |
165 ;; go to the modeline | |
166 ;; o cursor is in the minibuffer, which somehow looks right. | |
167 ;; o minibuffer can be resized dynamically to show all the possible matching | |
168 ;; buffers rather than just the first line's worth (using rsz-mini). | |
169 ;; | |
170 ;; Disadvantages: | |
171 ;; o cant change the prompt to indicate status of searching (eg whether | |
172 ;; regexp searching is currently on). | |
173 | |
174 | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
175 ;;; TODO |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
176 ;; Could this selection also be used for other buffer selection |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
177 ;; routines, such as append-to-buffer and kill-buffer? |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
178 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
179 ;; Pressing Tab key twice (without completion) does not scroll the |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
180 ;; list of buffers. |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
181 |
17616 | 182 ;;; Acknowledgements |
183 | |
184 ;; Thanks to Jari Aalto <jari.aalto@poboxes.com> for help with the | |
185 ;; first version of this package, iswitch-buffer. Thanks also to many | |
186 ;; others for testing earlier versions. | |
187 | |
188 ;;; Code: | |
189 | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
190 ;; Set up the custom library. |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
191 ;; taken from http://www.dina.kvl.dk/~abraham/custom/ |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
192 (eval-and-compile |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
193 (condition-case () |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
194 (require 'custom) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
195 (error nil)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
196 (if (and (featurep 'custom) (fboundp 'custom-declare-variable)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
197 nil ;; We've got what we needed |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
198 ;; We have the old custom-library, hack around it! |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
199 (defmacro defgroup (&rest args) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
200 nil) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
201 (defmacro defcustom (var value doc &rest args) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
202 (` (defvar (, var) (, value) (, doc)))))) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
203 |
17616 | 204 ;;; User Variables |
205 ;; | |
206 ;; These are some things you might want to change. | |
207 | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
208 (defgroup iswitchb nil |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
209 "switch between buffers using substrings." |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
210 :group 'extensions |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
211 ;; These links are to be added in later versions of custom and |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
212 ;; so are currently commented out. |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
213 :link '(emacs-commentary-link :tag "Commentary" "iswitchb.el") |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
214 :link '(emacs-library-link :tag "Lisp File" "iswitchb.el") |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
215 ) |
17616 | 216 |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
217 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
218 (defcustom iswitchb-case case-fold-search |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
219 "*Non-nil if searching of buffer names should ignore case." |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
220 :type 'boolean |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
221 :group 'iswitchb) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
222 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
223 (defcustom iswitchb-buffer-ignore |
17616 | 224 '("^ ") |
17617 | 225 "*List of regexps or functions matching buffer names to ignore. |
226 For example, traditional behavior is not to list buffers whose names begin | |
227 with a space, for which the regexp is `^ '. See the source file for | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
228 example functions that filter buffernames." |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
229 :type '(repeat regexp) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
230 :group 'iswitchb) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
231 |
17616 | 232 |
233 ;;; Examples for setting the value of iswitchb-buffer-ignore | |
234 ;(defun -c-mode (name) | |
235 ; "Ignore all c mode buffers -- example function for iswitchb." | |
236 ; (save-excursion | |
237 ; (set-buffer name) | |
238 ; (string-match "^C$" mode-name))) | |
239 | |
240 ;(setq iswitchb-buffer-ignore '("^ " ignore-c-mode)) | |
241 ;(setq iswitchb-buffer-ignore '("^ " "\\.c$" "\\.h$")) | |
242 | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
243 (defcustom iswitchb-default-method 'always-frame |
17617 | 244 "*How to switch to new buffer when using `iswitchb-buffer'. |
17616 | 245 Possible values: |
246 `samewindow' Show new buffer in same window | |
247 `otherwindow' Show new buffer in another window (same frame) | |
17618
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
248 `display' Display buffer in another window without switching to it |
17616 | 249 `otherframe' Show new buffer in another frame |
250 `maybe-frame' If a buffer is visible in another frame, prompt to ask if you | |
251 you want to see the buffer in the same window of the current | |
252 frame or in the other frame. | |
253 `always-frame' If a buffer is visible in another frame, raise that | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
254 frame. Otherwise, visit the buffer in the same window." |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
255 :type '(choice (const :tag "samewindow" samewindow) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
256 (const :tag "otherwindow" otherwindow) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
257 (const :tag "display" display) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
258 (const :tag "otherframe" otherframe) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
259 (const :tag "maybe-frame" maybe-frame) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
260 (const :tag "always-frame" always-frame)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
261 :group 'iswitchb) |
17616 | 262 |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
263 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
264 (defcustom iswitchb-regexp nil |
17617 | 265 "*Non-nil means that `iswitchb' will do regexp matching. |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
266 Value can be toggled within `iswitchb'." |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
267 :type 'boolean |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
268 :group 'iswitchb) |
17616 | 269 |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
270 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
271 (defcustom iswitchb-newbuffer t |
17616 | 272 "*Non-nil means create new buffer if no buffer matches substring. |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
273 See also `iswitchb-prompt-newbuffer'." |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
274 :type 'boolean |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
275 :group 'iswitchb) |
17616 | 276 |
277 | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
278 (defcustom iswitchb-prompt-newbuffer t |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
279 "*Non-nil means prompt user to confirm before creating new buffer. |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
280 See also `iswitchb-newbuffer'." |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
281 :type 'boolean |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
282 :group 'iswitchb) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
283 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
284 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
285 (defcustom iswitchb-define-mode-map-hook nil |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
286 "*Hook to define keys in `iswitchb-mode-map' for extra keybindings." |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
287 :type 'hook |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
288 :group 'iswitchb) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
289 |
17616 | 290 |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
291 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
292 (defcustom iswitchb-use-fonts t |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
293 "*Non-nil means use fonts for showing first match." |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
294 :type 'boolean |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
295 :group 'iswitchb) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
296 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
297 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
298 (defcustom iswitchb-make-buflist-hook nil |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
299 "*Hook to run when list of matching buffers is created." |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
300 :type 'hook |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
301 :group 'iswitchb) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
302 |
17616 | 303 |
304 | |
305 (defvar iswitchb-method nil | |
17617 | 306 "*Stores the method for viewing the selected buffer. |
17618
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
307 Its value is one of `samewindow', `otherwindow', `display', `otherframe', |
17617 | 308 `maybe-frame' or `always-frame'. See `iswitchb-default-method' for |
309 details of values.") | |
17616 | 310 |
311 (defvar iswitchb-all-frames 'visible | |
312 "*Argument to pass to `walk-windows' when finding visible buffers. | |
313 See documentation of `walk-windows' for useful values.") | |
314 | |
315 | |
316 | |
317 ;; Do we need the variable iswitchb-use-mycompletion? | |
318 | |
319 | |
320 ;;; Internal Variables | |
321 (defvar iswitchb-minibuffer-setup-hook nil | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
322 "Iswitchb-specific customization of minibuffer setup. |
17616 | 323 |
17617 | 324 This hook is run during minibuffer setup iff `iswitchb' will be active. |
17616 | 325 It is intended for use in customizing iswitchb for interoperation |
326 with other packages. For instance: | |
327 | |
328 \(add-hook 'iswitchb-minibuffer-setup-hook | |
329 \(function | |
330 \(lambda () | |
331 \(make-local-variable 'resize-minibuffer-window-max-height) | |
332 \(setq resize-minibuffer-window-max-height 3)))) | |
333 | |
334 will constrain rsz-mini to a maximum minibuffer height of 3 lines when | |
17617 | 335 iswitchb is running. Copied from `icomplete-minibuffer-setup-hook'.") |
17616 | 336 |
337 (defvar iswitchb-eoinput 1 | |
338 "Point where minibuffer input ends and completion info begins. | |
17617 | 339 Copied from `icomplete-eoinput'.") |
17616 | 340 (make-variable-buffer-local 'iswitchb-eoinput) |
341 | |
342 | |
343 (defvar iswitchb-buflist nil | |
344 "Stores the current list of buffers that will be searched through. | |
345 The list is ordered, so that the most recent buffers come first, | |
346 although by default, the buffers visible in the current frame are put | |
347 at the end of the list. Created by `iswitchb-make-buflist'.") | |
348 | |
349 ;; todo -- is this necessary? | |
350 | |
351 (defvar iswitchb-use-mycompletion nil | |
17617 | 352 "Non-nil means use `iswitchb-buffer' completion feedback. |
353 Should only be set to t by iswitchb functions, so that it doesn't | |
354 interfere with other minibuffer usage.") | |
17616 | 355 |
356 (defvar iswitchb-change-word-sub nil | |
357 "Private variable used by `iswitchb-word-matching-substring'.") | |
358 | |
359 | |
360 (defvar iswitchb-common-match-string nil | |
361 "Stores the string that is common to all matching buffers.") | |
362 | |
363 | |
364 (defvar iswitchb-rescan nil | |
365 "Non-nil means we need to regenerate the list of matching buffers.") | |
366 | |
367 (defvar iswitchb-text nil | |
368 "Stores the users string as it is typed in.") | |
369 | |
370 (defvar iswitchb-matches nil | |
371 "List of buffers currenly matching `iswitchb-text'.") | |
372 | |
373 (defvar iswitchb-mode-map nil | |
17617 | 374 "Keymap for `iswitchb-buffer'.") |
17616 | 375 |
376 (defvar iswitchb-history nil | |
17617 | 377 "History of buffers selected using `iswitchb-buffer'.") |
17616 | 378 |
379 (defvar iswitchb-exit nil | |
17617 | 380 "Flag to monitor how `iswitchb-buffer' exits. |
381 If equal to `takeprompt', we use the prompt as the buffer name to be | |
382 selected.") | |
17616 | 383 |
384 (defvar iswitchb-buffer-ignore-orig nil | |
385 "Stores original value of `iswitchb-buffer-ignore'.") | |
386 | |
387 (defvar iswitchb-xemacs (string-match "XEmacs" (emacs-version)) | |
388 "Non-nil if we are running XEmacs. Otherwise, assume we are running Emacs.") | |
389 | |
390 | |
391 ;;; FUNCTIONS | |
392 | |
393 | |
394 ;;; ISWITCHB KEYMAP | |
395 (defun iswitchb-define-mode-map () | |
17617 | 396 "Set up the keymap for `iswitchb-buffer'." |
17616 | 397 (interactive) |
398 (let (map) | |
399 ;; generated every time so that it can inheret new functions. | |
400 ;;(or iswitchb-mode-map | |
401 | |
402 (setq map (copy-keymap minibuffer-local-map)) | |
403 (define-key map "?" 'iswitchb-completion-help) | |
404 (define-key map "\C-s" 'iswitchb-next-match) | |
405 (define-key map "\C-r" 'iswitchb-prev-match) | |
406 (define-key map "\t" 'iswitchb-complete) | |
407 (define-key map "\C-j" 'iswitchb-select-buffer-text) | |
408 (define-key map "\C-t" 'iswitchb-toggle-regexp) | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
409 (define-key map "\C-x\C-f" 'iswitchb-find-file) |
17616 | 410 ;;(define-key map "\C-a" 'iswitchb-toggle-ignore) |
411 (define-key map "\C-c" 'iswitchb-toggle-case) | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
412 (define-key map "\C-k" 'iswitchb-kill-buffer) |
17616 | 413 (setq iswitchb-mode-map map) |
414 (run-hooks 'iswitchb-define-mode-map-hook) | |
415 )) | |
416 | |
417 | |
418 | |
419 ;;; MAIN FUNCTION | |
420 (defun iswitchb () | |
421 "Switch to buffer matching a substring. | |
422 As you type in a string, all of the buffers matching the string are | |
423 displayed. When you have found the buffer you want, it can then be | |
424 selected. As you type, most keys have their normal keybindings, | |
425 except for the following: | |
426 \\<iswitchb-mode-map> | |
427 | |
428 RET Select the buffer at the front of the list of matches. If the | |
17617 | 429 list is empty, possibly prompt to create new buffer. |
17616 | 430 |
431 \\[iswitchb-select-buffer-text] Select the current prompt as the buffer. | |
432 If no buffer is found, prompt for a new one. | |
433 | |
434 \\[iswitchb-next-match] Put the first element at the end of the list. | |
435 \\[iswitchb-prev-match] Put the last element at the start of the list. | |
436 \\[iswitchb-complete] Complete a common suffix to the current string that | |
437 matches all buffers. If there is only one match, select that buffer. | |
438 If there is no common suffix, show a list of all matching buffers | |
439 in a separate window. | |
440 \\[iswitchb-toggle-regexp] Toggle rexep searching. | |
441 \\[iswitchb-toggle-case] Toggle case-sensitive searching of buffer names. | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
442 \\[iswitchb-completion-help] Show list of matching buffers in separate window. |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
443 \\[iswitchb-find-file] Exit iswitchb and drop into find-file. |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
444 \\[iswitchb-kill-buffer] Kill buffer at head of buffer list." |
17616 | 445 ;;\\[iswitchb-toggle-ignore] Toggle ignoring certain buffers (see \ |
446 ;;`iswitchb-buffer-ignore') | |
447 | |
448 (let | |
449 ( | |
450 prompt | |
451 buf-sel | |
452 iswitchb-final-text | |
453 (minibuffer-confirm-incomplete nil) ;XEmacs todo: prevent `;confirm' | |
454 (icomplete-mode nil) ;; prevent icomplete starting up | |
455 ;; can only use fonts if they have been bound. | |
456 (iswitchb-use-fonts (and iswitchb-use-fonts | |
457 (boundp 'font-lock-comment-face) | |
458 (boundp 'font-lock-function-name-face))) | |
459 ) | |
460 | |
461 (iswitchb-define-mode-map) | |
462 (setq iswitchb-exit nil) | |
463 (setq iswitchb-rescan t) | |
464 (setq iswitchb-text "") | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
465 (iswitchb-set-matches) |
17616 | 466 (setq prompt (format "iswitch ")) |
467 (iswitchb-make-buflist) | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
468 (let |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
469 ((minibuffer-local-completion-map iswitchb-mode-map)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
470 ;; prompt the user for the buffer name |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
471 (setq iswitchb-final-text (completing-read prompt |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
472 ;;nil |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
473 '(("dummy".1)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
474 ;;("2".2) ("3".3)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
475 nil nil |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
476 nil;init string |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
477 'iswitchb-history))) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
478 |
17616 | 479 ;;(message "chosen text %s" iswitchb-final-text) |
480 ;; Choose the buffer name: either the text typed in, or the head | |
481 ;; of the list of matches | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
482 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
483 (cond ( (eq iswitchb-exit 'findfile) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
484 (call-interactively 'find-file)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
485 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
486 (t |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
487 (if (or |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
488 (eq iswitchb-exit 'takeprompt) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
489 (null iswitchb-matches)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
490 (setq buf-sel iswitchb-final-text) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
491 ;; else take head of list |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
492 (setq buf-sel (car iswitchb-matches))) |
17616 | 493 |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
494 ;; Or possibly choose the default buffer |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
495 (if (equal iswitchb-final-text "") |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
496 (setq buf-sel (car iswitchb-matches))) |
17616 | 497 |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
498 ;; View the buffer |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
499 (message "go to buf %s" buf-sel) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
500 ;; Check buf-sel is non-nil. |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
501 (if buf-sel |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
502 (if (get-buffer buf-sel) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
503 ;; buffer exists, so view it and then exit |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
504 (iswitchb-visit-buffer buf-sel) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
505 ;; else buffer doesnt exist |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
506 (iswitchb-possible-new-buffer buf-sel))) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
507 )) |
17616 | 508 |
509 )) | |
510 | |
511 | |
512 ;;; COMPLETION CODE | |
513 | |
514 (defun iswitchb-set-common-completion () | |
17617 | 515 "Find common completion of `iswitchb-text' in `iswitchb-matches'. |
516 The result is stored in `iswitchb-common-match-string'." | |
17616 | 517 |
518 (let* (val) | |
519 (setq iswitchb-common-match-string nil) | |
520 (if (and iswitchb-matches | |
521 (stringp iswitchb-text) | |
522 (> (length iswitchb-text) 0)) | |
523 (if (setq val (iswitchb-find-common-substring | |
524 iswitchb-matches iswitchb-text)) | |
525 (setq iswitchb-common-match-string val))) | |
526 val | |
527 )) | |
528 | |
529 | |
530 (defun iswitchb-complete () | |
531 "Try and complete the current pattern amongst the buffer names." | |
532 (interactive) | |
533 (let (res) | |
534 (cond ((not iswitchb-matches) | |
535 (iswitchb-completion-help) | |
536 ) | |
537 | |
538 ((eq 1 (length iswitchb-matches)) | |
539 ;; only one choice, so select it. | |
540 (exit-minibuffer)) | |
541 | |
542 (t | |
543 ;; else there could be some completions | |
544 | |
545 (setq res (iswitchb-find-common-substring | |
546 iswitchb-matches iswitchb-text)) | |
547 (if (and (not (memq res '(t nil))) | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
548 (not (equal res iswitchb-text))) |
17616 | 549 ;; found something to complete, so put it in the minibuff. |
550 (progn | |
551 (setq iswitchb-rescan nil) | |
552 (delete-region (point-min) (point)) | |
553 (insert res)) | |
554 ;; else nothing to complete | |
555 (iswitchb-completion-help) | |
556 ) | |
557 ) | |
558 ))) | |
559 | |
560 | |
561 | |
562 ;;; TOGGLE FUNCTIONS | |
563 | |
564 (defun iswitchb-toggle-case () | |
565 "Toggle the value of `iswitchb-case'." | |
566 (interactive) | |
567 (setq iswitchb-case (not iswitchb-case)) | |
568 ;; ask for list to be regenerated. | |
569 (setq iswitchb-rescan t) | |
570 ) | |
571 | |
572 (defun iswitchb-toggle-regexp () | |
573 "Toggle the value of `iswitchb-regexp'." | |
574 (interactive) | |
575 (setq iswitchb-regexp (not iswitchb-regexp)) | |
576 ;; ask for list to be regenerated. | |
577 (setq iswitchb-rescan t) | |
578 ) | |
579 | |
580 | |
581 (defun iswitchb-toggle-ignore () | |
582 "Toggle ignoring buffers specified with `iswitchb-buffer-ignore'." | |
583 (interactive) | |
584 (if iswitchb-buffer-ignore | |
585 (progn | |
586 (setq iswitchb-buffer-ignore-orig iswitchb-buffer-ignore) | |
587 (setq iswitchb-buffer-ignore nil) | |
588 ) | |
589 ;; else | |
590 (setq iswitchb-buffer-ignore iswitchb-buffer-ignore-orig) | |
591 ) | |
592 ;; ask for list to be regenerated. | |
593 (setq iswitchb-rescan t) | |
594 ) | |
595 | |
596 | |
597 (defun iswitchb-select-buffer-text () | |
17617 | 598 "Select the buffer named by the prompt. |
599 If no buffer exactly matching the prompt exists, maybe create a new one." | |
17616 | 600 (interactive) |
601 (setq iswitchb-exit 'takeprompt) | |
602 (exit-minibuffer)) | |
603 | |
604 | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
605 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
606 (defun iswitchb-find-file () |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
607 "Drop into find-file from buffer switching." |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
608 (interactive) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
609 (setq iswitchb-exit 'findfile) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
610 (exit-minibuffer)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
611 |
17616 | 612 (defun iswitchb-next-match () |
613 "Put first element of `iswitchb-matches' at the end of the list." | |
614 (interactive) | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
615 (let ((next (cadr iswitchb-matches))) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
616 (setq iswitchb-buflist (iswitchb-chop iswitchb-buflist next)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
617 (setq iswitchb-rescan t) |
17616 | 618 )) |
619 | |
620 (defun iswitchb-prev-match () | |
621 "Put last element of `iswitchb-matches' at the front of the list." | |
622 (interactive) | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
623 (let ((prev (car (last iswitchb-matches)))) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
624 (setq iswitchb-buflist (iswitchb-chop iswitchb-buflist prev)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
625 (setq iswitchb-rescan t) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
626 )) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
627 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
628 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
629 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
630 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
631 (defun iswitchb-chop (list elem) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
632 "Remove all elements before ELEM and put them at the end of LIST." |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
633 (let ((ret nil) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
634 (next nil) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
635 (sofar nil)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
636 (while (not ret) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
637 (setq next (car list)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
638 (if (equal next elem) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
639 (setq ret (append list (nreverse sofar))) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
640 ;; else |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
641 (progn |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
642 (setq list (cdr list)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
643 (setq sofar (cons next sofar))))) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
644 ret)) |
17616 | 645 |
646 | |
647 | |
648 | |
649 ;;; CREATE LIST OF ALL CURRENT BUFFERS | |
650 | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
651 |
17616 | 652 (defun iswitchb-make-buflist () |
17617 | 653 "Set `iswitchb-buflist' to the current list of buffers. |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
654 Currently visible buffers are put at the end of the list. |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
655 The hook `iswitchb-make-buflist-hook' is run after the list has been |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
656 created to allow the user to further modify the order of the buffer names |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
657 in this list." |
17616 | 658 (setq iswitchb-buflist |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
659 (let* ((iswitchb-current-buffers (iswitchb-get-buffers-in-frames)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
660 (buflist |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
661 (delq nil |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
662 (mapcar |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
663 (lambda (x) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
664 (let ((b-name (buffer-name x))) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
665 (if (not |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
666 (or |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
667 (iswitchb-ignore-buffername-p b-name) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
668 (memq b-name iswitchb-current-buffers))) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
669 b-name))) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
670 (buffer-list))))) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
671 (nconc buflist iswitchb-current-buffers) |
17616 | 672 (run-hooks 'iswitchb-make-buflist-hook) |
673 buflist))) | |
674 | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
675 (defun iswitchb-to-end (lst) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
676 "Move the elements from LST to the end of BUFLIST." |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
677 (mapcar |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
678 (lambda (elem) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
679 (setq buflist (delq elem buflist))) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
680 lst) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
681 (nconc buflist lst)) |
17616 | 682 |
683 | |
684 | |
685 (defun iswitchb-get-buffers-in-frames (&optional current) | |
686 "Return the list of buffers that are visible in the current frame. | |
687 If optional argument `current' is given, restrict searching to the | |
688 current frame, rather than all frames, regardless of value of | |
689 `iswitchb-all-frames'." | |
690 (let ((iswitchb-bufs-in-frame nil)) | |
691 (walk-windows 'iswitchb-get-bufname nil | |
692 (if current | |
693 nil | |
694 iswitchb-all-frames)) | |
695 iswitchb-bufs-in-frame)) | |
696 | |
697 | |
698 (defun iswitchb-get-bufname (win) | |
699 "Used by `iswitchb-get-buffers-in-frames' to walk through all windows." | |
700 (setq iswitchb-bufs-in-frame | |
701 (cons (buffer-name (window-buffer win)) | |
702 iswitchb-bufs-in-frame))) | |
703 | |
704 | |
705 ;;; FIND MATCHING BUFFERS | |
706 | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
707 |
17616 | 708 (defun iswitchb-set-matches () |
709 "Set `iswitchb-matches' to the list of buffers matching prompt." | |
710 (if iswitchb-rescan | |
711 (setq iswitchb-matches | |
712 (let* ((buflist iswitchb-buflist) | |
713 ) | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
714 (iswitchb-get-matched-buffers iswitchb-text iswitchb-regexp |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
715 buflist))))) |
17616 | 716 |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
717 (defun iswitchb-get-matched-buffers (regexp |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
718 &optional string-format buffer-list) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
719 "Return buffers matching REGEXP. |
17618
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
720 If STRING-FORMAT is non-nil, consider REGEXP as string. |
17617 | 721 BUFFER-LIST can be list of buffers or list of strings." |
17616 | 722 (let* ((case-fold-search iswitchb-case) |
723 ;; need reverse since we are building up list backwards | |
724 (list (reverse buffer-list)) | |
725 (do-string (stringp (car list))) | |
726 name | |
727 ret | |
728 ) | |
729 (mapcar | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
730 (lambda (x) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
731 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
732 (if do-string |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
733 (setq name x) ;We already have the name |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
734 (setq name (buffer-name x))) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
735 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
736 (cond |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
737 ((and (or (and string-format (string-match regexp name)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
738 (and (null string-format) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
739 (string-match (regexp-quote regexp) name))) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
740 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
741 ;; todo (not (iswitchb-ignore-buffername-p name)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
742 ) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
743 (setq ret (cons name ret)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
744 ))) |
17616 | 745 list) |
746 ret | |
747 )) | |
748 | |
749 | |
750 | |
751 | |
752 (defun iswitchb-ignore-buffername-p (bufname) | |
753 "Return t if the buffer BUFNAME should be ignored." | |
754 (let ((data (match-data)) | |
755 (re-list iswitchb-buffer-ignore) | |
756 ignorep | |
757 nextstr | |
758 ) | |
759 (while re-list | |
760 (setq nextstr (car re-list)) | |
761 (cond | |
762 ((stringp nextstr) | |
763 (if (string-match nextstr bufname) | |
764 (progn | |
765 (setq ignorep t) | |
766 (setq re-list nil)))) | |
767 ((fboundp nextstr) | |
768 (if (funcall nextstr bufname) | |
769 (progn | |
770 (setq ignorep t) | |
771 (setq re-list nil)) | |
772 )) | |
773 ) | |
774 (setq re-list (cdr re-list))) | |
775 (store-match-data data) | |
776 | |
777 ;; return the result | |
778 ignorep) | |
779 ) | |
780 | |
781 | |
782 | |
783 (defun iswitchb-word-matching-substring (word) | |
784 "Return part of WORD before 1st match to `iswitchb-change-word-sub'. | |
785 If `iswitchb-change-word-sub' cannot be found in WORD, return nil." | |
786 (let ((case-fold-search iswitchb-case)) | |
787 (let ((m (string-match iswitchb-change-word-sub word))) | |
788 (if m | |
789 (substring word m) | |
790 ;; else no match | |
791 nil)))) | |
792 | |
793 | |
794 | |
795 | |
796 | |
797 | |
798 (defun iswitchb-find-common-substring (lis subs) | |
799 "Return common string following SUBS in each element of LIS." | |
800 (let (res | |
801 alist | |
802 iswitchb-change-word-sub | |
803 ) | |
804 (setq iswitchb-change-word-sub | |
805 (if iswitchb-regexp | |
806 subs | |
807 (regexp-quote subs))) | |
808 (setq res (mapcar 'iswitchb-word-matching-substring lis)) | |
809 (setq res (delq nil res)) ;; remove any nil elements (shouldnt happen) | |
810 (setq alist (mapcar 'iswitchb-makealist res)) ;; could use an OBARRAY | |
811 | |
812 ;; try-completion returns t if there is an exact match. | |
813 (let ((completion-ignore-case iswitchb-case)) | |
814 | |
815 (try-completion subs alist) | |
816 ))) | |
817 | |
818 | |
819 (defun iswitchb-makealist (res) | |
820 "Return dotted pair (RES . 1)." | |
821 (cons res 1)) | |
822 | |
823 ;; from Wayne Mesard <wmesard@esd.sgi.com> | |
824 (defun iswitchb-rotate-list (lis) | |
825 "Destructively removes the last element from LIS. | |
826 Return the modified list with the last element prepended to it." | |
827 (if (<= (length lis) 1) | |
828 lis | |
829 (let ((las lis) | |
830 (prev lis)) | |
831 (while (consp (cdr las)) | |
832 (setq prev las | |
833 las (cdr las))) | |
834 (setcdr prev nil) | |
835 (cons (car las) lis)) | |
836 )) | |
837 | |
838 | |
839 (defun iswitchb-completion-help () | |
840 "Show possible completions in a *Buffer Completions* buffer." | |
841 ;; we could allow this buffer to be used to select match, but I think | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
842 ;; choose-completion-string will need redefining, so it just inserts |
17616 | 843 ;; choice with out any previous input. |
844 (interactive) | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
845 (setq iswitchb-rescan nil) |
17616 | 846 (let ((completion-setup-hook nil) ;disable fancy highlight/selection. |
847 ) | |
848 (with-output-to-temp-buffer "*Buffer Completions*" | |
849 (if iswitchb-xemacs | |
850 | |
851 ;; XEmacs extents are put on by default, doesn't seem to be | |
852 ;; any way of switching them off. | |
853 (display-completion-list (if iswitchb-matches | |
854 iswitchb-matches | |
855 iswitchb-buflist) | |
856 :help-string "iswitchb " | |
857 :activate-callback | |
858 '(lambda (x y z) | |
859 (message "doesnt work yet, sorry!"))) | |
860 ;; else running Emacs | |
861 (display-completion-list (if iswitchb-matches | |
862 iswitchb-matches | |
863 iswitchb-buflist)) | |
864 )))) | |
865 | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
866 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
867 ;;; KILL CURRENT BUFFER |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
868 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
869 (defun iswitchb-kill-buffer () |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
870 "Kill the buffer at the head of `iswtichb-matches'." |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
871 (interactive) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
872 (let ( (enable-recursive-minibuffers t) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
873 buf) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
874 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
875 (setq buf (car iswitchb-matches)) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
876 ;; check to see if buf is non-nil. |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
877 (if buf |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
878 (progn |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
879 (kill-buffer buf) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
880 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
881 ;; Check if buffer exists. XEmacs gnuserv.el makes alias |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
882 ;; for kill-buffer which does not return t if buffer is |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
883 ;; killed, so we can't rely on kill-buffer return value. |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
884 (if (get-buffer buf) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
885 ;; buffer couldn't be killed. |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
886 (setq iswitchb-rescan t) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
887 ;; else buffer was killed so remove name from list. |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
888 (setq iswitchb-buflist (delq buf iswitchb-buflist))))))) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
889 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
890 |
17616 | 891 ;;; VISIT CHOSEN BUFFER |
892 (defun iswitchb-visit-buffer (buffer) | |
893 "Visit buffer named BUFFER according to `iswitchb-method'." | |
894 (let* (win newframe) | |
895 (cond | |
896 ((eq iswitchb-method 'samewindow) | |
897 (switch-to-buffer buffer)) | |
898 | |
899 ((memq iswitchb-method '(always-frame maybe-frame)) | |
900 (cond | |
901 ((and (setq win (iswitchb-window-buffer-p buffer)) | |
902 (or (eq iswitchb-method 'always-frame) | |
903 (y-or-n-p "Jump to frame? "))) | |
904 (setq newframe (window-frame win)) | |
905 (raise-frame newframe) | |
906 (select-frame newframe) | |
907 (select-window win) | |
908 (if (not iswitchb-xemacs) | |
909 ;; reposition mouse to make frame active. not needed in XEmacs | |
910 ;; This line came from the other-frame defun in Emacs. | |
911 (set-mouse-position (selected-frame) (1- (frame-width)) 0)) | |
912 ) | |
913 (t | |
914 ;; No buffer in other frames... | |
915 (switch-to-buffer buffer) | |
916 ))) | |
917 | |
918 | |
919 | |
920 ((eq iswitchb-method 'otherwindow) | |
921 (switch-to-buffer-other-window buffer)) | |
922 | |
17618
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
923 ((eq iswitchb-method 'display) |
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
924 (display-buffer buffer)) |
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
925 |
17616 | 926 ((eq iswitchb-method 'otherframe) |
927 (progn | |
928 (switch-to-buffer-other-frame buffer) | |
929 (if (not iswitchb-xemacs) | |
930 (set-mouse-position (selected-frame) (1- (frame-width)) 0)) | |
931 ) | |
932 ) ))) | |
933 | |
934 (defun iswitchb-possible-new-buffer (buf) | |
935 "Possibly create and visit a new buffer called BUF." | |
936 | |
937 (let ((newbufcreated)) | |
938 (if (and iswitchb-newbuffer | |
939 (or | |
940 (not iswitchb-prompt-newbuffer) | |
941 | |
942 (and iswitchb-prompt-newbuffer | |
943 (y-or-n-p | |
944 (format | |
945 "No buffer matching `%s', create one? " | |
946 buf))))) | |
947 ;; then create a new buffer | |
948 (progn | |
949 (setq newbufcreated (get-buffer-create buf)) | |
950 (if (fboundp 'set-buffer-major-mode) | |
951 (set-buffer-major-mode newbufcreated)) | |
952 (iswitchb-visit-buffer newbufcreated)) | |
953 ;; else wont create new buffer | |
954 (message (format "no buffer matching `%s'" buf)) | |
955 ))) | |
956 | |
957 (defun iswitchb-window-buffer-p (buffer) | |
17617 | 958 "Return window pointer if BUFFER is visible in another frame. |
959 If BUFFER is visible in the current frame, return nil." | |
17616 | 960 (interactive) |
961 (let ((blist (iswitchb-get-buffers-in-frames 'current))) | |
962 ;;If the buffer is visible in current frame, return nil | |
963 (if (memq buffer blist) | |
964 nil | |
965 ;; maybe in other frame... | |
966 (get-buffer-window buffer 'visible) | |
967 ))) | |
968 | |
17617 | 969 ;;;###autoload |
17616 | 970 (defun iswitchb-default-keybindings () |
17617 | 971 "Set up default keybindings for `iswitchb-buffer'. |
17616 | 972 Call this function to override the normal bindings." |
973 (interactive) | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
974 (global-set-key (read-kbd-macro "C-x b") 'iswitchb-buffer) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
975 (global-set-key (read-kbd-macro "C-x 4 b") 'iswitchb-buffer-other-window) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
976 (global-set-key (read-kbd-macro "C-x 4 C-o") 'iswitchb-display-buffer) |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
977 (global-set-key (read-kbd-macro "C-x 5 b") 'iswitchb-buffer-other-frame)) |
17616 | 978 |
979 | |
980 ;;;###autoload | |
981 (defun iswitchb-buffer () | |
982 "Switch to another buffer. | |
983 | |
984 The buffer name is selected interactively by typing a substring. The | |
985 buffer is displayed according to `iswitchb-default-method' -- the | |
986 default is to show it in the same window, unless it is already visible | |
17617 | 987 in another frame. |
988 For details of keybindings, do `\\[describe-function] iswitchb'." | |
17616 | 989 (interactive) |
990 (setq iswitchb-method iswitchb-default-method) | |
991 (iswitchb-entry)) | |
992 | |
993 | |
994 ;;;###autoload | |
995 (defun iswitchb-buffer-other-window () | |
996 "Switch to another buffer and show it in another window. | |
997 The buffer name is selected interactively by typing a substring. | |
17617 | 998 For details of keybindings, do `\\[describe-function] iswitchb'." |
17616 | 999 (interactive) |
1000 (setq iswitchb-method 'otherwindow) | |
1001 (iswitchb-entry)) | |
1002 | |
1003 | |
1004 | |
1005 ;;;###autoload | |
17618
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
1006 (defun iswitchb-display-buffer () |
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
1007 "Display a buffer in another window but don't select it. |
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
1008 The buffer name is selected interactively by typing a substring. |
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
1009 For details of keybindings, do `\\[describe-function] iswitchb'." |
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
1010 (interactive) |
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
1011 (setq iswitchb-method 'display) |
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
1012 (iswitchb-entry)) |
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
1013 |
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
1014 |
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
1015 |
8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
Richard M. Stallman <rms@gnu.org>
parents:
17617
diff
changeset
|
1016 ;;;###autoload |
17616 | 1017 (defun iswitchb-buffer-other-frame () |
1018 "Switch to another buffer and show it in another frame. | |
1019 The buffer name is selected interactively by typing a substring. | |
17617 | 1020 For details of keybindings, do `\\[describe-function] iswitchb'." |
17616 | 1021 (interactive) |
1022 (setq iswitchb-method 'otherframe) | |
1023 (iswitchb-entry)) | |
1024 | |
1025 | |
1026 | |
1027 (defun iswitchb-entry () | |
17617 | 1028 "Simply fall into `iswitchb' -- the main function." |
17616 | 1029 (iswitchb)) |
1030 | |
1031 | |
1032 | |
1033 | |
1034 | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1035 ;;; XEmacs hack for showing default buffer |
17616 | 1036 |
1037 ;; The first time we enter the minibuffer, Emacs puts up the default | |
1038 ;; buffer to switch to, but XEmacs doesnt -- presumably there is a | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1039 ;; subtle difference in the two versions of post-command-hook. The |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1040 ;; default is shown for both whenever we delete all of our text |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1041 ;; though, indicating its just a problem the first time we enter the |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1042 ;; function. To solve this, we use another entry hook for emacs to |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1043 ;; show the default the first time we enter the minibuffer. |
17616 | 1044 |
1045 (defun iswitchb-init-Xemacs-trick () | |
17617 | 1046 "Display default buffer when first entering minibuffer. |
1047 This is a hack for XEmacs, and should really be handled by `iswitchb-exhibit'." | |
17616 | 1048 (if (iswitchb-entryfn-p) |
1049 (progn | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1050 (iswitchb-exhibit) |
17616 | 1051 (goto-char (point-min))))) |
1052 | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1053 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1054 ;; add this hook for XEmacs only. |
17616 | 1055 (if iswitchb-xemacs |
1056 (add-hook 'iswitchb-minibuffer-setup-hook | |
1057 'iswitchb-init-Xemacs-trick)) | |
1058 | |
1059 | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1060 ;;; XEmacs / backspace key |
17616 | 1061 ;; For some reason, if the backspace key is pressed in xemacs, the |
1062 ;; line gets confused, so I've added a simple key definition to make | |
1063 ;; backspace act like the normal delete key. | |
1064 | |
1065 (defun iswitchb-xemacs-backspacekey () | |
1066 "Bind backspace to `backward-delete-char'." | |
1067 (define-key iswitchb-mode-map '[backspace] 'backward-delete-char) | |
1068 (define-key iswitchb-mode-map '[(meta backspace)] 'backward-kill-word) | |
1069 ) | |
1070 | |
1071 | |
1072 (if iswitchb-xemacs | |
1073 (add-hook 'iswitchb-define-mode-map-hook | |
1074 'iswitchb-xemacs-backspacekey)) | |
1075 | |
1076 | |
1077 | |
1078 ;;; ICOMPLETE TYPE CODE | |
1079 | |
1080 (defun iswitchb-exhibit () | |
17617 | 1081 "Find matching buffers and display a list in the minibuffer. |
17616 | 1082 Copied from `icomplete-exhibit' with two changes: |
1083 1. It prints a default buffer name when there is no text yet entered. | |
1084 2. It calls my completion routine rather than the standard completion." | |
1085 | |
1086 (if iswitchb-use-mycompletion | |
1087 (let ((contents (buffer-substring (point-min)(point-max))) | |
1088 (buffer-undo-list t)) | |
1089 (save-excursion | |
1090 (goto-char (point-max)) | |
1091 ; Register the end of input, so we | |
1092 ; know where the extra stuff | |
1093 ; (match-status info) begins: | |
1094 (if (not (boundp 'iswitchb-eoinput)) | |
1095 ;; In case it got wiped out by major mode business: | |
1096 (make-local-variable 'iswitchb-eoinput)) | |
1097 (setq iswitchb-eoinput (point)) | |
1098 ;; Update the list of matches | |
1099 (setq iswitchb-text contents) | |
1100 (iswitchb-set-matches) | |
1101 (setq iswitchb-rescan t) | |
1102 (iswitchb-set-common-completion) | |
1103 | |
1104 ;; Insert the match-status information: | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1105 (insert-string |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1106 (iswitchb-completions |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1107 contents |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1108 minibuffer-completion-table |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1109 minibuffer-completion-predicate |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1110 (not minibuffer-completion-confirm))) |
17616 | 1111 )))) |
1112 | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1113 |
17616 | 1114 |
1115 (defun iswitchb-completions | |
1116 (name candidates predicate require-match) | |
1117 "Return the string that is displayed after the user's text. | |
1118 Modified from `icomplete-completions'." | |
1119 | |
1120 (let ((comps iswitchb-matches) | |
1121 ; "-determined" - only one candidate | |
1122 (open-bracket-determined (if require-match "(" "[")) | |
1123 (close-bracket-determined (if require-match ")" "]")) | |
1124 ;"-prospects" - more than one candidate | |
1125 (open-bracket-prospects "{") | |
1126 (close-bracket-prospects "}") | |
1127 first | |
1128 ) | |
1129 | |
1130 (if (and iswitchb-use-fonts comps) | |
1131 (progn | |
1132 (setq first (car comps)) | |
1133 (setq first (format "%s" first)) | |
1134 (put-text-property 0 (length first) 'face | |
1135 (if (eq (length comps) 1) | |
1136 'font-lock-comment-face | |
1137 'font-lock-function-name-face) | |
1138 first) | |
1139 (setq comps (cons first (cdr comps))) | |
1140 )) | |
1141 | |
1142 (cond ((null comps) (format " %sNo match%s" | |
1143 open-bracket-determined | |
1144 close-bracket-determined)) | |
1145 | |
1146 ((null (cdr comps)) ;one match | |
1147 (concat (if (and (> (length (car comps)) | |
1148 (length name))) | |
1149 (concat open-bracket-determined | |
1150 ;; when there is one match, show the | |
1151 ;; matching buffer name in full | |
1152 (car comps) | |
1153 close-bracket-determined) | |
1154 "") | |
1155 (if (not iswitchb-use-fonts) " [Matched]") | |
1156 )) | |
1157 (t ;multiple matches | |
1158 (let* ( | |
1159 ;;(most (try-completion name candidates predicate)) | |
1160 (most nil) | |
1161 (most-len (length most)) | |
1162 most-is-exact | |
1163 first | |
1164 (alternatives | |
1165 (apply | |
1166 (function concat) | |
1167 (cdr (apply | |
1168 (function nconc) | |
1169 (mapcar '(lambda (com) | |
1170 (if (= (length com) most-len) | |
1171 ;; Most is one exact match, | |
1172 ;; note that and leave out | |
1173 ;; for later indication: | |
1174 (progn | |
1175 (setq most-is-exact t) | |
1176 ()) | |
1177 (list "," | |
1178 (substring com | |
1179 most-len)))) | |
1180 comps)))))) | |
1181 | |
1182 (concat | |
1183 | |
1184 ;; put in common completion item -- what you get by | |
1185 ;; pressing tab | |
1186 (if (> (length iswitchb-common-match-string) (length name)) | |
1187 (concat open-bracket-determined | |
1188 (substring iswitchb-common-match-string | |
1189 (length name)) | |
1190 close-bracket-determined) | |
1191 ) | |
1192 ;; end of partial matches... | |
1193 | |
1194 ;; think this bit can be ignored. | |
1195 (and (> most-len (length name)) | |
1196 (concat open-bracket-determined | |
1197 (substring most (length name)) | |
1198 close-bracket-determined)) | |
1199 | |
1200 ;; list all alternatives | |
1201 open-bracket-prospects | |
1202 (if most-is-exact | |
1203 (concat "," alternatives) | |
1204 alternatives) | |
1205 close-bracket-prospects))) | |
1206 ))) | |
1207 | |
1208 (defun iswitchb-minibuffer-setup () | |
17617 | 1209 "Set up minibuffer for `iswitchb-buffer'. |
1210 Copied from `icomplete-minibuffer-setup-hook'." | |
17616 | 1211 (if (iswitchb-entryfn-p) |
1212 (progn | |
1213 | |
1214 (make-local-variable 'iswitchb-use-mycompletion) | |
1215 (setq iswitchb-use-mycompletion t) | |
1216 (make-local-hook 'pre-command-hook) | |
1217 (add-hook 'pre-command-hook | |
1218 'iswitchb-pre-command | |
1219 nil t) | |
1220 (make-local-hook 'post-command-hook) | |
1221 (add-hook 'post-command-hook | |
1222 'iswitchb-post-command | |
1223 nil t) | |
1224 | |
1225 (run-hooks 'iswitchb-minibuffer-setup-hook) | |
1226 ) | |
1227 )) | |
1228 | |
1229 | |
1230 (defun iswitchb-pre-command () | |
17617 | 1231 "Run before command in `iswitchb-buffer'." |
17616 | 1232 (iswitchb-tidy)) |
1233 | |
1234 | |
1235 (defun iswitchb-post-command () | |
17617 | 1236 "Run after command in `iswitchb-buffer'." |
17616 | 1237 (iswitchb-exhibit) |
1238 ) | |
1239 | |
1240 | |
1241 | |
1242 (defun iswitchb-tidy () | |
1243 "Remove completions display, if any, prior to new user input. | |
1244 Copied from `icomplete-tidy'." | |
1245 | |
1246 (if (and (boundp 'iswitchb-eoinput) | |
1247 iswitchb-eoinput) | |
1248 | |
1249 (if (> iswitchb-eoinput (point-max)) | |
1250 ;; Oops, got rug pulled out from under us - reinit: | |
1251 (setq iswitchb-eoinput (point-max)) | |
1252 (let ((buffer-undo-list buffer-undo-list )) ; prevent entry | |
1253 (delete-region iswitchb-eoinput (point-max)))) | |
1254 | |
1255 ;; Reestablish the local variable 'cause minibuffer-setup is weird: | |
1256 (make-local-variable 'iswitchb-eoinput) | |
1257 (setq iswitchb-eoinput 1))) | |
1258 | |
1259 | |
1260 (defun iswitchb-entryfn-p () | |
17617 | 1261 "Return non-nil if `this-command' shows we are using `iswitchb-buffer'." |
17616 | 1262 (and (symbolp this-command) ; ignore lambda functions |
17619
c8e876b73dcd
(iswitchb-entryfn-p): Use memq, not member.
Richard M. Stallman <rms@gnu.org>
parents:
17618
diff
changeset
|
1263 (memq this-command |
c8e876b73dcd
(iswitchb-entryfn-p): Use memq, not member.
Richard M. Stallman <rms@gnu.org>
parents:
17618
diff
changeset
|
1264 '(iswitchb-buffer |
c8e876b73dcd
(iswitchb-entryfn-p): Use memq, not member.
Richard M. Stallman <rms@gnu.org>
parents:
17618
diff
changeset
|
1265 iswitchb-buffer-other-frame |
c8e876b73dcd
(iswitchb-entryfn-p): Use memq, not member.
Richard M. Stallman <rms@gnu.org>
parents:
17618
diff
changeset
|
1266 iswitchb-display-buffer |
c8e876b73dcd
(iswitchb-entryfn-p): Use memq, not member.
Richard M. Stallman <rms@gnu.org>
parents:
17618
diff
changeset
|
1267 iswitchb-buffer-other-window)))) |
17616 | 1268 |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1269 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1270 |
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1271 |
17616 | 1272 (defun iswitchb-summaries-to-end () |
17617 | 1273 "Move the summaries to the end of the list. |
1274 This is an example function which can be hooked on to | |
1275 `iswitchb-make-buflist-hook'. Any buffer matching the regexps | |
1276 `Summary' or `output\*$'are put to the end of the list." | |
17616 | 1277 (let ((summaries (delq nil (mapcar |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1278 (lambda (x) |
17616 | 1279 (if (or |
1280 (string-match "Summary" x) | |
1281 (string-match "output\\*$" x)) | |
1282 x)) | |
1283 buflist) | |
1284 ))) | |
1285 | |
18776
61751ba33c8f
All user variables now converted to custom.
Richard M. Stallman <rms@gnu.org>
parents:
17619
diff
changeset
|
1286 (iswitchb-to-end summaries))) |
17616 | 1287 |
1288 | |
1289 | |
1290 ;;; HOOKS | |
1291 (add-hook 'minibuffer-setup-hook 'iswitchb-minibuffer-setup) | |
1292 | |
1293 (provide 'iswitchb) | |
1294 | |
17617 | 1295 ;;; iswitchb.el ends here |