The problem in brief
I want to redefine what clicking (on an org
link) does. My code works, if I click slowly enough, but for a normal (fast) click it does not -- instead I get the default behavior. Changing ordinary keyboard shortcuts in the org-mode
keymap
works fine.
[Sidenote: If I could instead change the behavior of org-open-at-point
, to call delete-other-windows
after running, that would be a more natural, if less declarative, solution.]
I'm finding nothing in the Emacs docs about click duration, although I do see that events have timestamps.
My code, and the reasoning behind it
I've tried both of the following:
(define-key org-mode-map [mouse-1] 'jbb-org-open-at-point)
(define-key org-mode-map (kbd "<mouse-1>") 'jbb-org-open-at-point)
Both have the same effect. Slow-clicking on a link runs jbb-org-open-at-point
, like I hoped, but fast-clicking runs the default org-open-at-point
.
Thanks to @Drew I understand that mouse-1
represents releasing the button, and down-mouse-1
represents pressing the button. Since I want to preserve the default down-mouse-1
behavior, which is to move the cursor to wherever the mouse is, I'm not mentioning down-mouse-1
in my code.
I tried replacing mouse-1
in the above code with up-mouse-1
. That was no good -- short clicks still had the default behavior, but long clicks had no effect.
Details that might not be important
My definition of jbb-org-open-at-point
It's just like org-open-at-point
,
except the new buffer occupies the entire window,
rather than half of it.
It does nothing if org-mode
is not the major mode.
(defun jbb-org-open-at-point ()
(interactive)
(if ;; TODO ? Maybe I should simplify this.
;; This if-else clause testing the major mode is unnecessary,
;; because `jbb-org-open-at-point`
;; will only be called via the shortcut defined next,
;; which is only available from org-mode.
(equal "org-mode" (symbol-name major-mode))
(progn (call-interactively 'org-open-at-point)
(delete-other-windows))
(message ("jbb-org-open-at-point does nothing outside of org-mode."))
))
Remapping keyboard (as opposed to mouse) shortcuts works as expected
I can successfully redefine C-c C-o
in the org-mode
keyboard map,
so that it uses the new jbb-org-open-at-point
instead of the default org-open-at-point
:
(define-key org-mode-map (kbd "C-c C-o") 'jbb-org-open-at-point)
I know that works because after doing that,
if I type C-c C-o
while the cursor is on an org
link,
the new buffer occupies the entire window, rather than half of it.