* Footnote tooltips (an attempt)
@ 2022-02-22 4:32 Juan Manuel Macías
2022-02-22 22:15 ` Juan Manuel Macías
0 siblings, 1 reply; 9+ messages in thread
From: Juan Manuel Macías @ 2022-02-22 4:32 UTC (permalink / raw)
To: orgmode
[-- Attachment #1: Type: text/plain, Size: 953 bytes --]
Hi all,
I think sometimes it would be nice to have tooltips in the footnote
references, so I can see the contents of each footnote definition,
especially when I'm in a narrowed subtree; so I've tried to write some
code. I have achieved a "semi-automatic" solution. It doesn't work bad
at all, but I'm not entirely convinced either. With a minor mode the
`org-activate-footnote-links' function is overridden, and tooltips content
for all footnotes in the document are added or updated after a couple of
actions when you finish writing or editing a footnote:
`org-edit-src-exit' and `org-mark-ring-goto'. And that's where the
automatic part ends. Beyond that, tooltips must be updated/added by
calling the `my-org-fn-make-tooltips' function.
Here is a short video demo: https://cloud.disroot.org/s/a4gejYc6PSwNWHY
I attach the code of my poor man's footnote tooltips. Of course, any
comment and/or feedback is appreciated.
Best regards,
Juan Manuel
[-- Attachment #2: fn-tooltips.org --]
[-- Type: application/vnd.lotus-organizer, Size: 3405 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Footnote tooltips (an attempt)
2022-02-22 4:32 Juan Manuel Macías
@ 2022-02-22 22:15 ` Juan Manuel Macías
0 siblings, 0 replies; 9+ messages in thread
From: Juan Manuel Macías @ 2022-02-22 22:15 UTC (permalink / raw)
To: orgmode
I answer myself to comment a couple more things on this question of
footnotes and tooltips. I think my approach is quite poor, and also when
it comes to files with many notes, it takes a long time to create or
update the list of tooltips. So I think I'll give up on' footnote
tooltips. If what it is about is being able to see the content of a
footnote quickly, I have written this other simpler function, which
displays the content of a footnote at point, in the echo area. Since
`<C-h .>' (`display-local-help') is not very useful in a footnote
reference, I recycle the shortcut for my function, if the context is a
footnote reference. I share it here, in case it is useful to someone.
┌────
│ (defun my-org-footnote-show-content ()
│ "Displays the content of a footnote at point, in the echo area"
│ (interactive)
│ (if (not (equal (org-element-type (org-element-context)) 'footnote-reference))
│ (error "Not on a footnote reference!")
│ (let* ((elt (org-element-context))
│ (label (org-element-property :label elt))
│ (def (org-with-wide-buffer
│ (org-footnote-goto-definition label)
│ (let* ((e (org-element-context))
│ (from (org-element-property :contents-begin e))
│ (to (org-element-property :contents-end e)))
│ (buffer-substring-no-properties from to)))))
│ (message def))))
│
│ (defun mi-display-local-help ()
│ (interactive)
│ (if (and (derived-mode-p 'org-mode)
│ (equal (org-element-type (org-element-context)) 'footnote-reference))
│ (my-org-footnote-show-content)
│ (call-interactively 'display-local-help)))
│
│ (global-set-key (kbd "C-h .") 'mi-display-local-help)
└────
Best regards,
Juan Manuel
Juan Manuel Macías writes:
Hi all,
>
> I think sometimes it would be nice to have tooltips in the footnote
> references, so I can see the contents of each footnote definition,
> especially when I'm in a narrowed subtree; so I've tried to write some
> code. I have achieved a "semi-automatic" solution. It doesn't work bad
> at all, but I'm not entirely convinced either. With a minor mode the
> `org-activate-footnote-links' function is overridden, and tooltips content
> for all footnotes in the document are added or updated after a couple of
> actions when you finish writing or editing a footnote:
> `org-edit-src-exit' and `org-mark-ring-goto'. And that's where the
> automatic part ends. Beyond that, tooltips must be updated/added by
> calling the `my-org-fn-make-tooltips' function.
>
> Here is a short video demo: https://cloud.disroot.org/s/a4gejYc6PSwNWHY
>
> I attach the code of my poor man's footnote tooltips. Of course, any
> comment and/or feedback is appreciated.
>
> Best regards,
>
> Juan Manuel
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Footnote tooltips (an attempt)
[not found] <mailman.57.1645549224.6185.emacs-orgmode@gnu.org>
@ 2022-02-22 22:30 ` Ypo
2022-02-23 2:26 ` Juan Manuel Macías
0 siblings, 1 reply; 9+ messages in thread
From: Ypo @ 2022-02-22 22:30 UTC (permalink / raw)
To: emacs-orgmode, Juan Manuel Macías
I love it!
I am going to read your code, Juan Manuel, I won't understand anything but that function is very interesting for me, since it could be used too with internal links, I suppose.
Thanks
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Footnote tooltips (an attempt)
2022-02-22 22:30 ` Footnote tooltips (an attempt) Ypo
@ 2022-02-23 2:26 ` Juan Manuel Macías
[not found] ` <CAJcAo8tsK5o+789Wv=i6ddiSrM4fDyX8HCvjAgDLXGyLXWRWmQ@mail.gmail.com>
0 siblings, 1 reply; 9+ messages in thread
From: Juan Manuel Macías @ 2022-02-23 2:26 UTC (permalink / raw)
To: Ypo; +Cc: orgmode
Ypo writes:
> I love it!
> I am going to read your code, Juan Manuel, I won't understand anything
> but that function is very interesting for me, since it could be used
> too with internal links, I suppose.
Org links already have tooltips out of the box. You can also display the
tooltip in the echo area by pressing <C-h .> (`display-local-help').
If you want to try the code from my first post, please replace the
`my-org-fn-make-tooltips' function with this new version, which is much
simpler and doesn't have time-consuming issues to create or update
tooltips.
(However, I find the function I put in my second post more useful (for
my use case: I don't use the mouse very much).
#+begin_src emacs-lisp
(defun my-org-fn-make-tooltips ()
(interactive)
(org-element-map (org-element-parse-buffer) 'footnote-reference
(lambda (ref)
(let* ((label (org-element-property :label ref))
(label-from (org-element-property :begin ref))
(label-to (org-element-property :end ref))
(def (org-with-wide-buffer
(org-footnote-goto-definition label)
(let* ((e (org-element-context))
(from (org-element-property :contents-begin e))
(to (org-element-property :contents-end e)))
(buffer-substring-no-properties from to))))
(tooltip def))
(add-text-properties label-from label-to
`(help-echo
,tooltip))))
nil nil))
#+end_src
Best regards,
Juan Manuel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Footnote tooltips (an attempt)
[not found] ` <CAJcAo8tsK5o+789Wv=i6ddiSrM4fDyX8HCvjAgDLXGyLXWRWmQ@mail.gmail.com>
@ 2022-02-23 19:52 ` Juan Manuel Macías
2022-02-23 22:05 ` John Kitchin
0 siblings, 1 reply; 9+ messages in thread
From: Juan Manuel Macías @ 2022-02-23 19:52 UTC (permalink / raw)
To: Samuel Wales, Ypo; +Cc: orgmode
[-- Attachment #1: Type: text/plain, Size: 1620 bytes --]
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
[-- Attachment #2: fn-tooltips.org --]
[-- Type: application/vnd.lotus-organizer, Size: 3004 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Footnote tooltips (an attempt)
2022-02-23 19:52 ` Juan Manuel Macías
@ 2022-02-23 22:05 ` John Kitchin
2022-02-24 2:04 ` Juan Manuel Macías
0 siblings, 1 reply; 9+ messages in thread
From: John Kitchin @ 2022-02-23 22:05 UTC (permalink / raw)
To: Juan Manuel Macías; +Cc: Ypo, orgmode
[-- Attachment #1: Type: text/plain, Size: 4080 bytes --]
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 <maciaschain@posteo.net>
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
>
>
[-- Attachment #2: Type: text/html, Size: 5282 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Footnote tooltips (an attempt)
2022-02-23 22:05 ` John Kitchin
@ 2022-02-24 2:04 ` Juan Manuel Macías
2022-02-24 13:01 ` John Kitchin
0 siblings, 1 reply; 9+ messages in thread
From: Juan Manuel Macías @ 2022-02-24 2:04 UTC (permalink / raw)
To: John Kitchin; +Cc: orgmode
Hi John,
John Kitchin writes:
> 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.
Thank you very much for your comment and code, which has helped me to
clarify my ideas. Your approach is in a certain way similar to the last
version of my attempt, which I attached in the previous message: through
a first function I get the definition of each note, which is returned as
a text string. And I also override via `advice-add'
'org-activate-footnonte-links' with a new function, which is also
slightly modified, including a variable that gets the tooltip from the
first function. The problem is that with my approach the tooltip does
not appear on the fly, but when the next note is added. I think what my
first function (the one that gets the footnote definition) was missing
was the three arguments of your first function: `_win _obj position' and
the (goto-char position), and pass it as a symbol (not as a variable) to
the second function that overrides org-activate-footnote-links, as you
do in your code. Modifying my function from your code, it would look
something like this:
(defun my-org-fn-get-def (_win _obj position)
(save-excursion
(goto-char position)
(let* ((el (org-element-context))
(label (org-element-property :label el))
(def (nth 3 (org-footnote-get-definition label))))
(when def (concat "Footnonte: " def)))))
And it seems that now the tooltips appear instantly, and are updated in
real time.
Best regards,
Juan Manuel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Footnote tooltips (an attempt)
2022-02-24 2:04 ` Juan Manuel Macías
@ 2022-02-24 13:01 ` John Kitchin
2022-02-24 16:25 ` Juan Manuel Macías
0 siblings, 1 reply; 9+ messages in thread
From: John Kitchin @ 2022-02-24 13:01 UTC (permalink / raw)
To: Juan Manuel Macías; +Cc: orgmode
[-- Attachment #1: Type: text/plain, Size: 2771 bytes --]
that is a nice solution. I probably should have read the docstring on
org-footnote-get-definition a little more closely, it has the definition
you need in it!
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 9:04 PM Juan Manuel Macías <maciaschain@posteo.net>
wrote:
> Hi John,
>
> John Kitchin writes:
>
> > 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.
>
> Thank you very much for your comment and code, which has helped me to
> clarify my ideas. Your approach is in a certain way similar to the last
> version of my attempt, which I attached in the previous message: through
> a first function I get the definition of each note, which is returned as
> a text string. And I also override via `advice-add'
> 'org-activate-footnonte-links' with a new function, which is also
> slightly modified, including a variable that gets the tooltip from the
> first function. The problem is that with my approach the tooltip does
> not appear on the fly, but when the next note is added. I think what my
> first function (the one that gets the footnote definition) was missing
> was the three arguments of your first function: `_win _obj position' and
> the (goto-char position), and pass it as a symbol (not as a variable) to
> the second function that overrides org-activate-footnote-links, as you
> do in your code. Modifying my function from your code, it would look
> something like this:
>
> (defun my-org-fn-get-def (_win _obj position)
> (save-excursion
> (goto-char position)
> (let* ((el (org-element-context))
> (label (org-element-property :label el))
> (def (nth 3 (org-footnote-get-definition label))))
> (when def (concat "Footnonte: " def)))))
>
> And it seems that now the tooltips appear instantly, and are updated in
> real time.
>
> Best regards,
>
> Juan Manuel
>
[-- Attachment #2: Type: text/html, Size: 3511 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Footnote tooltips (an attempt)
2022-02-24 13:01 ` John Kitchin
@ 2022-02-24 16:25 ` Juan Manuel Macías
0 siblings, 0 replies; 9+ messages in thread
From: Juan Manuel Macías @ 2022-02-24 16:25 UTC (permalink / raw)
To: John Kitchin; +Cc: orgmode
John Kitchin writes:
> that is a nice solution. I probably should have read the docstring on
> org-footnote-get-definition a little more closely, it has the
> definition you need in it!
Well, it's a minor detail. The really brilliant thing here is your idea
of passing the function as a help-echo value, instead of a text string.
It works like a charm! :-).
(I didn't know that the help-echo property could accept a function as a
value, and reading the documentation I realize that this has a lot of
potential...).
Best regards, And thanks again,
Juan Manuel
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-02-24 16:26 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.57.1645549224.6185.emacs-orgmode@gnu.org>
2022-02-22 22:30 ` Footnote tooltips (an attempt) Ypo
2022-02-23 2:26 ` Juan Manuel Macías
[not found] ` <CAJcAo8tsK5o+789Wv=i6ddiSrM4fDyX8HCvjAgDLXGyLXWRWmQ@mail.gmail.com>
2022-02-23 19:52 ` Juan Manuel Macías
2022-02-23 22:05 ` John Kitchin
2022-02-24 2:04 ` Juan Manuel Macías
2022-02-24 13:01 ` John Kitchin
2022-02-24 16:25 ` Juan Manuel Macías
2022-02-22 4:32 Juan Manuel Macías
2022-02-22 22:15 ` Juan Manuel Macías
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
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).