emacs-devel
[Top][All Lists]
Advanced

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

Re: Changing default mouse bindings


From: Stefan Monnier
Subject: Re: Changing default mouse bindings
Date: Fri, 17 Nov 2017 10:28:52 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

>> (global-set-key [mouse-3] 'mouse-context-menu)
>> (defun mouse-context-menu (event)
>> (interactive "e")
>> (or (poplife-mouse-dir-menu event)       ; DIR menu
>> (poplife-mouse-url-menu event)       ; URL menu
>> (mouse3-region-menu event)           ; region menu
>> (mouse-context-menu-default event))) ; default menu <<<<<

> I don't think binding this to mouse-3 by default can fly, because it
> contradicts the usual GUI meaning of that button related to
> selections, something that is honored by all well-behaving GUI
> applications in the X world.  It would be unwise for Emacs not to
> comply.

Indeed, I think we should first focus on the command itself, and leave
the discussion about where to bind it to for later.

I don't think we want the command to hardcode things like dir-menu,
region-menu, ..., so we'll want to have a hook where we can add
a function that gives the region-part of the menu, and another for the
dir-part of a menu, ...

Maybe we could do something like the code below.  The intention is to
make it reasonably easy to add functions to the hook that add a few
elements to the menu, and to also make it possible to add functions that
completely override the default menu (e.g. for flyspell's context menu).

This sample solution doesn't provide any direct way to specify the
context-menu from text-properties, so maybe we'd want to add to the
default definition of mouse-context-menu-function some function which
looks up some `context-menu` text-property, tho maybe we don't need that
and we can let packages add their own function to lookup their own
text-properties instead.


        Stefan


(defvar mouse-context-menu-function #'mouse-default-context-menu
  "Function that builds the context-menu.
Takes one argument (the EVENT that requests the menu) and should return
a list of menu items.")

(defun mouse-context-menu (event)
  "Open up the context menu."
  (interactive "@e")
  (let* ((menu-items (funcall mouse-context-menu-function event))
         (keymap `(keymap ,(apply #'vector menu-items))))
    (popup-menu leymap event)))



reply via email to

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