unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Pop up context menu (at point) with <menu> key rather than mouse
@ 2018-11-09 19:19 N. Jackson
  2018-11-09 19:29 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: N. Jackson @ 2018-11-09 19:19 UTC (permalink / raw)
  To: help-gnu-emacs

I would like to configure my Emacs so that when I press the <menu> key
on my keyboard, a pop-up menu is displayed.

I think I want this to be same pop-up menu that is displayed when I
press C-mouse-3. Although I am not quite clear how this menu differs
from the one that pops up when I press F10 -- sometimes they are the
same, sometimes they are different.

Possibly what I really want is the pop-up menu that appears when I press
just mouse-3, although that doesn't seem to pop up a menu at the moment
(rather is seems to select random-seeming text) but I think it used to
give a pop-up menu -- or maybe it just does in certain contexts. Yes. It
works on "buttons" in the Gnus Article buffer for example.

In any case, I want the menu to pop up in the context of point, not in
the context of the mouse pointer.

Initially I tried

  (define-key key-translation-map (kbd "<menu>") (kbd "<C-mouse-3>"))

but obviously that is too naïve, as clearly I'm going to need to do
something about making the menu's position be the position of point.

I think what I need to move forward on this, is to know what function is
run to display the menus popped up by C-mouse-3 (and by mouse-3 (when it
pops up a menu at all)), I suppose I can find these functions by running
Emacs under GDB, popping up a menu, halting Emacs in GDB, and displaying
a backtrace, although I feel there must be a much easier way.

Does anyone have any information that might help with this?

N.






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

* Re: Pop up context menu (at point) with <menu> key rather than mouse
  2018-11-09 19:19 Pop up context menu (at point) with <menu> key rather than mouse N. Jackson
@ 2018-11-09 19:29 ` Eli Zaretskii
  2018-11-10 17:11   ` N. Jackson
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2018-11-09 19:29 UTC (permalink / raw)
  To: help-gnu-emacs

> From: "N. Jackson" <nljlistbox2@gmail.com>
> Date: Fri, 09 Nov 2018 14:19:50 -0500
> 
> I think what I need to move forward on this, is to know what function is
> run to display the menus popped up by C-mouse-3 (and by mouse-3 (when it
> pops up a menu at all)), I suppose I can find these functions by running
> Emacs under GDB, popping up a menu, halting Emacs in GDB, and displaying
> a backtrace, although I feel there must be a much easier way.
> 
> Does anyone have any information that might help with this?

From mouse.el:

  ;; By binding these to down-going events, we let the user use the up-going
  ;; event to make the selection, saving a click.
  (global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
  (if (not (eq system-type 'ms-dos))
      (global-set-key [S-down-mouse-1] 'mouse-appearance-menu))
  ;; C-down-mouse-2 is bound in facemenu.el.
  (global-set-key [C-down-mouse-3]
    `(menu-item ,(purecopy "Menu Bar") ignore
      :filter (lambda (_)
		(if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
		    (mouse-menu-bar-map)
		  (mouse-menu-major-mode-map)))))



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

* Re: Pop up context menu (at point) with <menu> key rather than mouse
  2018-11-09 19:29 ` Eli Zaretskii
@ 2018-11-10 17:11   ` N. Jackson
  2018-11-10 17:27     ` Yuri Khan
  2018-11-10 18:00     ` Eli Zaretskii
  0 siblings, 2 replies; 6+ messages in thread
From: N. Jackson @ 2018-11-10 17:11 UTC (permalink / raw)
  To: help-gnu-emacs

At 21:29 +0200 on Friday 2018-11-09, Eli Zaretskii wrote:
>
> From mouse.el:
>
>   ;; By binding these to down-going events, we let the user use the up-going
>   ;; event to make the selection, saving a click.
>   (global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
>   (if (not (eq system-type 'ms-dos))
>       (global-set-key [S-down-mouse-1] 'mouse-appearance-menu))
>   ;; C-down-mouse-2 is bound in facemenu.el.
>   (global-set-key [C-down-mouse-3]
>     `(menu-item ,(purecopy "Menu Bar") ignore
>       :filter (lambda (_)
> 		(if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
> 		    (mouse-menu-bar-map)
> 		  (mouse-menu-major-mode-map)))))

Hmm... where is `menu-item' defined?

  C-h f menu-item RET
    => [No match]

  C-h r i menu-item RET
    => No `menu-item' in index

  C-u M-x xref-find-definitions RET menu-item RET
    =>  No definitions found for: menu-item





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

* Re: Pop up context menu (at point) with <menu> key rather than mouse
  2018-11-10 17:11   ` N. Jackson
@ 2018-11-10 17:27     ` Yuri Khan
  2018-11-10 17:50       ` N. Jackson
  2018-11-10 18:00     ` Eli Zaretskii
  1 sibling, 1 reply; 6+ messages in thread
From: Yuri Khan @ 2018-11-10 17:27 UTC (permalink / raw)
  To: nljlistbox2; +Cc: help-gnu-emacs

On Sun, Nov 11, 2018 at 12:11 AM N. Jackson <nljlistbox2@gmail.com> wrote:

> >   (global-set-key [C-down-mouse-3]
> >     `(menu-item ,(purecopy "Menu Bar") ignore
> >       :filter (lambda (_)
> >               (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
> >                   (mouse-menu-bar-map)
> >                 (mouse-menu-major-mode-map)))))
>
> Hmm... where is `menu-item' defined?

See the ‘`’ character? That indicates that the following is a quoted
list (except that the part prefixed with ‘,’ is not quoted. Anyway,
that is a list whose first element is the symbol 'menu-item, and that
list is passed to ‘global-set-key’.

So you want to go look what ‘global-set-key’ does with that. You might
know, or learn from the source, that ‘global-set-key’ is a wrapper
function around ‘define-key’. Then, C-h f define-key tells you its
last argument can take a number of forms, none of which seem to match
a list '(menu-item …), except possibly this:

    DEF is anything that can be a key’s definition:
    […]
     or an extended menu item definition.
     (See info node ‘(elisp)Extended Menu Items’.)

So you dive into that info node, and sure enough, it explains that an
extended menu item is a list starting with 'menu-item.



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

* Re: Pop up context menu (at point) with <menu> key rather than mouse
  2018-11-10 17:27     ` Yuri Khan
@ 2018-11-10 17:50       ` N. Jackson
  0 siblings, 0 replies; 6+ messages in thread
From: N. Jackson @ 2018-11-10 17:50 UTC (permalink / raw)
  To: Yuri Khan; +Cc: help-gnu-emacs

At 00:27 +0700 on Sunday 2018-11-11, Yuri Khan wrote:
>
> On Sun, Nov 11, 2018 at 12:11 AM N. Jackson <nljlistbox2@gmail.com> wrote:
>
>> >   (global-set-key [C-down-mouse-3]
>> >     `(menu-item ,(purecopy "Menu Bar") ignore
>> >       :filter (lambda (_)
>> >               (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
>> >                   (mouse-menu-bar-map)
>> >                 (mouse-menu-major-mode-map)))))
>>
>> Hmm... where is `menu-item' defined?
>
> See the ‘`’ character? That indicates that the following is a quoted
> list (except that the part prefixed with ‘,’ is not quoted. Anyway,
> that is a list whose first element is the symbol 'menu-item, and that
> list is passed to ‘global-set-key’.
>
> So you want to go look what ‘global-set-key’ does with that. You might
> know, or learn from the source, that ‘global-set-key’ is a wrapper
> function around ‘define-key’.

Thanks Yuri. This far I had already stumbled, although it's nice to see
it set out more crisply than the fuzzy version of it in my head!

> Then, C-h f define-key tells you its
> last argument can take a number of forms, none of which seem to match
> a list '(menu-item …), except possibly this:
>
>     DEF is anything that can be a key’s definition:
>     […]
>      or an extended menu item definition.
>      (See info node ‘(elisp)Extended Menu Items’.)

Aha! That info node (and those around it) are a wealth of useful
information!

Thanks.




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

* Re: Pop up context menu (at point) with <menu> key rather than mouse
  2018-11-10 17:11   ` N. Jackson
  2018-11-10 17:27     ` Yuri Khan
@ 2018-11-10 18:00     ` Eli Zaretskii
  1 sibling, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2018-11-10 18:00 UTC (permalink / raw)
  To: help-gnu-emacs

> From: "N. Jackson" <nljlistbox2@gmail.com>
> Date: Sat, 10 Nov 2018 12:11:08 -0500
> 
> Hmm... where is `menu-item' defined?
> 
>   C-h f menu-item RET
>     => [No match]
> 
>   C-h r i menu-item RET
>     => No `menu-item' in index
> 
>   C-u M-x xref-find-definitions RET menu-item RET
>     =>  No definitions found for: menu-item

Stopped too early: "C-h i m elisp RET i menu-item RET" would have
landed you where this is explained.  (The ELisp manual should be the
first place to look in this case if "C-h f" doesn't help; the Emacs
manual is only for user-level commands and variables.)



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

end of thread, other threads:[~2018-11-10 18:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-09 19:19 Pop up context menu (at point) with <menu> key rather than mouse N. Jackson
2018-11-09 19:29 ` Eli Zaretskii
2018-11-10 17:11   ` N. Jackson
2018-11-10 17:27     ` Yuri Khan
2018-11-10 17:50       ` N. Jackson
2018-11-10 18:00     ` Eli Zaretskii

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