diff options
| author | Stefan Monnier | 2011-11-15 21:26:00 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2011-11-15 21:26:00 -0500 |
| commit | 3ae704f4fda38eae017521e886f1f016a6682486 (patch) | |
| tree | 95b92ace74bb947038523fe27d4fce1b1d7211af | |
| parent | 6ad1cdded9db68c3152e15e46647ae53febca953 (diff) | |
| download | emacs-3ae704f4fda38eae017521e886f1f016a6682486.tar.gz emacs-3ae704f4fda38eae017521e886f1f016a6682486.zip | |
* lisp/tmm.el (tmm-prompt): Use minibuffer-with-setup-hook.
`completing-read' will remove *Completions* and will preserve
current-buffer for us.
(tmm-add-prompt): Users of *Completions* will always (re)set its
major mode.
(tmm-old-comp-map): Remove.
Fixes: debbugs:10053
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/tmm.el | 43 |
2 files changed, 26 insertions, 26 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 384e7f276dc..27dd6689746 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2011-11-16 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * tmm.el (tmm-prompt): Use minibuffer-with-setup-hook (bug#10053). | ||
| 4 | `completing-read' will remove *Completions* and will preserve | ||
| 5 | current-buffer for us. | ||
| 6 | (tmm-add-prompt): Users of *Completions* will always (re)set its | ||
| 7 | major mode. | ||
| 8 | (tmm-old-comp-map): Remove. | ||
| 9 | |||
| 1 | 2011-11-16 Glenn Morris <rgm@gnu.org> | 10 | 2011-11-16 Glenn Morris <rgm@gnu.org> |
| 2 | 11 | ||
| 3 | * mail/rmailedit.el: Require rmailmm when compiling. | 12 | * mail/rmailedit.el: Require rmailmm when compiling. |
diff --git a/lisp/tmm.el b/lisp/tmm.el index 52704e70a55..5722c2c8f79 100644 --- a/lisp/tmm.el +++ b/lisp/tmm.el | |||
| @@ -37,7 +37,6 @@ | |||
| 37 | ;;; The following will be localized, added only to pacify the compiler. | 37 | ;;; The following will be localized, added only to pacify the compiler. |
| 38 | (defvar tmm-short-cuts) | 38 | (defvar tmm-short-cuts) |
| 39 | (defvar tmm-old-mb-map nil) | 39 | (defvar tmm-old-mb-map nil) |
| 40 | (defvar tmm-old-comp-map) | ||
| 41 | (defvar tmm-c-prompt nil) | 40 | (defvar tmm-c-prompt nil) |
| 42 | (defvar tmm-km-list) | 41 | (defvar tmm-km-list) |
| 43 | (defvar tmm-next-shortcut-digit) | 42 | (defvar tmm-next-shortcut-digit) |
| @@ -98,7 +97,7 @@ See the documentation for `tmm-prompt'." | |||
| 98 | 97 | ||
| 99 | (defcustom tmm-mid-prompt "==>" | 98 | (defcustom tmm-mid-prompt "==>" |
| 100 | "String to insert between shortcut and menu item. | 99 | "String to insert between shortcut and menu item. |
| 101 | If nil, there will be no shortcuts. It should not consist only of spaces, | 100 | If nil, there will be no shortcuts. It should not consist only of spaces, |
| 102 | or else the correct item might not be found in the `*Completions*' buffer." | 101 | or else the correct item might not be found in the `*Completions*' buffer." |
| 103 | :type 'string | 102 | :type 'string |
| 104 | :group 'tmm) | 103 | :group 'tmm) |
| @@ -158,7 +157,7 @@ Its value should be an event that has a binding in MENU." | |||
| 158 | (let ((gl-str "Menu bar") ;; The menu bar itself is not a menu keymap | 157 | (let ((gl-str "Menu bar") ;; The menu bar itself is not a menu keymap |
| 159 | ; so it doesn't have a name. | 158 | ; so it doesn't have a name. |
| 160 | tmm-km-list out history history-len tmm-table-undef tmm-c-prompt | 159 | tmm-km-list out history history-len tmm-table-undef tmm-c-prompt |
| 161 | tmm-old-mb-map tmm-old-comp-map tmm-short-cuts | 160 | tmm-old-mb-map tmm-short-cuts |
| 162 | chosen-string choice | 161 | chosen-string choice |
| 163 | (not-menu (not (keymapp menu)))) | 162 | (not-menu (not (keymapp menu)))) |
| 164 | (run-hooks 'activate-menubar-hook) | 163 | (run-hooks 'activate-menubar-hook) |
| @@ -219,23 +218,16 @@ Its value should be an event that has a binding in MENU." | |||
| 219 | (setq history-len (length history)) | 218 | (setq history-len (length history)) |
| 220 | (setq history (append history history history history)) | 219 | (setq history (append history history history history)) |
| 221 | (setq tmm-c-prompt (nth (- history-len 1 index-of-default) history)) | 220 | (setq tmm-c-prompt (nth (- history-len 1 index-of-default) history)) |
| 222 | (add-hook 'minibuffer-setup-hook 'tmm-add-prompt) | 221 | (setq out |
| 223 | (if default-item | 222 | (if default-item |
| 224 | (setq out (car (nth index-of-default tmm-km-list))) | 223 | (car (nth index-of-default tmm-km-list)) |
| 225 | (save-excursion | 224 | (minibuffer-with-setup-hook #'tmm-add-prompt |
| 226 | (unwind-protect | 225 | (completing-read |
| 227 | (setq out | 226 | (concat gl-str |
| 228 | (completing-read | 227 | " (up/down to change, PgUp to menu): ") |
| 229 | (concat gl-str | 228 | tmm-km-list nil t nil |
| 230 | " (up/down to change, PgUp to menu): ") | 229 | (cons 'history |
| 231 | tmm-km-list nil t nil | 230 | (- (* 2 history-len) index-of-default)))))))) |
| 232 | (cons 'history | ||
| 233 | (- (* 2 history-len) index-of-default)))) | ||
| 234 | (remove-hook 'minibuffer-setup-hook 'tmm-add-prompt) | ||
| 235 | (if (get-buffer "*Completions*") | ||
| 236 | (with-current-buffer "*Completions*" | ||
| 237 | (use-local-map tmm-old-comp-map) | ||
| 238 | (bury-buffer (current-buffer))))))))) | ||
| 239 | (setq choice (cdr (assoc out tmm-km-list))) | 231 | (setq choice (cdr (assoc out tmm-km-list))) |
| 240 | (and (null choice) | 232 | (and (null choice) |
| 241 | (> (length out) (length tmm-c-prompt)) | 233 | (> (length out) (length tmm-c-prompt)) |
| @@ -270,7 +262,7 @@ Its value should be an event that has a binding in MENU." | |||
| 270 | choice))))) | 262 | choice))))) |
| 271 | 263 | ||
| 272 | (defun tmm-add-shortcuts (list) | 264 | (defun tmm-add-shortcuts (list) |
| 273 | "Adds shortcuts to cars of elements of the list. | 265 | "Add shortcuts to cars of elements of the list. |
| 274 | Takes a list of lists with a string as car, returns list with | 266 | Takes a list of lists with a string as car, returns list with |
| 275 | shortcuts added to these cars. | 267 | shortcuts added to these cars. |
| 276 | Stores a list of all the shortcuts in the free variable `tmm-short-cuts'." | 268 | Stores a list of all the shortcuts in the free variable `tmm-short-cuts'." |
| @@ -362,7 +354,6 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'." | |||
| 362 | (set-buffer-modified-p nil))) | 354 | (set-buffer-modified-p nil))) |
| 363 | 355 | ||
| 364 | (defun tmm-add-prompt () | 356 | (defun tmm-add-prompt () |
| 365 | (remove-hook 'minibuffer-setup-hook 'tmm-add-prompt) | ||
| 366 | (add-hook 'minibuffer-exit-hook 'tmm-delete-map nil t) | 357 | (add-hook 'minibuffer-exit-hook 'tmm-delete-map nil t) |
| 367 | (unless tmm-c-prompt | 358 | (unless tmm-c-prompt |
| 368 | (error "No active menu entries")) | 359 | (error "No active menu entries")) |
| @@ -387,9 +378,7 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'." | |||
| 387 | (save-selected-window | 378 | (save-selected-window |
| 388 | (other-window 1) ; Electric-pop-up-window does | 379 | (other-window 1) ; Electric-pop-up-window does |
| 389 | ; not work in minibuffer | 380 | ; not work in minibuffer |
| 390 | (Electric-pop-up-window "*Completions*") | 381 | (Electric-pop-up-window "*Completions*")) |
| 391 | (with-current-buffer "*Completions*" | ||
| 392 | (setq tmm-old-comp-map (tmm-define-keys nil)))) | ||
| 393 | (insert tmm-c-prompt)) | 382 | (insert tmm-c-prompt)) |
| 394 | 383 | ||
| 395 | (defun tmm-delete-map () | 384 | (defun tmm-delete-map () |
| @@ -424,16 +413,18 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'." | |||
| 424 | (exit-minibuffer))))) | 413 | (exit-minibuffer))))) |
| 425 | 414 | ||
| 426 | (defun tmm-goto-completions () | 415 | (defun tmm-goto-completions () |
| 416 | "Jump to the completions buffer." | ||
| 427 | (interactive) | 417 | (interactive) |
| 428 | (let ((prompt-end (minibuffer-prompt-end))) | 418 | (let ((prompt-end (minibuffer-prompt-end))) |
| 429 | (setq tmm-c-prompt (buffer-substring prompt-end (point-max))) | 419 | (setq tmm-c-prompt (buffer-substring prompt-end (point-max))) |
| 420 | ;; FIXME: Why? | ||
| 430 | (delete-region prompt-end (point-max))) | 421 | (delete-region prompt-end (point-max))) |
| 431 | (switch-to-buffer-other-window "*Completions*") | 422 | (switch-to-buffer-other-window "*Completions*") |
| 432 | (search-forward tmm-c-prompt) | 423 | (search-forward tmm-c-prompt) |
| 433 | (search-backward tmm-c-prompt)) | 424 | (search-backward tmm-c-prompt)) |
| 434 | 425 | ||
| 435 | (defun tmm-get-keymap (elt &optional in-x-menu) | 426 | (defun tmm-get-keymap (elt &optional in-x-menu) |
| 436 | "Prepends (DOCSTRING EVENT BINDING) to free variable `tmm-km-list'. | 427 | "Prepend (DOCSTRING EVENT BINDING) to free variable `tmm-km-list'. |
| 437 | The values are deduced from the argument ELT, that should be an | 428 | The values are deduced from the argument ELT, that should be an |
| 438 | element of keymap, an `x-popup-menu' argument, or an element of | 429 | element of keymap, an `x-popup-menu' argument, or an element of |
| 439 | `x-popup-menu' argument (when IN-X-MENU is not-nil). | 430 | `x-popup-menu' argument (when IN-X-MENU is not-nil). |