Mercurial > emacs
comparison lisp/iswitchb.el @ 17617:4851316697c1
Many doc fixes.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 02 May 1997 00:24:00 +0000 |
parents | a64126a1f870 |
children | 8d33666b1152 |
comparison
equal
deleted
inserted
replaced
17616:a64126a1f870 | 17617:4851316697c1 |
---|---|
1 ;;; ISWITCHB.EL --- switch between buffers using substrings | 1 ;;; iswitchb.el --- switch between buffers using substrings |
2 | 2 |
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Stephen Eglen <stephene@cogs.susx.ac.uk> | 5 ;; Author: Stephen Eglen <stephene@cogs.susx.ac.uk> |
6 ;; Maintainer: Stephen Eglen <stephene@cogs.susx.ac.uk> | 6 ;; Maintainer: Stephen Eglen <stephene@cogs.susx.ac.uk> |
7 ;; Created: 15 Dec 1996 | |
8 ;; $Revision: 1.26 $ | |
9 ;; Keywords: extensions | 7 ;; Keywords: extensions |
10 ;; location: http://www.cogs.susx.ac.uk/users/stephene/emacs | 8 ;; location: http://www.cogs.susx.ac.uk/users/stephene/emacs |
11 | 9 |
12 | 10 ;; This file is part of GNU Emacs. |
13 ;; This program is free software; you can redistribute it and/or modify | 11 |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
14 ;; it under the terms of the GNU General Public License as published by | 13 ;; it under the terms of the GNU General Public License as published by |
15 ;; the Free Software Foundation; either version 2, or (at your option) | 14 ;; the Free Software Foundation; either version 2, or (at your option) |
16 ;; any later version. | 15 ;; any later version. |
17 | 16 |
18 ;; This program is distributed in the hope that it will be useful, | 17 ;; GNU Emacs is distributed in the hope that it will be useful, |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | 18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 ;; GNU General Public License for more details. | 20 ;; GNU General Public License for more details. |
22 | 21 |
23 ;; You should have received a copy of the GNU General Public License | 22 ;; You should have received a copy of the GNU General Public License |
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
26 ;; Boston, MA 02111-1307, USA. | 25 ;; Boston, MA 02111-1307, USA. |
27 | 26 |
28 ;; LCD Archive Entry: | |
29 ;; iswitchb|Stephen Eglen|<stephene@cogs.susx.ac.uk> | |
30 ;; |switch between buffers using substrings | |
31 ;; |$Date: 1997/03/23 18:10:48 $|$Revision: 1.26 $|~/packages/iswitchb.el | |
32 | |
33 | |
34 ;;; Installation: | 27 ;;; Installation: |
35 | 28 |
36 ;; To load the package, do | |
37 ;; (require 'iswitchb) | |
38 ;; To get the functions in this package bound to keys, do | 29 ;; To get the functions in this package bound to keys, do |
39 ;; (iswitchb-default-keybindings) | 30 ;; (iswitchb-default-keybindings) |
40 ;; | |
41 ;; Has been tested on Emacs 19.34 and XEmacs 19.14. I think it needs | |
42 ;; at least Emacs 19.29 to run. | |
43 | 31 |
44 ;;; Commentary: | 32 ;;; Commentary: |
45 | 33 |
46 ;; As you type in a substring, the list of buffers currently matching | 34 ;; As you type in a substring, the list of buffers currently matching |
47 ;; the substring are displayed as you type. The list is ordered so | 35 ;; the substring are displayed as you type. The list is ordered so |
181 ;; first version of this package, iswitch-buffer. Thanks also to many | 169 ;; first version of this package, iswitch-buffer. Thanks also to many |
182 ;; others for testing earlier versions. | 170 ;; others for testing earlier versions. |
183 | 171 |
184 ;;; Code: | 172 ;;; Code: |
185 | 173 |
186 (defconst iswitchb-version (substring "$Revision: 1.26 $" 11 -2) | |
187 "$Id: iswitchb.el,v 1.26 1997/03/23 18:10:48 stephene Exp $ | |
188 | |
189 Report bugs to: Stephen Eglen <stephene@cogs.susx.ac.uk>") | |
190 | |
191 | |
192 ;;; User Variables | 174 ;;; User Variables |
193 ;; | 175 ;; |
194 ;; These are some things you might want to change. | 176 ;; These are some things you might want to change. |
195 | 177 |
196 (defvar iswitchb-case case-fold-search | 178 (defvar iswitchb-case case-fold-search |
197 "*Non-nil if searching of buffer names should ignore case.") | 179 "*Non-nil if searching of buffer names should ignore case.") |
198 | 180 |
199 (defvar iswitchb-buffer-ignore | 181 (defvar iswitchb-buffer-ignore |
200 '("^ ") | 182 '("^ ") |
201 "*List of regexps or functions matching buffer names to ignore. For | 183 "*List of regexps or functions matching buffer names to ignore. |
202 example, traditional behavior is not to list buffers whose names begin | 184 For example, traditional behavior is not to list buffers whose names begin |
203 with a space, for which the regexp is \"^ \". See the source file for | 185 with a space, for which the regexp is `^ '. See the source file for |
204 example functions that filter buffernames.") | 186 example functions that filter buffernames.") |
205 | 187 |
206 ;;; Examples for setting the value of iswitchb-buffer-ignore | 188 ;;; Examples for setting the value of iswitchb-buffer-ignore |
207 ;(defun -c-mode (name) | 189 ;(defun -c-mode (name) |
208 ; "Ignore all c mode buffers -- example function for iswitchb." | 190 ; "Ignore all c mode buffers -- example function for iswitchb." |
213 ;(setq iswitchb-buffer-ignore '("^ " ignore-c-mode)) | 195 ;(setq iswitchb-buffer-ignore '("^ " ignore-c-mode)) |
214 ;(setq iswitchb-buffer-ignore '("^ " "\\.c$" "\\.h$")) | 196 ;(setq iswitchb-buffer-ignore '("^ " "\\.c$" "\\.h$")) |
215 | 197 |
216 | 198 |
217 (defvar iswitchb-default-method 'always-frame | 199 (defvar iswitchb-default-method 'always-frame |
218 "*How to switch to new buffer when using iswitchb. | 200 "*How to switch to new buffer when using `iswitchb-buffer'. |
219 Possible values: | 201 Possible values: |
220 `samewindow' Show new buffer in same window | 202 `samewindow' Show new buffer in same window |
221 `otherwindow' Show new buffer in another window (same frame) | 203 `otherwindow' Show new buffer in another window (same frame) |
222 `otherframe' Show new buffer in another frame | 204 `otherframe' Show new buffer in another frame |
223 `maybe-frame' If a buffer is visible in another frame, prompt to ask if you | 205 `maybe-frame' If a buffer is visible in another frame, prompt to ask if you |
225 frame or in the other frame. | 207 frame or in the other frame. |
226 `always-frame' If a buffer is visible in another frame, raise that | 208 `always-frame' If a buffer is visible in another frame, raise that |
227 frame. Otherwise, visit the buffer in the same window.") | 209 frame. Otherwise, visit the buffer in the same window.") |
228 | 210 |
229 (defvar iswitchb-regexp nil | 211 (defvar iswitchb-regexp nil |
230 "*Non-nil means that iswitchb will do regexp matching. Value can be | 212 "*Non-nil means that `iswitchb' will do regexp matching. |
231 toggled within iswitchb.") | 213 Value can be toggled within `iswitchb'.") |
232 | 214 |
233 (defvar iswitchb-newbuffer t | 215 (defvar iswitchb-newbuffer t |
234 "*Non-nil means create new buffer if no buffer matches substring. | 216 "*Non-nil means create new buffer if no buffer matches substring. |
235 See also `iswitchb-prompt-newbuffer'.") | 217 See also `iswitchb-prompt-newbuffer'.") |
236 | 218 |
248 (defvar iswitchb-make-buflist-hook nil | 230 (defvar iswitchb-make-buflist-hook nil |
249 "*Hook to run when list of matching buffers is created.") | 231 "*Hook to run when list of matching buffers is created.") |
250 | 232 |
251 | 233 |
252 (defvar iswitchb-method nil | 234 (defvar iswitchb-method nil |
253 "*Stores the method for viewing the selected buffer. Its value is | 235 "*Stores the method for viewing the selected buffer. |
254 one of `samewindow', `otherwindow', `otherframe', `maybe-frame' or | 236 Its value is one of `samewindow', `otherwindow', `otherframe', |
255 `always-frame'. See `iswitchb-default-method' for details of | 237 `maybe-frame' or `always-frame'. See `iswitchb-default-method' for |
256 values.") | 238 details of values.") |
257 | 239 |
258 (defvar iswitchb-all-frames 'visible | 240 (defvar iswitchb-all-frames 'visible |
259 "*Argument to pass to `walk-windows' when finding visible buffers. | 241 "*Argument to pass to `walk-windows' when finding visible buffers. |
260 See documentation of `walk-windows' for useful values.") | 242 See documentation of `walk-windows' for useful values.") |
261 | 243 |
280 | 262 |
281 ;;; Internal Variables | 263 ;;; Internal Variables |
282 (defvar iswitchb-minibuffer-setup-hook nil | 264 (defvar iswitchb-minibuffer-setup-hook nil |
283 "*Iswitchb-specific customization of minibuffer setup. | 265 "*Iswitchb-specific customization of minibuffer setup. |
284 | 266 |
285 This hook is run during minibuffer setup iff iswitchb will be active. | 267 This hook is run during minibuffer setup iff `iswitchb' will be active. |
286 It is intended for use in customizing iswitchb for interoperation | 268 It is intended for use in customizing iswitchb for interoperation |
287 with other packages. For instance: | 269 with other packages. For instance: |
288 | 270 |
289 \(add-hook 'iswitchb-minibuffer-setup-hook | 271 \(add-hook 'iswitchb-minibuffer-setup-hook |
290 \(function | 272 \(function |
291 \(lambda () | 273 \(lambda () |
292 \(make-local-variable 'resize-minibuffer-window-max-height) | 274 \(make-local-variable 'resize-minibuffer-window-max-height) |
293 \(setq resize-minibuffer-window-max-height 3)))) | 275 \(setq resize-minibuffer-window-max-height 3)))) |
294 | 276 |
295 will constrain rsz-mini to a maximum minibuffer height of 3 lines when | 277 will constrain rsz-mini to a maximum minibuffer height of 3 lines when |
296 iswitchb is running. Copied from icomplete-minibuffer-setup-hook") | 278 iswitchb is running. Copied from `icomplete-minibuffer-setup-hook'.") |
297 | 279 |
298 (defvar iswitchb-eoinput 1 | 280 (defvar iswitchb-eoinput 1 |
299 "Point where minibuffer input ends and completion info begins. | 281 "Point where minibuffer input ends and completion info begins. |
300 Copied from icomplete-eoinput.") | 282 Copied from `icomplete-eoinput'.") |
301 (make-variable-buffer-local 'iswitchb-eoinput) | 283 (make-variable-buffer-local 'iswitchb-eoinput) |
302 | 284 |
303 | 285 |
304 (defvar iswitchb-buflist nil | 286 (defvar iswitchb-buflist nil |
305 "Stores the current list of buffers that will be searched through. | 287 "Stores the current list of buffers that will be searched through. |
308 at the end of the list. Created by `iswitchb-make-buflist'.") | 290 at the end of the list. Created by `iswitchb-make-buflist'.") |
309 | 291 |
310 ;; todo -- is this necessary? | 292 ;; todo -- is this necessary? |
311 | 293 |
312 (defvar iswitchb-use-mycompletion nil | 294 (defvar iswitchb-use-mycompletion nil |
313 "Non-nil means use iswitchb completion feedback. Should only be set | 295 "Non-nil means use `iswitchb-buffer' completion feedback. |
314 to t by iswitchb functions, so that it doesnt interfere with other | 296 Should only be set to t by iswitchb functions, so that it doesn't |
315 minibuffer usage.") | 297 interfere with other minibuffer usage.") |
316 | 298 |
317 (defvar iswitchb-change-word-sub nil | 299 (defvar iswitchb-change-word-sub nil |
318 "Private variable used by `iswitchb-word-matching-substring'.") | 300 "Private variable used by `iswitchb-word-matching-substring'.") |
319 | 301 |
320 | 302 |
333 | 315 |
334 (defvar iswitchb-default-buffer nil | 316 (defvar iswitchb-default-buffer nil |
335 "Default buffer to switch to.") | 317 "Default buffer to switch to.") |
336 | 318 |
337 (defvar iswitchb-mode-map nil | 319 (defvar iswitchb-mode-map nil |
338 "Keymap for iswitchb.") | 320 "Keymap for `iswitchb-buffer'.") |
339 | 321 |
340 (defvar iswitchb-history nil | 322 (defvar iswitchb-history nil |
341 "History of buffers selected using iswitchb.") | 323 "History of buffers selected using `iswitchb-buffer'.") |
342 | 324 |
343 (defvar iswitchb-exit nil | 325 (defvar iswitchb-exit nil |
344 "Flag to monitor how iswitchb exits. If equal to `takeprompt', we | 326 "Flag to monitor how `iswitchb-buffer' exits. |
345 use the prompt as the buffer name to be selected.") | 327 If equal to `takeprompt', we use the prompt as the buffer name to be |
328 selected.") | |
346 | 329 |
347 (defvar iswitchb-buffer-ignore-orig nil | 330 (defvar iswitchb-buffer-ignore-orig nil |
348 "Stores original value of `iswitchb-buffer-ignore'.") | 331 "Stores original value of `iswitchb-buffer-ignore'.") |
349 | 332 |
350 (defvar iswitchb-xemacs (string-match "XEmacs" (emacs-version)) | 333 (defvar iswitchb-xemacs (string-match "XEmacs" (emacs-version)) |
354 ;;; FUNCTIONS | 337 ;;; FUNCTIONS |
355 | 338 |
356 | 339 |
357 ;;; ISWITCHB KEYMAP | 340 ;;; ISWITCHB KEYMAP |
358 (defun iswitchb-define-mode-map () | 341 (defun iswitchb-define-mode-map () |
359 "Set up the keymap for iswitchb." | 342 "Set up the keymap for `iswitchb-buffer'." |
360 (interactive) | 343 (interactive) |
361 (let (map) | 344 (let (map) |
362 ;; generated every time so that it can inheret new functions. | 345 ;; generated every time so that it can inheret new functions. |
363 ;;(or iswitchb-mode-map | 346 ;;(or iswitchb-mode-map |
364 | 347 |
385 selected. As you type, most keys have their normal keybindings, | 368 selected. As you type, most keys have their normal keybindings, |
386 except for the following: | 369 except for the following: |
387 \\<iswitchb-mode-map> | 370 \\<iswitchb-mode-map> |
388 | 371 |
389 RET Select the buffer at the front of the list of matches. If the | 372 RET Select the buffer at the front of the list of matches. If the |
390 list is emptty, possibly prompt to create new buffer. | 373 list is empty, possibly prompt to create new buffer. |
391 | 374 |
392 \\[iswitchb-select-buffer-text] Select the current prompt as the buffer. | 375 \\[iswitchb-select-buffer-text] Select the current prompt as the buffer. |
393 If no buffer is found, prompt for a new one. | 376 If no buffer is found, prompt for a new one. |
394 | 377 |
395 \\[iswitchb-next-match] Put the first element at the end of the list. | 378 \\[iswitchb-next-match] Put the first element at the end of the list. |
398 matches all buffers. If there is only one match, select that buffer. | 381 matches all buffers. If there is only one match, select that buffer. |
399 If there is no common suffix, show a list of all matching buffers | 382 If there is no common suffix, show a list of all matching buffers |
400 in a separate window. | 383 in a separate window. |
401 \\[iswitchb-toggle-regexp] Toggle rexep searching. | 384 \\[iswitchb-toggle-regexp] Toggle rexep searching. |
402 \\[iswitchb-toggle-case] Toggle case-sensitive searching of buffer names. | 385 \\[iswitchb-toggle-case] Toggle case-sensitive searching of buffer names. |
403 \\[iswitchb-completion-help] Show list of matching buffers in separate window. | 386 \\[iswitchb-completion-help] Show list of matching buffers in separate window." |
404 " | |
405 ;;\\[iswitchb-toggle-ignore] Toggle ignoring certain buffers (see \ | 387 ;;\\[iswitchb-toggle-ignore] Toggle ignoring certain buffers (see \ |
406 ;;`iswitchb-buffer-ignore') | 388 ;;`iswitchb-buffer-ignore') |
407 | 389 |
408 (let | 390 (let |
409 ( | 391 ( |
473 | 455 |
474 | 456 |
475 ;;; COMPLETION CODE | 457 ;;; COMPLETION CODE |
476 | 458 |
477 (defun iswitchb-set-common-completion () | 459 (defun iswitchb-set-common-completion () |
478 "Find common completion of `iswitchb-text' in `iswitchb-matches'. The | 460 "Find common completion of `iswitchb-text' in `iswitchb-matches'. |
479 result is stored in `iswitchb-common-match-string'." | 461 The result is stored in `iswitchb-common-match-string'." |
480 | 462 |
481 (let* (val) | 463 (let* (val) |
482 (setq iswitchb-common-match-string nil) | 464 (setq iswitchb-common-match-string nil) |
483 (if (and iswitchb-matches | 465 (if (and iswitchb-matches |
484 (stringp iswitchb-text) | 466 (stringp iswitchb-text) |
560 (setq iswitchb-rescan t) | 542 (setq iswitchb-rescan t) |
561 ) | 543 ) |
562 | 544 |
563 | 545 |
564 (defun iswitchb-select-buffer-text () | 546 (defun iswitchb-select-buffer-text () |
565 "Select the buffer named by the prompt. If no buffer exactly | 547 "Select the buffer named by the prompt. |
566 matching the prompt exists, a new one is possibly created." | 548 If no buffer exactly matching the prompt exists, maybe create a new one." |
567 (interactive) | 549 (interactive) |
568 (setq iswitchb-exit 'takeprompt) | 550 (setq iswitchb-exit 'takeprompt) |
569 (exit-minibuffer)) | 551 (exit-minibuffer)) |
570 | 552 |
571 | 553 |
589 | 571 |
590 | 572 |
591 ;;; CREATE LIST OF ALL CURRENT BUFFERS | 573 ;;; CREATE LIST OF ALL CURRENT BUFFERS |
592 | 574 |
593 (defun iswitchb-make-buflist () | 575 (defun iswitchb-make-buflist () |
594 "Set `iswitchb-buflist' to the current list of buffers. Buffers | 576 "Set `iswitchb-buflist' to the current list of buffers. |
595 that are currently visible are put at the end of the list." | 577 Currently visible buffers are put at the end of the list." |
596 | |
597 (setq iswitchb-buflist | 578 (setq iswitchb-buflist |
598 (let (buflist | 579 (let (buflist |
599 iswitchb-current-buffers) | 580 iswitchb-current-buffers) |
600 (setq iswitchb-current-buffers (iswitchb-get-buffers-in-frames)) | 581 (setq iswitchb-current-buffers (iswitchb-get-buffers-in-frames)) |
601 (setq buflist (mapcar 'buffer-name (buffer-list))) | 582 (setq buflist (mapcar 'buffer-name (buffer-list))) |
619 | 600 |
620 | 601 |
621 | 602 |
622 | 603 |
623 (defun iswitchb-get-buffers-in-frames (&optional current) | 604 (defun iswitchb-get-buffers-in-frames (&optional current) |
624 | |
625 "Return the list of buffers that are visible in the current frame. | 605 "Return the list of buffers that are visible in the current frame. |
626 If optional argument `current' is given, restrict searching to the | 606 If optional argument `current' is given, restrict searching to the |
627 current frame, rather than all frames, regardless of value of | 607 current frame, rather than all frames, regardless of value of |
628 `iswitchb-all-frames'." | 608 `iswitchb-all-frames'." |
629 | |
630 (let ((iswitchb-bufs-in-frame nil)) | 609 (let ((iswitchb-bufs-in-frame nil)) |
631 | |
632 (walk-windows 'iswitchb-get-bufname nil | 610 (walk-windows 'iswitchb-get-bufname nil |
633 (if current | 611 (if current |
634 nil | 612 nil |
635 iswitchb-all-frames)) | 613 iswitchb-all-frames)) |
636 iswitchb-bufs-in-frame)) | 614 iswitchb-bufs-in-frame)) |
645 | 623 |
646 ;;; FIND MATCHING BUFFERS | 624 ;;; FIND MATCHING BUFFERS |
647 | 625 |
648 (defun iswitchb-set-matches () | 626 (defun iswitchb-set-matches () |
649 "Set `iswitchb-matches' to the list of buffers matching prompt." | 627 "Set `iswitchb-matches' to the list of buffers matching prompt." |
650 | |
651 (if iswitchb-rescan | 628 (if iswitchb-rescan |
652 (setq iswitchb-matches | 629 (setq iswitchb-matches |
653 (let* ((buflist iswitchb-buflist) | 630 (let* ((buflist iswitchb-buflist) |
654 ) | 631 ) |
655 (if (> (length iswitchb-text) 0) | 632 (if (> (length iswitchb-text) 0) |
656 (iswitchb-get-matched-buffers iswitchb-text iswitchb-regexp | 633 (iswitchb-get-matched-buffers iswitchb-text iswitchb-regexp |
657 buflist) | 634 buflist) |
658 ;; else no text, no matches | 635 ;; else no text, no matches |
659 nil))))) | 636 nil))))) |
660 | 637 |
661 (defun iswitchb-get-matched-buffers | 638 (defun iswitchb-get-matched-buffers (regexp &optional string-format buffer-list) |
662 (regexp &optional string-format buffer-list) | 639 "Return matched buffers. |
663 "Return matched buffers. If STRING-FORMAT is non-nil, consider | 640 If STRING-FORMAT is non-nil, consider EGEXP as string. |
664 REGEXP as string. BUFFER-LIST can be list of buffers or list of | 641 BUFFER-LIST can be list of buffers or list of strings." |
665 strings." | |
666 | |
667 (let* ((case-fold-search iswitchb-case) | 642 (let* ((case-fold-search iswitchb-case) |
668 ;; need reverse since we are building up list backwards | 643 ;; need reverse since we are building up list backwards |
669 (list (reverse buffer-list)) | 644 (list (reverse buffer-list)) |
670 (do-string (stringp (car list))) | 645 (do-string (stringp (car list))) |
671 name | 646 name |
870 ;; else wont create new buffer | 845 ;; else wont create new buffer |
871 (message (format "no buffer matching `%s'" buf)) | 846 (message (format "no buffer matching `%s'" buf)) |
872 ))) | 847 ))) |
873 | 848 |
874 (defun iswitchb-window-buffer-p (buffer) | 849 (defun iswitchb-window-buffer-p (buffer) |
875 "Return window pointer if BUFFER is visible in another frame. If | 850 "Return window pointer if BUFFER is visible in another frame. |
876 BUFFER is visible in the current frame, return nil." | 851 If BUFFER is visible in the current frame, return nil." |
877 | 852 (interactive) |
878 (interactive) | |
879 | |
880 (let ((blist (iswitchb-get-buffers-in-frames 'current))) | 853 (let ((blist (iswitchb-get-buffers-in-frames 'current))) |
881 ;;If the buffer is visible in current frame, return nil | 854 ;;If the buffer is visible in current frame, return nil |
882 (if (memq buffer blist) | 855 (if (memq buffer blist) |
883 nil | 856 nil |
884 ;; maybe in other frame... | 857 ;; maybe in other frame... |
885 (get-buffer-window buffer 'visible) | 858 (get-buffer-window buffer 'visible) |
886 ))) | 859 ))) |
887 | 860 |
888 ;;; KEYBINDINGS AND TOP LEVEL FUNCTIONS. | 861 ;;;###autoload |
889 (defun iswitchb-default-keybindings () | 862 (defun iswitchb-default-keybindings () |
890 "Set up default keybindings for iswitchb. | 863 "Set up default keybindings for `iswitchb-buffer'. |
891 Call this function to override the normal bindings." | 864 Call this function to override the normal bindings." |
892 (interactive) | 865 (interactive) |
893 (global-set-key "b" 'iswitchb-buffer) | 866 (global-set-key "b" 'iswitchb-buffer) |
894 (global-set-key "4b" 'iswitchb-buffer-other-window) | 867 (global-set-key "4b" 'iswitchb-buffer-other-window) |
895 (global-set-key "5b" 'iswitchb-buffer-other-frame)) | 868 (global-set-key "5b" 'iswitchb-buffer-other-frame)) |
901 "Switch to another buffer. | 874 "Switch to another buffer. |
902 | 875 |
903 The buffer name is selected interactively by typing a substring. The | 876 The buffer name is selected interactively by typing a substring. The |
904 buffer is displayed according to `iswitchb-default-method' -- the | 877 buffer is displayed according to `iswitchb-default-method' -- the |
905 default is to show it in the same window, unless it is already visible | 878 default is to show it in the same window, unless it is already visible |
906 in another frame. For details of keybindings, do `C-h f | 879 in another frame. |
907 iswitchb-mode'." | 880 For details of keybindings, do `\\[describe-function] iswitchb'." |
908 | |
909 (interactive) | 881 (interactive) |
910 (setq iswitchb-method iswitchb-default-method) | 882 (setq iswitchb-method iswitchb-default-method) |
911 (iswitchb-entry)) | 883 (iswitchb-entry)) |
912 | 884 |
913 | 885 |
914 ;;;###autoload | 886 ;;;###autoload |
915 (defun iswitchb-buffer-other-window () | 887 (defun iswitchb-buffer-other-window () |
916 "Switch to another buffer and show it in another window. | 888 "Switch to another buffer and show it in another window. |
917 The buffer name is selected interactively by typing a substring. | 889 The buffer name is selected interactively by typing a substring. |
918 For details of keybindings, do `C-h f iswitchb-mode'." | 890 For details of keybindings, do `\\[describe-function] iswitchb'." |
919 (interactive) | 891 (interactive) |
920 (setq iswitchb-method 'otherwindow) | 892 (setq iswitchb-method 'otherwindow) |
921 (iswitchb-entry)) | 893 (iswitchb-entry)) |
922 | 894 |
923 | 895 |
924 | 896 |
925 ;;;###autoload | 897 ;;;###autoload |
926 (defun iswitchb-buffer-other-frame () | 898 (defun iswitchb-buffer-other-frame () |
927 "Switch to another buffer and show it in another frame. | 899 "Switch to another buffer and show it in another frame. |
928 The buffer name is selected interactively by typing a substring. | 900 The buffer name is selected interactively by typing a substring. |
929 For details of keybindings, do `C-h f iswitchb-mode'." | 901 For details of keybindings, do `\\[describe-function] iswitchb'." |
930 (interactive) | 902 (interactive) |
931 (setq iswitchb-method 'otherframe) | 903 (setq iswitchb-method 'otherframe) |
932 (iswitchb-entry)) | 904 (iswitchb-entry)) |
933 | 905 |
934 | 906 |
935 | 907 |
936 (defun iswitchb-entry () | 908 (defun iswitchb-entry () |
937 "Simply fall into iswitchb -- the main function." | 909 "Simply fall into `iswitchb' -- the main function." |
938 (iswitchb)) | 910 (iswitchb)) |
939 | 911 |
940 | 912 |
941 | 913 |
942 | 914 |
950 ;; text though, indicating its just a problem the first time we enter | 922 ;; text though, indicating its just a problem the first time we enter |
951 ;; the function. To solve this, we use another entry hook for emacs | 923 ;; the function. To solve this, we use another entry hook for emacs |
952 ;; to show the default the first time we enter the minibuffer. | 924 ;; to show the default the first time we enter the minibuffer. |
953 | 925 |
954 (defun iswitchb-init-Xemacs-trick () | 926 (defun iswitchb-init-Xemacs-trick () |
955 "Display default buffer when first entering minibuffer. This is a | 927 "Display default buffer when first entering minibuffer. |
956 hack for XEmacs, and should really be handled by iswitchb-exhibit." | 928 This is a hack for XEmacs, and should really be handled by `iswitchb-exhibit'." |
957 (if (iswitchb-entryfn-p) | 929 (if (iswitchb-entryfn-p) |
958 (progn | 930 (progn |
959 (iswitchb-show-default-buffer) | 931 (iswitchb-show-default-buffer) |
960 (goto-char (point-min))))) | 932 (goto-char (point-min))))) |
961 | 933 |
984 | 956 |
985 | 957 |
986 ;;; ICOMPLETE TYPE CODE | 958 ;;; ICOMPLETE TYPE CODE |
987 | 959 |
988 (defun iswitchb-exhibit () | 960 (defun iswitchb-exhibit () |
989 "Find matching buffers and display them in the minibuffer. | 961 "Find matching buffers and display a list in the minibuffer. |
990 Copied from `icomplete-exhibit' with two changes: | 962 Copied from `icomplete-exhibit' with two changes: |
991 1. It prints a default buffer name when there is no text yet entered. | 963 1. It prints a default buffer name when there is no text yet entered. |
992 2. It calls my completion routine rather than the standard completion." | 964 2. It calls my completion routine rather than the standard completion." |
993 | 965 |
994 (if iswitchb-use-mycompletion | 966 (if iswitchb-use-mycompletion |
1118 alternatives) | 1090 alternatives) |
1119 close-bracket-prospects))) | 1091 close-bracket-prospects))) |
1120 ))) | 1092 ))) |
1121 | 1093 |
1122 (defun iswitchb-minibuffer-setup () | 1094 (defun iswitchb-minibuffer-setup () |
1123 "Set up minibuffer for iswitchb. Copied from | 1095 "Set up minibuffer for `iswitchb-buffer'. |
1124 `icomplete-minibuffer-setup-hook'." | 1096 Copied from `icomplete-minibuffer-setup-hook'." |
1125 (if (iswitchb-entryfn-p) | 1097 (if (iswitchb-entryfn-p) |
1126 (progn | 1098 (progn |
1127 | 1099 |
1128 (make-local-variable 'iswitchb-use-mycompletion) | 1100 (make-local-variable 'iswitchb-use-mycompletion) |
1129 (setq iswitchb-use-mycompletion t) | 1101 (setq iswitchb-use-mycompletion t) |
1140 ) | 1112 ) |
1141 )) | 1113 )) |
1142 | 1114 |
1143 | 1115 |
1144 (defun iswitchb-pre-command () | 1116 (defun iswitchb-pre-command () |
1145 "Run before command in iswitchb." | 1117 "Run before command in `iswitchb-buffer'." |
1146 (iswitchb-tidy)) | 1118 (iswitchb-tidy)) |
1147 | 1119 |
1148 | 1120 |
1149 (defun iswitchb-post-command () | 1121 (defun iswitchb-post-command () |
1150 "Run after command in iswitchb." | 1122 "Run after command in `iswitchb-buffer'." |
1151 (iswitchb-exhibit) | 1123 (iswitchb-exhibit) |
1152 ) | 1124 ) |
1153 | 1125 |
1154 | 1126 |
1155 | 1127 |
1170 (make-local-variable 'iswitchb-eoinput) | 1142 (make-local-variable 'iswitchb-eoinput) |
1171 (setq iswitchb-eoinput 1))) | 1143 (setq iswitchb-eoinput 1))) |
1172 | 1144 |
1173 | 1145 |
1174 (defun iswitchb-entryfn-p () | 1146 (defun iswitchb-entryfn-p () |
1175 "Return non-nil if `this-command' shows we are using iswitchb-buffer." | 1147 "Return non-nil if `this-command' shows we are using `iswitchb-buffer'." |
1176 (and (symbolp this-command) ; ignore lambda functions | 1148 (and (symbolp this-command) ; ignore lambda functions |
1177 (member (symbol-name this-command) | 1149 (member (symbol-name this-command) |
1178 '("iswitchb-buffer" | 1150 '("iswitchb-buffer" |
1179 "iswitchb-buffer-other-frame" | 1151 "iswitchb-buffer-other-frame" |
1180 "iswitchb-buffer-other-window")))) | 1152 "iswitchb-buffer-other-window")))) |
1181 | 1153 |
1182 (defun iswitchb-summaries-to-end () | 1154 (defun iswitchb-summaries-to-end () |
1183 "Move the summaries to the end of the list. This is an example | 1155 "Move the summaries to the end of the list. |
1184 function which can be hooked on to `iswitchb-make-buflist-hook'. | 1156 This is an example function which can be hooked on to |
1185 Any buffer matching the regexps `Summary' or `output\*$'are put to | 1157 `iswitchb-make-buflist-hook'. Any buffer matching the regexps |
1186 the end of the list." | 1158 `Summary' or `output\*$'are put to the end of the list." |
1187 | |
1188 (let ((summaries (delq nil (mapcar | 1159 (let ((summaries (delq nil (mapcar |
1189 '(lambda (x) | 1160 '(lambda (x) |
1190 (if (or | 1161 (if (or |
1191 (string-match "Summary" x) | 1162 (string-match "Summary" x) |
1192 (string-match "output\\*$" x)) | 1163 (string-match "output\\*$" x)) |
1201 ;;; HOOKS | 1172 ;;; HOOKS |
1202 (add-hook 'minibuffer-setup-hook 'iswitchb-minibuffer-setup) | 1173 (add-hook 'minibuffer-setup-hook 'iswitchb-minibuffer-setup) |
1203 | 1174 |
1204 (provide 'iswitchb) | 1175 (provide 'iswitchb) |
1205 | 1176 |
1206 ;;; ISWITCHB.EL ends here | 1177 ;;; iswitchb.el ends here |