aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Giraud2024-09-25 10:31:12 +0200
committerJuri Linkov2024-10-06 20:29:05 +0300
commit1adcbdb21c19b42552736b60a5c1629b5d53a7a2 (patch)
tree56792b9c550e1cbfe6575f5ef1798771b84997d8
parent9102f1eaafd51404ca93dacec8785dccad2a2ea0 (diff)
downloademacs-1adcbdb21c19b42552736b60a5c1629b5d53a7a2.tar.gz
emacs-1adcbdb21c19b42552736b60a5c1629b5d53a7a2.zip
Add a shortcut to go up in the menu hierarchy.
* lisp/tmm.el (tmm-prompt): Add a shortcut to go up in the menu hierarchy (bug#73498). (tmm-completion-prompt): Document it in help message. (tmm-define-keys): Add the shortcut in the keymap. * etc/NEWS: Document the change.
-rw-r--r--etc/NEWS6
-rw-r--r--lisp/tmm.el42
2 files changed, 32 insertions, 16 deletions
diff --git a/etc/NEWS b/etc/NEWS
index d1bd469435f..935caba5c0d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -494,6 +494,12 @@ instead.
494--- 494---
495*** Support 'electric-layout-mode'. 495*** Support 'electric-layout-mode'.
496 496
497** Tmm Menubar
498
499---
500*** Add a shortcut to navigate to previous menu
501The hardcoded "^" shortcut gets you back to the previous menu.
502
497 503
498* New Modes and Packages in Emacs 31.1 504* New Modes and Packages in Emacs 31.1
499 505
diff --git a/lisp/tmm.el b/lisp/tmm.el
index f52afb7e162..444d7945987 100644
--- a/lisp/tmm.el
+++ b/lisp/tmm.el
@@ -88,8 +88,9 @@ or else the correct item might not be found in the `*Completions*' buffer."
88(defcustom tmm-completion-prompt 88(defcustom tmm-completion-prompt
89 "Press PageUp key to reach this buffer from the minibuffer. 89 "Press PageUp key to reach this buffer from the minibuffer.
90Alternatively, you can use Up/Down keys (or your History keys) to change 90Alternatively, you can use Up/Down keys (or your History keys) to change
91the item in the minibuffer, and press RET when you are done, or press the 91the item in the minibuffer, and press RET when you are done, or press
92marked letters to pick up your choice. Type C-g or ESC ESC ESC to cancel. 92the marked letters to pick up your choice. Type ^ to go to the parent
93menu. Type C-g or ESC ESC ESC to cancel.
93" 94"
94 "Help text to insert on the top of the completion buffer. 95 "Help text to insert on the top of the completion buffer.
95To save space, you can set this to nil, 96To save space, you can set this to nil,
@@ -123,7 +124,7 @@ specify nil for this variable."
123(defvar tmm--history nil) 124(defvar tmm--history nil)
124 125
125;;;###autoload 126;;;###autoload
126(defun tmm-prompt (menu &optional in-popup default-item no-execute) 127(defun tmm-prompt (menu &optional in-popup default-item no-execute path)
127 "Text-mode emulation of calling the bindings in keymap. 128 "Text-mode emulation of calling the bindings in keymap.
128Creates a text-mode menu of possible choices. You can access the elements 129Creates a text-mode menu of possible choices. You can access the elements
129in the menu in two ways: 130in the menu in two ways:
@@ -136,7 +137,9 @@ keymap or an alist of alists.
136DEFAULT-ITEM, if non-nil, specifies an initial default choice. 137DEFAULT-ITEM, if non-nil, specifies an initial default choice.
137Its value should be an event that has a binding in MENU. 138Its value should be an event that has a binding in MENU.
138NO-EXECUTE, if non-nil, means to return the command the user selects 139NO-EXECUTE, if non-nil, means to return the command the user selects
139instead of executing it." 140instead of executing it.
141PATH is a stack that keeps track your path into sub-menus. It is used
142to go back in the menu hierarchy."
140 ;; If the optional argument IN-POPUP is t, 143 ;; If the optional argument IN-POPUP is t,
141 ;; then MENU is an alist of elements of the form (STRING . VALUE). 144 ;; then MENU is an alist of elements of the form (STRING . VALUE).
142 ;; That is used for recursive calls only. 145 ;; That is used for recursive calls only.
@@ -227,22 +230,28 @@ instead of executing it."
227 " (up/down to change, PgUp to menu): ") 230 " (up/down to change, PgUp to menu): ")
228 (tmm--completion-table tmm-km-list) nil t nil 231 (tmm--completion-table tmm-km-list) nil t nil
229 'tmm--history (reverse tmm--history))))))) 232 'tmm--history (reverse tmm--history)))))))
230 (setq choice (cdr (assoc out tmm-km-list))) 233 (if (and (stringp out) (string= "^" out))
231 (and (null choice) 234 ;; a fake choice to please the destructuring later.
232 (string-prefix-p tmm-c-prompt out) 235 (setq choice (cons out out))
233 (setq out (substring out (length tmm-c-prompt)) 236 (setq choice (cdr (assoc out tmm-km-list)))
234 choice (cdr (assoc out tmm-km-list)))) 237 (and (null choice)
235 (and (null choice) out 238 (string-prefix-p tmm-c-prompt out)
236 (setq out (try-completion out tmm-km-list) 239 (setq out (substring out (length tmm-c-prompt))
237 choice (cdr (assoc out tmm-km-list))))) 240 choice (cdr (assoc out tmm-km-list))))
241 (and (null choice) out
242 (setq out (try-completion out tmm-km-list)
243 choice (cdr (assoc out tmm-km-list))))))
238 ;; CHOICE is now (STRING . MEANING). Separate the two parts. 244 ;; CHOICE is now (STRING . MEANING). Separate the two parts.
239 (setq chosen-string (car choice)) 245 (setq chosen-string (car choice))
240 (setq choice (cdr choice)) 246 (setq choice (cdr choice))
241 (cond (in-popup 247 (cond ((and (stringp choice) (string= "^" choice))
248 ;; User wants to go up: do it first.
249 (if path (tmm-prompt (pop path) in-popup nil nil path)))
250 (in-popup
242 ;; We just did the inner level of a -popup menu. 251 ;; We just did the inner level of a -popup menu.
243 choice) 252 choice)
244 ;; We just did the outer level. Do the inner level now. 253 ;; We just did the outer level. Do the inner level now.
245 (not-menu (tmm-prompt choice t nil no-execute)) 254 (not-menu (tmm-prompt choice t nil no-execute (cons menu path)))
246 ;; We just handled a menu keymap and found another keymap. 255 ;; We just handled a menu keymap and found another keymap.
247 ((keymapp choice) 256 ((keymapp choice)
248 (if (symbolp choice) 257 (if (symbolp choice)
@@ -250,7 +259,7 @@ instead of executing it."
250 (condition-case nil 259 (condition-case nil
251 (require 'mouse) 260 (require 'mouse)
252 (error nil)) 261 (error nil))
253 (tmm-prompt choice nil nil no-execute)) 262 (tmm-prompt choice nil nil no-execute (cons menu path)))
254 ;; We just handled a menu keymap and found a command. 263 ;; We just handled a menu keymap and found a command.
255 (choice 264 (choice
256 (if chosen-string 265 (if chosen-string
@@ -322,7 +331,8 @@ Stores a list of all the shortcuts in the free variable `tmm-short-cuts'."
322 (define-key map [prior] 'tmm-goto-completions) 331 (define-key map [prior] 'tmm-goto-completions)
323 (define-key map "\ev" 'tmm-goto-completions) 332 (define-key map "\ev" 'tmm-goto-completions)
324 (define-key map "\C-n" 'next-history-element) 333 (define-key map "\C-n" 'next-history-element)
325 (define-key map "\C-p" 'previous-history-element))) 334 (define-key map "\C-p" 'previous-history-element)
335 (define-key map "^" 'self-insert-and-exit)))
326 (prog1 (current-local-map) 336 (prog1 (current-local-map)
327 (use-local-map (append map (current-local-map)))))) 337 (use-local-map (append map (current-local-map))))))
328 338