Subject: bug#50067: Context menus

From: Juri Linkov <[email-masked]>
Date: Mon, 23 Aug 2021 10:24:22 +0300

>> I tried to implement this, but soon found that long-left-click is unusable,
>> because such artificial delay is a hassle - no one would have
>> patience to wait even half a second until the menu finally appears.
>> But this could be implemented anyway when users will demand this.
>
> I think this is useful especially on laptop computer with Mac.
> As inferred on other posts laptop computer with Mac does not have
> mouse-3.  However, it is possible that I’m the only one.

Recently Mattias bound C-mouse-1 to use instead of mouse-3 on Mac.

> `ffap-at-mouse’ will open a file under pointer on `this window’.
> Randomly I want to open it by `other frame’.
> It’s good if I can choose open the file on `this window’ or `other frame’.
> Is there a way to detect meta key pressed when select one of menu items?

There is no way to detect meta key.  But you can create a new command
to open in a new frame, and add this command to the menu.  Or use
the existing `ffap-other-frame'.

>>> It is handy to have buffer menu when right click mode bar.
>
> This suggestion may be unrelated to context-menu.
> On mode bar, both mouse-1 and mouse-3 switches buffer. 
> I think mouse-3 should show something like (mouse-buffer-menu-map).

Yes, this would be useful.

>>> On paste when there is a region and delete-selection-mode is t, the
>>> region should be replaced by the text.
>> 
>> Please explain how the region should be replaced by the text,
>> when mouse-yank-at-click or mouse-yank-primary is used
>> to paste where the mouse is clicked.  Should it delete the region
>> and paste where mouse is clicked on another part of the buffer?
>> What if the mouse is clicked in another window?
>
> When there is a region and yank text by `C-y’, the text would
> be replaced.
>
> I think when there is a region and point in on region, region
> should be replaced by text.  No?

mouse-yank-at-click is intended to paste where you click.
So when there is a region, and you click mouse-3 at some other position
where you want to paste, and select "Paste" from the context-menu,
it's unclear what to do with the region.  It makes no sense
to delete the region, when you paste at the clicked position
outside of the region, but not on the region.

Please see more in mouse-yank-at-click and mouse-yank-primary
that contain such comment about the need to deactivate the region:

  ;; Without this, confusing things happen upon e.g. inserting into
  ;; the middle of an active region.
  (when select-active-regions
    (let (select-active-regions)
      (deactivate-mark)))

>>> I cannot figure out how to include pre-existing menu such for
>>> (mouse-buffer-menu-map).

Actually, the right function to use is (mouse-buffer-menu-keymap)
instead of (mouse-buffer-menu-map).

> I cannot find guid line how the menu should be created.
> Do you know where to look?

Good documentation is in (info "(elisp) Defining Menus").