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: Wed, 30 Oct 2024 17:35:46 +0100 Message-ID: <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="20202"; 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 Wed Oct 30 17:37:36 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 1t6BhP-00050v-2l for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Oct 2024 17:37:35 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t6Bh4-0008Df-Cy; Wed, 30 Oct 2024 12:37:14 -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 1t6Bgs-0008D6-It for bug-gnu-emacs@gnu.org; Wed, 30 Oct 2024 12:37: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 1t6Bgs-0005Z3-Ab for bug-gnu-emacs@gnu.org; Wed, 30 Oct 2024 12:37: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:From:To:Subject; bh=4M28PqqF5ZaTvKBZdQWpXLN5k+/RleKv7QRyhcW6+h4=; b=nBSB2P+XjNWvFNg1UGxxhez1cGfS9vwRvBXfJcqXJJBo7t1HE9r1KQUXWM2hJxnPwysGw0vyGRQjtx37ohK+6jg2tJ9Eef3GkypAlUf+fbrTReq/tn8nB5eTZkMYnHhFt59b9P3jAe/AHGbttUm5WHZzgvRpE8cJBRWnJrHh+D3LryUUUJxWvWj0g4lYUFvMeKU5WH1MCAMLeNkpUFVKaLJkXcbSJwTeR1Kt9R5GUnu+1CzwrMGEpQM/bGIs2l1r4xbOOjjrnw9vhQfHrlfYYjq/BDEl/FAQtOwYgazjU0FHrloaoHQUOj90TrYfCXW2dICrNT3WqGXmVL8fjIc2/A==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t6Bgr-0008GS-Vw for bug-gnu-emacs@gnu.org; Wed, 30 Oct 2024 12:37: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: Wed, 30 Oct 2024 16:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 74111 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.173030616331728 (code B ref -1); Wed, 30 Oct 2024 16:37:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 30 Oct 2024 16:36:03 +0000 Original-Received: from localhost ([127.0.0.1]:36022 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t6Bfu-0008Fg-Ct for submit@debbugs.gnu.org; Wed, 30 Oct 2024 12:36:02 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:44212) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t6Bfq-0008FJ-4f for submit@debbugs.gnu.org; Wed, 30 Oct 2024 12:36:01 -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 1t6Bfo-0007r4-Rh for bug-gnu-emacs@gnu.org; Wed, 30 Oct 2024 12:35:56 -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 1t6Bfk-0005VA-Kj for bug-gnu-emacs@gnu.org; Wed, 30 Oct 2024 12:35:56 -0400 DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=A8eFPMjW 9wU9tQpytb0TBY1nZtt/0czGK6IBvssbOP0=; h=date:subject:to:from; d=ledu-giraud.fr; b=+kuFHG6jdkTGumjRDKPTYO1+SJ4JDW6z+oBKeOl1WgnC45jnjt 8udcb7HUbsIX45otSmkREyaZckcA2em5EtDA== DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=A8eFPMjW9wU9tQpy tb0TBY1nZtt/0czGK6IBvssbOP0=; h=date:subject:to:from; d=ledu-giraud.fr; b=Mm1D9MB4+RqcdeMXECCGo+1jpv8M+GPbUfDmL/7r8QiCq90ThR YTp/oGTciqOxhS0ugMFxjTlwsMqCQ94nKvy2VEBFaLPbbdsAZYhZLEvjIDlgQdr9CPiyA/ XCD4+9Duz+MMRecyOpXcWiZMFMUbePF8BGbD2TbxhdSLd97zBF8uEg8SN1eYwxKxki4gMn II23nGn9Jg9bYBVe1kB+cIGQ1nKweeAP9r5oKoVhJMvwlFUetXuu6IHAGxlX2nhaumYgSP TBNtk7dvfqGBxz1szkoh+REtMoGQgssizFjEGmcvYUPOkSuxesHRr1Fbz05cPgWQ7v+jtA V0Ez0mH0R4Uw== Original-Received: from computer ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id 8a3f34cb (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 30 Oct 2024 17:35:47 +0100 (CET) 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:294571 Archived-At: --=-=-= Content-Type: text/plain Tags: patch Hi, Here is patch that add a new display style for tmm-menubar shortcuts where the shortcut character is inserted into the menu entry string and highlighted with the `highlight' face. This is controled by a new user option, `tmm-shortcut-inside-entry', and off by default. In GNU Emacs 31.0.50 (build 82, x86_64-unknown-openbsd7.6, X toolkit) of 2024-10-30 built on computer Repository revision: 679c0c7b940687a63937a361d0439c68b7bf4d51 Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12101013 System Description: OpenBSD computer 7.6 GENERIC.MP#394 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=lucid --with-toolkit-scroll-bars=no --without-cairo --without-compress-install' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-New-tmm-menubar-shortcut-display-style.patch >From 2cfa06816f7238602bc4e0d6a358827214100f1f 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 * 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 | 43 +++++++++++++++++++++++++++++++------------ 2 files changed, 37 insertions(+), 12 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..a9d32d85ebf 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) @@ -407,11 +430,7 @@ tmm-shortcut ;; 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)) + (if (= (aref (car elt) 0) c) (setq s (car elt)))) (insert s) (exit-minibuffer))))) -- 2.47.0 --=-=-= Content-Type: text/plain -- Manuel Giraud --=-=-=--