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#74111: [PATCH] New `tmm-menubar' shortcut display style Date: Thu, 31 Oct 2024 17:04:22 +0100 Message-ID: <87frocz2bd.fsf@ledu-giraud.fr> References: <87r07xtuot.fsf@ledu-giraud.fr> <86sesc37x4.fsf@gnu.org> <87msikin17.fsf@ledu-giraud.fr> <86ikt835sc.fsf@gnu.org> <87ikt8ijc1.fsf@ledu-giraud.fr> <86a5ek2vtv.fsf@gnu.org> 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="35678"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 74111@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 31 17:05:23 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 1t6Xfm-000930-P6 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 31 Oct 2024 17:05:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t6XfW-0004aY-0A; Thu, 31 Oct 2024 12:05:06 -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 1t6XfS-0004Zy-Uw for bug-gnu-emacs@gnu.org; Thu, 31 Oct 2024 12:05:03 -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 1t6XfS-0007Qb-E6 for bug-gnu-emacs@gnu.org; Thu, 31 Oct 2024 12:05:02 -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=26uuwF5ngs8NqPDxHBA+NNw0a+p34M+LJ3z7Sr+kE8Q=; b=o+jl1Zf/zyob9nlpA2a6Pkcl4ieM4fkA9Ej9ZYk3zAWzxpb0jxb0uR0loP1yb9TZhhzHbrWPjlyYoOOICWEbJ+g6EslEhEQwnuUYDsVHeZEGA36G1B3IobwIMYhkp/97FdxnIBzDePAJQp8VL8NBk+hXdcYQ8weJHFQgsezFpILUS8LtTi781BQFl4jWtQLy3DZTT0RpTGS7lXawiLKGprKUFZGq7ks3OQUMiw4e+2SaKDXW9zf3NkpncKwer3wj3xjvl8AdZKvaZuUHL0u9vuZe7F8tS9riSDIk6jhAAqPw3fhFfZOsIabITusz+XoBE+z5fUoLKik+6M1TVEti0w==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t6XfR-0005uk-Ty for bug-gnu-emacs@gnu.org; Thu, 31 Oct 2024 12:05:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Manuel Giraud Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 31 Oct 2024 16:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74111 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 74111-submit@debbugs.gnu.org id=B74111.173039067422690 (code B ref 74111); Thu, 31 Oct 2024 16:05:01 +0000 Original-Received: (at 74111) by debbugs.gnu.org; 31 Oct 2024 16:04:34 +0000 Original-Received: from localhost ([127.0.0.1]:42819 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t6Xez-0005tu-FM for submit@debbugs.gnu.org; Thu, 31 Oct 2024 12:04:34 -0400 Original-Received: from ledu-giraud.fr ([51.159.28.247]:35838) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t6Xew-0005tk-Hn for 74111@debbugs.gnu.org; Thu, 31 Oct 2024 12:04:31 -0400 DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=MnD1TpiR wC5mp8xMf1LJ0eCO1WnjvZB4BdpPOPnq3zI=; h=date:references:in-reply-to: subject:cc:to:from; d=ledu-giraud.fr; b=U6BcNGOnwc3Tu3d2yYL5qzX++YB6Wu IxiJ/Ms5HpdR5eD9Fr15v6qhSAAbZjYgO8qGd8n3Vt5bFy1dY8vD0JAQ== DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=MnD1TpiRwC5mp8xM f1LJ0eCO1WnjvZB4BdpPOPnq3zI=; h=date:references:in-reply-to:subject: cc:to:from; d=ledu-giraud.fr; b=Ysmi0nCbuP6jlhmTi7nIG8kTppJ0olVXD9Kv2Q 2AkzocAVx8Bti7fJOrQ7BEwamXkMtqPvFxvwuOADt+gv+iJ4bp2Zm98D2DdjdElqSXbs0z MMVNi7X2V3N8u+tZZ4pCnq3P3rQKOR5C2FW25iGkT4efC9MoqsAVdYNqa4FwXI2iY8ydNC rdGMfMkCJeuqhmv/rQDH8uIYjPbmko1Z5sY5FvFIZFu8JhR8EkZJZO6Y+fCEThvMxhrNJ6 Rcmfo2Veob40OKaSsqYn7Ot64LfQg541oT8BUaOtxgudIL1H7uvysRK/vTuvJQGjCKTzZv OghMG8bS5e+Un/LmOHIrt7pA== Original-Received: from computer ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id 20b28189 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 31 Oct 2024 17:04:25 +0100 (CET) In-Reply-To: <86a5ek2vtv.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 31 Oct 2024 16:25:32 +0200") 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:294631 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Manuel Giraud >> Cc: 74111@debbugs.gnu.org >> Date: Thu, 31 Oct 2024 12:48:46 +0100 >> >> Eli Zaretskii writes: >> >> > Are we sure users will understand what "marked letters" mean in that >> > case? >> >> Maybe we could change it to "highlighted letters (or digits)". But >> FWIW, "marked letters" was not really more clear before this patch. So >> I think we could try to rewrite tmm-completion-prompt with something >> clearer that work for both options. WDYT? > > I agree, please suggest a better text that caters to both cases. What do you think of this new version of the patch? I removed the "PageUp" comment as it does not seem to work (while 'M-v' is) and I make the help adapt whether `tmm-shortcut-inside-entry' is on or not. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-New-tmm-menubar-shortcut-display-style.patch >From 87908786843fb9ce7f4ef150bee4c687a8f1f848 Mon Sep 17 00:00:00 2001 From: Manuel Giraud Date: Wed, 30 Oct 2024 17:24:24 +0100 Subject: [PATCH] New `tmm-menubar' shortcut display style Bug#74111 * lisp/tmm.el (tmm-shortcut-inside-entry): New user option to control if the shortcut character is placed inside the menu entry's string. (tmm-add-one-shortcut): Compute the new shortcut style. (tmm-prompt): Adapt the prompt regexp. (tmm-shortcut): Simplify and make it work with this change. * etc/NEWS: Announce the option. --- etc/NEWS | 6 +++++ lisp/tmm.el | 70 ++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 56 insertions(+), 20 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index d1c7303f976..c3fc8d46062 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -584,6 +584,12 @@ instead. *** A new shortcut to navigate to previous menu. The hardcoded '^' shortcut gets you back to the previous menu. +--- +*** New user option 'tmm-shortcut-inside-entry'. +When non-nil, insert the character shortcut of a menu entry inside its +string. This character is highlighted with a different face to help +identifying it. + ** Foldout --- diff --git a/lisp/tmm.el b/lisp/tmm.el index 252c1e45afa..3b94656a657 100644 --- a/lisp/tmm.el +++ b/lisp/tmm.el @@ -83,11 +83,10 @@ tmm-mid-prompt string)) (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 + "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 ^ to go to the parent -menu. Type C-g or ESC ESC ESC to cancel. +the %s 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, @@ -108,6 +107,13 @@ tmm-shortcut-words specify nil for this variable." :type '(choice integer (const nil))) +(defcustom tmm-shortcut-inside-entry nil + "Place the shortcut character into the menu entry's string. +When non-nil, the shortcut character will be inserted into its menu +entry string with a different face to help identifying it. The +`tmm-mid-prompt' string is not used then." + :type 'boolean) + (defface tmm-inactive '((t :inherit shadow)) "Face used for inactive menu items.") @@ -198,7 +204,8 @@ tmm-prompt (setq tail (cdr tail))))) (let ((prompt (concat "^" - (if (stringp tmm-mid-prompt) + (if (and (stringp tmm-mid-prompt) + (not tmm-shortcut-inside-entry)) (concat "." (regexp-quote tmm-mid-prompt)))))) (setq tmm--history @@ -224,7 +231,7 @@ tmm-prompt ;; reversed copy of the list. (completing-read-default (concat gl-str - " (up/down to change, PgUp to menu): ") + " (up/down to change): ") (tmm--completion-table tmm-km-list) nil t nil 'tmm--history (reverse tmm--history))))))) (if (and (stringp out) (string= "^" out)) @@ -283,7 +290,7 @@ tmm-add-one-shortcut (t (let* ((str (car elt)) (paren (string-search "(" str)) - (pos 0) (word 0) char) + (word 0) pos char) (catch 'done ; ??? is this slow? (while (and (or (not tmm-shortcut-words) ; no limit on words (< word tmm-shortcut-words)) ; try n words @@ -299,17 +306,32 @@ tmm-add-one-shortcut (if (not (memq char tmm-short-cuts)) (throw 'done char)))) (setq word (1+ word)) (setq pos (match-end 0))) + ;; A nil value for pos means that the shortcut is not inside the + ;; string of the menu entry + (setq pos nil) (while (<= tmm-next-shortcut-digit ?9) ; no letter shortcut, pick a digit (setq char tmm-next-shortcut-digit) (setq tmm-next-shortcut-digit (1+ tmm-next-shortcut-digit)) (if (not (memq char tmm-short-cuts)) (throw 'done char))) (setq char nil)) (if char (setq tmm-short-cuts (cons char tmm-short-cuts))) - (cons (concat (if char (concat (char-to-string char) tmm-mid-prompt) - ;; keep them lined up in columns - (make-string (1+ (length tmm-mid-prompt)) ?\s)) - str) - (cdr elt)))))) + (cons + (if tmm-shortcut-inside-entry + (if char + (if pos + ;; A character inside the menu entry + (let ((res (copy-sequence str))) + (aset res pos char) + (add-text-properties pos (1+ pos) '(face highlight) res) + res) + ;; A fallback digit character: place it in front of the menu entry + (concat (propertize (char-to-string char) 'face 'highlight) " " str)) + (make-string 2 ?\s)) + (concat (if char (concat (char-to-string char) tmm-mid-prompt) + ;; keep them lined up in columns + (make-string (1+ (length tmm-mid-prompt)) ?\s)) + str)) + (cdr elt)))))) ;; This returns the old map. (defun tmm-define-keys (minibuffer) @@ -384,7 +406,12 @@ tmm-add-prompt (let ((inhibit-read-only t) (window (get-buffer-window "*Completions*"))) (goto-char (point-min)) - (insert tmm-completion-prompt) + (insert + (if tmm-shortcut-inside-entry + (format tmm-completion-prompt + (concat (propertize "highlighted" 'face 'highlight) " character")) + (format tmm-completion-prompt + (concat "character right before '" tmm-mid-prompt "' ")))) (when window ;; Try to show everything just inserted and preserve height of ;; *Completions* window. This should fix a behavior described @@ -406,13 +433,16 @@ tmm-shortcut (choose-completion)) ;; In minibuffer (delete-region (minibuffer-prompt-end) (point-max)) - (dolist (elt tmm-km-list) - (if (string= - (substring (car elt) 0 - (min (1+ (length tmm-mid-prompt)) - (length (car elt)))) - (concat (char-to-string c) tmm-mid-prompt)) - (setq s (car elt)))) + (dolist (elt tmm-km-list) + (let ((str (car elt)) + (index 0)) + (when tmm-shortcut-inside-entry + (if (get-char-property 0 'face str) + (setq index 0) + (let ((next (next-single-char-property-change 0 'face str))) + (setq index (if (= (length str) next) 0 next))))) + (if (= (aref str index) c) + (setq s str)))) (insert s) (exit-minibuffer))))) -- 2.47.0 --=-=-= Content-Type: text/plain -- Manuel Giraud --=-=-=--