unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: 50067@debbugs.gnu.org
Subject: bug#50067: Context menus
Date: Mon, 27 Sep 2021 18:30:23 +0300	[thread overview]
Message-ID: <877df211vs.fsf@mail.linkov.net> (raw)
In-Reply-To: <87pmufb3u0.fsf@mail.linkov.net> (Juri Linkov's message of "Sun,  15 Aug 2021 11:48:55 +0300")

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

Other programs don't show the keys in context menus.
The Human Interface Guidelines say:

  Show keyboard shortcuts in menu bar menus, not contextual menus.
  Contextual menus are already shortcuts to task-specific commands;
  it's redundant to display keyboard shortcuts too.

This patch hides all keys from the context menus:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: inhibit-menu-keys.patch --]
[-- Type: text/x-diff, Size: 3680 bytes --]

diff --git a/lisp/mouse.el b/lisp/mouse.el
index 5f3db46516..2d9b1c8f0b 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -314,7 +314,9 @@ context-menu-map
 it overrides all functions from `context-menu-functions'.
 At the end, it's possible to modify the final menu by specifying
 the function `context-menu-filter-function'."
-  (let* ((menu (make-sparse-keymap (propertize "Context Menu" 'hide t)))
+  (let* ((menu (make-sparse-keymap (propertize "Context Menu"
+                                               'hide t
+                                               'no-keys t)))
          (click (or click last-input-event))
          (fun (mouse-posn-property (event-start click)
                                    'context-menu-function)))
diff --git a/src/keyboard.c b/src/keyboard.c
index 462b415c1d..8c90292137 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -7832,16 +7832,20 @@ parse_menu_item (Lisp_Object item, int inmenubar)
 		filter = item;
 	      else if (EQ (tem, QCkey_sequence))
 		{
-		  tem = XCAR (item);
-		  if (SYMBOLP (tem) || STRINGP (tem) || VECTORP (tem))
-		    /* Be GC protected. Set keyhint to item instead of tem.  */
-		    keyhint = item;
-		}
+		  if (!inhibit_menu_keys)
+		    {
+		      tem = XCAR (item);
+		      if (SYMBOLP (tem) || STRINGP (tem) || VECTORP (tem))
+			/* Be GC protected. Set keyhint to item instead of tem.  */
+			keyhint = item;
+		    }		}
 	      else if (EQ (tem, QCkeys))
 		{
-		  tem = XCAR (item);
-		  if (CONSP (tem) || STRINGP (tem))
-		    ASET (item_properties, ITEM_PROPERTY_KEYEQ, tem);
+		  if (!inhibit_menu_keys){
+		    tem = XCAR (item);
+		    if (CONSP (tem) || STRINGP (tem))
+		      ASET (item_properties, ITEM_PROPERTY_KEYEQ, tem);
+		  }
 		}
 	      else if (EQ (tem, QCbutton) && CONSP (XCAR (item)))
 		{
@@ -7916,6 +7920,7 @@ parse_menu_item (Lisp_Object item, int inmenubar)
   if (inmenubar > 0)
     return 1;
 
+  if (!inhibit_menu_keys)
   { /* This is a command.  See if there is an equivalent key binding.  */
     Lisp_Object keyeq = AREF (item_properties, ITEM_PROPERTY_KEYEQ);
     AUTO_STRING (space_space, "  ");
@@ -12495,6 +12500,11 @@ syms_of_keyboard (void)
                Vwhile_no_input_ignore_events,
                doc: /* Ignored events from while-no-input.  */);
 
+  DEFVAR_BOOL ("inhibit-menu-keys",
+               inhibit_menu_keys,
+               doc: /* If non-nil, inhibit menu keys.  */);
+  inhibit_menu_keys = false;
+
   pdumper_do_now_and_after_load (syms_of_keyboard_for_pdumper);
 }
 
diff --git a/src/menu.c b/src/menu.c
index 1aafa78c3c..e7e7ecca6a 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -1281,13 +1281,18 @@ x_popup_menu_1 (Lisp_Object position, Lisp_Object menu)
       /* We were given a keymap.  Extract menu info from the keymap.  */
       Lisp_Object prompt;
 
-      /* Extract the detailed info to make one pane.  */
-      keymap_panes (&menu, 1);
-
       /* Search for a string appearing directly as an element of the keymap.
 	 That string is the title of the menu.  */
       prompt = Fkeymap_prompt (keymap);
 
+      if (STRINGP (prompt)
+	  && SCHARS (prompt) > 0
+	  && !NILP (Fget_text_property (make_fixnum (0), Qno_keys, prompt)))
+      specbind (Qinhibit_menu_keys, Qt);
+
+      /* Extract the detailed info to make one pane.  */
+      keymap_panes (&menu, 1);
+
 #if defined (USE_GTK) || defined (HAVE_NS)
       if (STRINGP (prompt)
 	  && SCHARS (prompt) > 0
@@ -1583,6 +1588,8 @@ syms_of_menu (void)
   staticpro (&menu_items);
 
   DEFSYM (Qhide, "hide");
+  DEFSYM (Qno_keys, "no-keys");
+  DEFSYM (Qinhibit_menu_keys, "inhibit-menu-keys");
 
   defsubr (&Sx_popup_menu);
   defsubr (&Sx_popup_dialog);

  parent reply	other threads:[~2021-09-27 15:30 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-15  8:48 bug#50067: Context menus Juri Linkov
2021-08-15 11:56 ` Lars Ingebrigtsen
2021-08-15 16:12   ` Juri Linkov
2021-08-16 11:31     ` Lars Ingebrigtsen
2021-08-17  8:12       ` Juri Linkov
2021-08-18  4:38         ` Tak Kunihiro
2021-08-18  7:47           ` Juri Linkov
2021-08-28  9:08 ` Naoya Yamashita
2021-08-28 18:50   ` Juri Linkov
2021-09-27 15:30 ` Juri Linkov [this message]
2021-09-27 15:50   ` Lars Ingebrigtsen
2021-09-27 16:17     ` bug#50067: [External] : " Drew Adams
2021-09-28 18:49     ` Juri Linkov
2021-09-28 22:08       ` bug#50067: [External] : " Drew Adams
2021-09-29  7:00       ` Juri Linkov
2021-09-27 18:41   ` Eli Zaretskii
2021-09-28 18:54     ` Juri Linkov
2021-09-28 19:31       ` Eli Zaretskii
2021-09-27 15:33 ` Juri Linkov
2021-10-20 16:59 ` Juri Linkov
2021-11-08 20:05   ` Juri Linkov
2021-11-18 18:38     ` Juri Linkov
2021-11-25  7:50       ` Juri Linkov
2021-11-25  8:38         ` Eli Zaretskii
2021-11-25 19:28           ` Juri Linkov
2021-11-30 18:12             ` Juri Linkov
     [not found] <74BC00E9-2509-47DA-9428-1523FF7F3B33@acm.org>
2021-08-18 16:42 ` Juri Linkov
2021-08-18 17:46   ` Mattias Engdegård
2021-08-18 17:53     ` Eli Zaretskii
2021-08-19 14:22     ` Mattias Engdegård
2021-08-20  7:31       ` Juri Linkov
2021-08-20 17:06         ` Mattias Engdegård
2021-08-20 23:31           ` Dmitry Gutov
2021-08-21  4:43         ` Tak Kunihiro
2021-08-21  6:33           ` Tak Kunihiro
2021-08-22  8:28           ` Juri Linkov
2021-08-23  3:11             ` Tak Kunihiro
2021-08-23  7:24               ` Juri Linkov
2021-08-24 10:12                 ` Tak Kunihiro
2021-08-24 17:23                   ` Juri Linkov
2021-08-24 23:43                     ` Tak Kunihiro
2021-08-25 17:45                       ` Juri Linkov
2021-08-26  6:13                         ` Juri Linkov
2021-08-27  6:24                           ` Juri Linkov
2021-08-28  5:18                             ` Tak Kunihiro
2021-08-31 17:37                 ` Juri Linkov
2021-08-31 17:43               ` Juri Linkov
2021-08-31 18:58                 ` Eli Zaretskii
2021-09-01  7:12                   ` Juri Linkov
2021-08-18 17:46   ` Eli Zaretskii
2021-08-18 18:01     ` Mattias Engdegård
2021-08-18 18:11       ` Eli Zaretskii
2021-08-18 18:06     ` Juri Linkov
2021-08-18 18:12       ` Eli Zaretskii
2021-08-18 18:39         ` Eli Zaretskii
2021-08-19  1:31           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-19  6:44             ` Eli Zaretskii
2021-08-18 18:40         ` Juri Linkov
2021-08-18 18:59           ` Eli Zaretskii
2021-08-19  7:12             ` Juri Linkov
2021-08-19  7:57               ` Eli Zaretskii
2021-08-20  7:29                 ` Juri Linkov
2021-08-20 10:29                   ` Mattias Engdegård
2021-08-20 10:53                     ` Eli Zaretskii
2021-08-20 11:32                       ` Mattias Engdegård
2021-08-20 16:50                         ` Juri Linkov
2021-08-20 17:11                           ` Mattias Engdegård
2021-08-20 11:32                   ` Eli Zaretskii
2021-08-20 16:36                     ` Juri Linkov
2021-08-20 17:59                       ` Eli Zaretskii
2021-08-20 19:29                         ` Mattias Engdegård
2021-08-21  9:42                           ` Alan Third
2021-08-21 10:57                             ` Mattias Engdegård
2021-08-21 11:17                               ` Eli Zaretskii
2021-08-21 11:45                                 ` Mattias Engdegård
2021-08-21 12:16                                   ` Eli Zaretskii
2021-08-22 19:11                                     ` Dmitry Gutov
2021-08-22 19:22                                       ` Eli Zaretskii
2021-08-22 19:54                                         ` Dmitry Gutov
2021-08-23  2:21                                           ` Eli Zaretskii
2021-08-23 11:18                                             ` Dmitry Gutov
2021-08-23 11:40                                               ` Eli Zaretskii
2021-08-23 16:02                                                 ` Juri Linkov
2021-08-24 17:59                                                   ` Dmitry Gutov
2021-08-25 14:15                                                     ` Dmitry Gutov
2021-08-25 15:59                                                       ` Eli Zaretskii
2021-08-26 13:01                                                     ` Eli Zaretskii
2021-08-26 21:05                                                       ` Dmitry Gutov
2021-08-26 21:07                                                         ` Dmitry Gutov
2021-08-27  6:13                                                           ` Juri Linkov
2021-08-27  6:26                                                         ` Eli Zaretskii
2021-08-30  2:45                                                           ` Dmitry Gutov
2021-08-30 11:57                                                             ` Eli Zaretskii
2021-08-31  7:05                                                               ` Juri Linkov
2021-08-31 12:24                                                                 ` Dmitry Gutov
2021-08-31 16:56                                                                   ` Juri Linkov
2021-08-31 20:23                                                                     ` Dmitry Gutov
2021-09-01  7:08                                                                       ` Juri Linkov
2021-09-01 19:03                                                                         ` Dmitry Gutov
2021-09-05  0:55                                                                         ` Dmitry Gutov
2021-09-05  8:37                                                                           ` Juri Linkov
2021-09-05 19:25                                                                             ` Dmitry Gutov
2021-08-22  8:46                         ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877df211vs.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=50067@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).