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).

2021-04-07T181500_link-preview-2

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.

I came here with the same question as @midas (OP) so I tried out @nobiot’s code. To my surprise the code doesn’t seem to work as expected (which came as a surprise as @nobiot’s suggestions/solutions in this discourse group have helped me a lot in the past).

Indeed, the org-roam file to which the link points does open but not in a side-window, it replaces the current buffer in the active window. Bear in mind that I’m using doom emacs, so I’ve made sure to not be using the +popup module to test the code.

I’ve tried this on several files and all I could get is that this seems to work with org files but not with any of my org-roam files. I understand both are the same in the sense of extension, I’m just pointing out my findings in case anyone could come up with a reason for the weird behavior that I’m observing.

Thanks for all your help.

Ok I think I’ve found the reason and a way, proposed by another generous poster. See this link: org-roam-window-mode for easy roaming · Issue #1479 · org-roam/org-roam · GitHub

1 Like

This behaviour may be because of this mod Doom does to org-open-at-point.

I do not know what doom-set-jump-h does.

In any case, I am glad that you have found a solution that works for you :slight_smile: