I think this might be a simpler approach. what you want (I think) is to
leverage font-lock on tooltips to set a help-echo function instead of a
string. You can override org-activate-footnote-links with an advice (which
makes it easy to undo of you need). The tooltip function then looks up the
tooltip when you ask for it. The 3 pieces are below. the first function
looks up and returns a tooltip. the second is a lightly modified version of
org-activate-footnote-links which just replaces the footnote reference
string with the first function. the last piece is the override advice. you
could use a minor mode to toggle the advice on and off.
#+BEGIN_SRC emacs-lisp
(defun footnote-reference-tooltip (_win _obj position)
"Get footnote contents"
(save-excursion
(goto-char position)
(let* ((fnf (org-element-context))
(label (org-element-property :label fnf))
(p (nth 1 (org-footnote-get-definition label))))
(when p
(goto-char p)))
(let ((fnd (org-element-context)))
(string-trim
(buffer-substring (org-element-property :contents-begin fnd)
(org-element-property :contents-end fnd))))))
(defun footnote-tooltip (limit)
"Add text properties for footnotes."
(let ((fn (org-footnote-next-reference-or-definition limit)))
(when fn
(let* ((beg (nth 1 fn))
(end (nth 2 fn))
(label (car fn))
(referencep (/= (line-beginning-position) beg)))
(when (and referencep (nth 3 fn))
(save-excursion
(goto-char beg)
(search-forward (or label "fn:"))
(org-remove-flyspell-overlays-in beg (match-end 0))))
(add-text-properties beg end
(list 'mouse-face 'highlight
'keymap org-mouse-map
'help-echo
(if referencep #'footnote-reference-tooltip
"Footnote definition")
'font-lock-fontified t
'font-lock-multiline t
'face 'org-footnote))))))
(advice-add 'org-activate-footnote-links :override 'footnote-tooltip)
#+END_SRC
John
-----------------------------------
John Kitchin (he/his)
Professor
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu
https://pointbreezepubs.gumroad.com/ pycse bookstore
On Wed, Feb 23, 2022 at 2:52 PM Juan Manuel Macías <[email protected]>
wrote:
> Hi Samuel,
>
> Samuel Wales writes:
>
> > what a great idea. i am interested in your comments. emacs has lots
> > of tooltip-related features. eldoc, help-at-pt, mouse-avoidance, etc.
> > you don't want tooltips when your mouse happens to end up over. or
> > for your mouse to go haywire just because you ended up over. i ran
> > into a lot of confusion with various mechanisms.
> >
> > [e.g. i like having tooltips in echo area, and don't like eldoc for
> > function sigs, and do want cursor/mouse consistency.]
> >
> > i found that some tooltip features actually break others. just
> > wondering if you noticed this and what you think of it.
>
> I don't have much experience with Emacs tooltips and I haven't studied
> them much, because I hardly use the mouse in Emacs :-) But I noticed
> that you can also display the content of a tooltip in the echo area,
> with `<C-h .>' (`display-local-help'), or even set to non-nil
> `help-at-pt-display-when-idle' and evaluate `help-at-pt-set-timer', so
> that a tootltip is displayed at point; and in this scenario, they can be
> useful to me to quickly have some type of information.
>
> You can also set this variable to force tooltips always in the echo
> area:
>
> (setq tooltip-use-echo-area t)
>
> Anyway, I haven't given up on the idea of footnote tooltips yet. Here's
> a new version of the code I attached in my first post in this thread,
> and I think it's simpler now and works better, though I don't know if it
> might have any side effects... Footnote tooltips are activated with the
> minor mode `my-org-fn-tooltip-mode'.
>
> A new demo video:
>
> https://cloud.disroot.org/s/sBGJjCzbYgYbn5k
>
> Best regards,
>
> Juan Manuel
>
>