# Preview link target?

**URL:** <https://org-roam.discourse.group/t/preview-link-target/1452>\
**Category:** How To\
**Created:** [April 6, 2021, 7:29pm UTC](https://org-roam.discourse.group/t/preview-link-target/1452 "2021-04-06T19:29:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![midas](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@midas](https://org-roam.discourse.group/u/midas)\
**Post date:** [April 6, 2021, 7:29pm UTC](https://org-roam.discourse.group/t/preview-link-target/1452/1 "2021-04-06T19:29:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)\
**Post date:** [April 7, 2021, 4:49pm UTC](https://org-roam.discourse.group/t/preview-link-target/1452/2 "2021-04-07T16:49:49Z")

</div>

> [@midas](#):
>
> 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)

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](https://global.discourse-cdn.com/free1/uploads/orgroam/original/1X/6fc73b20166fce103ba95222346525d915c2b768.gif)

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.

> [@midas](#):
>
> Another option is to show a preview when mouse hovers over the link

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](https://org-roam.discourse.group/t/prototype-org-marginalia-write-margin-notes-with-org-mode/1080/3) that you could look to apply to this purpose with `postframe`.

> [@midas](#):
>
> a preview when looking at list of org-roam files would also be useful. One use-case is when executing org-roam-find-file.

This would be something you might like to consider using `consult` package. For example, see [the video demo](https://org-roam.discourse.group/t/using-consult-ripgrep-with-org-roam-for-searching-notes/1226) @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](https://org-roam.discourse.group/t/find-node-ui-possibilities-for-v2/1422) that @bruce is considering for V2 might be going in this direction.

> [@midas](#):
>
> Another more interesting use-case is when using dired buffer

As a similar attempt for Dired, I have done [this](https://org-roam.discourse.group/t/org-roam-dailies-how-to-browse-through-previous-days/1018/5), 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…

```auto
#+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

```

---

<div class="post-metadata">

**Author:** ![midas](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@midas](https://org-roam.discourse.group/u/midas)\
**Post date:** [April 8, 2021, 3:34am UTC](https://org-roam.discourse.group/t/preview-link-target/1452/3 "2021-04-08T03:34:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gusgustavsohn](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/gusgustavsohn/32/1189_2.png) [@gusgustavsohn](https://org-roam.discourse.group/u/gusgustavsohn)\
**Post date:** [November 19, 2022, 9:08pm UTC](https://org-roam.discourse.group/t/preview-link-target/1452/4 "2022-11-19T21:08:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gusgustavsohn](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/gusgustavsohn/32/1189_2.png) [@gusgustavsohn](https://org-roam.discourse.group/u/gusgustavsohn)\
**Post date:** [November 19, 2022, 10:39pm UTC](https://org-roam.discourse.group/t/preview-link-target/1452/5 "2022-11-19T22:39:57Z")

</div>

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](https://github.com/org-roam/org-roam/issues/1479#issuecomment-844283079)

---

<div class="post-metadata">

**Author:** ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)\
**Post date:** [November 20, 2022, 12:40pm UTC](https://org-roam.discourse.group/t/preview-link-target/1452/6 "2022-11-20T12:40:05Z")

</div>

> [@gusgustavsohn](#):
>
> 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.

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

> <https://github.com/doomemacs/doomemacs/blob/master/modules/lang/org/config.el#L1457>

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 🙂
