comparison lisp/iswitchb.el @ 21326:8150549598cc

Many doc fixes. (iswitchb-method): No longer a user variable. (iswitchb-minibuffer-setup-hook): Customized. (iswitchb-default): New variable. (iswitchb-complete): Use iswitchb-common-match-string rather than recomputing the value. (iswitchb-toggle-ignore): Recompute list of buffers. (iswitchb-init-XEmacs-trick): Renamed from iswitchb-init-Xemacs-trick.
author Stephen Eglen <stephen@gnu.org>
date Tue, 31 Mar 1998 20:14:55 +0000
parents cbdbd307fdb7
children a0c3ee34362d
comparison
equal deleted inserted replaced
21325:8b4db8ce1da3 21326:8150549598cc
118 ;;(defun iswitchb-my-keys () 118 ;;(defun iswitchb-my-keys ()
119 ;; "Add my keybindings for iswitchb." 119 ;; "Add my keybindings for iswitchb."
120 ;; (define-key iswitchb-mode-map " " 'iswitchb-next-match) 120 ;; (define-key iswitchb-mode-map " " 'iswitchb-next-match)
121 ;; ) 121 ;; )
122 ;; 122 ;;
123 ;; Seeing all the matching buffers. 123 ;; Seeing all the matching buffers
124 ;; 124 ;;
125 ;; If you have many matching buffers, they may not all fit onto one 125 ;; If you have many matching buffers, they may not all fit onto one
126 ;; line of the minibuffer. In this case, you should use rsz-mini 126 ;; line of the minibuffer. In this case, you should use rsz-mini
127 ;; (resize-minibuffer-mode). You can also limit iswitchb so that it 127 ;; (resize-minibuffer-mode). You can also limit iswitchb so that it
128 ;; only shows a certain number of lines -- see the documentation for 128 ;; only shows a certain number of lines -- see the documentation for
129 ;; `iswitchb-minibuffer-setup-hook'. 129 ;; `iswitchb-minibuffer-setup-hook'.
130 130
131 131
132 ;; Changing the list of buffers. 132 ;; Changing the list of buffers
133 133
134 ;; By default, the list of current buffers is most recent first, 134 ;; By default, the list of current buffers is most recent first,
135 ;; oldest last, with the exception that the buffers visible in the 135 ;; oldest last, with the exception that the buffers visible in the
136 ;; current frame are put at the end of the list. A hook exists to 136 ;; current frame are put at the end of the list. A hook exists to
137 ;; allow other functions to order the list. For example, if you add: 137 ;; allow other functions to order the list. For example, if you add:
152 ;; I don't use font-lock that much, so I've hardcoded the faces. If 152 ;; I don't use font-lock that much, so I've hardcoded the faces. If
153 ;; this is too harsh, let me know. Colouring of the matching buffer 153 ;; this is too harsh, let me know. Colouring of the matching buffer
154 ;; name was suggested by Carsten Dominik (dominik@strw.leidenuniv.nl) 154 ;; name was suggested by Carsten Dominik (dominik@strw.leidenuniv.nl)
155 155
156 156
157 ;; Replacement for read-buffer. 157 ;; Replacement for read-buffer
158 158
159 ;; iswitchb-read-buffer has been written to be a drop in replacement 159 ;; iswitchb-read-buffer has been written to be a drop in replacement
160 ;; for the normal buffer selection routine `read-buffer'. To use 160 ;; for the normal buffer selection routine `read-buffer'. To use
161 ;; iswitch for all buffer selections in Emacs, add: 161 ;; iswitch for all buffer selections in Emacs, add:
162 ;; (setq read-buffer-function 'iswitchb-read-buffer) 162 ;; (setq read-buffer-function 'iswitchb-read-buffer)
163 ;; (This variable should be present in Emacs 20.3+) 163 ;; (This variable should be present in Emacs 20.3+)
164 ;; XEmacs users can get the same behaviour by doing: 164 ;; XEmacs users can get the same behaviour by doing:
165 ;; (defalias 'read-buffer 'iswitchb-read-buffer) 165 ;; (defalias 'read-buffer 'iswitchb-read-buffer)
166 ;; since `read-buffer' is defined in lisp. 166 ;; since `read-buffer' is defined in lisp.
167
168 ;; Regexp matching
169
170 ;; There is limited provision for regexp matching within iswitchb,
171 ;; enabled through `iswitchb-regexp'. This allows you to type `c$'
172 ;; for example and see all buffer names ending in `c'. This facility
173 ;; is quite limited though in two respects. First, you can't
174 ;; currently type in expressions like `[0-9]' directly -- you have to
175 ;; type them in when iswitchb-regexp is nil and then toggle on the
176 ;; regexp functionality. Likewise, don't enter an expression
177 ;; containing `\' in regexp mode. If you try, iswitchb gets confused,
178 ;; so just hit C-g and try again. Secondly, no completion mechanism
179 ;; is currently offered when regexp searching.
167 180
168 ;;; TODO 181 ;;; TODO
169 182
170 ;;; Acknowledgements 183 ;;; Acknowledgements
171 184
221 :type '(repeat regexp) 234 :type '(repeat regexp)
222 :group 'iswitchb) 235 :group 'iswitchb)
223 236
224 237
225 ;;; Examples for setting the value of iswitchb-buffer-ignore 238 ;;; Examples for setting the value of iswitchb-buffer-ignore
226 ;(defun -c-mode (name) 239 ;(defun iswitchb-ignore-c-mode (name)
227 ; "Ignore all c mode buffers -- example function for iswitchb." 240 ; "Ignore all c mode buffers -- example function for iswitchb."
228 ; (save-excursion 241 ; (save-excursion
229 ; (set-buffer name) 242 ; (set-buffer name)
230 ; (string-match "^C$" mode-name))) 243 ; (string-match "^C$" mode-name)))
231 244
232 ;(setq iswitchb-buffer-ignore '("^ " ignore-c-mode)) 245 ;(setq iswitchb-buffer-ignore '("^ " iswitchb-ignore-c-mode))
233 ;(setq iswitchb-buffer-ignore '("^ " "\\.c$" "\\.h$")) 246 ;(setq iswitchb-buffer-ignore '("^ " "\\.c$" "\\.h$"))
234 247
235 (defcustom iswitchb-default-method 'always-frame 248 (defcustom iswitchb-default-method 'always-frame
236 "*How to switch to new buffer when using `iswitchb-buffer'. 249 "*How to switch to new buffer when using `iswitchb-buffer'.
237 Possible values: 250 Possible values:
253 :group 'iswitchb) 266 :group 'iswitchb)
254 267
255 268
256 (defcustom iswitchb-regexp nil 269 (defcustom iswitchb-regexp nil
257 "*Non-nil means that `iswitchb' will do regexp matching. 270 "*Non-nil means that `iswitchb' will do regexp matching.
258 Value can be toggled within `iswitchb'." 271 Value can be toggled within `iswitchb' using `iswitchb-toggle-regexp'."
259 :type 'boolean 272 :type 'boolean
260 :group 'iswitchb) 273 :group 'iswitchb)
261 274
262 275
263 (defcustom iswitchb-newbuffer t 276 (defcustom iswitchb-newbuffer t
280 :group 'iswitchb) 293 :group 'iswitchb)
281 294
282 295
283 296
284 (defcustom iswitchb-use-fonts t 297 (defcustom iswitchb-use-fonts t
285 "*Non-nil means use fonts for showing first match." 298 "*Non-nil means use font-lock fonts for showing first match."
286 :type 'boolean 299 :type 'boolean
287 :group 'iswitchb) 300 :group 'iswitchb)
288 301
289 302
290 (defcustom iswitchb-make-buflist-hook nil 303 (defcustom iswitchb-make-buflist-hook nil
291 "*Hook to run when list of matching buffers is created." 304 "*Hook to run when list of matching buffers is created."
292 :type 'hook 305 :type 'hook
293 :group 'iswitchb) 306 :group 'iswitchb)
294 307
295
296
297 (defvar iswitchb-method nil
298 "*Stores the method for viewing the selected buffer.
299 Its value is one of `samewindow', `otherwindow', `display', `otherframe',
300 `maybe-frame' or `always-frame'. See `iswitchb-default-method' for
301 details of values.")
302
303 (defvar iswitchb-all-frames 'visible 308 (defvar iswitchb-all-frames 'visible
304 "*Argument to pass to `walk-windows' when finding visible buffers. 309 "*Argument to pass to `walk-windows' when finding visible buffers.
305 See documentation of `walk-windows' for useful values.") 310 See documentation of `walk-windows' for useful values.")
306 311
307 312 (defcustom iswitchb-minibuffer-setup-hook nil
308 313 "*Iswitchb-specific customization of minibuffer setup.
309 ;; Do we need the variable iswitchb-use-mycompletion?
310
311
312 ;;; Internal Variables
313 (defvar iswitchb-minibuffer-setup-hook nil
314 "Iswitchb-specific customization of minibuffer setup.
315 314
316 This hook is run during minibuffer setup iff `iswitchb' will be active. 315 This hook is run during minibuffer setup iff `iswitchb' will be active.
317 It is intended for use in customizing iswitchb for interoperation 316 It is intended for use in customizing iswitchb for interoperation
318 with other packages. For instance: 317 with other packages. For instance:
319 318
322 \(lambda () 321 \(lambda ()
323 \(make-local-variable 'resize-minibuffer-window-max-height) 322 \(make-local-variable 'resize-minibuffer-window-max-height)
324 \(setq resize-minibuffer-window-max-height 3)))) 323 \(setq resize-minibuffer-window-max-height 3))))
325 324
326 will constrain rsz-mini to a maximum minibuffer height of 3 lines when 325 will constrain rsz-mini to a maximum minibuffer height of 3 lines when
327 iswitchb is running. Copied from `icomplete-minibuffer-setup-hook'.") 326 iswitchb is running. Copied from `icomplete-minibuffer-setup-hook'."
327 :type 'hook
328 :group 'iswitchb)
329
330 ;; Do we need the variable iswitchb-use-mycompletion?
331
332
333 ;;; Internal Variables
334
335 (defvar iswitchb-method nil
336 "Stores the method for viewing the selected buffer.
337 Its value is one of `samewindow', `otherwindow', `display', `otherframe',
338 `maybe-frame' or `always-frame'. See `iswitchb-default-method' for
339 details of values.")
328 340
329 (defvar iswitchb-eoinput 1 341 (defvar iswitchb-eoinput 1
330 "Point where minibuffer input ends and completion info begins. 342 "Point where minibuffer input ends and completion info begins.
331 Copied from `icomplete-eoinput'.") 343 Copied from `icomplete-eoinput'.")
332 (make-variable-buffer-local 'iswitchb-eoinput) 344 (make-variable-buffer-local 'iswitchb-eoinput)
346 interfere with other minibuffer usage.") 358 interfere with other minibuffer usage.")
347 359
348 (defvar iswitchb-change-word-sub nil 360 (defvar iswitchb-change-word-sub nil
349 "Private variable used by `iswitchb-word-matching-substring'.") 361 "Private variable used by `iswitchb-word-matching-substring'.")
350 362
351
352 (defvar iswitchb-common-match-string nil 363 (defvar iswitchb-common-match-string nil
353 "Stores the string that is common to all matching buffers.") 364 "Stores the string that is common to all matching buffers.")
354
355 365
356 (defvar iswitchb-rescan nil 366 (defvar iswitchb-rescan nil
357 "Non-nil means we need to regenerate the list of matching buffers.") 367 "Non-nil means we need to regenerate the list of matching buffers.")
358 368
359 (defvar iswitchb-text nil 369 (defvar iswitchb-text nil
377 "Stores original value of `iswitchb-buffer-ignore'.") 387 "Stores original value of `iswitchb-buffer-ignore'.")
378 388
379 (defvar iswitchb-xemacs (string-match "XEmacs" (emacs-version)) 389 (defvar iswitchb-xemacs (string-match "XEmacs" (emacs-version))
380 "Non-nil if we are running XEmacs. Otherwise, assume we are running Emacs.") 390 "Non-nil if we are running XEmacs. Otherwise, assume we are running Emacs.")
381 391
392 (defvar iswitchb-default nil
393 "Default buffer for iswitchb.")
382 394
383 ;;; FUNCTIONS 395 ;;; FUNCTIONS
384 396
385 397
386 ;;; ISWITCHB KEYMAP 398 ;;; ISWITCHB KEYMAP
487 499
488 (iswitchb-define-mode-map) 500 (iswitchb-define-mode-map)
489 (setq iswitchb-exit nil) 501 (setq iswitchb-exit nil)
490 (setq iswitchb-rescan t) 502 (setq iswitchb-rescan t)
491 (setq iswitchb-text "") 503 (setq iswitchb-text "")
492 (iswitchb-make-buflist 504 (setq iswitchb-default
493 (if (bufferp default) 505 (if (bufferp default)
494 (buffer-name default) 506 (buffer-name default)
495 default)) 507 default))
508 (iswitchb-make-buflist iswitchb-default)
496 (iswitchb-set-matches) 509 (iswitchb-set-matches)
497 (let 510 (let
498 ((minibuffer-local-completion-map iswitchb-mode-map) 511 ((minibuffer-local-completion-map iswitchb-mode-map)
499 (iswitchb-prepost-hooks t) 512 (iswitchb-prepost-hooks t)
500 (iswitchb-require-match require-match) 513 (iswitchb-require-match require-match)
537 The result is stored in `iswitchb-common-match-string'." 550 The result is stored in `iswitchb-common-match-string'."
538 551
539 (let* (val) 552 (let* (val)
540 (setq iswitchb-common-match-string nil) 553 (setq iswitchb-common-match-string nil)
541 (if (and iswitchb-matches 554 (if (and iswitchb-matches
555 (not iswitchb-regexp) ;; testing
542 (stringp iswitchb-text) 556 (stringp iswitchb-text)
543 (> (length iswitchb-text) 0)) 557 (> (length iswitchb-text) 0))
544 (if (setq val (iswitchb-find-common-substring 558 (if (setq val (iswitchb-find-common-substring
545 iswitchb-matches iswitchb-text)) 559 iswitchb-matches iswitchb-text))
546 (setq iswitchb-common-match-string val))) 560 (setq iswitchb-common-match-string val)))
560 ;; only one choice, so select it. 574 ;; only one choice, so select it.
561 (exit-minibuffer)) 575 (exit-minibuffer))
562 576
563 (t 577 (t
564 ;; else there could be some completions 578 ;; else there could be some completions
565 579 (setq res iswitchb-common-match-string)
566 (setq res (iswitchb-find-common-substring
567 iswitchb-matches iswitchb-text))
568 (if (and (not (memq res '(t nil))) 580 (if (and (not (memq res '(t nil)))
569 (not (equal res iswitchb-text))) 581 (not (equal res iswitchb-text)))
570 ;; found something to complete, so put it in the minibuffer. 582 ;; found something to complete, so put it in the minibuffer.
571 (progn 583 (progn
572 (setq iswitchb-rescan nil) 584 (setq iswitchb-rescan nil)
608 (setq iswitchb-buffer-ignore nil) 620 (setq iswitchb-buffer-ignore nil)
609 ) 621 )
610 ;; else 622 ;; else
611 (setq iswitchb-buffer-ignore iswitchb-buffer-ignore-orig) 623 (setq iswitchb-buffer-ignore iswitchb-buffer-ignore-orig)
612 ) 624 )
625 (iswitchb-make-buflist iswitchb-default)
613 ;; ask for list to be regenerated. 626 ;; ask for list to be regenerated.
614 (setq iswitchb-rescan t) 627 (setq iswitchb-rescan t)
615 ) 628 )
616 629
617 (defun iswitchb-exit-minibuffer () 630 (defun iswitchb-exit-minibuffer ()
750 (if iswitchb-rescan 763 (if iswitchb-rescan
751 (setq iswitchb-matches 764 (setq iswitchb-matches
752 (let* ((buflist iswitchb-buflist) 765 (let* ((buflist iswitchb-buflist)
753 ) 766 )
754 (iswitchb-get-matched-buffers iswitchb-text iswitchb-regexp 767 (iswitchb-get-matched-buffers iswitchb-text iswitchb-regexp
755 buflist))))) 768 buflist)))))
756 769
757 (defun iswitchb-get-matched-buffers (regexp 770 (defun iswitchb-get-matched-buffers (regexp
758 &optional string-format buffer-list) 771 &optional string-format buffer-list)
759 "Return buffers matching REGEXP. 772 "Return buffers matching REGEXP.
760 If STRING-FORMAT is non-nil, consider REGEXP as string. 773 If STRING-FORMAT is nil, consider REGEXP as just a string.
761 BUFFER-LIST can be list of buffers or list of strings." 774 BUFFER-LIST can be list of buffers or list of strings."
762 (let* ((case-fold-search iswitchb-case) 775 (let* ((case-fold-search iswitchb-case)
763 ;; need reverse since we are building up list backwards 776 ;; need reverse since we are building up list backwards
764 (list (reverse buffer-list)) 777 (list (reverse buffer-list))
765 (do-string (stringp (car list))) 778 (do-string (stringp (car list)))
766 name 779 name
767 ret 780 ret
768 ) 781 )
769 (mapcar 782 (mapcar
770 (lambda (x) 783 (lambda (x)
776 (cond 789 (cond
777 ((and (or (and string-format (string-match regexp name)) 790 ((and (or (and string-format (string-match regexp name))
778 (and (null string-format) 791 (and (null string-format)
779 (string-match (regexp-quote regexp) name))) 792 (string-match (regexp-quote regexp) name)))
780 793
781 ;; todo (not (iswitchb-ignore-buffername-p name)) 794 (not (iswitchb-ignore-buffername-p name))
782 ) 795 )
783 (setq ret (cons name ret)) 796 (setq ret (cons name ret))
784 ))) 797 )))
785 list) 798 list)
786 ret 799 ret
816 829
817 ;; return the result 830 ;; return the result
818 ignorep) 831 ignorep)
819 ) 832 )
820 833
821
822
823 (defun iswitchb-word-matching-substring (word) 834 (defun iswitchb-word-matching-substring (word)
824 "Return part of WORD before 1st match to `iswitchb-change-word-sub'. 835 "Return part of WORD before 1st match to `iswitchb-change-word-sub'.
825 If `iswitchb-change-word-sub' cannot be found in WORD, return nil." 836 If `iswitchb-change-word-sub' cannot be found in WORD, return nil."
826 (let ((case-fold-search iswitchb-case)) 837 (let ((case-fold-search iswitchb-case))
827 (let ((m (string-match iswitchb-change-word-sub word))) 838 (let ((m (string-match iswitchb-change-word-sub word)))
828 (if m 839 (if m
829 (substring word m) 840 (substring word m)
830 ;; else no match 841 ;; else no match
831 nil)))) 842 nil))))
832
833
834
835
836
837 843
838 (defun iswitchb-find-common-substring (lis subs) 844 (defun iswitchb-find-common-substring (lis subs)
839 "Return common string following SUBS in each element of LIS." 845 "Return common string following SUBS in each element of LIS."
840 (let (res 846 (let (res
841 alist 847 alist
1087 ;; default is shown for both whenever we delete all of our text 1093 ;; default is shown for both whenever we delete all of our text
1088 ;; though, indicating its just a problem the first time we enter the 1094 ;; though, indicating its just a problem the first time we enter the
1089 ;; function. To solve this, we use another entry hook for emacs to 1095 ;; function. To solve this, we use another entry hook for emacs to
1090 ;; show the default the first time we enter the minibuffer. 1096 ;; show the default the first time we enter the minibuffer.
1091 1097
1092 (defun iswitchb-init-Xemacs-trick () 1098 (defun iswitchb-init-XEmacs-trick ()
1093 "Display default buffer when first entering minibuffer. 1099 "Display default buffer when first entering minibuffer.
1094 This is a hack for XEmacs, and should really be handled by `iswitchb-exhibit'." 1100 This is a hack for XEmacs, and should really be handled by `iswitchb-exhibit'."
1095 (if (iswitchb-entryfn-p) 1101 (if (iswitchb-entryfn-p)
1096 (progn 1102 (progn
1097 (iswitchb-exhibit) 1103 (iswitchb-exhibit)
1099 1105
1100 1106
1101 ;; add this hook for XEmacs only. 1107 ;; add this hook for XEmacs only.
1102 (if iswitchb-xemacs 1108 (if iswitchb-xemacs
1103 (add-hook 'iswitchb-minibuffer-setup-hook 1109 (add-hook 'iswitchb-minibuffer-setup-hook
1104 'iswitchb-init-Xemacs-trick)) 1110 'iswitchb-init-XEmacs-trick))
1105 1111
1106 1112
1107 ;;; XEmacs / backspace key 1113 ;;; XEmacs / backspace key
1108 ;; For some reason, if the backspace key is pressed in XEmacs, the 1114 ;; For some reason, if the backspace key is pressed in XEmacs, the
1109 ;; line gets confused, so I've added a simple key definition to make 1115 ;; line gets confused, so I've added a simple key definition to make