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 10:46:37 +0100 Message-ID: <87r07wiozm.fsf@ledu-giraud.fr> References: <87r07xtuot.fsf@ledu-giraud.fr> 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="32464"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: 74111@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 31 10:47:13 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 1t6Rlp-0008Fk-B8 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 31 Oct 2024 10:47:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t6Rlg-0004Uq-VD; Thu, 31 Oct 2024 05:47:05 -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 1t6Rle-0004UL-Ji for bug-gnu-emacs@gnu.org; Thu, 31 Oct 2024 05:47:02 -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 1t6Rle-0000Zc-Ad for bug-gnu-emacs@gnu.org; Thu, 31 Oct 2024 05:47: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=BePaQGyQK+Lbbr3UA0rPZ+Rxy7zA8yaG28ZYVgrNGnw=; b=bFez50fGQlpvfw7TtiTc1MIb3f9gsHOsc5WXUasBBIlz2sQr3VRwALK5ogR0eLA9V4gN5RiDCII7Qr3XsfJjuPooAKx0T5e8o5lV5pPtRwPwBNG/xk6lzTBg1o0K4dxavdfV0hGiZx/gbqAOyik2BshZygnKoPzRyc7btDGuiABfffZWgoNjecjh9l4H8jNeOzBTPIz3qELUoMSi2sVmD9W0dmj7Ssh0Ls+gx9oQX5bUlkX3vz3XfHjjzvSoFYEDvqf5VIYnPoCIs7tKNwNv7GEnQExMkv5iWfP3DOE97WWujUzAe8unxDNejMJVCP8xHtEcNv9gBrGqLhUARpHUsg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t6Rle-0001Cm-4J for bug-gnu-emacs@gnu.org; Thu, 31 Oct 2024 05:47: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: Thu, 31 Oct 2024 09:47:02 +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 X-Debbugs-Original-To: Manuel Giraud via "Bug reports for GNU Emacs, the Swiss army knife of text editors" X-Debbugs-Original-Cc: 74111@debbugs.gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.17303680074613 (code B ref -1); Thu, 31 Oct 2024 09:47:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 31 Oct 2024 09:46:47 +0000 Original-Received: from localhost ([127.0.0.1]:41225 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t6RlP-0001CK-BA for submit@debbugs.gnu.org; Thu, 31 Oct 2024 05:46:47 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:59734) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t6RlM-0001C7-Hx for submit@debbugs.gnu.org; Thu, 31 Oct 2024 05:46:45 -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 1t6RlM-0004Rl-BQ for bug-gnu-emacs@gnu.org; Thu, 31 Oct 2024 05:46:44 -0400 Original-Received: from ledu-giraud.fr ([51.159.28.247]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t6RlJ-0000Wm-Mu for bug-gnu-emacs@gnu.org; Thu, 31 Oct 2024 05:46:43 -0400 DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=bqElPCyw CAqTv4eP3tcCo9HZmBil8Ju8yqa9ds8nMwg=; h=date:references:in-reply-to: subject:cc:to:from; d=ledu-giraud.fr; b=TlA2a+xnikqvF421JNWW04fKcaauC5 cKIoS7JwNOUP93QlQLzesdiri8uSDfko8VIbyr32fBZnNBb/FfmfwnBQ== DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=bqElPCywCAqTv4eP 3tcCo9HZmBil8Ju8yqa9ds8nMwg=; h=date:references:in-reply-to:subject: cc:to:from; d=ledu-giraud.fr; b=WuFDkm7IgmxWCOVdpZRkZonKJIxZy3zDSb5Xsh mWNRRRY0HgZZHWlWkqfNpCWLThS0cxAWyv7AXFNcfvG9i+dtnM1typnn2tWMArUKbdl5d3 1rTgx2bJlKlg35pcEog+EYio3cZKa5zD6ueFye3UrAb2qRHvZK8GWNd0JaBnxcRWtr3/IW ZeLzIy0GKOB5OlcXN0C66e6alRJDZe4t/HT7updi5W2iqaLyjB6uYEI8clHhBZQOulAqAL EdjGFQS7ILQcHblHNQVwC4CTpDadQAsaHRRSInv7HV9IFrVDZn+WZ5ICNCMh5yyJbxasPt ZYZso573Qi/3A7BxhQUTDCDg== Original-Received: from computer ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id e595ad7a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 31 Oct 2024 10:46:39 +0100 (CET) In-Reply-To: <87r07xtuot.fsf@ledu-giraud.fr> (Manuel Giraud via's message of "Wed, 30 Oct 2024 17:35:46 +0100") Received-SPF: pass client-ip=51.159.28.247; envelope-from=manuel@ledu-giraud.fr; helo=ledu-giraud.fr X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:294600 Archived-At: --=-=-= Content-Type: text/plain Sorry, my previous patch misses a lots of cases to correctly match a shortcut. This new one fixes it. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-New-tmm-menubar-shortcut-display-style.patch >From 2cc969daae5505e2bd13fa6ef978325cd312ff89 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 | 54 +++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 46 insertions(+), 14 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..fa6afbf4baf 100644 --- a/lisp/tmm.el +++ b/lisp/tmm.el @@ -108,6 +108,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 +205,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 @@ -283,7 +291,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 +307,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) @@ -406,13 +429,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 --=-=-=--