Control-Click in Aquamacs #70

Open
vzaliva opened this Issue Jan 29, 2016 · 16 comments

Comments

Projects
None yet
2 participants
@vzaliva

vzaliva commented Jan 29, 2016

This is follow up to #65

I found a way to make control-click work under Aquamacs. I am not Elisp hacker, so here is quick and dirty solution which works. Hopefully you can rework it and include into main package. I will be glad to test:

(defun company-coq-toggle-aquamacs-definition-overlay (event &optional  prefix)
  "Toggle inline docs for symbol at point in Aquamacs Emacs."
  (interactive)
  (company-coq-error-unless-feature-active 'inline-docs)
  (if company-coq-definition-overlay
      (company-coq-clear-definition-overlay)
    (company-coq-show-definition-overlay-under-pointer event)
    (message (substitute-command-keys "Press \\[company-coq-toggle-definition-overlay] again to hide the inline docs."))))

(custom-set-variables
     '(osx-key-mode-mouse-3-behavior
     #'company-coq-toggle-aquamacs-definition-overlay))
@cpitclaudel

This comment has been minimized.

Show comment
Hide comment
@cpitclaudel

cpitclaudel Jan 29, 2016

Owner

Thanks for looking into this. Is that really the right solution though? It seems to be binding the popup to right click (which is then emulated as C-click by aquamacs). Aren't other aquamacs users be displeased with that?

Owner

cpitclaudel commented Jan 29, 2016

Thanks for looking into this. Is that really the right solution though? It seems to be binding the popup to right click (which is then emulated as C-click by aquamacs). Aren't other aquamacs users be displeased with that?

@vzaliva

This comment has been minimized.

Show comment
Hide comment
@vzaliva

vzaliva Jan 29, 2016

First of all, this binding should be specific to company-coq buffers. I am not familiar enough with emacs modes to ensure that but I guess it should be easy to do.

For company-coq users I would guess that this binding should be an improvement. Standard popup menu us pretty useless in this mode, and simulating control-click behaviour from other platforms should be a plus.

Finally, we can make it customizable, so users can switch back to standard behaviour.

vzaliva commented Jan 29, 2016

First of all, this binding should be specific to company-coq buffers. I am not familiar enough with emacs modes to ensure that but I guess it should be easy to do.

For company-coq users I would guess that this binding should be an improvement. Standard popup menu us pretty useless in this mode, and simulating control-click behaviour from other platforms should be a plus.

Finally, we can make it customizable, so users can switch back to standard behaviour.

@cpitclaudel

This comment has been minimized.

Show comment
Hide comment
@cpitclaudel

cpitclaudel Jan 29, 2016

Owner

Ok, I buy that :)

Can you try the following snippet?

(define-key company-coq-map (kbd "<down-mouse-3>") #'company-coq-show-definition-overlay-under-pointer)
(define-key company-coq-map (kbd "<mouse-3>")      #'company-coq-clear-definition-overlay)
Owner

cpitclaudel commented Jan 29, 2016

Ok, I buy that :)

Can you try the following snippet?

(define-key company-coq-map (kbd "<down-mouse-3>") #'company-coq-show-definition-overlay-under-pointer)
(define-key company-coq-map (kbd "<mouse-3>")      #'company-coq-clear-definition-overlay)
@vzaliva

This comment has been minimized.

Show comment
Hide comment
@vzaliva

vzaliva Jan 29, 2016

I just tried that and it did not work. Standard popup still shows.

vzaliva commented Jan 29, 2016

I just tried that and it did not work. Standard popup still shows.

@vzaliva

This comment has been minimized.

Show comment
Hide comment
@vzaliva

vzaliva Jan 29, 2016

Documentation on the variable I am using:

osx-key-mode-mouse-3-behavior is a variable defined in `osxkeys.el'.
Its value is aquamacs-popup-context-menu

Documentation:
Determine behavior of (down-)mouse-3 in osx-key-mode.
When set to `aquamacs-popup-context-menu' or nil,  down-mouse-3
(usually: clicking the right mouse button) will bring up a
context menu.  When set to `mouse-save-then-kill', mouse-3 will
extend the region with `mouse-save-then-kill' (traditional Emacs
behavior).

You can customize this variable.

vzaliva commented Jan 29, 2016

Documentation on the variable I am using:

osx-key-mode-mouse-3-behavior is a variable defined in `osxkeys.el'.
Its value is aquamacs-popup-context-menu

Documentation:
Determine behavior of (down-)mouse-3 in osx-key-mode.
When set to `aquamacs-popup-context-menu' or nil,  down-mouse-3
(usually: clicking the right mouse button) will bring up a
context menu.  When set to `mouse-save-then-kill', mouse-3 will
extend the region with `mouse-save-then-kill' (traditional Emacs
behavior).

You can customize this variable.
@cpitclaudel

This comment has been minimized.

Show comment
Hide comment
@cpitclaudel

cpitclaudel Jan 29, 2016

Owner

Thanks, but that variable isn't really enough for our purposes; we want access to both the mouse down and the mouse up events.

Owner

cpitclaudel commented Jan 29, 2016

Thanks, but that variable isn't really enough for our purposes; we want access to both the mouse down and the mouse up events.

@vzaliva

This comment has been minimized.

Show comment
Hide comment
@vzaliva

vzaliva Jan 29, 2016

Tried your snipped again. It gives me error:

eval: Wrong number of arguments: define-key, 4

vzaliva commented Jan 29, 2016

Tried your snipped again. It gives me error:

eval: Wrong number of arguments: define-key, 4

@cpitclaudel

This comment has been minimized.

Show comment
Hide comment
@cpitclaudel

cpitclaudel Jan 29, 2016

Owner

How are you running that snippet?

Owner

cpitclaudel commented Jan 29, 2016

How are you running that snippet?

@vzaliva

This comment has been minimized.

Show comment
Hide comment
@vzaliva

vzaliva Jan 29, 2016

M-x eval-expression

vzaliva commented Jan 29, 2016

M-x eval-expression

@cpitclaudel

This comment has been minimized.

Show comment
Hide comment
@cpitclaudel

cpitclaudel Jan 29, 2016

Owner

One by one, right?

Owner

cpitclaudel commented Jan 29, 2016

One by one, right?

@vzaliva

This comment has been minimized.

Show comment
Hide comment
@vzaliva

vzaliva Jan 29, 2016

I tried to wrap them in progn first, but also tried one-by-one.

It looks like copy-pasting them from github web interface was the problem. I thin it uses fancy unicode quotation signs which were causing problems. After retyping them manually I was able to execute these snippers (one by one) without errors.

Even after that, Control-Click still shows standard Aquamacs popup. However Control-Right click (on Apple mouse) or Control-Two-Finger-Click on MacbBook Pro touchpad now works and shows definition popup while I am holding the click. Is that the expected behaviour or it should toggle on each click?

vzaliva commented Jan 29, 2016

I tried to wrap them in progn first, but also tried one-by-one.

It looks like copy-pasting them from github web interface was the problem. I thin it uses fancy unicode quotation signs which were causing problems. After retyping them manually I was able to execute these snippers (one by one) without errors.

Even after that, Control-Click still shows standard Aquamacs popup. However Control-Right click (on Apple mouse) or Control-Two-Finger-Click on MacbBook Pro touchpad now works and shows definition popup while I am holding the click. Is that the expected behaviour or it should toggle on each click?

@cpitclaudel

This comment has been minimized.

Show comment
Hide comment
@cpitclaudel

cpitclaudel Jan 30, 2016

Owner

Ah, great, sorry for the trouble.
I was expecting these snippets to make C-click and right click show the popup when you click, and hide it when you release the mouse button. Aquamacs is confusing.
Can you try the following? In a clean Emacs (without the snippets above) press C-h k, then control and mouse click. That will display a popup; can you paste its contents here?

Owner

cpitclaudel commented Jan 30, 2016

Ah, great, sorry for the trouble.
I was expecting these snippets to make C-click and right click show the popup when you click, and hide it when you release the mouse button. Aquamacs is confusing.
Can you try the following? In a clean Emacs (without the snippets above) press C-h k, then control and mouse click. That will display a popup; can you paste its contents here?

@vzaliva

This comment has been minimized.

Show comment
Hide comment
@vzaliva

vzaliva Jan 30, 2016

Sorry for confusion, but let me clarify my previous statement. Your snippets alone, did not work.
However these did work. (I've added "C-" prefix).

  (define-key company-coq-map (kbd "<C-down-mouse-3>") #'company-coq-show-definition-overlay-under-pointer)
  (define-key company-coq-map (kbd "<C-mouse-3>") #'company-coq-clear-definition-overlay)


I think we are pretty close. We got desired behaviour but not on normal click but on the Control-"right" Magic Mouse or Control-"two finger" touchpad click. If nothing else works, that would be acceptable workaround. However it might be annoying to have different binding on different platforms, especially for people who frequently switch between them.

Anyway, here is the output you requested for Control-Click:

<down-mouse-3> at that spot runs the command
osx-key-mode-down-mouse-3, which is an interactive Lisp function in
`osxkeys.el'.

It is bound to <down-mouse-3>.

(osx-key-mode-down-mouse-3 EVENT &optional PREFIX)

Activate context menu, when `osx-key-mode-mouse-3-behavior' is
set to `aquamacs-popup-context-menu' or nil

----------------- up-event ----------------

<mouse-3> at that spot runs the command osx-key-mode-mouse-3, which is
an interactive Lisp function in `osxkeys.el'.

It is bound to <mouse-3>.

(osx-key-mode-mouse-3 EVENT &optional PREFIX)

Run command specified in `osx-key-mode-mouse-3-behavior'.

It looks like this event could not be easily intercepted via key-map. However this one could be:

<C-down-mouse-3> at that spot runs the command
company-coq-show-definition-overlay-under-pointer, which is an
interactive compiled Lisp function in `company-coq.el'.

It is bound to <C-down-mouse-3>, <C-down-mouse-1>.

(company-coq-show-definition-overlay-under-pointer EVENT)

Show inline definition for symbol under pointer.
EVENT is the mouse EVENT that triggered the call t this
function.

----------------- up-event ----------------

<C-mouse-3> at that spot runs the command
company-coq-clear-definition-overlay, which is an interactive compiled
Lisp function in `company-coq.el'.

It is bound to <C-mouse-3>, <C-mouse-1>.

(company-coq-clear-definition-overlay)

Clear inline definition popup.

[back]

vzaliva commented Jan 30, 2016

Sorry for confusion, but let me clarify my previous statement. Your snippets alone, did not work.
However these did work. (I've added "C-" prefix).

  (define-key company-coq-map (kbd "<C-down-mouse-3>") #'company-coq-show-definition-overlay-under-pointer)
  (define-key company-coq-map (kbd "<C-mouse-3>") #'company-coq-clear-definition-overlay)


I think we are pretty close. We got desired behaviour but not on normal click but on the Control-"right" Magic Mouse or Control-"two finger" touchpad click. If nothing else works, that would be acceptable workaround. However it might be annoying to have different binding on different platforms, especially for people who frequently switch between them.

Anyway, here is the output you requested for Control-Click:

<down-mouse-3> at that spot runs the command
osx-key-mode-down-mouse-3, which is an interactive Lisp function in
`osxkeys.el'.

It is bound to <down-mouse-3>.

(osx-key-mode-down-mouse-3 EVENT &optional PREFIX)

Activate context menu, when `osx-key-mode-mouse-3-behavior' is
set to `aquamacs-popup-context-menu' or nil

----------------- up-event ----------------

<mouse-3> at that spot runs the command osx-key-mode-mouse-3, which is
an interactive Lisp function in `osxkeys.el'.

It is bound to <mouse-3>.

(osx-key-mode-mouse-3 EVENT &optional PREFIX)

Run command specified in `osx-key-mode-mouse-3-behavior'.

It looks like this event could not be easily intercepted via key-map. However this one could be:

<C-down-mouse-3> at that spot runs the command
company-coq-show-definition-overlay-under-pointer, which is an
interactive compiled Lisp function in `company-coq.el'.

It is bound to <C-down-mouse-3>, <C-down-mouse-1>.

(company-coq-show-definition-overlay-under-pointer EVENT)

Show inline definition for symbol under pointer.
EVENT is the mouse EVENT that triggered the call t this
function.

----------------- up-event ----------------

<C-mouse-3> at that spot runs the command
company-coq-clear-definition-overlay, which is an interactive compiled
Lisp function in `company-coq.el'.

It is bound to <C-mouse-3>, <C-mouse-1>.

(company-coq-clear-definition-overlay)

Clear inline definition popup.

[back]
@cpitclaudel

This comment has been minimized.

Show comment
Hide comment
@cpitclaudel

cpitclaudel Jan 30, 2016

Owner

Thanks, that's very useful. So what happens is that:

  • osx-key-mode gets priority over company-coq, so it catches the key
  • Aquamacs mechanism for overriding that key is broken: you can get mouse down to show a menu or to do nothing, but you can't rebind it to an arbitrary definition.

I need to think a bit more about how to do this.

Owner

cpitclaudel commented Jan 30, 2016

Thanks, that's very useful. So what happens is that:

  • osx-key-mode gets priority over company-coq, so it catches the key
  • Aquamacs mechanism for overriding that key is broken: you can get mouse down to show a menu or to do nothing, but you can't rebind it to an arbitrary definition.

I need to think a bit more about how to do this.

@vzaliva

This comment has been minimized.

Show comment
Hide comment
@vzaliva

vzaliva Jan 30, 2016

Thanks for looking into that. I would like to add few final comments summarising our today's progress:

  1. It seems that 'osx-key-mode-mouse-3-behavior' variable allows to intercept control-mouse clicks before Aquamacs does. The function called have an 'event' parameter which might allow us to distinguish between mouse up and down and implement desired behaviour. I just do not know how to test this.
  2. If nothing else works, the following workaround might be acceptable solution for Aquamacs users (better than nothing):
(define-key company-coq-map (kbd "<C-down-mouse-3>") #'company-coq-show-definition-overlay-under-pointer)
(define-key company-coq-map (kbd "<C-mouse-3>") #'company-coq-clear-definition-overlay)

vzaliva commented Jan 30, 2016

Thanks for looking into that. I would like to add few final comments summarising our today's progress:

  1. It seems that 'osx-key-mode-mouse-3-behavior' variable allows to intercept control-mouse clicks before Aquamacs does. The function called have an 'event' parameter which might allow us to distinguish between mouse up and down and implement desired behaviour. I just do not know how to test this.
  2. If nothing else works, the following workaround might be acceptable solution for Aquamacs users (better than nothing):
(define-key company-coq-map (kbd "<C-down-mouse-3>") #'company-coq-show-definition-overlay-under-pointer)
(define-key company-coq-map (kbd "<C-mouse-3>") #'company-coq-clear-definition-overlay)
@cpitclaudel

This comment has been minimized.

Show comment
Hide comment
@cpitclaudel

cpitclaudel Jan 30, 2016

Owner

Indeed. Re 1: the issue is that only gives us the mouse up, not the mouse down (that's why I call it broken). See the implementation:

(defun osx-key-mode-down-mouse-3 (event &optional prefix)
  "Activate context menu, when `osx-key-mode-mouse-3-behavior' is
set to `aquamacs-popup-context-menu' or nil"
  (interactive "@e \nP")
  (if (or (eq osx-key-mode-mouse-3-behavior #'aquamacs-popup-context-menu)
      (not osx-key-mode-mouse-3-behavior))
      (aquamacs-popup-context-menu event prefix)
    ;; else: pretend this command never happened
    ;; (for the benefit of mouse-save-then-kill)
    (setq this-command last-command
      last-command nil)))
Owner

cpitclaudel commented Jan 30, 2016

Indeed. Re 1: the issue is that only gives us the mouse up, not the mouse down (that's why I call it broken). See the implementation:

(defun osx-key-mode-down-mouse-3 (event &optional prefix)
  "Activate context menu, when `osx-key-mode-mouse-3-behavior' is
set to `aquamacs-popup-context-menu' or nil"
  (interactive "@e \nP")
  (if (or (eq osx-key-mode-mouse-3-behavior #'aquamacs-popup-context-menu)
      (not osx-key-mode-mouse-3-behavior))
      (aquamacs-popup-context-menu event prefix)
    ;; else: pretend this command never happened
    ;; (for the benefit of mouse-save-then-kill)
    (setq this-command last-command
      last-command nil)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment