Preview link target?

When working in a note, is it possible to preview the link-at-point? I know there are ways to open a separate buffer and jump to link-target. I was thinking of a more dynamic option. For example, the backlink buffer could be a place to display a few lines of the link-target (I imagine mini-buffer is too small). Another option is to show a preview when mouse hovers over the link.

EDIT: extending this question… a preview when looking at list of org-roam files would also be useful. One use-case is when executing org-roam-find-file. Another more interesting use-case is when using dired buffer.

I believe the answer is “Yes”, but it would be more for custom scripting. I do not know of any package that does it for you.

It’s probably useful to clarify what you are really going for with a simple prototype. See the GIF animation below (code follows, so you can try it yourself).

The script is very simple and does the following:

  1. Temporarily set display-buffer-alist so that a target buffer opens in a side-window at the bottom of a screen with a specified height of 25% of the screen
  2. Use the standard org-open-at-point function to open the link at point (depending on your Org config it might behave differently on your end)

You can see that I am trying to “preview” the ID link. When I call my/link-preview command, a new buffer opens at the bottom and my cursor (point) moves into it – because of this, my *org-roam* buffer refreshes. It’s a V2 backlink buffer but that is not relevant now.

This is probably missing some elements you are really going for, but I think it’s not too far off the mark. You probably want a couple of more elements:

  1. The cursor to stay in the note, so that you can keep working in your note
  2. It should be possible to toggle the “preview buffer” easily with a single function key for instance (e.g. F9)
  3. Display the preview buffer on the side, next to the backlink buffer (I prefer a side-buffer at the bottom this way)

These would be rather simple modifications to achieve.

This would be more involved. I am not interested in the mouse hover in Emacs in general, but as an example, @cool_ran has done something that you could look to apply to this purpose with postframe.

This would be something you might like to consider using consult package. For example, see the video demo @emacsomancer has put together for consult-ripgrep – if you run it for org-roam-directory, I think you get something pretty close.

New UI possibilities that @bruce is considering for V2 might be going in this direction.

As a similar attempt for Dired, I have done this, which might be close to what you are going for. There might be a better way with consult; it might converge with the V2 UI possibilities I mention above.

For all these options, my sense is that the first option that I did with a prototype is the easiest and most practical (for me). I might explorer it a bit more (I feel it rather useful for myself).

EDIT: Forgot to add the prototype script…

#+begin_src emacs-lisp
  (defun my/link-preview ()
    (interactive)
    (let ((display-buffer-alist
           '(;; Bottom side window
             (".*"
              (display-buffer-in-side-window)
              (window-height . 0.25)
              (side . bottom)
              (slot . 0)))))
      (org-open-at-point)))
#+end_src
1 Like

Thanks so much @nobiot for an incredible set of leads and suggestions. So much to explore in your post, and I look forward to going through it carefully.