* bug#73498: [PATCH] Add a shortcut to go up in the menu hierarchy.
@ 2024-09-26 11:27 Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-29 16:04 ` Juri Linkov
0 siblings, 1 reply; 5+ messages in thread
From: Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-26 11:27 UTC (permalink / raw)
To: 73498
[-- Attachment #1: Type: text/plain, Size: 694 bytes --]
Tags: patch
Hi,
Here is a patch that add a shortcut (^) to `tmm-menubar' to go upward in
the menu hierarchy.
In GNU Emacs 31.0.50 (build 4, x86_64-unknown-openbsd7.6) of 2024-09-21
built on computer
Repository revision: 4745bafa6a1d6aeda5ad08e09541d076ee223382
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101013
System Description: OpenBSD computer 7.6 GENERIC.MP#321 amd64
Configured using:
'configure CC=egcc CPPFLAGS=-I/usr/local/include
LDFLAGS=-L/usr/local/lib MAKEINFO=gmakeinfo --prefix=/home/manuel/emacs
--bindir=/home/manuel/bin --with-x-toolkit=no
--with-toolkit-scroll-bars=no --without-cairo
--without-compress-install'
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-a-shortcut-to-go-up-in-the-menu-hierarchy.patch --]
[-- Type: text/patch, Size: 4820 bytes --]
From f86caa4cf06801c1917247519a16594b8fad9de9 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
Date: Wed, 25 Sep 2024 10:31:12 +0200
Subject: [PATCH] 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.
(tmm-completion-prompt): Document it in help message.
(tmm-define-keys): Add the shortcut in the keymap.
---
lisp/tmm.el | 42 ++++++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 16 deletions(-)
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 @@ tmm-mb-map
(defcustom tmm-completion-prompt
"Press PageUp key to reach this buffer from the minibuffer.
Alternatively, you can use Up/Down keys (or your History keys) to change
-the item in the minibuffer, and press RET when you are done, or press the
-marked letters to pick up your choice. Type C-g or ESC ESC ESC to cancel.
+the item in the minibuffer, and press RET when you are done, or press
+the marked letters to pick up your choice. Type ^ to go to the parent
+menu. Type C-g or ESC ESC ESC to cancel.
"
"Help text to insert on the top of the completion buffer.
To save space, you can set this to nil,
@@ -123,7 +124,7 @@ tmm--completion-table
(defvar tmm--history nil)
;;;###autoload
-(defun tmm-prompt (menu &optional in-popup default-item no-execute)
+(defun tmm-prompt (menu &optional in-popup default-item no-execute path)
"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:
@@ -136,7 +137,9 @@ tmm-prompt
DEFAULT-ITEM, if non-nil, specifies an initial default choice.
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."
+instead of executing it.
+PATH is a stack that keeps track your path into sub-menus. It is used
+to go back in the menu hierarchy."
;; 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.
@@ -227,22 +230,28 @@ tmm-prompt
" (up/down to change, PgUp to menu): ")
(tmm--completion-table tmm-km-list) nil t nil
'tmm--history (reverse tmm--history)))))))
- (setq choice (cdr (assoc out tmm-km-list)))
- (and (null choice)
- (string-prefix-p tmm-c-prompt out)
- (setq out (substring out (length tmm-c-prompt))
- choice (cdr (assoc out tmm-km-list))))
- (and (null choice) out
- (setq out (try-completion out tmm-km-list)
- choice (cdr (assoc out tmm-km-list)))))
+ (if (and (stringp out) (string= "^" out))
+ ;; a fake choice to please the destructuring later.
+ (setq choice (cons out out))
+ (setq choice (cdr (assoc out tmm-km-list)))
+ (and (null choice)
+ (string-prefix-p tmm-c-prompt out)
+ (setq out (substring out (length tmm-c-prompt))
+ choice (cdr (assoc out tmm-km-list))))
+ (and (null choice) out
+ (setq out (try-completion out tmm-km-list)
+ choice (cdr (assoc out tmm-km-list))))))
;; CHOICE is now (STRING . MEANING). Separate the two parts.
(setq chosen-string (car choice))
(setq choice (cdr choice))
- (cond (in-popup
+ (cond ((and (stringp choice) (string= "^" choice))
+ ;; User wants to go up: do it first.
+ (if path (tmm-prompt (pop path) in-popup nil nil path)))
+ (in-popup
;; 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 nil no-execute))
+ (not-menu (tmm-prompt choice t nil no-execute (cons menu path)))
;; We just handled a menu keymap and found another keymap.
((keymapp choice)
(if (symbolp choice)
@@ -250,7 +259,7 @@ tmm-prompt
(condition-case nil
(require 'mouse)
(error nil))
- (tmm-prompt choice nil nil no-execute))
+ (tmm-prompt choice nil nil no-execute (cons menu path)))
;; We just handled a menu keymap and found a command.
(choice
(if chosen-string
@@ -322,7 +331,8 @@ tmm-define-keys
(define-key map [prior] 'tmm-goto-completions)
(define-key map "\ev" 'tmm-goto-completions)
(define-key map "\C-n" 'next-history-element)
- (define-key map "\C-p" 'previous-history-element)))
+ (define-key map "\C-p" 'previous-history-element)
+ (define-key map "^" 'self-insert-and-exit)))
(prog1 (current-local-map)
(use-local-map (append map (current-local-map))))))
--
2.46.1
[-- Attachment #3: Type: text/plain, Size: 19 bytes --]
--
Manuel Giraud
^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#73498: [PATCH] Add a shortcut to go up in the menu hierarchy.
2024-09-26 11:27 bug#73498: [PATCH] Add a shortcut to go up in the menu hierarchy Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-09-29 16:04 ` Juri Linkov
2024-09-30 7:54 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-30 15:49 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 2 replies; 5+ messages in thread
From: Juri Linkov @ 2024-09-29 16:04 UTC (permalink / raw)
To: Manuel Giraud; +Cc: 73498
> Here is a patch that add a shortcut (^) to `tmm-menubar' to go upward in
> the menu hierarchy.
Thanks, I tried it, and it works nicely.
Should it be mentioned in NEWS?
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#73498: [PATCH] Add a shortcut to go up in the menu hierarchy.
2024-09-29 16:04 ` Juri Linkov
@ 2024-09-30 7:54 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-30 15:49 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
1 sibling, 0 replies; 5+ messages in thread
From: Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-30 7:54 UTC (permalink / raw)
To: Juri Linkov; +Cc: 73498
Juri Linkov <juri@linkov.net> writes:
>> Here is a patch that add a shortcut (^) to `tmm-menubar' to go upward in
>> the menu hierarchy.
>
> Thanks, I tried it, and it works nicely.
>
> Should it be mentioned in NEWS?
I guess yes, I'll add one.
--
Manuel Giraud
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#73498: [PATCH] Add a shortcut to go up in the menu hierarchy.
2024-09-29 16:04 ` Juri Linkov
2024-09-30 7:54 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-09-30 15:49 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-06 17:29 ` Juri Linkov
1 sibling, 1 reply; 5+ messages in thread
From: Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-30 15:49 UTC (permalink / raw)
To: Juri Linkov; +Cc: 73498
[-- Attachment #1: Type: text/plain, Size: 274 bytes --]
Juri Linkov <juri@linkov.net> writes:
>> Here is a patch that add a shortcut (^) to `tmm-menubar' to go upward in
>> the menu hierarchy.
>
> Thanks, I tried it, and it works nicely.
>
> Should it be mentioned in NEWS?
Here is a new version of the patch with a NEWS entry.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-a-shortcut-to-go-up-in-the-menu-hierarchy.patch --]
[-- Type: text/x-patch, Size: 5323 bytes --]
From bd772c361f5060776b5134fcd4dcd71606affc5f Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
Date: Wed, 25 Sep 2024 10:31:12 +0200
Subject: [PATCH] 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.
(tmm-completion-prompt): Document it in help message.
(tmm-define-keys): Add the shortcut in the keymap.
* etc/NEWS: Document the change.
---
etc/NEWS | 6 ++++++
lisp/tmm.el | 42 ++++++++++++++++++++++++++----------------
2 files changed, 32 insertions(+), 16 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index c1a0524c8ba..8445015d16c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -403,6 +403,12 @@ toggle.
Putting (require 'midnight) in your init file no longer activates the
mode. Now, one needs to say (midnight-mode +1) instead.
+** Tmm Menubar
+
+---
+*** Add a shortcut to navigate to previous menu
+The hardcoded "^" shortcut gets you back to the previous menu.
+
\f
* New Modes and Packages in Emacs 31.1
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 @@ tmm-mb-map
(defcustom tmm-completion-prompt
"Press PageUp key to reach this buffer from the minibuffer.
Alternatively, you can use Up/Down keys (or your History keys) to change
-the item in the minibuffer, and press RET when you are done, or press the
-marked letters to pick up your choice. Type C-g or ESC ESC ESC to cancel.
+the item in the minibuffer, and press RET when you are done, or press
+the marked letters to pick up your choice. Type ^ to go to the parent
+menu. Type C-g or ESC ESC ESC to cancel.
"
"Help text to insert on the top of the completion buffer.
To save space, you can set this to nil,
@@ -123,7 +124,7 @@ tmm--completion-table
(defvar tmm--history nil)
;;;###autoload
-(defun tmm-prompt (menu &optional in-popup default-item no-execute)
+(defun tmm-prompt (menu &optional in-popup default-item no-execute path)
"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:
@@ -136,7 +137,9 @@ tmm-prompt
DEFAULT-ITEM, if non-nil, specifies an initial default choice.
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."
+instead of executing it.
+PATH is a stack that keeps track your path into sub-menus. It is used
+to go back in the menu hierarchy."
;; 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.
@@ -227,22 +230,28 @@ tmm-prompt
" (up/down to change, PgUp to menu): ")
(tmm--completion-table tmm-km-list) nil t nil
'tmm--history (reverse tmm--history)))))))
- (setq choice (cdr (assoc out tmm-km-list)))
- (and (null choice)
- (string-prefix-p tmm-c-prompt out)
- (setq out (substring out (length tmm-c-prompt))
- choice (cdr (assoc out tmm-km-list))))
- (and (null choice) out
- (setq out (try-completion out tmm-km-list)
- choice (cdr (assoc out tmm-km-list)))))
+ (if (and (stringp out) (string= "^" out))
+ ;; a fake choice to please the destructuring later.
+ (setq choice (cons out out))
+ (setq choice (cdr (assoc out tmm-km-list)))
+ (and (null choice)
+ (string-prefix-p tmm-c-prompt out)
+ (setq out (substring out (length tmm-c-prompt))
+ choice (cdr (assoc out tmm-km-list))))
+ (and (null choice) out
+ (setq out (try-completion out tmm-km-list)
+ choice (cdr (assoc out tmm-km-list))))))
;; CHOICE is now (STRING . MEANING). Separate the two parts.
(setq chosen-string (car choice))
(setq choice (cdr choice))
- (cond (in-popup
+ (cond ((and (stringp choice) (string= "^" choice))
+ ;; User wants to go up: do it first.
+ (if path (tmm-prompt (pop path) in-popup nil nil path)))
+ (in-popup
;; 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 nil no-execute))
+ (not-menu (tmm-prompt choice t nil no-execute (cons menu path)))
;; We just handled a menu keymap and found another keymap.
((keymapp choice)
(if (symbolp choice)
@@ -250,7 +259,7 @@ tmm-prompt
(condition-case nil
(require 'mouse)
(error nil))
- (tmm-prompt choice nil nil no-execute))
+ (tmm-prompt choice nil nil no-execute (cons menu path)))
;; We just handled a menu keymap and found a command.
(choice
(if chosen-string
@@ -322,7 +331,8 @@ tmm-define-keys
(define-key map [prior] 'tmm-goto-completions)
(define-key map "\ev" 'tmm-goto-completions)
(define-key map "\C-n" 'next-history-element)
- (define-key map "\C-p" 'previous-history-element)))
+ (define-key map "\C-p" 'previous-history-element)
+ (define-key map "^" 'self-insert-and-exit)))
(prog1 (current-local-map)
(use-local-map (append map (current-local-map))))))
--
2.46.1
[-- Attachment #3: Type: text/plain, Size: 18 bytes --]
--
Manuel Giraud
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-10-06 17:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-26 11:27 bug#73498: [PATCH] Add a shortcut to go up in the menu hierarchy Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-29 16:04 ` Juri Linkov
2024-09-30 7:54 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-30 15:49 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-06 17:29 ` Juri Linkov
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).