emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Kitchin <johnrkitchin@gmail.com>
To: "Juan Manuel Macías" <maciaschain@posteo.net>
Cc: Ypo <ypuntot@gmail.com>, orgmode <emacs-orgmode@gnu.org>
Subject: Re: Footnote tooltips (an attempt)
Date: Wed, 23 Feb 2022 17:05:05 -0500	[thread overview]
Message-ID: <CAJ51ETq=MQz5iUeeXQg4w85FiwP7p_QaUnAoL6OhhWU8R0Hp=A@mail.gmail.com> (raw)
In-Reply-To: <87czjdgy2v.fsf@posteo.net>

[-- 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 --]

  reply	other threads:[~2022-02-23 22:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJ51ETq=MQz5iUeeXQg4w85FiwP7p_QaUnAoL6OhhWU8R0Hp=A@mail.gmail.com' \
    --to=johnrkitchin@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=maciaschain@posteo.net \
    --cc=ypuntot@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).