summaryrefslogtreecommitdiff
path: root/lisp/tmm.el
diff options
context:
space:
mode:
authorCharles A. Roelli <charles@aurox.ch>2018-11-24 13:48:57 +0100
committerCharles A. Roelli <charles@aurox.ch>2018-11-24 13:48:57 +0100
commit57b14370cd6d221b123eab98adfed8d12229057f (patch)
tree19bf59654cc22b17f613e8dd34b1beaf05c7ee94 /lisp/tmm.el
parent4ef9bcd0ff0eccb0c0810f43370eaa76aef2f4ec (diff)
downloademacs-57b14370cd6d221b123eab98adfed8d12229057f.tar.gz
Add tool-bar and menu-bar menu for Isearch (Bug#32990)
* etc/NEWS (Search and Replace): Mention this change. * lisp/isearch.el: Declare the new, non-autoloaded function 'tmm-menubar-keymap'. (isearch-tmm-menubar): New function. (isearch-menu-bar-commands): New variable. (isearch-menu-bar-yank-map, isearch-menu-bar-map): New variables. (isearch-mode-map): Define a menu-bar search menu and remap 'tmm-menubar' bindings to point to 'isearch-tmm-menubar'. (isearch-tool-bar-old-map): New variable. (isearch-tool-bar-image): New function. (isearch-tool-bar-map): New variable. (minor-mode-map-alist): Add an entry for Isearch so that 'isearch-menu-bar-map' shows during search. (isearch-mode, isearch-done): Save and restore possible buffer-local 'tool-bar-map' using 'isearch-tool-bar-old-map'. (iseacrh-mouse-commands): New variable. (isearch-mouse-leave-buffer): Allow commands in isearch-mouse-commands. (with-isearch-suspended): Only push changed states of Isearch after running the body argument of this macro. (isearch-pre-command-hook): Additionally allow bindings in 'isearch-tool-bar-map' to pass through, as well as commands in isearch-menu-bar-commands. (isearch-post-command-hook): Call 'force-mode-line-update' at its end to make sure the menu- and tool-bars are up-to-date. * lisp/tmm.el (tmm-menubar-keymap): New function factored out from 'tmm-menubar'. (tmm-menubar): Use 'tmm-menubar-keymap'. (tmm-prompt): New optional argument 'no-execute'.
Diffstat (limited to 'lisp/tmm.el')
-rw-r--r--lisp/tmm.el42
1 files changed, 25 insertions, 17 deletions
diff --git a/lisp/tmm.el b/lisp/tmm.el
index ff6277419df..4e3f25441cb 100644
--- a/lisp/tmm.el
+++ b/lisp/tmm.el
@@ -42,6 +42,23 @@
(defvar tmm-next-shortcut-digit)
(defvar tmm-table-undef)
+(defun tmm-menubar-keymap ()
+ "Return the current menu-bar keymap.
+
+The ordering of the return value respects `menu-bar-final-items'."
+ (let ((menu-bar '())
+ (menu-end '()))
+ (map-keymap
+ (lambda (key binding)
+ (push (cons key binding)
+ ;; If KEY is the name of an item that we want to put last,
+ ;; move it to the end.
+ (if (memq key menu-bar-final-items)
+ menu-end
+ menu-bar)))
+ (tmm-get-keybind [menu-bar]))
+ `(keymap ,@(nreverse menu-bar) ,@(nreverse menu-end))))
+
;;;###autoload (define-key global-map "\M-`" 'tmm-menubar)
;;;###autoload (define-key global-map [menu-bar mouse-1] 'tmm-menubar-mouse)
@@ -58,19 +75,8 @@ to invoke `tmm-menubar' instead, customize the variable
(interactive)
(run-hooks 'menu-bar-update-hook)
;; Obey menu-bar-final-items; put those items last.
- (let ((menu-bar '())
- (menu-end '())
+ (let ((menu-bar (tmm-menubar-keymap))
menu-bar-item)
- (map-keymap
- (lambda (key binding)
- (push (cons key binding)
- ;; If KEY is the name of an item that we want to put last,
- ;; move it to the end.
- (if (memq key menu-bar-final-items)
- menu-end
- menu-bar)))
- (tmm-get-keybind [menu-bar]))
- (setq menu-bar `(keymap ,@(nreverse menu-bar) ,@(nreverse menu-end)))
(if x-position
(let ((column 0)
prev-key)
@@ -154,7 +160,7 @@ specify nil for this variable."
(defvar tmm--history nil)
;;;###autoload
-(defun tmm-prompt (menu &optional in-popup default-item)
+(defun tmm-prompt (menu &optional in-popup default-item no-execute)
"Text-mode emulation of calling the bindings in keymap.
Creates a text-mode menu of possible choices. You can access the elements
in the menu in two ways:
@@ -165,7 +171,9 @@ The last alternative is currently a hack, you cannot use mouse reliably.
MENU is like the MENU argument to `x-popup-menu': either a
keymap or an alist of alists.
DEFAULT-ITEM, if non-nil, specifies an initial default choice.
-Its value should be an event that has a binding in MENU."
+Its value should be an event that has a binding in MENU.
+NO-EXECUTE, if non-nil, means to return the command the user selects
+instead of executing it."
;; If the optional argument IN-POPUP is t,
;; then MENU is an alist of elements of the form (STRING . VALUE).
;; That is used for recursive calls only.
@@ -268,7 +276,7 @@ Its value should be an event that has a binding in MENU."
;; We just did the inner level of a -popup menu.
choice)
;; We just did the outer level. Do the inner level now.
- (not-menu (tmm-prompt choice t))
+ (not-menu (tmm-prompt choice t nil no-execute))
;; We just handled a menu keymap and found another keymap.
((keymapp choice)
(if (symbolp choice)
@@ -276,11 +284,11 @@ Its value should be an event that has a binding in MENU."
(condition-case nil
(require 'mouse)
(error nil))
- (tmm-prompt choice))
+ (tmm-prompt choice nil nil no-execute))
;; We just handled a menu keymap and found a command.
(choice
(if chosen-string
- (progn
+ (if no-execute choice
(setq last-command-event chosen-string)
(call-interactively choice))
choice)))))