unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#52293: 29.0.50; [PATCH] Prevent further cases of duplicated separators in context menus
@ 2021-12-05  5:58 Jim Porter
  2021-12-05  9:39 ` Juri Linkov
  2021-12-05 17:59 ` Juri Linkov
  0 siblings, 2 replies; 53+ messages in thread
From: Jim Porter @ 2021-12-05  5:58 UTC (permalink / raw)
  To: 52293

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

This is a followup to bug#52237. I'll just quote my message describing 
the issue from there[1]:

> I found another odd case, but I'm not 100% sure the best way to fix it:
> 
>   emacs -Q --eval '(context-menu-mode)'
>   C-h o identity RET
>   ;; Right-click somewhere in the Help buffer
> 
> There's a doubled separator after "Next Topic". Looking at the code, this is because `help-mode-context-menu' inserts new items using `define-key', which has the effect of putting the new items *before* the (hidden) menu title. The resulting keymap ends up looking like this:
> 
>   (keymap
>    (Previous\ Topic ...)
>    (Next\ Topic ...)
>    (help-mode-separator "--")
>    #("Context Menu" 0 12 (hide t))
>    (separator-undo "--")
>    ...)
> 
> Since there's a hidden item (the keymap title) between the `help-mode-separator' and `separator-undo'[1], the de-duplication doesn't handle that.

Attached is a patch to fix this based on the discussion in bug#52237. 
One slightly odd thing is that for context menu functions that put their 
items at the top, they place their separator *below* the items. Other 
functions place the separator *above* the items. It might be too late to 
fix this though, given that Emacs 28 is only open for fixing 
regressions, and changing it in 29 would be a (small) compatibility 
break. However, I can update the patch to put the separators in these 
functions at the top if people think that's best.

[1] https://lists.gnu.org/archive/html/bug-gnu-emacs/2021-12/msg00143.html

[-- Attachment #2: 0001-Add-a-top-separator-to-the-context-menu.patch --]
[-- Type: text/plain, Size: 9036 bytes --]

From 2b395a2cb1efca85cdca992804b614cdf2641413 Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Sat, 4 Dec 2021 21:42:57 -0800
Subject: [PATCH] Add a 'top-separator' to the context menu

This provides an anchor for context menu functions to use to insert
their menu items after it. Using 'define-key' doesn't work properly in
this case, since it inserts the items before the menu title, confusing
the separator de-duplication in 'context-menu-map'.

* lisp/mouse.el (context-menu-top-separator): New function.
(context-menu-functions): Use it.
* lisp/dired.el (dired-context-menu):
* lisp/help-mode.el (help-mode-context-menu):
* lisp/info.el (Info-context-menu):
* lisp/net/eww.el (eww-context-menu):
* lisp/net/goto-addr.el (goto-address-context-menu):
Use 'top-separator'.
---
 lisp/dired.el         |  5 +++--
 lisp/help-mode.el     | 10 ++++++----
 lisp/info.el          |  9 +++++----
 lisp/mouse.el         | 12 ++++++++++--
 lisp/net/eww.el       | 14 ++++++++------
 lisp/net/goto-addr.el |  8 +++++---
 6 files changed, 37 insertions(+), 21 deletions(-)

diff --git a/lisp/dired.el b/lisp/dired.el
index d0e547ba0b..b004d81495 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2282,7 +2282,7 @@ dired-mode-operate-menu
 (defun dired-context-menu (menu click)
   "Populate MENU with Dired mode commands at CLICK."
   (when (mouse-posn-property (event-start click) 'dired-filename)
-    (define-key menu [dired-separator] menu-bar-separator)
+    (define-key-after menu [dired-separator] menu-bar-separator 'top-separator)
     (let ((easy-menu (make-sparse-keymap "Immediate")))
       (easy-menu-define nil easy-menu nil
         '("Immediate"
@@ -2292,7 +2292,8 @@ dired-context-menu
            :help "Edit file at mouse click in other window"]))
       (dolist (item (reverse (lookup-key easy-menu [menu-bar immediate])))
         (when (consp item)
-          (define-key menu (vector (car item)) (cdr item))))))
+          (define-key-after menu (vector (car item)) (cdr item)
+            'top-separator)))))
   menu)
 
 \f
diff --git a/lisp/help-mode.el b/lisp/help-mode.el
index 792f2e5af3..2ed20577f5 100644
--- a/lisp/help-mode.el
+++ b/lisp/help-mode.el
@@ -74,7 +74,8 @@ help-mode-menu
 
 (defun help-mode-context-menu (menu click)
   "Populate MENU with Help mode commands at CLICK."
-  (define-key menu [help-mode-separator] menu-bar-separator)
+  (define-key-after menu [help-mode-separator] menu-bar-separator
+    'top-separator)
   (let ((easy-menu (make-sparse-keymap "Help-Mode")))
     (easy-menu-define nil easy-menu nil
       '("Help-Mode"
@@ -86,14 +87,15 @@ help-mode-context-menu
          :active help-xref-forward-stack]))
     (dolist (item (reverse (lookup-key easy-menu [menu-bar help-mode])))
       (when (consp item)
-        (define-key menu (vector (car item)) (cdr item)))))
+        (define-key-after menu (vector (car item)) (cdr item) 'top-separator))))
 
   (when (mouse-posn-property (event-start click) 'mouse-face)
-    (define-key menu [help-mode-push-button]
+    (define-key-after menu [help-mode-push-button]
       '(menu-item "Follow Link" (lambda (event)
                                   (interactive "e")
                                   (push-button event))
-                  :help "Follow the link at click")))
+                  :help "Follow the link at click")
+      'top-separator))
 
   menu)
 
diff --git a/lisp/info.el b/lisp/info.el
index 94537c2417..76963af41c 100644
--- a/lisp/info.el
+++ b/lisp/info.el
@@ -4191,7 +4191,7 @@ Info-check-pointer
 
 (defun Info-context-menu (menu click)
   "Populate MENU with Info commands at CLICK."
-  (define-key menu [Info-separator] menu-bar-separator)
+  (define-key-after menu [Info-separator] menu-bar-separator 'top-separator)
   (let ((easy-menu (make-sparse-keymap "Info")))
     (easy-menu-define nil easy-menu nil
       '("Info"
@@ -4201,12 +4201,13 @@ Info-context-menu
          :help "Go forward in history"]))
     (dolist (item (reverse (lookup-key easy-menu [menu-bar info])))
       (when (consp item)
-        (define-key menu (vector (car item)) (cdr item)))))
+        (define-key-after menu (vector (car item)) (cdr item) 'top-separator))))
 
   (when (mouse-posn-property (event-start click) 'mouse-face)
-    (define-key menu [Info-mouse-follow-nearest-node]
+    (define-key-after menu [Info-mouse-follow-nearest-node]
       '(menu-item "Follow Link" Info-mouse-follow-nearest-node
-                  :help "Follow a link where you click")))
+                  :help "Follow a link where you click")
+      'top-separator))
 
   menu)
 
diff --git a/lisp/mouse.el b/lisp/mouse.el
index b5ca80a446..a7a7bb6eae 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -279,7 +279,8 @@ mouse-menu-bar-map
 \f
 ;; Context menus.
 
-(defcustom context-menu-functions '(context-menu-undo
+(defcustom context-menu-functions '(context-menu-top-separator
+                                    context-menu-undo
                                     context-menu-region
                                     context-menu-middle-separator
                                     context-menu-local
@@ -288,7 +289,8 @@ context-menu-functions
 Each function receives the menu and the mouse click event as its arguments
 and should return the same menu with changes such as added new menu items."
   :type '(repeat
-          (choice (function-item context-menu-undo)
+          (choice (function-item context-menu-top-separator)
+                  (function-item context-menu-undo)
                   (function-item context-menu-region)
                   (function-item context-menu-middle-separator)
                   (function-item context-menu-toolbar)
@@ -348,6 +350,12 @@ context-menu-map
       (setq menu (funcall context-menu-filter-function menu click)))
     menu))
 
+(defun context-menu-top-separator (menu _click)
+  "Add separator to the top of the context menu.
+Some context functions add menu items below the separator."
+  (define-key-after menu [top-separator] menu-bar-separator)
+  menu)
+
 (defun context-menu-middle-separator (menu _click)
   "Add separator to the middle of the context menu.
 Some context functions add menu items below the separator."
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index e86d21f889..7303e01a37 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -1106,7 +1106,7 @@ eww-mode-map
 
 (defun eww-context-menu (menu click)
   "Populate MENU with eww commands at CLICK."
-  (define-key menu [eww-separator] menu-bar-separator)
+  (define-key-after menu [eww-separator] menu-bar-separator 'top-separator)
   (let ((easy-menu (make-sparse-keymap "Eww")))
     (easy-menu-define nil easy-menu nil
       '("Eww"
@@ -1117,20 +1117,22 @@ eww-context-menu
 	["Reload" eww-reload t]))
     (dolist (item (reverse (lookup-key easy-menu [menu-bar eww])))
       (when (consp item)
-        (define-key menu (vector (car item)) (cdr item)))))
+        (define-key-after menu (vector (car item)) (cdr item) 'top-separator))))
 
   (when (or (mouse-posn-property (event-start click) 'shr-url)
             (mouse-posn-property (event-start click) 'image-url))
-    (define-key menu [shr-mouse-browse-url-new-window]
+    (define-key-after menu [shr-mouse-browse-url-new-window]
       `(menu-item "Follow URL in new window" ,(if browse-url-new-window-flag
                                                   'shr-mouse-browse-url
                                                 'shr-mouse-browse-url-new-window)
-                  :help "Browse the URL under the mouse cursor in a new window"))
-    (define-key menu [shr-mouse-browse-url]
+                  :help "Browse the URL under the mouse cursor in a new window")
+      'top-separator)
+    (define-key-after menu [shr-mouse-browse-url]
       `(menu-item "Follow URL" ,(if browse-url-new-window-flag
                                     'shr-mouse-browse-url-new-window
                                   'shr-mouse-browse-url)
-                  :help "Browse the URL under the mouse cursor")))
+                  :help "Browse the URL under the mouse cursor")
+      'top-separator))
 
   menu)
 
diff --git a/lisp/net/goto-addr.el b/lisp/net/goto-addr.el
index 848bad3b0d..bb0f0b00ee 100644
--- a/lisp/net/goto-addr.el
+++ b/lisp/net/goto-addr.el
@@ -127,10 +127,12 @@ goto-address-highlight-keymap
 (defun goto-address-context-menu (menu click)
   "Populate MENU with `goto-address' commands at CLICK."
   (when (mouse-posn-property (event-start click) 'goto-address)
-    (define-key menu [goto-address-separator] menu-bar-separator)
-    (define-key menu [goto-address-at-mouse]
+    (define-key-after menu [goto-address-separator] menu-bar-separator
+      'top-separator)
+    (define-key-after menu [goto-address-at-mouse]
       '(menu-item "Follow Link" goto-address-at-mouse
-                  :help "Follow a link where you click")))
+                  :help "Follow a link where you click")
+      'top-separator))
   menu)
 
 (defcustom goto-address-url-face 'link
-- 
2.25.1


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

end of thread, other threads:[~2022-01-04 21:14 UTC | newest]

Thread overview: 53+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-05  5:58 bug#52293: 29.0.50; [PATCH] Prevent further cases of duplicated separators in context menus Jim Porter
2021-12-05  9:39 ` Juri Linkov
2021-12-06  4:07   ` Jim Porter
2021-12-05 17:59 ` Juri Linkov
2021-12-06  4:50   ` Jim Porter
2021-12-06  9:23     ` Juri Linkov
2021-12-07  3:54       ` bug#52293: 29.0.50; [PATCH v2] " Jim Porter
2021-12-07  8:19         ` Juri Linkov
2021-12-08  4:37           ` bug#52293: 29.0.50; [PATCH v3] " Jim Porter
2021-12-08 12:59             ` Eli Zaretskii
2021-12-08 17:43               ` Jim Porter
2021-12-08 19:07               ` Juri Linkov
2021-12-08 19:47                 ` Eli Zaretskii
2021-12-09  9:06                   ` Juri Linkov
2021-12-09  9:39                     ` Eli Zaretskii
2021-12-12  4:02                       ` Jim Porter
2021-12-12  7:02                         ` Eli Zaretskii
2021-12-12 20:27                           ` Jim Porter
2021-12-12 20:43                             ` Eli Zaretskii
2021-12-12 21:59                               ` Jim Porter
2021-12-13 12:23                                 ` Eli Zaretskii
2021-12-13 18:13                                   ` Jim Porter
2021-12-12 21:00                             ` bug#52293: [External] : " Drew Adams
2021-12-12 22:12                               ` Jim Porter
2021-12-12 23:14                                 ` Jim Porter
2021-12-13  1:16                                 ` Drew Adams
2021-12-13  1:46                                   ` Jim Porter
2021-12-13  2:41                                     ` Drew Adams
2021-12-13  8:47                                     ` Juri Linkov
2021-12-13 17:25                                       ` Jim Porter
2021-12-13 18:58                                         ` Juri Linkov
2021-12-14  5:41                                           ` Jim Porter
2021-12-14  8:30                                             ` Juri Linkov
2021-12-14 13:04                                               ` Eli Zaretskii
2021-12-14 16:49                                                 ` Drew Adams
2021-12-14 20:51                                                   ` Juri Linkov
2021-12-14 22:02                                                     ` Drew Adams
2021-12-15  8:59                                                       ` Juri Linkov
2021-12-15 18:10                                                         ` Drew Adams
2021-12-15 18:24                                                           ` Juri Linkov
2021-12-15 21:36                                                             ` Drew Adams
2021-12-16 17:20                                                               ` Juri Linkov
2021-12-16 17:51                                                                 ` Drew Adams
2021-12-16 17:56                                                                   ` Drew Adams
2021-12-17  8:20                                                                   ` Juri Linkov
2021-12-17 17:21                                                                     ` Drew Adams
2021-12-15  0:17                                               ` Jim Porter
2021-12-15  8:57                                                 ` Juri Linkov
2022-01-01  7:13                                                   ` Jim Porter
2022-01-02 19:27                                                     ` Juri Linkov
2022-01-03  6:14                                                       ` bug#52293: 29.0.50; [PATCH v4] " Jim Porter
2022-01-04  8:19                                                         ` Juri Linkov
2022-01-04 21:14                                                           ` Jim Porter

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