RESOLVED: Styling links in the roam buffer?

In my roam buffer, unless I toggle visible-mode, links in the displayed blocks just looks like regular text. I’d like to have links styled in the same way they are in an org buffer, so I can scan more quickly for context of those backlinks. I can’t seem to find any references on how to do this; is it possible? Thanks!

The value of org-descriptive-links should be t

(setopt org-descriptive-links t)

I do not need to enable visible mode for anything. Did you change this value? This is how it shows up in my case.

Take a look at here

      (insert (org-roam-fontify-like-in-org-mode
               (org-roam-preview-get-contents (org-roam-node-file source-node) point))
              "\n")

in org-roam/org-roam-mode.el at 425d53d56d0d338c781741df87824b1bfe7f88bc · org-roam/org-roam · GitHub

This is responsible for rendering contents as in org-mode inside org-roam-mode. org-roam-fontify-like-in-org-mode would respect fontification settings including those for rendering links.
So links should be presented AS IS for org, inside org-roam-mode.

I have the same experience as @akashp – By default, the links in the backlinks buffer (org-roam-buffer) show descriptions only.

I take it that you’d need to toggle visible-mode off, because it should be off by default. This means you have explicitly enabled it somewhere – manual or in your configuration. If you have a reason to keep the settings for visible-mode, then perhaps you can do the following, with using org-roam-mode-hookorg-roam-mode is a major mode, so the hook is provided for it.

(add-hook 'org-roam-mode-hook 'visible-mode) ; simply toggling it

;; Alternatively, turn it off explicitly
(add-hook 'org-roam-mode-hook (lambda () (visible-mode -1)))

Hey guys, thanks for the help! So the visible mode bit is a red herring, what I meant is that turning it on (it is off by default) I can see the [[id:xyz][link]] markup. Which isn’t really that helpful anyway.

org-descriptive-links is t. Links in regular org buffers are fontified, but nothing is fontified in the org-roam buffer; here’s what I have (visible mode enabled to show what should be fontified)

that one link is highlighted as a mouseover action.

I am using a custom org-roam-preview-function from here: How to configure org-roam-buffer char length? - #14 by akashp like this:

#+begin_src elisp
(defun custom/org-roam-preview-default-function ()
    "Return the preview content at point.

This function returns the text of the immediate line(s) where the link is located."
    (let ((beg (save-excursion
		 (org-beginning-of-line 1) (point)))
          (end (save-excursion
		 (org-end-of-line 1) (point))))
      (string-trim (buffer-substring-no-properties beg end))))

(setopt org-roam-preview-function #'custom/org-roam-preview-default-function)
#+end_src

Could this be disabling fontification somehow? I’m not sure what else might be changing the roam buffer styles…

Well I wrote it so that it wouldn’t cut off the links, from the screenshot you posted it doesn’t seem like the link is getting cut off either … strange, I tested the code myself too and it didn’t mess up the fontification…

Would you be upto some diagnostics ? Try not using the function and report first if the links are showing like this anyways.

Also please post a screenshot without Visible mode, when you turn on visible mode, the link is forced to be full descriptive. I think there is some misunderstanding involved somewhere, I am not getting the problem accurately. What is the result when visible mode is turned off? Can we see this result? we can proceed with further diagnostics if required.

(defun debug/org-roam-fontify-like-in-org-mode (s)
  "Debug setup using a new buffer."
  (let ((new-buffer (generate-new-buffer "*debug-org-roam*")))
    (with-current-buffer new-buffer
      (insert s)
      (let ((org-ref-buffer-hacked t))
        (org-mode)
        (setq-local org-fold-core-style 'overlays)
        (font-lock-ensure))
      (switch-to-buffer new-buffer))))

(debug/org-roam-fontify-like-in-org-mode "[[id:madeuplink][desc]]")

Try this simple debug if the problem is not with the preview function.

We pass a simple link, this function is a replica of org-roam-fontify-like-in-org-mode with the notable exception that it pastes the result in a new buffer instead of processing it and passing it along - if the link is fontified correctly in the new buffer, then something else is amiss. I will see the results if you post it tomorrow.

I am confused about what your issue is and what you want to achieve.

Do you want to show [[id:xyz][link]] or show only link? If you want to show the whole markup by turning visibility-mode on, then you say you can do this (correct?). Then what is the issue? I thought you wanted to hide the whole markup, showing only link… But that does not seem to be what you are saying

Ok, here we go! Here’s a screenie of the org buffer without visible mode:

Deactivating the preview function does not change the fontification.

Running your debug function, it seems to do what is expected, here’s the result:
(oops I can only post one image at a time since I’m new here)

Although the resulting buffer is in org mode, which isn’t the case for the org-roam buffer.

Ok, here’s the result of that debug function. Again, it’s in org-mode, unlike the org-roam buffer.

@niobot I’m sorry, my original post was not clear. The behaviour that I want really has nothing to do with visible-mode. What I’m wanting to do is have links in the org-roam buffer underlined & a different colour than the regular text there. All visible-mode does is make links evident by displaying their markup. I was saying that that is not a very good substitute for having the links coloured. Ideally other org markup would be rendred too, like *bold* /italics/ +strikethrough+ and so on.

Thanks, no worries. Hmm. Can’t repro the issue. My backlink buffer does fontification as we expect it to (org-roam-preview-function is default, but you report that with or without the custom preview function didn’t change the behavior).

By the way, do you happen to be using Doom Emacs?

Edit: in the screenshot the italics does not appear working but that’s just because of my fixed-pitch font. Italics works if I activate variable-pitch-mode

Yes, I’m using doom. Might it be doing something unexpected?

Theme issue. Try changing theme and report please.

It’s likely. Neither @akashp or I use Doom and we have no issue.
It will not be easy for us to get to the bottom of it because our configuration is not based on Doom and we do not have access to runtime debugging with Doom. I hope you can accept the fact that we are stabbing in the dark – the quicker way may be to ask the question in the Doom community.

Having said this, we can still continue as @akashp suggests:

This may help.

In addition to the theme, it may help to modify the Akashp’s debug code like this below. This is to test function org-roam-fontify-like-in-org-mode and compare the result with the second one org-fontify-like-in-org-mode in Fundamental mode (not Org mode). You should then look at the fontified link’s face with describe-char with your cursor within the link.

(defun debug/org-roam-fontify-like-in-org-mode (s)
  "Debug setup using a new buffer."
  (let ((new-buffer (generate-new-buffer "*debug-org-roam*")))
    (with-current-buffer new-buffer
      (insert (org-roam-fontify-like-in-org-mode s))
      (switch-to-buffer new-buffer))))

(debug/org-roam-fontify-like-in-org-mode "[[id:madeuplink][desc]] **bold** /italic/ +strike-throuhg+")

As you can see in the image below, The text is fontified as Org does in the Fundamental mode buffer.

Secondary, we can test the Org-mode (upstream Org’s similar function that org-roam emulates). The code looks similar, but it is different in that it calls org-fontify-like-in-org-mode (instead of org-roam-fontify-like-in-org-mode above).

(defun debug/org-fontify-like-in-org-mode (s)
  "Debug setup using a new buffer."
  (let ((new-buffer (generate-new-buffer "*debug-org-fontify-like-org-mode*")))
    (with-current-buffer new-buffer
      (insert (org-fontify-like-in-org-mode s))
      (switch-to-buffer new-buffer))))

(debug/org-fontify-like-in-org-mode "[[id:madeuplink][desc]] **bold** /italic/ +strike-throuhg+")

The resultant fontification is the same in Fundamental mode buffer.

If I then do M-x describe-char on the “s” character in the “desc” link for Org-roam test buffer, I get this:

I suspect you might not get the same face (org-link) in your case. Or org-link has the same face as your body text’s face.

1 Like

Wow guys, thank you for engaging with this! I absolutely understand it’s a stab in the dark and appreciate you going the extra mile! Here’s what I’ve found:

  1. Changing themes makes no difference (I’ve checked several ef- themes as well as ‘default’).
  2. I can explicitly change the roam buffer’s major mode to org-mode, and then links are fontafied correctly, though of course I lose the functionality of org-roam-mode.
  3. Doing what @nobiot suggested with describe-char in the roam buffer in those two modes does indeed show a difference; in org-roam-mode, the link does not have the org-link face:
There are 2 overlays here:
 From 106 to 1280
  evaporate            t
  font-lock-face       magit-section-highlight
 From 106 to 1279
  face                 hl-line
  priority             -50
  window               nil


There are text properties here:
  fontified            t
  help-echo            [Show]
  htmlize-link         [Show]
  keymap               [Show]
  magit-section        [Show]
  mouse-face           highlight

in org-mode:

There is an overlay here:
 From 106 to 1279
  face                 hl-line
  priority             -50
  window               nil


There are text properties here:
  face                 org-link
  font-lock-multiline  t
  fontified            t
  help-echo            [Show]
  htmlize-link         [Show]
  keymap               [Show]
  line-prefix          ""
  magit-section        [Show]
  mouse-face           highlight
  wrap-prefix          ""

  1. With the adjusted debug code, here is the result:
    first one:
Character code properties: customize what to show
  name: LATIN SMALL LETTER E
  general-category: Ll (Letter, Lowercase)
  decomposition: (101) ('e')

There are text properties here:
  face                 org-link
  font-lock-multiline  t
  help-echo            "LINK: id:madeuplink"
  htmlize-link         (:uri "id:madeuplink")
  keymap               [Show]
  mouse-face           highlight

and the second one:

Character code properties: customize what to show
  name: LATIN SMALL LETTER D
  general-category: Ll (Letter, Lowercase)
  decomposition: (100) ('d')

There are text properties here:
  face                 org-link
  font-lock-multiline  t
  help-echo            "LINK: id:madeuplink"
  htmlize-link         (:uri "id:madeuplink")
  keymap               [Show]
  mouse-face           highlight


So it looks like the fontify function is not being called within org-roam-mode.

  1. On a larf I tried calling fontify (both org- and org-roam- variants) from the preview funciton, but to no effect:
(defun custom/org-roam-preview-default-function ()
    "Return the preview content at point.

This function returns the text of the immediate line(s) where the link is located."
    (let ((beg (save-excursion
		 (org-beginning-of-line 1) (point)))
          (end (save-excursion
		 (org-end-of-line 1) (point))))
      (org-roam-fontify-like-in-org-mode (string-trim (buffer-substring-no-properties beg end)))
      ))

So at this point best guess is that somewhere up the call stack font info is being stripped? I went back a bit and wound up in magit-insert-section, and didn’t see anything obvious, but my elisp is less than stellar.

Anyway, if either of you has any more ideas I’m all ears, but my time is limited for debugging. For the moment just switching the roam buffer to org-mode gets me maybe 50% of the way there. I’ll crosspost to the doom community when I have a little more time.

It looks like it. I have a feeling this is done somewhere outside of Org-roam but can’t be sure.

This is as far as I can come with you. I hope your post in the Doom community will get you somewhere – if you do, please come back and enlighten me…

Oh no guys, I’ve figured it out. Randomly, the fontification started working again, but some other things weren’t, I’d introduced an error in my config. Fixed the error and the fontsstopped being applied again – but very interestingly, I opened a node with a lot of backlinks, and the roam buffer displayed – with fontification of links – and then the styles disappeared after half a second.

Went about bisecting my config, and it turns out the problem was rainbow-mode which I had enabled globally like this:

(define-globalized-minor-mode global-rainbow-mode rainbow-mode
  (lambda ()
    (when (not (memq major-mode
                (list 'org-agenda-mode )))
     (rainbow-mode 1))))
(global-rainbow-mode 1 )

So adding org-roam-mode to the blacklist there has fixed the problem.

Thank you both for your help, and I’m sorry for taking up your time on this!

2 Likes