unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#74111: [PATCH] New `tmm-menubar' shortcut display style
@ 2024-10-30 16:35 Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-10-31  9:46 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-10-31 10:04 ` Eli Zaretskii
  0 siblings, 2 replies; 15+ messages in thread
From: Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-30 16:35 UTC (permalink / raw)
  To: 74111

[-- Attachment #1: Type: text/plain, Size: 886 bytes --]

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'


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-New-tmm-menubar-shortcut-display-style.patch --]
[-- Type: text/patch, Size: 4990 bytes --]

From 2cfa06816f7238602bc4e0d6a358827214100f1f Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
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


[-- Attachment #3: Type: text/plain, Size: 19 bytes --]


-- 
Manuel Giraud

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#74111: [PATCH] New `tmm-menubar' shortcut display style
  2024-10-30 16:35 bug#74111: [PATCH] New `tmm-menubar' shortcut display style Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-10-31  9:46 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-10-31 10:04 ` Eli Zaretskii
  1 sibling, 0 replies; 15+ messages in thread
From: Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-31  9:46 UTC (permalink / raw)
  To: 74111

[-- Attachment #1: Type: text/plain, Size: 103 bytes --]

Sorry, my previous patch misses a lots of cases to correctly match a
shortcut.  This new one fixes it.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-New-tmm-menubar-shortcut-display-style.patch --]
[-- Type: text/x-patch, Size: 5467 bytes --]

From 2cc969daae5505e2bd13fa6ef978325cd312ff89 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
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


[-- Attachment #3: Type: text/plain, Size: 18 bytes --]

-- 
Manuel Giraud

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#74111: [PATCH] New `tmm-menubar' shortcut display style
  2024-10-30 16:35 bug#74111: [PATCH] New `tmm-menubar' shortcut display style Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-10-31  9:46 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-10-31 10:04 ` Eli Zaretskii
  2024-10-31 10:28   ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2024-10-31 10:04 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: 74111

> Date: Wed, 30 Oct 2024 17:35:46 +0100
> From:  Manuel Giraud via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> 
> 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.

When this option is turned on, we should use a different default value
of tmm-completion-prompt, no?  Because otherwise the instructions
there make no sense with this new display style.

Thanks.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#74111: [PATCH] New `tmm-menubar' shortcut display style
  2024-10-31 10:04 ` Eli Zaretskii
@ 2024-10-31 10:28   ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-10-31 10:50     ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-31 10:28 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 74111

Eli Zaretskii <eliz@gnu.org> writes:

>> Date: Wed, 30 Oct 2024 17:35:46 +0100
>> From:  Manuel Giraud via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>> 
>> 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.
>
> When this option is turned on, we should use a different default value
> of tmm-completion-prompt, no?  Because otherwise the instructions
> there make no sense with this new display style.

I don't think so.  The Up/Down keys work the same whether this option is
active or not.  And with this option activated, the "marked letters" are
the ones highlighted.
-- 
Manuel Giraud





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#74111: [PATCH] New `tmm-menubar' shortcut display style
  2024-10-31 10:28   ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-10-31 10:50     ` Eli Zaretskii
  2024-10-31 11:48       ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2024-10-31 10:50 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: 74111

> From: Manuel Giraud <manuel@ledu-giraud.fr>
> Cc: 74111@debbugs.gnu.org
> Date: Thu, 31 Oct 2024 11:28:52 +0100
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > When this option is turned on, we should use a different default value
> > of tmm-completion-prompt, no?  Because otherwise the instructions
> > there make no sense with this new display style.
> 
> I don't think so.  The Up/Down keys work the same whether this option is
> active or not.  And with this option activated, the "marked letters" are
> the ones highlighted.

Are we sure users will understand what "marked letters" mean in that
case?





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#74111: [PATCH] New `tmm-menubar' shortcut display style
  2024-10-31 10:50     ` Eli Zaretskii
@ 2024-10-31 11:48       ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-10-31 14:25         ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-31 11:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 74111

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Manuel Giraud <manuel@ledu-giraud.fr>
>> Cc: 74111@debbugs.gnu.org
>> Date: Thu, 31 Oct 2024 11:28:52 +0100
>> 
>> Eli Zaretskii <eliz@gnu.org> writes:
>> 
>> > When this option is turned on, we should use a different default value
>> > of tmm-completion-prompt, no?  Because otherwise the instructions
>> > there make no sense with this new display style.
>> 
>> I don't think so.  The Up/Down keys work the same whether this option is
>> active or not.  And with this option activated, the "marked letters" are
>> the ones highlighted.
>
> 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?
-- 
Manuel Giraud





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#74111: [PATCH] New `tmm-menubar' shortcut display style
  2024-10-31 11:48       ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-10-31 14:25         ` Eli Zaretskii
  2024-10-31 16:04           ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2024-10-31 14:25 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: 74111

> From: Manuel Giraud <manuel@ledu-giraud.fr>
> Cc: 74111@debbugs.gnu.org
> Date: Thu, 31 Oct 2024 12:48:46 +0100
> 
> Eli Zaretskii <eliz@gnu.org> 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.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#74111: [PATCH] New `tmm-menubar' shortcut display style
  2024-10-31 14:25         ` Eli Zaretskii
@ 2024-10-31 16:04           ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-10-31 16:57             ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-31 16:04 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 74111

[-- Attachment #1: Type: text/plain, Size: 832 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Manuel Giraud <manuel@ledu-giraud.fr>
>> Cc: 74111@debbugs.gnu.org
>> Date: Thu, 31 Oct 2024 12:48:46 +0100
>> 
>> Eli Zaretskii <eliz@gnu.org> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-New-tmm-menubar-shortcut-display-style.patch --]
[-- Type: text/x-patch, Size: 7285 bytes --]

From 87908786843fb9ce7f4ef150bee4c687a8f1f848 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
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


[-- Attachment #3: Type: text/plain, Size: 18 bytes --]

-- 
Manuel Giraud

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#74111: [PATCH] New `tmm-menubar' shortcut display style
  2024-10-31 16:04           ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-10-31 16:57             ` Eli Zaretskii
  2024-10-31 22:07               ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 15+ messages in thread
From: Eli Zaretskii @ 2024-10-31 16:57 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: 74111

> From: Manuel Giraud <manuel@ledu-giraud.fr>
> Cc: 74111@debbugs.gnu.org
> Date: Thu, 31 Oct 2024 17:04:22 +0100
> 
> >> 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?

LGTM, thanks.

> I removed the
> "PageUp" comment as it does not seem to work (while 'M-v' is)

PageUp does work here, so I think we should leave that sentence, but
modify it to say "M-v/PageUp".

> +*** New user option 'tmm-shortcut-inside-entry'.
> +When non-nil, insert the character shortcut of a menu entry inside its

The "insert...inside its string" is not really accurate, is it?  The
code tries to highlight a character that already exists in the choice
string, and prepends a digit if it fails to find such a character.

> +(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."

Same here.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#74111: [PATCH] New `tmm-menubar' shortcut display style
  2024-10-31 16:57             ` Eli Zaretskii
@ 2024-10-31 22:07               ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-11-01  7:16                 ` Eli Zaretskii
  0 siblings, 1 reply; 15+ messages in thread
From: Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-10-31 22:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 74111

[-- Attachment #1: Type: text/plain, Size: 1494 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Manuel Giraud <manuel@ledu-giraud.fr>
>> Cc: 74111@debbugs.gnu.org
>> Date: Thu, 31 Oct 2024 17:04:22 +0100
>> 
>> >> 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?
>
> LGTM, thanks.
>
>> I removed the
>> "PageUp" comment as it does not seem to work (while 'M-v' is)
>
> PageUp does work here, so I think we should leave that sentence, but
> modify it to say "M-v/PageUp".
>
>> +*** New user option 'tmm-shortcut-inside-entry'.
>> +When non-nil, insert the character shortcut of a menu entry inside its
>
> The "insert...inside its string" is not really accurate, is it?  The
> code tries to highlight a character that already exists in the choice
> string, and prepends a digit if it fails to find such a character.
>
>> +(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."
>
> Same here.

Here is a new version taking your remarks into account.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-New-tmm-menubar-shortcut-display-style.patch --]
[-- Type: text/x-patch, Size: 6859 bytes --]

From dbaf9698dc176b8eb64c3373808943cede2b4bce Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
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    |  5 ++++
 lisp/tmm.el | 69 ++++++++++++++++++++++++++++++++++++++---------------
 2 files changed, 55 insertions(+), 19 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index d1c7303f976..db13a1dd971 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -584,6 +584,11 @@ 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, highlight the character shortcut in the menu entry's
+string instead of preprending it and `tmm-mid-prompt' to said entry.
+
 ** Foldout
 
 ---
diff --git a/lisp/tmm.el b/lisp/tmm.el
index 252c1e45afa..1992ff0f73c 100644
--- a/lisp/tmm.el
+++ b/lisp/tmm.el
@@ -83,11 +83,11 @@ 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
+  "Press M-v/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 ^ 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 +108,13 @@ tmm-shortcut-words
 specify nil for this variable."
   :type '(choice integer (const nil)))
 
+(defcustom tmm-shortcut-inside-entry nil
+  "Highlight the shortcut character in the menu entry's string.
+When non-nil, the shortcut character will be highlighted into its menu
+entry's string with the `highlight' 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)
@@ -384,7 +407,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 +434,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


[-- Attachment #3: Type: text/plain, Size: 18 bytes --]

-- 
Manuel Giraud

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#74111: [PATCH] New `tmm-menubar' shortcut display style
  2024-10-31 22:07               ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-11-01  7:16                 ` Eli Zaretskii
  2024-11-01  9:31                   ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-11-01 14:25                   ` Howard Melman
  0 siblings, 2 replies; 15+ messages in thread
From: Eli Zaretskii @ 2024-11-01  7:16 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: 74111

> From: Manuel Giraud <manuel@ledu-giraud.fr>
> Cc: 74111@debbugs.gnu.org
> Date: Thu, 31 Oct 2024 23:07:00 +0100
> 
> Here is a new version taking your remarks into account.

Thanks, just a few nits now:

> +(defcustom tmm-shortcut-inside-entry nil
> +  "Highlight the shortcut character in the menu entry's string.
> +When non-nil, the shortcut character will be highlighted into its menu
> +entry's string with the `highlight' face to help identifying it.

I'd rephrase the last sentence like this:

  When non-nil, the first menu-entry's character that acts as a
  shortcut will be highlighted with the `highlight' face to help
  identifying it.

> +        ;; A nil value for pos means that the shortcut is not inside the
> +        ;; string of the menu entry

Please end this comment with a period.  Likewise elsewhere in the
patch.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#74111: [PATCH] New `tmm-menubar' shortcut display style
  2024-11-01  7:16                 ` Eli Zaretskii
@ 2024-11-01  9:31                   ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-11-01 12:11                     ` Eli Zaretskii
  2024-11-01 14:25                   ` Howard Melman
  1 sibling, 1 reply; 15+ messages in thread
From: Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-11-01  9:31 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 74111

[-- Attachment #1: Type: text/plain, Size: 163 bytes --]

Hi,

I think I have address all the left issues with this patch.  I've also
updated the log: tell me what you think and feel free to reword it if
needed.  Thanks.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-New-tmm-menubar-shortcut-display-style.patch --]
[-- Type: text/x-patch, Size: 7487 bytes --]

From 28102a18a9edbdcc85ffd5254a8968611a25615d Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
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 highlighted inside the menu
entry's string.
(tmm-add-one-shortcut): Compute the new shortcut style.
(tmm-add-prompt, tmm-completion-prompt): Adapt the completion
prompt according to the shortcut display style.
(tmm-prompt): Adapt the prompt regexp.
(tmm-shortcut): Simplify default case and make it work with this
change.
* etc/NEWS: Announce the option.
---
 etc/NEWS    |  5 ++++
 lisp/tmm.el | 73 ++++++++++++++++++++++++++++++++++++++---------------
 2 files changed, 58 insertions(+), 20 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index d1c7303f976..db13a1dd971 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -584,6 +584,11 @@ 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, highlight the character shortcut in the menu entry's
+string instead of preprending it and `tmm-mid-prompt' to said entry.
+
 ** Foldout
 
 ---
diff --git a/lisp/tmm.el b/lisp/tmm.el
index 252c1e45afa..80991b246b6 100644
--- a/lisp/tmm.el
+++ b/lisp/tmm.el
@@ -83,11 +83,11 @@ 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
+  "Press M-v/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 ^ 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 +108,13 @@ tmm-shortcut-words
 specify nil for this variable."
   :type '(choice integer (const nil)))
 
+(defcustom tmm-shortcut-inside-entry nil
+  "Highlight the shortcut character in the menu entry's string.
+When non-nil, the first menu-entry's character that acts as a shortcut
+will be highlighted with the `highlight' 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,34 @@ 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)
@@ -328,7 +353,7 @@ tmm-define-keys
       (define-key map "\ev" 'tmm-goto-completions)
       (define-key map "\C-n" 'next-history-element)
       (define-key map "\C-p" 'previous-history-element)
-      ;; Previous menu shortcut (see `tmm-prompt')
+      ;; Previous menu shortcut (see `tmm-prompt').
       (define-key map "^" 'self-insert-and-exit))
     (prog1 (current-local-map)
       (use-local-map (append map (current-local-map))))))
@@ -384,7 +409,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 +436,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


[-- Attachment #3: Type: text/plain, Size: 18 bytes --]

-- 
Manuel Giraud

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#74111: [PATCH] New `tmm-menubar' shortcut display style
  2024-11-01  9:31                   ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-11-01 12:11                     ` Eli Zaretskii
  0 siblings, 0 replies; 15+ messages in thread
From: Eli Zaretskii @ 2024-11-01 12:11 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: 74111-done

> From: Manuel Giraud <manuel@ledu-giraud.fr>
> Cc: 74111@debbugs.gnu.org
> Date: Fri, 01 Nov 2024 10:31:20 +0100
> 
> I think I have address all the left issues with this patch.  I've also
> updated the log: tell me what you think and feel free to reword it if
> needed.  Thanks.

Thanks, installed on the master branch.

The commit log message was okay, but please don't leave an empty line
between the change entries and the preceding text that is not the
header line.  (I deleted that empty line this time when installing the
changes.)

I'm therefore closing this bug.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#74111: [PATCH] New `tmm-menubar' shortcut display style
  2024-11-01  7:16                 ` Eli Zaretskii
  2024-11-01  9:31                   ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-11-01 14:25                   ` Howard Melman
  2024-11-01 17:34                     ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 15+ messages in thread
From: Howard Melman @ 2024-11-01 14:25 UTC (permalink / raw)
  To: 74111

Eli Zaretskii <eliz@gnu.org> writes:

> I'd rephrase the last sentence like this:
>
>   When non-nil, the first menu-entry's character that acts as a
>   shortcut will be highlighted with the `highlight' face to help
>   identifying it.

That should be "to help identify it."

I think this would be a little better:

    When non-nil, the first menu-entry's character that acts as a
    shortcut is displayed with the `highlight' face to help identify it.

-- 

Howard






^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#74111: [PATCH] New `tmm-menubar' shortcut display style
  2024-11-01 14:25                   ` Howard Melman
@ 2024-11-01 17:34                     ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 15+ messages in thread
From: Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-11-01 17:34 UTC (permalink / raw)
  To: Howard Melman; +Cc: Eli Zaretskii, 74111

[-- Attachment #1: Type: text/plain, Size: 567 bytes --]

Howard Melman <hmelman@gmail.com> writes:

> Eli Zaretskii <eliz@gnu.org> writes:
>
>> I'd rephrase the last sentence like this:
>>
>>   When non-nil, the first menu-entry's character that acts as a
>>   shortcut will be highlighted with the `highlight' face to help
>>   identifying it.
>
> That should be "to help identify it."
>
> I think this would be a little better:
>
>     When non-nil, the first menu-entry's character that acts as a
>     shortcut is displayed with the `highlight' face to help identify
>     it.

Thanks.  Here's a fix to apply on master.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-tmm-shortcut-inside-entry-docstring-fix.patch --]
[-- Type: text/x-patch, Size: 962 bytes --]

From 44520536c998d4cad90f4e5fc1dca5aba28afa53 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
Date: Fri, 1 Nov 2024 18:30:40 +0100
Subject: [PATCH] `tmm-shortcut-inside-entry' docstring fix

* lisp/tmm.el (tmm-shortcut-inside-entry): Docstring fix.
---
 lisp/tmm.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/tmm.el b/lisp/tmm.el
index 80991b246b6..eeea1cf20be 100644
--- a/lisp/tmm.el
+++ b/lisp/tmm.el
@@ -111,8 +111,8 @@ tmm-shortcut-words
 (defcustom tmm-shortcut-inside-entry nil
   "Highlight the shortcut character in the menu entry's string.
 When non-nil, the first menu-entry's character that acts as a shortcut
-will be highlighted with the `highlight' face to help identifying it.
-The `tmm-mid-prompt' string is not used then."
+is displayed with the `highlight' face to help identify it.  The
+`tmm-mid-prompt' string is not used then."
   :type 'boolean)
 
 (defface tmm-inactive
-- 
2.47.0


[-- Attachment #3: Type: text/plain, Size: 18 bytes --]

-- 
Manuel Giraud

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2024-11-01 17:34 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-30 16:35 bug#74111: [PATCH] New `tmm-menubar' shortcut display style Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-31  9:46 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-31 10:04 ` Eli Zaretskii
2024-10-31 10:28   ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-31 10:50     ` Eli Zaretskii
2024-10-31 11:48       ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-31 14:25         ` Eli Zaretskii
2024-10-31 16:04           ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-31 16:57             ` Eli Zaretskii
2024-10-31 22:07               ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-01  7:16                 ` Eli Zaretskii
2024-11-01  9:31                   ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-01 12:11                     ` Eli Zaretskii
2024-11-01 14:25                   ` Howard Melman
2024-11-01 17:34                     ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors

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).