From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Manuel Giraud via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#73498: [PATCH] Add a shortcut to go up in the menu hierarchy. Date: Mon, 30 Sep 2024 17:49:44 +0200 Message-ID: <87ttdxnntz.fsf@ledu-giraud.fr> References: <87cykqhcyr.fsf@ledu-giraud.fr> <86ldzamqzq.fsf@mail.linkov.net> Reply-To: Manuel Giraud Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10262"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 73498@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 30 17:50:42 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1svIfa-0002VM-7p for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 30 Sep 2024 17:50:42 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svIfP-0003AS-Td; Mon, 30 Sep 2024 11:50:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1svIfN-0003A0-SW for bug-gnu-emacs@gnu.org; Mon, 30 Sep 2024 11:50:30 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1svIfN-0000YF-JO for bug-gnu-emacs@gnu.org; Mon, 30 Sep 2024 11:50:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=ie3P7/NLIdYtmH4uYS1BB82Q6YLrZ6wfclFfW4V7ihQ=; b=AkvOzp7H0Qn/a8LvT68Cm3lDzrVfOjxaRXaU8SrDn9hKQusmVdN28uORVCSNi5hwfmWfVpS55OrHCrQYWrDgKZQf+cOF7aaS0pm6g7UKCmS7Mf6bwVlGjzdFAx6tCxJYBtVUt7fud2YRt/LGnVZqxefGRpv9NXzcr2S7rWpLhAa4XPQ3tNEeDJEUPgLfLgTAB+CJ5TXHR0m2nbcSK2PavEsqqa4vhHL9R0cEn4AfPbpZsfxnel70Zw/jQw/SHz5jBDwKoBlMyI/s1pwEdVN3kRrksG8DAQc4IXd6d2e0is2KZcUmFnQTjLDwnddK0y6z44dWF9iIKXJ/LEHK/77lJQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1svIfu-0000fl-75 for bug-gnu-emacs@gnu.org; Mon, 30 Sep 2024 11:51:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Manuel Giraud Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 30 Sep 2024 15:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73498 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 73498-submit@debbugs.gnu.org id=B73498.17277114232068 (code B ref 73498); Mon, 30 Sep 2024 15:51:02 +0000 Original-Received: (at 73498) by debbugs.gnu.org; 30 Sep 2024 15:50:23 +0000 Original-Received: from localhost ([127.0.0.1]:45551 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1svIfH-0000XI-0W for submit@debbugs.gnu.org; Mon, 30 Sep 2024 11:50:23 -0400 Original-Received: from ledu-giraud.fr ([51.159.28.247]:30375) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1svIfE-0000XA-Ft for 73498@debbugs.gnu.org; Mon, 30 Sep 2024 11:50:22 -0400 DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=A3/LzFRT fT/Jb3qu6JlLFlDrOXvC40K0qRfWU0Vh7ss=; h=date:references:in-reply-to: subject:cc:to:from; d=ledu-giraud.fr; b=eRfpCbFP2wTEa7AX3Vno6k5jcAZIV8 7SLla2/83YnyJqR8I2XYeMfifeH5r9aszlZkOJwU9UFTmE20pn2sCQAw== DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=A3/LzFRTfT/Jb3qu 6JlLFlDrOXvC40K0qRfWU0Vh7ss=; h=date:references:in-reply-to:subject: cc:to:from; d=ledu-giraud.fr; b=TLL0sJrsomR+qcYX4UlszgCeyIUKu1U80sDLMx /vWBbIMBhAQFzF5qcty46elmEUMAn7PIAEwyMc0x7QyxkZs6afN/EBDaom+TILzAgyWFKL J0rM9Ryjz1Ld0nv7Cug10Oy0Z9D6cwPEfpnV/HGx267eqtsaWr6R68lIW2ZCjroM8diQAK TSgCCFwe3PTSm6EsN83ImAdLkcVTlJKktXa6U+U94fdJ4GI2d0hwDz1O3wOfy+RJjRDxuB hgvsZZIyGPhpscvWMyDjv28zE02H9WYb9+2xZcpZ7c3RfbKP/vpQBSTNhBZpoS1Q3U56gW 74RVlh/VG5MFA5HL5bd6ckew== Original-Received: from computer ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id 927c5876 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 30 Sep 2024 17:49:44 +0200 (CEST) In-Reply-To: <86ldzamqzq.fsf@mail.linkov.net> (Juri Linkov's message of "Sun, 29 Sep 2024 19:04:33 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:292723 Archived-At: --=-=-= Content-Type: text/plain Juri Linkov 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-a-shortcut-to-go-up-in-the-menu-hierarchy.patch >From bd772c361f5060776b5134fcd4dcd71606affc5f Mon Sep 17 00:00:00 2001 From: Manuel Giraud 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. + * 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 --=-=-= Content-Type: text/plain -- Manuel Giraud --=-=-=--