aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1997-07-14 07:30:11 +0000
committerRichard M. Stallman1997-07-14 07:30:11 +0000
commit36a3b01cf8542fe5249ad83189938875ca200e20 (patch)
tree0f9781b7c0bd6f123399c607f5f12424e8056bfb
parent5c1aae96f952b34e78042c330845ac57be996a3c (diff)
downloademacs-36a3b01cf8542fe5249ad83189938875ca200e20.tar.gz
emacs-36a3b01cf8542fe5249ad83189938875ca200e20.zip
All user variables now converted to custom.
(iswitchb): New variable for use by the custom package. (iswitchb-default-buffer): Variable deleted. (iswitchb-define-mode-map): Addition of keybindings for iswitchb-kill-buffer and iswitchb-find-file. (iswitchb): When no text typed in, show all buffers. (iswitchb-complete): Use equal rather than eq. (iswitchb-next-match, iswitchb-prev-match): Use iswitchb-chop to handle reordering the buffer list. (iswitchb-chop): New function. (iswitchb-make-buflist): Rewritten for efficiency. (iswitchb-to-end): Operate on a list of buffers, not just one. (iswitchb-set-matches): Always return list of matching buffers, even in absence of user input. (iswitchb-kill-buffer): New function. (iswitchb-default-keybindings): Use read-kbd-macro for keys to define. (iswitchb-exhibit): Always return list of matching buffers. (iswitchb-show-default-buffer): Function deleted.
-rw-r--r--lisp/iswitchb.el433
1 files changed, 267 insertions, 166 deletions
diff --git a/lisp/iswitchb.el b/lisp/iswitchb.el
index ddd14e0188d..4aa3803ea2a 100644
--- a/lisp/iswitchb.el
+++ b/lisp/iswitchb.el
@@ -52,9 +52,9 @@
52 52
53;;If I have two buffers called "123456" and "123", with "123456" the 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 54;;most recent, when I use iswitchb, I first of all get presented with
55;;the default buffer (xxx) to switch to: 55;;the list of all the buffers
56;; 56;;
57;; iswitch {default xxx} 57;; iswitch {123456,123}
58;; 58;;
59;; If I then press 2: 59;; If I then press 2:
60;; iswitch 2[3]{123456,123} 60;; iswitch 2[3]{123456,123}
@@ -96,6 +96,13 @@
96;; hit ? or press TAB when there are no further completions to the 96;; hit ? or press TAB when there are no further completions to the
97;; substring. 97;; substring.
98 98
99;; The buffer at the head of the list can be killed by pressing C-k.
100;; If the buffer needs saving, you will be queried before the buffer
101;; is killed.
102
103;; If you find that the file you are after is not in a buffer, you can
104;; press C-x C-f to immediately drop into find-file.
105
99;; 106;;
100;; See the doc string of iswitchb for full keybindings and features. 107;; See the doc string of iswitchb for full keybindings and features.
101;; (describe-function 'iswitchb) 108;; (describe-function 'iswitchb)
@@ -103,7 +110,8 @@
103;;; Customisation 110;;; Customisation
104 111
105;; See the User Variables section below for easy ways to change the 112;; See the User Variables section below for easy ways to change the
106;; functionality of the program. 113;; functionality of the program. These are accessible using the
114;; custom package.
107;; To modify the keybindings, use the hook provided. For example: 115;; To modify the keybindings, use the hook provided. For example:
108;;(add-hook 'iswitchb-define-mode-map-hook 116;;(add-hook 'iswitchb-define-mode-map-hook
109;; 'iswitchb-my-keys) 117;; 'iswitchb-my-keys)
@@ -114,6 +122,7 @@
114;; ) 122;; )
115;; 123;;
116;; Seeing all the matching buffers. 124;; Seeing all the matching buffers.
125;;
117;; If you have many matching buffers, they may not all fit onto one 126;; If you have many matching buffers, they may not all fit onto one
118;; line of the minibuffer. In this case, you should use rsz-mini 127;; line of the minibuffer. In this case, you should use rsz-mini
119;; (resize-minibuffer-mode). You can also limit iswitchb so that it 128;; (resize-minibuffer-mode). You can also limit iswitchb so that it
@@ -163,6 +172,13 @@
163;; regexp searching is currently on). 172;; regexp searching is currently on).
164 173
165 174
175;;; TODO
176;; Could this selection also be used for other buffer selection
177;; routines, such as append-to-buffer and kill-buffer?
178
179;; Pressing Tab key twice (without completion) does not scroll the
180;; list of buffers.
181
166;;; Acknowledgements 182;;; Acknowledgements
167 183
168;; Thanks to Jari Aalto <jari.aalto@poboxes.com> for help with the 184;; Thanks to Jari Aalto <jari.aalto@poboxes.com> for help with the
@@ -171,19 +187,48 @@
171 187
172;;; Code: 188;;; Code:
173 189
190;; Set up the custom library.
191;; taken from http://www.dina.kvl.dk/~abraham/custom/
192(eval-and-compile
193 (condition-case ()
194 (require 'custom)
195 (error nil))
196 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
197 nil ;; We've got what we needed
198 ;; We have the old custom-library, hack around it!
199 (defmacro defgroup (&rest args)
200 nil)
201 (defmacro defcustom (var value doc &rest args)
202 (` (defvar (, var) (, value) (, doc))))))
203
174;;; User Variables 204;;; User Variables
175;; 205;;
176;; These are some things you might want to change. 206;; These are some things you might want to change.
177 207
178(defvar iswitchb-case case-fold-search 208(defgroup iswitchb nil
179 "*Non-nil if searching of buffer names should ignore case.") 209 "switch between buffers using substrings."
210 :group 'extensions
211 ;; These links are to be added in later versions of custom and
212 ;; so are currently commented out.
213 :link '(emacs-commentary-link :tag "Commentary" "iswitchb.el")
214 :link '(emacs-library-link :tag "Lisp File" "iswitchb.el")
215)
216
217
218(defcustom iswitchb-case case-fold-search
219 "*Non-nil if searching of buffer names should ignore case."
220 :type 'boolean
221 :group 'iswitchb)
180 222
181(defvar iswitchb-buffer-ignore 223(defcustom iswitchb-buffer-ignore
182 '("^ ") 224 '("^ ")
183 "*List of regexps or functions matching buffer names to ignore. 225 "*List of regexps or functions matching buffer names to ignore.
184For example, traditional behavior is not to list buffers whose names begin 226For example, traditional behavior is not to list buffers whose names begin
185with a space, for which the regexp is `^ '. See the source file for 227with a space, for which the regexp is `^ '. See the source file for
186example functions that filter buffernames.") 228example functions that filter buffernames."
229 :type '(repeat regexp)
230 :group 'iswitchb)
231
187 232
188;;; Examples for setting the value of iswitchb-buffer-ignore 233;;; Examples for setting the value of iswitchb-buffer-ignore
189;(defun -c-mode (name) 234;(defun -c-mode (name)
@@ -195,8 +240,7 @@ example functions that filter buffernames.")
195;(setq iswitchb-buffer-ignore '("^ " ignore-c-mode)) 240;(setq iswitchb-buffer-ignore '("^ " ignore-c-mode))
196;(setq iswitchb-buffer-ignore '("^ " "\\.c$" "\\.h$")) 241;(setq iswitchb-buffer-ignore '("^ " "\\.c$" "\\.h$"))
197 242
198 243(defcustom iswitchb-default-method 'always-frame
199(defvar iswitchb-default-method 'always-frame
200 "*How to switch to new buffer when using `iswitchb-buffer'. 244 "*How to switch to new buffer when using `iswitchb-buffer'.
201Possible values: 245Possible values:
202`samewindow' Show new buffer in same window 246`samewindow' Show new buffer in same window
@@ -207,29 +251,55 @@ Possible values:
207 you want to see the buffer in the same window of the current 251 you want to see the buffer in the same window of the current
208 frame or in the other frame. 252 frame or in the other frame.
209`always-frame' If a buffer is visible in another frame, raise that 253`always-frame' If a buffer is visible in another frame, raise that
210 frame. Otherwise, visit the buffer in the same window.") 254 frame. Otherwise, visit the buffer in the same window."
255 :type '(choice (const :tag "samewindow" samewindow)
256 (const :tag "otherwindow" otherwindow)
257 (const :tag "display" display)
258 (const :tag "otherframe" otherframe)
259 (const :tag "maybe-frame" maybe-frame)
260 (const :tag "always-frame" always-frame))
261 :group 'iswitchb)
211 262
212(defvar iswitchb-regexp nil 263
264(defcustom iswitchb-regexp nil
213 "*Non-nil means that `iswitchb' will do regexp matching. 265 "*Non-nil means that `iswitchb' will do regexp matching.
214Value can be toggled within `iswitchb'.") 266Value can be toggled within `iswitchb'."
267 :type 'boolean
268 :group 'iswitchb)
269
215 270
216(defvar iswitchb-newbuffer t 271(defcustom iswitchb-newbuffer t
217 "*Non-nil means create new buffer if no buffer matches substring. 272 "*Non-nil means create new buffer if no buffer matches substring.
218See also `iswitchb-prompt-newbuffer'.") 273See also `iswitchb-prompt-newbuffer'."
274 :type 'boolean
275 :group 'iswitchb)
219 276
220(defvar iswitchb-prompt-newbuffer t 277
278(defcustom iswitchb-prompt-newbuffer t
221 "*Non-nil means prompt user to confirm before creating new buffer. 279 "*Non-nil means prompt user to confirm before creating new buffer.
222See also `iswitchb-newbuffer'.") 280See also `iswitchb-newbuffer'."
281 :type 'boolean
282 :group 'iswitchb)
283
284
285(defcustom iswitchb-define-mode-map-hook nil
286 "*Hook to define keys in `iswitchb-mode-map' for extra keybindings."
287 :type 'hook
288 :group 'iswitchb)
289
223 290
224(defvar iswitchb-define-mode-map-hook nil
225 "*Hook to define keys in `iswitchb-mode-map' for extra keybindings.")
226 291
292(defcustom iswitchb-use-fonts t
293 "*Non-nil means use fonts for showing first match."
294 :type 'boolean
295 :group 'iswitchb)
227 296
228(defvar iswitchb-use-fonts t
229 "*Non-nil means use fonts for showing first match.")
230 297
231(defvar iswitchb-make-buflist-hook nil 298(defcustom iswitchb-make-buflist-hook nil
232 "*Hook to run when list of matching buffers is created.") 299 "*Hook to run when list of matching buffers is created."
300 :type 'hook
301 :group 'iswitchb)
302
233 303
234 304
235(defvar iswitchb-method nil 305(defvar iswitchb-method nil
@@ -242,20 +312,6 @@ details of values.")
242 "*Argument to pass to `walk-windows' when finding visible buffers. 312 "*Argument to pass to `walk-windows' when finding visible buffers.
243See documentation of `walk-windows' for useful values.") 313See documentation of `walk-windows' for useful values.")
244 314
245;;; THINGS TO DO / BUGS
246
247;; In Xemacs, the default buffer is not shown the first time you enter
248; the minibuffer, but if you type a char and then delete a char, the
249; default appears. The first time we enter the minibuffer in XEmacs,
250; the default msg is not displayed, presumably because the hook is not
251; being called. I have put in a temporary hack therefore at the
252; bottom of this file.
253;
254; There is also a problem with the backspace key in XEmacs, so I have
255; bound it to the normal backward-delete-char.
256
257;; iswitch-buffer features Not yet implemented:
258; C-f Quit iswitch and drop into find-file
259 315
260 316
261;; Do we need the variable iswitchb-use-mycompletion? 317;; Do we need the variable iswitchb-use-mycompletion?
@@ -263,7 +319,7 @@ See documentation of `walk-windows' for useful values.")
263 319
264;;; Internal Variables 320;;; Internal Variables
265(defvar iswitchb-minibuffer-setup-hook nil 321(defvar iswitchb-minibuffer-setup-hook nil
266 "*Iswitchb-specific customization of minibuffer setup. 322 "Iswitchb-specific customization of minibuffer setup.
267 323
268This hook is run during minibuffer setup iff `iswitchb' will be active. 324This hook is run during minibuffer setup iff `iswitchb' will be active.
269It is intended for use in customizing iswitchb for interoperation 325It is intended for use in customizing iswitchb for interoperation
@@ -314,9 +370,6 @@ interfere with other minibuffer usage.")
314(defvar iswitchb-matches nil 370(defvar iswitchb-matches nil
315 "List of buffers currenly matching `iswitchb-text'.") 371 "List of buffers currenly matching `iswitchb-text'.")
316 372
317(defvar iswitchb-default-buffer nil
318 "Default buffer to switch to.")
319
320(defvar iswitchb-mode-map nil 373(defvar iswitchb-mode-map nil
321 "Keymap for `iswitchb-buffer'.") 374 "Keymap for `iswitchb-buffer'.")
322 375
@@ -353,8 +406,10 @@ selected.")
353 (define-key map "\t" 'iswitchb-complete) 406 (define-key map "\t" 'iswitchb-complete)
354 (define-key map "\C-j" 'iswitchb-select-buffer-text) 407 (define-key map "\C-j" 'iswitchb-select-buffer-text)
355 (define-key map "\C-t" 'iswitchb-toggle-regexp) 408 (define-key map "\C-t" 'iswitchb-toggle-regexp)
409 (define-key map "\C-x\C-f" 'iswitchb-find-file)
356 ;;(define-key map "\C-a" 'iswitchb-toggle-ignore) 410 ;;(define-key map "\C-a" 'iswitchb-toggle-ignore)
357 (define-key map "\C-c" 'iswitchb-toggle-case) 411 (define-key map "\C-c" 'iswitchb-toggle-case)
412 (define-key map "\C-k" 'iswitchb-kill-buffer)
358 (setq iswitchb-mode-map map) 413 (setq iswitchb-mode-map map)
359 (run-hooks 'iswitchb-define-mode-map-hook) 414 (run-hooks 'iswitchb-define-mode-map-hook)
360 )) 415 ))
@@ -384,7 +439,9 @@ If there is no common suffix, show a list of all matching buffers
384in a separate window. 439in a separate window.
385\\[iswitchb-toggle-regexp] Toggle rexep searching. 440\\[iswitchb-toggle-regexp] Toggle rexep searching.
386\\[iswitchb-toggle-case] Toggle case-sensitive searching of buffer names. 441\\[iswitchb-toggle-case] Toggle case-sensitive searching of buffer names.
387\\[iswitchb-completion-help] Show list of matching buffers in separate window." 442\\[iswitchb-completion-help] Show list of matching buffers in separate window.
443\\[iswitchb-find-file] Exit iswitchb and drop into find-file.
444\\[iswitchb-kill-buffer] Kill buffer at head of buffer list."
388 ;;\\[iswitchb-toggle-ignore] Toggle ignoring certain buffers (see \ 445 ;;\\[iswitchb-toggle-ignore] Toggle ignoring certain buffers (see \
389 ;;`iswitchb-buffer-ignore') 446 ;;`iswitchb-buffer-ignore')
390 447
@@ -395,7 +452,6 @@ in a separate window.
395 iswitchb-final-text 452 iswitchb-final-text
396 (minibuffer-confirm-incomplete nil) ;XEmacs todo: prevent `;confirm' 453 (minibuffer-confirm-incomplete nil) ;XEmacs todo: prevent `;confirm'
397 (icomplete-mode nil) ;; prevent icomplete starting up 454 (icomplete-mode nil) ;; prevent icomplete starting up
398 (minibuffer-local-completion-map minibuffer-local-completion-map)
399 ;; can only use fonts if they have been bound. 455 ;; can only use fonts if they have been bound.
400 (iswitchb-use-fonts (and iswitchb-use-fonts 456 (iswitchb-use-fonts (and iswitchb-use-fonts
401 (boundp 'font-lock-comment-face) 457 (boundp 'font-lock-comment-face)
@@ -403,54 +459,52 @@ in a separate window.
403 ) 459 )
404 460
405 (iswitchb-define-mode-map) 461 (iswitchb-define-mode-map)
406 (setq minibuffer-local-completion-map iswitchb-mode-map)
407
408 (setq iswitchb-exit nil) 462 (setq iswitchb-exit nil)
409 (setq iswitchb-rescan t) 463 (setq iswitchb-rescan t)
410 (setq iswitchb-text "") 464 (setq iswitchb-text "")
411 (setq iswitchb-matches nil) 465 (iswitchb-set-matches)
412 ;;(setq iswitchb-default-buffer (buffer-name (other-buffer)))
413 (setq prompt (format "iswitch ")) 466 (setq prompt (format "iswitch "))
414 (iswitchb-make-buflist) 467 (iswitchb-make-buflist)
415 (setq iswitchb-default-buffer (format "%s" (car iswitchb-buflist))) 468 (let
416 469 ((minibuffer-local-completion-map iswitchb-mode-map))
417 ;; highlight the default. 470 ;; prompt the user for the buffer name
418 (if iswitchb-use-fonts 471 (setq iswitchb-final-text (completing-read prompt
419 (put-text-property 0 (length iswitchb-default-buffer) 472 ;;nil
420 'face 473 '(("dummy".1))
421 'font-lock-function-name-face 474 ;;("2".2) ("3".3))
422 iswitchb-default-buffer)) 475 nil nil
423 476 nil;init string
424 ;; prompt the user for the buffer name 477 'iswitchb-history)))
425 (setq iswitchb-final-text (completing-read prompt 478
426 ;;nil
427 '(("dummy".1))
428 ;;("2".2) ("3".3))
429 nil nil
430 nil;init string
431 'iswitchb-history))
432 ;;(message "chosen text %s" iswitchb-final-text) 479 ;;(message "chosen text %s" iswitchb-final-text)
433 ;; Choose the buffer name: either the text typed in, or the head 480 ;; Choose the buffer name: either the text typed in, or the head
434 ;; of the list of matches 481 ;; of the list of matches
435 (if (or 482
436 (eq iswitchb-exit 'takeprompt) 483 (cond ( (eq iswitchb-exit 'findfile)
437 (null iswitchb-matches)) 484 (call-interactively 'find-file))
438 (setq buf-sel iswitchb-final-text) 485
439 ;; else take head of list 486 (t
440 (setq buf-sel (car iswitchb-matches))) 487 (if (or
441 488 (eq iswitchb-exit 'takeprompt)
442 ;; Or possibly choose the default buffer 489 (null iswitchb-matches))
443 (if (equal iswitchb-final-text "") 490 (setq buf-sel iswitchb-final-text)
444 (setq buf-sel iswitchb-default-buffer)) 491 ;; else take head of list
492 (setq buf-sel (car iswitchb-matches)))
445 493
446 ;; View the buffer 494 ;; Or possibly choose the default buffer
447 (message "go to buf %s" buf-sel) 495 (if (equal iswitchb-final-text "")
496 (setq buf-sel (car iswitchb-matches)))
448 497
449 (if (get-buffer buf-sel) 498 ;; View the buffer
450 ;; buffer exists, so view it and then exit 499 (message "go to buf %s" buf-sel)
451 (iswitchb-visit-buffer buf-sel) 500 ;; Check buf-sel is non-nil.
452 ;; else buffer doesnt exist 501 (if buf-sel
453 (iswitchb-possible-new-buffer buf-sel)) 502 (if (get-buffer buf-sel)
503 ;; buffer exists, so view it and then exit
504 (iswitchb-visit-buffer buf-sel)
505 ;; else buffer doesnt exist
506 (iswitchb-possible-new-buffer buf-sel)))
507 ))
454 508
455 )) 509 ))
456 510
@@ -478,10 +532,6 @@ The result is stored in `iswitchb-common-match-string'."
478 (interactive) 532 (interactive)
479 (let (res) 533 (let (res)
480 (cond ((not iswitchb-matches) 534 (cond ((not iswitchb-matches)
481
482 ;; todo
483 ;;(message "No buffer completions.")
484 ;;(sit-for 0.3)
485 (iswitchb-completion-help) 535 (iswitchb-completion-help)
486 ) 536 )
487 537
@@ -495,7 +545,7 @@ The result is stored in `iswitchb-common-match-string'."
495 (setq res (iswitchb-find-common-substring 545 (setq res (iswitchb-find-common-substring
496 iswitchb-matches iswitchb-text)) 546 iswitchb-matches iswitchb-text))
497 (if (and (not (memq res '(t nil))) 547 (if (and (not (memq res '(t nil)))
498 (not (eq res iswitchb-text))) 548 (not (equal res iswitchb-text)))
499 ;; found something to complete, so put it in the minibuff. 549 ;; found something to complete, so put it in the minibuff.
500 (progn 550 (progn
501 (setq iswitchb-rescan nil) 551 (setq iswitchb-rescan nil)
@@ -552,53 +602,83 @@ If no buffer exactly matching the prompt exists, maybe create a new one."
552 (exit-minibuffer)) 602 (exit-minibuffer))
553 603
554 604
605
606(defun iswitchb-find-file ()
607 "Drop into find-file from buffer switching."
608 (interactive)
609 (setq iswitchb-exit 'findfile)
610 (exit-minibuffer))
611
555(defun iswitchb-next-match () 612(defun iswitchb-next-match ()
556 "Put first element of `iswitchb-matches' at the end of the list." 613 "Put first element of `iswitchb-matches' at the end of the list."
557 (interactive) 614 (interactive)
558 (let ((tmp (car iswitchb-matches))) 615 (let ((next (cadr iswitchb-matches)))
559 (setq iswitchb-matches (cdr iswitchb-matches)) 616 (setq iswitchb-buflist (iswitchb-chop iswitchb-buflist next))
560 (setq iswitchb-matches (append iswitchb-matches (list tmp))) 617 (setq iswitchb-rescan t)
561 (setq iswitchb-rescan nil)
562 )) 618 ))
563 619
564(defun iswitchb-prev-match () 620(defun iswitchb-prev-match ()
565 "Put last element of `iswitchb-matches' at the front of the list." 621 "Put last element of `iswitchb-matches' at the front of the list."
566 (interactive) 622 (interactive)
567 (setq iswitchb-matches (iswitchb-rotate-list iswitchb-matches)) 623 (let ((prev (car (last iswitchb-matches))))
568 (setq iswitchb-rescan nil) 624 (setq iswitchb-buflist (iswitchb-chop iswitchb-buflist prev))
569 ) 625 (setq iswitchb-rescan t)
626 ))
627
628
629
630
631(defun iswitchb-chop (list elem)
632 "Remove all elements before ELEM and put them at the end of LIST."
633 (let ((ret nil)
634 (next nil)
635 (sofar nil))
636 (while (not ret)
637 (setq next (car list))
638 (if (equal next elem)
639 (setq ret (append list (nreverse sofar)))
640 ;; else
641 (progn
642 (setq list (cdr list))
643 (setq sofar (cons next sofar)))))
644 ret))
570 645
571 646
572 647
573 648
574;;; CREATE LIST OF ALL CURRENT BUFFERS 649;;; CREATE LIST OF ALL CURRENT BUFFERS
575 650
651
576(defun iswitchb-make-buflist () 652(defun iswitchb-make-buflist ()
577 "Set `iswitchb-buflist' to the current list of buffers. 653 "Set `iswitchb-buflist' to the current list of buffers.
578Currently visible buffers are put at the end of the list." 654Currently visible buffers are put at the end of the list.
655The hook `iswitchb-make-buflist-hook' is run after the list has been
656created to allow the user to further modify the order of the buffer names
657in this list."
579 (setq iswitchb-buflist 658 (setq iswitchb-buflist
580 (let (buflist 659 (let* ((iswitchb-current-buffers (iswitchb-get-buffers-in-frames))
581 iswitchb-current-buffers) 660 (buflist
582 (setq iswitchb-current-buffers (iswitchb-get-buffers-in-frames)) 661 (delq nil
583 (setq buflist (mapcar 'buffer-name (buffer-list))) 662 (mapcar
584 (setq buflist (delq nil 663 (lambda (x)
585 (mapcar 664 (let ((b-name (buffer-name x)))
586 '(lambda (x) 665 (if (not
587 (if (not (iswitchb-ignore-buffername-p x)) 666 (or
588 x)) 667 (iswitchb-ignore-buffername-p b-name)
589 buflist))) 668 (memq b-name iswitchb-current-buffers)))
590 (mapcar 'iswitchb-to-end iswitchb-current-buffers) 669 b-name)))
591 670 (buffer-list)))))
671 (nconc buflist iswitchb-current-buffers)
592 (run-hooks 'iswitchb-make-buflist-hook) 672 (run-hooks 'iswitchb-make-buflist-hook)
593 buflist))) 673 buflist)))
594 674
595 675(defun iswitchb-to-end (lst)
596(defun iswitchb-to-end (elem) 676 "Move the elements from LST to the end of BUFLIST."
597 "Move ELEM to the end of BUFLIST." 677 (mapcar
598 (setq buflist (delq elem buflist)) 678 (lambda (elem)
599 ;;(message "removing %s" elem) 679 (setq buflist (delq elem buflist)))
600 (setq buflist (append buflist (list elem)))) 680 lst)
601 681 (nconc buflist lst))
602 682
603 683
604 684
@@ -624,20 +704,19 @@ current frame, rather than all frames, regardless of value of
624 704
625;;; FIND MATCHING BUFFERS 705;;; FIND MATCHING BUFFERS
626 706
707
627(defun iswitchb-set-matches () 708(defun iswitchb-set-matches ()
628 "Set `iswitchb-matches' to the list of buffers matching prompt." 709 "Set `iswitchb-matches' to the list of buffers matching prompt."
629 (if iswitchb-rescan 710 (if iswitchb-rescan
630 (setq iswitchb-matches 711 (setq iswitchb-matches
631 (let* ((buflist iswitchb-buflist) 712 (let* ((buflist iswitchb-buflist)
632 ) 713 )
633 (if (> (length iswitchb-text) 0) 714 (iswitchb-get-matched-buffers iswitchb-text iswitchb-regexp
634 (iswitchb-get-matched-buffers iswitchb-text iswitchb-regexp 715 buflist)))))
635 buflist) 716
636 ;; else no text, no matches 717(defun iswitchb-get-matched-buffers (regexp
637 nil))))) 718 &optional string-format buffer-list)
638 719 "Return buffers matching REGEXP.
639(defun iswitchb-get-matched-buffers (regexp &optional string-format buffer-list)
640 "Return matched buffers.
641If STRING-FORMAT is non-nil, consider REGEXP as string. 720If STRING-FORMAT is non-nil, consider REGEXP as string.
642BUFFER-LIST can be list of buffers or list of strings." 721BUFFER-LIST can be list of buffers or list of strings."
643 (let* ((case-fold-search iswitchb-case) 722 (let* ((case-fold-search iswitchb-case)
@@ -648,22 +727,21 @@ BUFFER-LIST can be list of buffers or list of strings."
648 ret 727 ret
649 ) 728 )
650 (mapcar 729 (mapcar
651 (function 730 (lambda (x)
652 (lambda (x) 731
653 732 (if do-string
654 (if do-string 733 (setq name x) ;We already have the name
655 (setq name x) ;We already have the name 734 (setq name (buffer-name x)))
656 (setq name (buffer-name x))) 735
657 736 (cond
658 (cond 737 ((and (or (and string-format (string-match regexp name))
659 ((and (or (and string-format (string-match regexp name)) 738 (and (null string-format)
660 (and (null string-format) 739 (string-match (regexp-quote regexp) name)))
661 (string-match (regexp-quote regexp) name))) 740
662 741 ;; todo (not (iswitchb-ignore-buffername-p name))
663 ;; todo (not (iswitchb-ignore-buffername-p name)) 742 )
664 ) 743 (setq ret (cons name ret))
665 (setq ret (cons name ret)) 744 )))
666 ))))
667 list) 745 list)
668 ret 746 ret
669 )) 747 ))
@@ -761,9 +839,10 @@ Return the modified list with the last element prepended to it."
761(defun iswitchb-completion-help () 839(defun iswitchb-completion-help ()
762 "Show possible completions in a *Buffer Completions* buffer." 840 "Show possible completions in a *Buffer Completions* buffer."
763 ;; we could allow this buffer to be used to select match, but I think 841 ;; we could allow this buffer to be used to select match, but I think
764 ;; choose-completion-string will need redifining, so it just inserts 842 ;; choose-completion-string will need redefining, so it just inserts
765 ;; choice with out any previous input. 843 ;; choice with out any previous input.
766 (interactive) 844 (interactive)
845 (setq iswitchb-rescan nil)
767 (let ((completion-setup-hook nil) ;disable fancy highlight/selection. 846 (let ((completion-setup-hook nil) ;disable fancy highlight/selection.
768 ) 847 )
769 (with-output-to-temp-buffer "*Buffer Completions*" 848 (with-output-to-temp-buffer "*Buffer Completions*"
@@ -784,6 +863,31 @@ Return the modified list with the last element prepended to it."
784 iswitchb-buflist)) 863 iswitchb-buflist))
785 )))) 864 ))))
786 865
866
867;;; KILL CURRENT BUFFER
868
869(defun iswitchb-kill-buffer ()
870 "Kill the buffer at the head of `iswtichb-matches'."
871 (interactive)
872 (let ( (enable-recursive-minibuffers t)
873 buf)
874
875 (setq buf (car iswitchb-matches))
876 ;; check to see if buf is non-nil.
877 (if buf
878 (progn
879 (kill-buffer buf)
880
881 ;; Check if buffer exists. XEmacs gnuserv.el makes alias
882 ;; for kill-buffer which does not return t if buffer is
883 ;; killed, so we can't rely on kill-buffer return value.
884 (if (get-buffer buf)
885 ;; buffer couldn't be killed.
886 (setq iswitchb-rescan t)
887 ;; else buffer was killed so remove name from list.
888 (setq iswitchb-buflist (delq buf iswitchb-buflist)))))))
889
890
787;;; VISIT CHOSEN BUFFER 891;;; VISIT CHOSEN BUFFER
788(defun iswitchb-visit-buffer (buffer) 892(defun iswitchb-visit-buffer (buffer)
789 "Visit buffer named BUFFER according to `iswitchb-method'." 893 "Visit buffer named BUFFER according to `iswitchb-method'."
@@ -867,11 +971,10 @@ If BUFFER is visible in the current frame, return nil."
867 "Set up default keybindings for `iswitchb-buffer'. 971 "Set up default keybindings for `iswitchb-buffer'.
868Call this function to override the normal bindings." 972Call this function to override the normal bindings."
869 (interactive) 973 (interactive)
870 (global-set-key "b" 'iswitchb-buffer) 974 (global-set-key (read-kbd-macro "C-x b") 'iswitchb-buffer)
871 (global-set-key "4b" 'iswitchb-buffer-other-window) 975 (global-set-key (read-kbd-macro "C-x 4 b") 'iswitchb-buffer-other-window)
872 (global-set-key "4" 'iswitchb-display-buffer) 976 (global-set-key (read-kbd-macro "C-x 4 C-o") 'iswitchb-display-buffer)
873 (global-set-key "5b" 'iswitchb-buffer-other-frame)) 977 (global-set-key (read-kbd-macro "C-x 5 b") 'iswitchb-buffer-other-frame))
874
875 978
876 979
877;;;###autoload 980;;;###autoload
@@ -929,31 +1032,32 @@ For details of keybindings, do `\\[describe-function] iswitchb'."
929 1032
930 1033
931 1034
932;;; XEMACS HACK FOR SHOWING DEFAULT BUFFER 1035;;; XEmacs hack for showing default buffer
933 1036
934;; The first time we enter the minibuffer, Emacs puts up the default 1037;; The first time we enter the minibuffer, Emacs puts up the default
935;; buffer to switch to, but XEmacs doesnt -- presumably there is a 1038;; buffer to switch to, but XEmacs doesnt -- presumably there is a
936;; subtle difference in the two, either in icomplete or somewhere 1039;; subtle difference in the two versions of post-command-hook. The
937;; else. The default is shown for both whenever we delete all of our 1040;; default is shown for both whenever we delete all of our text
938;; text though, indicating its just a problem the first time we enter 1041;; though, indicating its just a problem the first time we enter the
939;; the function. To solve this, we use another entry hook for emacs 1042;; function. To solve this, we use another entry hook for emacs to
940;; to show the default the first time we enter the minibuffer. 1043;; show the default the first time we enter the minibuffer.
941 1044
942(defun iswitchb-init-Xemacs-trick () 1045(defun iswitchb-init-Xemacs-trick ()
943 "Display default buffer when first entering minibuffer. 1046 "Display default buffer when first entering minibuffer.
944This is a hack for XEmacs, and should really be handled by `iswitchb-exhibit'." 1047This is a hack for XEmacs, and should really be handled by `iswitchb-exhibit'."
945 (if (iswitchb-entryfn-p) 1048 (if (iswitchb-entryfn-p)
946 (progn 1049 (progn
947 (iswitchb-show-default-buffer) 1050 (iswitchb-exhibit)
948 (goto-char (point-min))))) 1051 (goto-char (point-min)))))
949 1052
950;; add this hook for Xemacs only. 1053
1054;; add this hook for XEmacs only.
951(if iswitchb-xemacs 1055(if iswitchb-xemacs
952 (add-hook 'iswitchb-minibuffer-setup-hook 1056 (add-hook 'iswitchb-minibuffer-setup-hook
953 'iswitchb-init-Xemacs-trick)) 1057 'iswitchb-init-Xemacs-trick))
954 1058
955 1059
956;;; XEMACS / BACKSPACE key 1060;;; XEmacs / backspace key
957;; For some reason, if the backspace key is pressed in xemacs, the 1061;; For some reason, if the backspace key is pressed in xemacs, the
958;; line gets confused, so I've added a simple key definition to make 1062;; line gets confused, so I've added a simple key definition to make
959;; backspace act like the normal delete key. 1063;; backspace act like the normal delete key.
@@ -998,21 +1102,15 @@ Copied from `icomplete-exhibit' with two changes:
998 (iswitchb-set-common-completion) 1102 (iswitchb-set-common-completion)
999 1103
1000 ;; Insert the match-status information: 1104 ;; Insert the match-status information:
1001 (if (> (point-max) 1) 1105 (insert-string
1002 (insert-string 1106 (iswitchb-completions
1003 (iswitchb-completions 1107 contents
1004 contents 1108 minibuffer-completion-table
1005 minibuffer-completion-table 1109 minibuffer-completion-predicate
1006 minibuffer-completion-predicate 1110 (not minibuffer-completion-confirm)))
1007 (not minibuffer-completion-confirm)))
1008 ;; else put in default
1009 (iswitchb-show-default-buffer))
1010 )))) 1111 ))))
1011 1112
1012(defun iswitchb-show-default-buffer () 1113
1013 "Insert the default buffer to switch to."
1014 ;; insert done this way to preserve any text-propertes.
1015 (insert (concat " {" iswitchb-default-buffer "} [Default]")))
1016 1114
1017(defun iswitchb-completions 1115(defun iswitchb-completions
1018 (name candidates predicate require-match) 1116 (name candidates predicate require-match)
@@ -1168,13 +1266,16 @@ Copied from `icomplete-tidy'."
1168 iswitchb-display-buffer 1266 iswitchb-display-buffer
1169 iswitchb-buffer-other-window)))) 1267 iswitchb-buffer-other-window))))
1170 1268
1269
1270
1271
1171(defun iswitchb-summaries-to-end () 1272(defun iswitchb-summaries-to-end ()
1172 "Move the summaries to the end of the list. 1273 "Move the summaries to the end of the list.
1173This is an example function which can be hooked on to 1274This is an example function which can be hooked on to
1174`iswitchb-make-buflist-hook'. Any buffer matching the regexps 1275`iswitchb-make-buflist-hook'. Any buffer matching the regexps
1175`Summary' or `output\*$'are put to the end of the list." 1276`Summary' or `output\*$'are put to the end of the list."
1176 (let ((summaries (delq nil (mapcar 1277 (let ((summaries (delq nil (mapcar
1177 '(lambda (x) 1278 (lambda (x)
1178 (if (or 1279 (if (or
1179 (string-match "Summary" x) 1280 (string-match "Summary" x)
1180 (string-match "output\\*$" x)) 1281 (string-match "output\\*$" x))
@@ -1182,7 +1283,7 @@ This is an example function which can be hooked on to
1182 buflist) 1283 buflist)
1183 ))) 1284 )))
1184 1285
1185 (mapcar 'iswitchb-to-end summaries))) 1286 (iswitchb-to-end summaries)))
1186 1287
1187 1288
1188 1289