GNU bug report logs - #62250
29.0.60; Allow context menu from text properties to not override everything

Previous Next

Package: emacs;

Reported by: Augusto Stoffel <arstoffel <at> gmail.com>

Date: Sat, 18 Mar 2023 07:52:01 UTC

Severity: wishlist

Found in version 29.0.60

Fixed in version 30.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 62250 in the body.
You can then email your comments to 62250 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to juri <at> linkov.net, bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Sat, 18 Mar 2023 07:52:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Augusto Stoffel <arstoffel <at> gmail.com>:
New bug report received and forwarded. Copy sent to juri <at> linkov.net, bug-gnu-emacs <at> gnu.org. (Sat, 18 Mar 2023 07:52:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Augusto Stoffel <arstoffel <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.60; Allow context menu from text properties to not override
 everything
Date: Sat, 18 Mar 2023 08:51:21 +0100
It would be nice if the context menu defined by a text property had the
option of adding to instead of overriding the menu specified by
`context-menu-functions'.

I think this can be done in a backwards-compatible way as follows:

--8<---------------cut here---------------start------------->8---
(defun context-menu-map (&optional click)
  "Return menu map constructed for context near mouse CLICK.
The menu is populated by calling functions from
`context-menu-functions'.  Each function receives the menu and the mouse
click event and returns the same menu after adding own menu items to the
composite menu.  Alternatively, it can return a completely new menu.  In
this case, no further functions from `context-menu-functions' are
called.

When there is a text property `context-menu-function' at CLICK, it is
handled as if it were the first entry of `context-menu-functions'.

At the end, it's possible to modify the final menu by specifying the
function `context-menu-filter-function'."
--8<---------------cut here---------------end--------------->8---




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Sat, 18 Mar 2023 08:32:01 GMT) Full text and rfc822 format available.

Message #8 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Augusto Stoffel <arstoffel <at> gmail.com>
Cc: 62250 <at> debbugs.gnu.org, juri <at> linkov.net
Subject: Re: bug#62250: 29.0.60;
 Allow context menu from text properties to not override everything
Date: Sat, 18 Mar 2023 10:31:36 +0200
> Cc: Juri Linkov <juri <at> linkov.net>
> From: Augusto Stoffel <arstoffel <at> gmail.com>
> Date: Sat, 18 Mar 2023 08:51:21 +0100
> 
> It would be nice if the context menu defined by a text property had the
> option of adding to instead of overriding the menu specified by
> `context-menu-functions'.
> 
> I think this can be done in a backwards-compatible way as follows:
> 
> --8<---------------cut here---------------start------------->8---
> (defun context-menu-map (&optional click)
>   "Return menu map constructed for context near mouse CLICK.
> The menu is populated by calling functions from
> `context-menu-functions'.  Each function receives the menu and the mouse
> click event and returns the same menu after adding own menu items to the
> composite menu.  Alternatively, it can return a completely new menu.  In
> this case, no further functions from `context-menu-functions' are
> called.
> 
> When there is a text property `context-menu-function' at CLICK, it is
> handled as if it were the first entry of `context-menu-functions'.
> 
> At the end, it's possible to modify the final menu by specifying the
> function `context-menu-filter-function'."
> --8<---------------cut here---------------end--------------->8---

What if a Lisp program _does_ want to override the menu specified by
context-menu-functions? or what if it wants the menu specified by the
text property to be the _last_ entry, not the first?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Sat, 18 Mar 2023 11:21:02 GMT) Full text and rfc822 format available.

Message #11 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Augusto Stoffel <arstoffel <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 62250 <at> debbugs.gnu.org, juri <at> linkov.net
Subject: Re: bug#62250: 29.0.60; Allow context menu from text properties to
 not override everything
Date: Sat, 18 Mar 2023 12:19:56 +0100
On Sat, 18 Mar 2023 at 10:31, Eli Zaretskii wrote:

>> Alternatively, it can return a completely new menu.  In
>> this case, no further functions from `context-menu-functions' are
>> called.

> What if a Lisp program _does_ want to override the menu specified by
> context-menu-functions? or what if it wants the menu specified by the
> text property to be the _last_ entry, not the first?

It's explained in the bit I kept: you ignore the MENU argument and
return a totally new keymap / not `eq'.  Adding things at the beginning
or end of a menu is an option that easy-menu-add-item etc already offer,
right?

Note that currently a member of context-menu-functions cannot override
the menu, and a context-menu-function cannot _not_ override it.  My
suggestions allows all possibilities.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Sat, 18 Mar 2023 11:25:02 GMT) Full text and rfc822 format available.

Message #14 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Augusto Stoffel <arstoffel <at> gmail.com>
Cc: 62250 <at> debbugs.gnu.org, juri <at> linkov.net
Subject: Re: bug#62250: 29.0.60; Allow context menu from text properties to
 not override everything
Date: Sat, 18 Mar 2023 13:24:39 +0200
> From: Augusto Stoffel <arstoffel <at> gmail.com>
> Cc: 62250 <at> debbugs.gnu.org,  juri <at> linkov.net
> Date: Sat, 18 Mar 2023 12:19:56 +0100
> 
> On Sat, 18 Mar 2023 at 10:31, Eli Zaretskii wrote:
> 
> >> Alternatively, it can return a completely new menu.  In
> >> this case, no further functions from `context-menu-functions' are
> >> called.
> 
> > What if a Lisp program _does_ want to override the menu specified by
> > context-menu-functions? or what if it wants the menu specified by the
> > text property to be the _last_ entry, not the first?
> 
> It's explained in the bit I kept: you ignore the MENU argument and
> return a totally new keymap / not `eq'.

What MENU argument?  I see only a CLICK argument.

> Adding things at the beginning or end of a menu is an option that
> easy-menu-add-item etc already offer, right?

I admit I don't see how easy-menu-add-item is related to this.

> Note that currently a member of context-menu-functions cannot override
> the menu, and a context-menu-function cannot _not_ override it.  My
> suggestions allows all possibilities.

That part I did understand, but it looked to me that your proposal
stops short of covering all the possible situations.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Sat, 18 Mar 2023 11:30:02 GMT) Full text and rfc822 format available.

Message #17 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Augusto Stoffel <arstoffel <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 62250 <at> debbugs.gnu.org, juri <at> linkov.net
Subject: Re: bug#62250: 29.0.60; Allow context menu from text properties to
 not override everything
Date: Sat, 18 Mar 2023 12:29:19 +0100
On Sat, 18 Mar 2023 at 13:24, Eli Zaretskii wrote:

> What MENU argument?  I see only a CLICK argument.

--8<---------------cut here---------------start------------->8---
(defun context-menu-map (&optional click)
  "Return menu map constructed for context near mouse CLICK.
The menu is populated by calling functions from `context-menu-functions'.
Each function receives the menu and the mouse click event
                           ^^^^
and returns the same menu after adding own menu items to the composite menu.
When there is a text property `context-menu-function' at CLICK,
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'."
--8<---------------cut here---------------end--------------->8---




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Sat, 18 Mar 2023 11:35:02 GMT) Full text and rfc822 format available.

Message #20 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Augusto Stoffel <arstoffel <at> gmail.com>
Cc: 62250 <at> debbugs.gnu.org, juri <at> linkov.net
Subject: Re: bug#62250: 29.0.60; Allow context menu from text properties to
 not override everything
Date: Sat, 18 Mar 2023 13:33:59 +0200
> From: Augusto Stoffel <arstoffel <at> gmail.com>
> Cc: 62250 <at> debbugs.gnu.org,  juri <at> linkov.net
> Date: Sat, 18 Mar 2023 12:29:19 +0100
> 
> On Sat, 18 Mar 2023 at 13:24, Eli Zaretskii wrote:
> 
> > What MENU argument?  I see only a CLICK argument.
> 
> --8<---------------cut here---------------start------------->8---
> (defun context-menu-map (&optional click)
>   "Return menu map constructed for context near mouse CLICK.
> The menu is populated by calling functions from `context-menu-functions'.
> Each function receives the menu and the mouse click event
>                            ^^^^
> and returns the same menu after adding own menu items to the composite menu.
> When there is a text property `context-menu-function' at CLICK,
> 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'."
> --8<---------------cut here---------------end--------------->8---

Now I'm completely confused regarding your proposal.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Sat, 18 Mar 2023 18:30:01 GMT) Full text and rfc822 format available.

Message #23 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Augusto Stoffel <arstoffel <at> gmail.com>
Cc: 62250 <at> debbugs.gnu.org
Subject: Re: bug#62250: 29.0.60; Allow context menu from text properties to
 not override everything
Date: Sat, 18 Mar 2023 20:08:34 +0200
> It would be nice if the context menu defined by a text property had the
> option of adding to instead of overriding the menu specified by
> `context-menu-functions'.
>
> I think this can be done in a backwards-compatible way as follows:
>
> (defun context-menu-map (&optional click)
> ...
> When there is a text property `context-menu-function' at CLICK, it is
> handled as if it were the first entry of `context-menu-functions'.

I already envisioned such request, so the text property is named
`context-menu-function' (singular).  As an improvement we could add
another text property `context-menu-functions' (plural) that will
play more nicely with the variable `context-menu-functions'.
For example, we could append the list from the text property
to the value of the variable before running `run-hook-wrapped'
on the composite list.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Sat, 18 Mar 2023 18:30:02 GMT) Full text and rfc822 format available.

Message #26 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Augusto Stoffel <arstoffel <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 62250 <at> debbugs.gnu.org
Subject: Re: bug#62250: 29.0.60; Allow context menu from text properties to
 not override everything
Date: Sat, 18 Mar 2023 20:10:40 +0200
> Note that currently a member of context-menu-functions cannot override
> the menu,

Actually, a member of context-menu-functions can override the
previous menu it receives as an argument.  And the last member
always wins by overriding the whole menu.  So it's just a question
of ordering the members of context-menu-functions.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Sat, 18 Mar 2023 18:40:02 GMT) Full text and rfc822 format available.

Message #29 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Augusto Stoffel <arstoffel <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 62250 <at> debbugs.gnu.org
Subject: Re: bug#62250: 29.0.60; Allow context menu from text properties to
 not override everything
Date: Sat, 18 Mar 2023 19:39:40 +0100
On Sat, 18 Mar 2023 at 20:08, Juri Linkov wrote:

> I already envisioned such request

All right.  Just for the record, this would be useful to create a
context menu for images.  Also, I could take advantage of it to slightly
simplify the context menu of jit-spell.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Sat, 18 Mar 2023 18:45:02 GMT) Full text and rfc822 format available.

Message #32 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Augusto Stoffel <arstoffel <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 62250 <at> debbugs.gnu.org
Subject: Re: bug#62250: 29.0.60; Allow context menu from text properties to
 not override everything
Date: Sat, 18 Mar 2023 19:44:38 +0100
On Sat, 18 Mar 2023 at 20:10, Juri Linkov wrote:

>> Note that currently a member of context-menu-functions cannot override
>> the menu,
>
> Actually, a member of context-menu-functions can override the
> previous menu it receives as an argument.  And the last member
> always wins by overriding the whole menu.  So it's just a question
> of ordering the members of context-menu-functions.

Right.  What I suggested would make the overriding independent of the
ordering of the members, which also (typically) influences the order of
the menu items.  But maybe overriding the menu is not such a common
use-case anyway, and either mechanism is sufficient.

The really interesting feature would be to be able to add to the context
menu with a text property.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Sun, 19 Mar 2023 17:54:03 GMT) Full text and rfc822 format available.

Message #35 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Augusto Stoffel <arstoffel <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 62250 <at> debbugs.gnu.org
Subject: Re: bug#62250: 29.0.60; Allow context menu from text properties to
 not override everything
Date: Sun, 19 Mar 2023 19:40:09 +0200
>> Actually, a member of context-menu-functions can override the
>> previous menu it receives as an argument.  And the last member
>> always wins by overriding the whole menu.  So it's just a question
>> of ordering the members of context-menu-functions.
>
> Right.  What I suggested would make the overriding independent of the
> ordering of the members, which also (typically) influences the order of
> the menu items.  But maybe overriding the menu is not such a common
> use-case anyway, and either mechanism is sufficient.

What I still don't understand is why a function in the middle of
context-menu-functions should be able to say "I'm the boss" and
override everything that comes later.  Maybe this could be
implemented as well if needed, but the current implementation already
allows adding such a function to the end by specifying quite a large
value for the argument DEPTH of `add-hook'.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Sun, 19 Mar 2023 17:54:03 GMT) Full text and rfc822 format available.

Message #38 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Augusto Stoffel <arstoffel <at> gmail.com>
Cc: 62250 <at> debbugs.gnu.org
Subject: Re: bug#62250: 29.0.60; Allow context menu from text properties to
 not override everything
Date: Sun, 19 Mar 2023 19:43:28 +0200
[Message part 1 (text/plain, inline)]
>> 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)

[context-menu-functions.patch (text/x-diff, inline)]
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.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Sun, 19 Mar 2023 18:11:02 GMT) Full text and rfc822 format available.

Message #41 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Augusto Stoffel <arstoffel <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 62250 <at> debbugs.gnu.org
Subject: Re: bug#62250: 29.0.60; Allow context menu from text properties to
 not override everything
Date: Sun, 19 Mar 2023 19:10:26 +0100
On Sun, 19 Mar 2023 at 19:40, Juri Linkov wrote:

> What I still don't understand is why a function in the middle of
> context-menu-functions should be able to say "I'm the boss" and
> override everything that comes later.

Right, I actually have the same question: why should the singular
context-menu-function override everything else?  Flyspell could just put
the suggestion list inside a submenu.  It would be more usable.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Sun, 19 Mar 2023 18:22:01 GMT) Full text and rfc822 format available.

Message #44 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Augusto Stoffel <arstoffel <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 62250 <at> debbugs.gnu.org
Subject: Re: bug#62250: 29.0.60; Allow context menu from text properties to
 not override everything
Date: Sun, 19 Mar 2023 19:21:21 +0100
On Sun, 19 Mar 2023 at 19:43, Juri Linkov wrote:

> The patch below will allow using the text property like
>
>   'context-menu-functions '(image-context-menu)

I didn't test the patch (I don't understand click events very well), but
does it find the context-menu-functions property of overlays as well?
And would those override the context-menu-functions text property or get
merged?

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

I believe this makes the menu entries coming from a text property appear
after the regular hook ones, while I would expect the opposite (stuff
specific to the point is more "urgent").




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Mon, 20 Mar 2023 18:37:02 GMT) Full text and rfc822 format available.

Message #47 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Augusto Stoffel <arstoffel <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 62250 <at> debbugs.gnu.org
Subject: Re: bug#62250: 29.0.60; Allow context menu from text properties to
 not override everything
Date: Mon, 20 Mar 2023 20:29:14 +0200
> I actually have the same question: why should the singular
> context-menu-function override everything else?  Flyspell could just put
> the suggestion list inside a submenu.  It would be more usable.

The problem is that flyspell requires too much refactoring to
be able to put the suggestion list inside a submenu.  No one
volunteered to undertake such an endeavor.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Mon, 20 Mar 2023 18:37:02 GMT) Full text and rfc822 format available.

Message #50 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Augusto Stoffel <arstoffel <at> gmail.com>
Cc: 62250 <at> debbugs.gnu.org
Subject: Re: bug#62250: 29.0.60; Allow context menu from text properties to
 not override everything
Date: Mon, 20 Mar 2023 20:34:59 +0200
>> The patch below will allow using the text property like
>>
>>   'context-menu-functions '(image-context-menu)
>
> I didn't test the patch (I don't understand click events very well), but
> does it find the context-menu-functions property of overlays as well?

It should be able to find the property in overlays as well.

> And would those override the context-menu-functions text property or get
> merged?

This needs confirming, but I guess overlays take priority over text properties.

>>        (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.
>
> I believe this makes the menu entries coming from a text property appear
> after the regular hook ones, while I would expect the opposite (stuff
> specific to the point is more "urgent").

When text properties are processed later, they have a chance to decide
where they add their menu items: at the top of the context menu, at the
bottom, or anywhere in the middle.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Sun, 02 Apr 2023 16:42:02 GMT) Full text and rfc822 format available.

Message #53 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Augusto Stoffel <arstoffel <at> gmail.com>
Cc: 62250 <at> debbugs.gnu.org
Subject: Re: bug#62250: 29.0.60; Allow context menu from text properties to
 not override everything
Date: Sun, 02 Apr 2023 19:35:15 +0300
[Message part 1 (text/plain, inline)]
>> 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)

Here is a complete patch that uses the new text property
for create a context menu for images:

[context-menu-functions.patch (text/x-diff, inline)]
diff --git a/lisp/iimage.el b/lisp/iimage.el
index b4c175a7b63..8235c4a6fdb 100644
--- a/lisp/iimage.el
+++ b/lisp/iimage.el
@@ -134,6 +134,7 @@ iimage-mode-buffer
                                     :max-width (- (nth 2 edges) (nth 0 edges))
 				    :max-height (- (nth 3 edges) (nth 1 edges)))
                      keymap ,image-map
+                     context-menu-functions (image-context-menu)
                      modification-hooks
                      (iimage-modification-hook)))
                 (remove-list-of-text-properties
diff --git a/lisp/image.el b/lisp/image.el
index 2372fd1ce09..11bf46c80cc 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -188,6 +188,29 @@ image-map
   "C-<wheel-up>"   #'image-mouse-increase-size
   "C-<mouse-4>"    #'image-mouse-increase-size)
 
+(defun image-context-menu (menu click)
+  "Populate MENU with image-related commands at CLICK."
+  (when (mouse-posn-property (event-start click) 'display)
+    (define-key menu [image-separator] menu-bar-separator)
+    (let ((easy-menu (make-sparse-keymap "Image")))
+      (easy-menu-define nil easy-menu nil
+        '("Image"
+          ["Zoom In" image-increase-size
+           :help "Enlarge the image"]
+          ["Zoom Out" image-decrease-size
+           :help "Shrink the image"]
+          ["Rotate Clockwise" image-rotate
+           :help "Rotate the image"]
+          ["Flip horizontally" image-flip-horizontally
+           :help "Flip horizontally"]
+          ["Flip vertically" image-flip-vertically
+           :help "Flip vertically"]))
+      (dolist (item (reverse (lookup-key easy-menu [menu-bar image])))
+        (when (consp item)
+          (define-key menu (vector (car item)) (cdr item))))))
+
+  menu)
+
 (defun image-load-path-for-library (library image &optional path no-error)
   "Return a suitable search path for images used by LIBRARY.
 
@@ -615,6 +638,7 @@ put-image
       (overlay-put overlay 'put-image t)
       (overlay-put overlay 'before-string string)
       (overlay-put overlay 'keymap image-map)
+      (overlay-put overlay 'context-menu-functions '(image-context-menu))
       overlay)))
 
 
@@ -665,7 +689,9 @@ insert-image
 				      image)
                                    rear-nonsticky t
 				   inhibit-isearch ,inhibit-isearch
-                                   keymap ,image-map))))
+                                   keymap ,image-map
+                                   context-menu-functions
+                                   (image-context-menu)))))
 
 
 ;;;###autoload
@@ -702,7 +728,9 @@ insert-sliced-image
 	  (add-text-properties start (point)
 			       `(display ,(list (list 'slice x y dx dy) image)
 					 rear-nonsticky (display)
-                                         keymap ,image-map))
+                                         keymap ,image-map
+                                         context-menu-functions
+                                         (image-context-menu)))
 	  (setq x (+ x dx))))
       (setq x 0.0
 	    y (+ y dy))
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.

Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 12 Sep 2023 00:13:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62250; Package emacs. (Tue, 05 Mar 2024 16:54:01 GMT) Full text and rfc822 format available.

Message #58 received at 62250 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Augusto Stoffel <arstoffel <at> gmail.com>
Cc: 62250 <at> debbugs.gnu.org
Subject: Re: bug#62250: 29.0.60; Allow context menu from text properties to
 not override everything
Date: Tue, 05 Mar 2024 18:51:23 +0200
close 62250 30.0.50
thanks

>>> 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)
>
> Here is a complete patch that uses the new text property
> for create a context menu for images:

So now the tested patch is pushed to master and closed.




bug marked as fixed in version 30.0.50, send any further explanations to 62250 <at> debbugs.gnu.org and Augusto Stoffel <arstoffel <at> gmail.com> Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Tue, 05 Mar 2024 16:54:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 03 Apr 2024 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 21 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.