When you hover the mouse pointer over a link in Org, Emacs displays a tooltip that shows the link's URL.0 This mimics the behavior of a web browser that displays the URL in the status bar.
Within Emacs, I try to avoid the mouse as much as possible. I already configured Emacs so that pressing ENTER on a link follows the link.1 But this method doesn't provide a way to preview the link before following it. I wondered, "What if Emacs displayed a tooltip whenever point is on a link?"
The answer came to me immediately; "It would be darn annoying."
So I decided that the user should invoke a function to "display tooltip at point." It didn't take long for me to find a solution on Stack Exchange, "farynaio/org-link-copy."2 The function's primary purpose is to add the URL to the kill-ring. But it also shows the URL in a message that indicates the URL was copied. It works perfectly.
However, the tricky part was binding a key to the function. It was
suggested that one could bind C-x C-l3 to the
function with this statement:
(define-key org-mode-map (kbd "C-x C-l") 'farynaio/org-link-copy)
Unfortunately, when I included it in my init file, it generated the error "Symbol's value as variable is void: org-mode-map" even while it worked after Org was enabled.
Eventually, after trying (unsuccessfully) to add the assignment to
org-mode-hook, I found it easy to include this statement above the
define-key statement: (require 'org-keys).
This provides a definition of org-mode-map, which is provided
in org-keys.el.
As Emacs is very keyboard-oriented, this little addition allowed my fingers (and thumbs) to stay on the keys.
Recall that my original objective was to display a tooltip, not a message. However, a tooltip would appear at the location of the mouse pointer, not at point, even if the mouse is hovering over another program's window. Just try it yourself:
(tooltip-show-help "MSG")
But this disadvantageous behavior of tooltip-show-help
could be useful if you wanted to locate the mouse pointer or signal
the status of some long-running asynchronous Emacs process. Setting
the message
to "****\n****\n****\n****\n****\n****\n****\n****" might
make the mouse obvious enough to notice. Feel free to play with that!
Trying to locate the mouse pointer leads me to another issue: how to locate point. So far, I've been using my overwrite-mode indicator to show me point.4 But I hope to devise a more effective solution soon. Perhaps.
0 If you don't see this, you might need to enable tooltip-mode.
1 Setting the variable org-return-follows-link to non-nil achieves
this.
2
See https://emacs.stackexchange.com/a/60555. The function is org-link-copy.
3 I chose to bind the function to "s-SPC".
Not sure if this works in org (it does in markdown). C-h . is bound to display-local-help. With point on a link I believe it will display the tooltip in the echo area. If not look in the manual for help-echo and figure out a way to echo the tooltip text which is in a help-echo text property.
ReplyDelete