diff options
| author | Stefan Monnier | 2001-11-19 21:06:17 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2001-11-19 21:06:17 +0000 |
| commit | 8ae3ef6ea3b19c257f55eff97e8decc19a4d5341 (patch) | |
| tree | 6ffd9b65d1c47dc1127058759bcbef0da759836a | |
| parent | 0603917d5f4e89880bb745058ac6430fb152e215 (diff) | |
| download | emacs-8ae3ef6ea3b19c257f55eff97e8decc19a4d5341.tar.gz emacs-8ae3ef6ea3b19c257f55eff97e8decc19a4d5341.zip | |
(iswitchb-mode): Use define-minor-mode.
(iswitchb): Fix the case where the result was selected with the mouse.
(iswitchb-completion-help): Use the normal *Completions* now that
mouse selection works.
(iswitchb-minibuffer-setup): Simplify.
| -rw-r--r-- | lisp/iswitchb.el | 93 |
1 files changed, 22 insertions, 71 deletions
diff --git a/lisp/iswitchb.el b/lisp/iswitchb.el index 74aa2085082..e3bb8ad76b3 100644 --- a/lisp/iswitchb.el +++ b/lisp/iswitchb.el | |||
| @@ -129,14 +129,12 @@ | |||
| 129 | ;; See the User Variables section below for easy ways to change the | 129 | ;; See the User Variables section below for easy ways to change the |
| 130 | ;; functionality of the program. These are accessible using the | 130 | ;; functionality of the program. These are accessible using the |
| 131 | ;; custom package. | 131 | ;; custom package. |
| 132 | ;; To modify the keybindings, use the hook provided. For example: | 132 | ;; To modify the keybindings, use something like: |
| 133 | ;;(add-hook 'iswitchb-define-mode-map-hook | ||
| 134 | ;; 'iswitchb-my-keys) | ||
| 135 | ;; | 133 | ;; |
| 134 | ;;(add-hook 'iswitchb-mode-hook 'iswitchb-my-keys) | ||
| 136 | ;;(defun iswitchb-my-keys () | 135 | ;;(defun iswitchb-my-keys () |
| 137 | ;; "Add my keybindings for iswitchb." | 136 | ;; "Add my keybindings for iswitchb." |
| 138 | ;; (define-key iswitchb-mode-map " " 'iswitchb-next-match) | 137 | ;; (define-key iswitchb-mode-map " " 'iswitchb-next-match)) |
| 139 | ;; ) | ||
| 140 | ;; | 138 | ;; |
| 141 | ;; Seeing all the matching buffers | 139 | ;; Seeing all the matching buffers |
| 142 | ;; | 140 | ;; |
| @@ -237,24 +235,6 @@ | |||
| 237 | :link '(url-link "http://www.anc.ed.ac.uk/~stephen/emacs/") | 235 | :link '(url-link "http://www.anc.ed.ac.uk/~stephen/emacs/") |
| 238 | :link '(emacs-library-link :tag "Lisp File" "iswitchb.el")) | 236 | :link '(emacs-library-link :tag "Lisp File" "iswitchb.el")) |
| 239 | 237 | ||
| 240 | ;;;###autoload | ||
| 241 | (defcustom iswitchb-mode nil | ||
| 242 | "Toggle Iswitchb mode. | ||
| 243 | Setting this variable directly does not take effect; | ||
| 244 | use either \\[customize] or the function `iswitchb-mode'." | ||
| 245 | :set (lambda (symbol value) | ||
| 246 | (iswitchb-mode (or value 0))) | ||
| 247 | :initialize 'custom-initialize-default | ||
| 248 | :group 'iswitchb | ||
| 249 | :require 'iswitchb | ||
| 250 | :version "21.1" | ||
| 251 | :type 'boolean) | ||
| 252 | |||
| 253 | (defcustom iswitchb-mode-hook nil | ||
| 254 | "Hook run at the end of function `iswitchb-mode'." | ||
| 255 | :group 'iswitchb | ||
| 256 | :type 'hook) | ||
| 257 | |||
| 258 | (defcustom iswitchb-case case-fold-search | 238 | (defcustom iswitchb-case case-fold-search |
| 259 | "*Non-nil if searching of buffer names should ignore case. | 239 | "*Non-nil if searching of buffer names should ignore case. |
| 260 | If this is non-nil but the user input has any upper case letters, matching | 240 | If this is non-nil but the user input has any upper case letters, matching |
| @@ -327,11 +307,6 @@ See also `iswitchb-newbuffer'." | |||
| 327 | :type 'boolean | 307 | :type 'boolean |
| 328 | :group 'iswitchb) | 308 | :group 'iswitchb) |
| 329 | 309 | ||
| 330 | (defcustom iswitchb-define-mode-map-hook nil | ||
| 331 | "Hook to define keys in `iswitchb-mode-map' for extra keybindings." | ||
| 332 | :type 'hook | ||
| 333 | :group 'iswitchb) | ||
| 334 | |||
| 335 | (defcustom iswitchb-use-fonts t | 310 | (defcustom iswitchb-use-fonts t |
| 336 | "*Non-nil means use font-lock fonts for showing first match." | 311 | "*Non-nil means use font-lock fonts for showing first match." |
| 337 | :type 'boolean | 312 | :type 'boolean |
| @@ -528,12 +503,8 @@ in a separate window. | |||
| 528 | ;;\\[iswitchb-toggle-ignore] Toggle ignoring certain buffers (see \ | 503 | ;;\\[iswitchb-toggle-ignore] Toggle ignoring certain buffers (see \ |
| 529 | ;;`iswitchb-buffer-ignore') | 504 | ;;`iswitchb-buffer-ignore') |
| 530 | 505 | ||
| 531 | (let | 506 | (let* ((prompt "iswitch ") |
| 532 | (prompt buf) | 507 | (buf (iswitchb-read-buffer prompt))) |
| 533 | |||
| 534 | (setq prompt (format "iswitch ")) | ||
| 535 | |||
| 536 | (setq buf (iswitchb-read-buffer prompt)) | ||
| 537 | 508 | ||
| 538 | ;;(message "chosen text %s" iswitchb-final-text) | 509 | ;;(message "chosen text %s" iswitchb-final-text) |
| 539 | ;; Choose the buffer name: either the text typed in, or the head | 510 | ;; Choose the buffer name: either the text typed in, or the head |
| @@ -596,6 +567,10 @@ If REQUIRE-MATCH is non-nil, an existing-buffer must be selected." | |||
| 596 | nil ;require-match [handled elsewhere] | 567 | nil ;require-match [handled elsewhere] |
| 597 | nil ;initial-contents | 568 | nil ;initial-contents |
| 598 | 'iswitchb-history))) | 569 | 'iswitchb-history))) |
| 570 | (if (get-buffer iswitchb-final-text) | ||
| 571 | ;; This happens for example if the buffer was chosen with the mouse. | ||
| 572 | (setq iswitchb-matches (list iswitchb-final-text))) | ||
| 573 | |||
| 599 | ;; Handling the require-match must be done in a better way. | 574 | ;; Handling the require-match must be done in a better way. |
| 600 | (if (and require-match (not (iswitchb-existing-buffer-p))) | 575 | (if (and require-match (not (iswitchb-existing-buffer-p))) |
| 601 | (error "Must specify valid buffer")) | 576 | (error "Must specify valid buffer")) |
| @@ -915,19 +890,17 @@ Return the modified list with the last element prepended to it." | |||
| 915 | (cons (car las) lis)))) | 890 | (cons (car las) lis)))) |
| 916 | 891 | ||
| 917 | (defun iswitchb-completion-help () | 892 | (defun iswitchb-completion-help () |
| 918 | "Show possible completions in a *Buffer Completions* buffer." | 893 | "Show possible completions in a *Completions* buffer." |
| 919 | ;; we could allow this buffer to be used to select match, but I think | 894 | ;; we could allow this buffer to be used to select match, but I think |
| 920 | ;; choose-completion-string will need redefining, so it just inserts | 895 | ;; choose-completion-string will need redefining, so it just inserts |
| 921 | ;; choice with out any previous input. | 896 | ;; choice with out any previous input. |
| 922 | (interactive) | 897 | (interactive) |
| 923 | (setq iswitchb-rescan nil) | 898 | (setq iswitchb-rescan nil) |
| 924 | (let ((completion-setup-hook nil) ;disable fancy highlight/selection. | 899 | (let ((buf (current-buffer)) |
| 925 | (buf (current-buffer)) | 900 | (temp-buf "*Completions*") |
| 926 | (temp-buf "*Buffer Completions*") | 901 | (win)) |
| 927 | (win) | ||
| 928 | (again (eq last-command this-command))) | ||
| 929 | 902 | ||
| 930 | (if again | 903 | (if (eq last-command this-command) |
| 931 | ;; scroll buffer | 904 | ;; scroll buffer |
| 932 | (progn | 905 | (progn |
| 933 | (set-buffer temp-buf) | 906 | (set-buffer temp-buf) |
| @@ -1266,21 +1239,11 @@ Modified from `icomplete-completions'." | |||
| 1266 | (defun iswitchb-minibuffer-setup () | 1239 | (defun iswitchb-minibuffer-setup () |
| 1267 | "Set up minibuffer for `iswitchb-buffer'. | 1240 | "Set up minibuffer for `iswitchb-buffer'. |
| 1268 | Copied from `icomplete-minibuffer-setup-hook'." | 1241 | Copied from `icomplete-minibuffer-setup-hook'." |
| 1269 | (if (iswitchb-entryfn-p) | 1242 | (when (iswitchb-entryfn-p) |
| 1270 | (progn | 1243 | (set (make-local-variable 'iswitchb-use-mycompletion) t) |
| 1271 | 1244 | (add-hook 'pre-command-hook 'iswitchb-pre-command nil t) | |
| 1272 | (make-local-variable 'iswitchb-use-mycompletion) | 1245 | (add-hook 'post-command-hook 'iswitchb-post-command nil t) |
| 1273 | (setq iswitchb-use-mycompletion t) | 1246 | (run-hooks 'iswitchb-minibuffer-setup-hook))) |
| 1274 | (make-local-hook 'pre-command-hook) | ||
| 1275 | (add-hook 'pre-command-hook | ||
| 1276 | 'iswitchb-pre-command | ||
| 1277 | nil t) | ||
| 1278 | (make-local-hook 'post-command-hook) | ||
| 1279 | (add-hook 'post-command-hook | ||
| 1280 | 'iswitchb-post-command | ||
| 1281 | nil t) | ||
| 1282 | |||
| 1283 | (run-hooks 'iswitchb-minibuffer-setup-hook)))) | ||
| 1284 | 1247 | ||
| 1285 | (defun iswitchb-pre-command () | 1248 | (defun iswitchb-pre-command () |
| 1286 | "Run before command in `iswitchb-buffer'." | 1249 | "Run before command in `iswitchb-buffer'." |
| @@ -1333,27 +1296,15 @@ See the variable `iswitchb-case' for details." | |||
| 1333 | (isearch-no-upper-case-p iswitchb-text t)))) | 1296 | (isearch-no-upper-case-p iswitchb-text t)))) |
| 1334 | 1297 | ||
| 1335 | ;;;###autoload | 1298 | ;;;###autoload |
| 1336 | (defun iswitchb-mode (&optional arg) | 1299 | (define-minor-mode iswitchb-mode |
| 1337 | "Toggle Iswitchb global minor mode. | 1300 | "Toggle Iswitchb global minor mode. |
| 1338 | With arg, turn Iswitchb mode on if and only iff ARG is positive. | 1301 | With arg, turn Iswitchb mode on if and only iff ARG is positive. |
| 1339 | This mode enables switching between buffers using substrings. See | 1302 | This mode enables switching between buffers using substrings. See |
| 1340 | `iswitchb' for details." | 1303 | `iswitchb' for details." |
| 1341 | (interactive "P") | 1304 | nil nil iswitchb-global-map :global t :group 'iswitchb |
| 1342 | (setq iswitchb-mode | ||
| 1343 | (if arg | ||
| 1344 | (> (prefix-numeric-value arg) 0) | ||
| 1345 | (not iswitchb-mode))) | ||
| 1346 | (if iswitchb-mode | 1305 | (if iswitchb-mode |
| 1347 | (add-hook 'minibuffer-setup-hook 'iswitchb-minibuffer-setup) | 1306 | (add-hook 'minibuffer-setup-hook 'iswitchb-minibuffer-setup) |
| 1348 | (remove-hook 'minibuffer-setup-hook 'iswitchb-minibuffer-setup)) | 1307 | (remove-hook 'minibuffer-setup-hook 'iswitchb-minibuffer-setup))) |
| 1349 | (run-hooks 'iswitchb-mode-hook) | ||
| 1350 | (if (interactive-p) | ||
| 1351 | (message "Iswitchb mode %sabled" | ||
| 1352 | (if iswitchb-mode "en" "dis")))) | ||
| 1353 | |||
| 1354 | (unless (assq 'iswitchb-mode minor-mode-map-alist) | ||
| 1355 | (push (cons 'iswitchb-mode iswitchb-global-map) | ||
| 1356 | minor-mode-map-alist)) | ||
| 1357 | 1308 | ||
| 1358 | (provide 'iswitchb) | 1309 | (provide 'iswitchb) |
| 1359 | 1310 | ||