bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#62250: 29.0.60; Allow context menu from text properties to not overr


From: Juri Linkov
Subject: bug#62250: 29.0.60; Allow context menu from text properties to not override everything
Date: Sun, 19 Mar 2023 19:43:28 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu)

>> I already envisioned such request
>
> All right.  Just for the record, this would be useful to create a
> context menu for images.

The patch below will allow using the text property like

  'context-menu-functions '(image-context-menu)

> Also, I could take advantage of it to slightly
> simplify the context menu of jit-spell.

Actually, flyspell was the reason why the text property
`context-menu-function' overrides everything:

1. `make-flyspell-overlay' puts an overlay property

   (overlay-put overlay 'context-menu-function 'flyspell-context-menu)

2. `flyspell-context-menu' returns `flyspell-correct-word'

3. `context-menu-map' should return this symbol unmodified

4. at the end, the symbol `flyspell-correct-word' is executed
   as a command from the menu binding in `context-menu-entry'
   or from `context-menu-open':

    (if (commandp map)
        (call-interactively map)

diff --git a/lisp/mouse.el b/lisp/mouse.el
index 6b9accd6758..2cd2840bad9 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -368,9 +368,10 @@ context-menu-map
 the function `context-menu-filter-function'."
   (let* ((menu (make-sparse-keymap (propertize "Context Menu" 'hide t)))
          (click (or click last-input-event))
-         (window (posn-window (event-start click)))
-         (fun (mouse-posn-property (event-start click)
-                                   'context-menu-function)))
+         (start (event-start click))
+         (window (posn-window start))
+         (fun (mouse-posn-property start 'context-menu-function))
+         (funs (mouse-posn-property start 'context-menu-functions)))
 
     (unless (eq (selected-window) window)
       (select-window window))
@@ -380,7 +381,9 @@ context-menu-map
       (run-hook-wrapped 'context-menu-functions
                         (lambda (fun)
                           (setq menu (funcall fun menu click))
-                          nil)))
+                          nil))
+      (dolist (fun funs)
+        (setq menu (funcall fun menu click))))
 
     ;; Remove duplicate separators as well as ones at the beginning or
     ;; end of the menu.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]