;; Installation:
;; To get the functions in this package bound to keys, use
;; M-x iswitchb-mode or customize the option `iswitchb-mode'.
+;; Alternatively, add the following line to your .emacs:
+;; (iswitchb-mode 1)
;; As you type in a substring, the list of buffers currently matching
;; the substring is displayed as you type. The list is ordered so
:type '(repeat (choice regexp function))
:group 'iswitchb)
+(defcustom iswitchb-max-to-show nil
+ "*If non-nil, limit the number of names shown in the minibuffer.
+If this value is N, and N is greater than the number of matching
+buffers, the first N/2 and the last N/2 matching buffers are
+shown. This can greatly speed up iswitchb if you have a
+multitude of buffers open."
+ :type '(choice (const :tag "Show all" nil) integer)
+ :group 'iswitchb)
+
(defcustom iswitchb-cannot-complete-hook 'iswitchb-completion-help
"*Hook run when `iswitchb-complete' can't complete any more.
The most useful values are `iswitchb-completion-help', which pops up a
"Iswitchb-specific customization of minibuffer setup.
This hook is run during minibuffer setup iff `iswitchb' will be active.
-It is intended for use in customizing iswitchb for interoperation
-with other packages."
-;;; For instance:
-
-;;; \(add-hook 'iswitchb-minibuffer-setup-hook
-;;; \(function
-;;; \(lambda ()
-;;; \(make-local-variable 'resize-minibuffer-window-max-height)
-;;; \(setq resize-minibuffer-window-max-height 3))))
-
-;;; will constrain rsz-mini to a maximum minibuffer height of 3 lines when
-;;; iswitchb is running. Copied from `icomplete-minibuffer-setup-hook'."
+For instance:
+\(add-hook 'iswitchb-minibuffer-setup-hook
+ '\(lambda () (set (make-local-variable 'max-mini-window-height) 3)))
+will constrain the minibuffer to a maximum height of 3 lines when
+iswitchb is running."
:type 'hook
:group 'iswitchb)
(substitute-key-definition 'display-buffer ; C-x 4 C-o
'iswitchb-display-buffer map global-map)
map)
- "Global keymap for `iswtichb-mode'.")
+ "Global keymap for `iswitchb-mode'.")
(defvar iswitchb-history nil
"History of buffers selected using `iswitchb-buffer'.")
(iswitchb-possible-new-buffer buf)))
))))
-;;;###autoload
(defun iswitchb-read-buffer (prompt &optional default require-match)
"Replacement for the built-in `read-buffer'.
Return the name of a buffer selected.
nil ;require-match [handled elsewhere]
nil ;initial-contents
'iswitchb-history)))
- (if (get-buffer iswitchb-final-text)
+ (if (and (not (eq iswitchb-exit 'usefirst))
+ (get-buffer iswitchb-final-text))
;; This happens for example if the buffer was chosen with the mouse.
(setq iswitchb-matches (list iswitchb-final-text)))
(interactive)
(if (or (not iswitchb-require-match)
(iswitchb-existing-buffer-p))
- (throw 'exit nil)))
+ (progn
+ (setq iswitchb-exit 'usefirst)
+ (throw 'exit nil))))
(defun iswitchb-select-buffer-text ()
"Select the buffer named by the prompt.
(get-buffer-window buffer 0) ; better than 'visible
)))
-;;;###autoload
(defun iswitchb-default-keybindings ()
"Set up default keybindings for `iswitchb-buffer'.
Call this function to override the normal bindings. This function also
(global-set-key "\C-x4\C-o" 'iswitchb-display-buffer)
(global-set-key "\C-x5b" 'iswitchb-buffer-other-frame))
-;;;###autoload
(defun iswitchb-buffer ()
"Switch to another buffer.
(setq iswitchb-method iswitchb-default-method)
(iswitchb))
-;;;###autoload
(defun iswitchb-buffer-other-window ()
"Switch to another buffer and show it in another window.
The buffer name is selected interactively by typing a substring.
(setq iswitchb-method 'otherwindow)
(iswitchb))
-;;;###autoload
(defun iswitchb-display-buffer ()
"Display a buffer in another window but don't select it.
The buffer name is selected interactively by typing a substring.
(setq iswitchb-method 'display)
(iswitchb))
-;;;###autoload
(defun iswitchb-buffer-other-frame ()
"Switch to another buffer and show it in another frame.
The buffer name is selected interactively by typing a substring.
contents
(not minibuffer-completion-confirm)))))))
+(defun iswitchb-output-completion (com)
+ (if (= (length com) most-len)
+ ;; Most is one exact match,
+ ;; note that and leave out
+ ;; for later indication:
+ (ignore
+ (setq most-is-exact t))
+ (substring com most-len)))
+
(defun iswitchb-completions (name require-match)
"Return the string that is displayed after the user's text.
Modified from `icomplete-completions'."
"")
(if (not iswitchb-use-fonts) " [Matched]")))
(t ;multiple matches
+ (if (and iswitchb-max-to-show
+ (> (length comps) iswitchb-max-to-show))
+ (setq comps
+ (append
+ (let ((res nil)
+ (comp comps)
+ (end (/ iswitchb-max-to-show 2)))
+ (while (>= (setq end (1- end)) 0)
+ (setq res (cons (car comp) res)
+ comp (cdr comp)))
+ (nreverse res))
+ (list "...")
+ (nthcdr (- (length comps)
+ (/ iswitchb-max-to-show 2)) comps))))
(let* (
;;(most (try-completion name candidates predicate))
(most nil)
(most-len (length most))
most-is-exact
- (alternatives
- (apply
- (function concat)
- (cdr (apply
- (function nconc)
- (mapcar '(lambda (com)
- (if (= (length com) most-len)
- ;; Most is one exact match,
- ;; note that and leave out
- ;; for later indication:
- (progn
- (setq most-is-exact t)
- ())
- (list ","
- (substring com
- most-len))))
- comps))))))
+ (alternatives (if most
+ (mapconcat 'iswitchb-output-completion
+ comps ",")
+ (mapconcat 'identity comps ","))))
(concat
(provide 'iswitchb)
+;;; arch-tag: d74198ae-753f-44f2-b34f-0c515398d90a
;;; iswitchb.el ends here