Tree-view for the backlinks buffer

I spent the afternoon hacking together a tree-based backlinks sections to help me get a better handle on what’s going on with my knowledge graph. It currently groups backlinks by the org files they come from, but it should be pretty easily adaptable to other groupings. Not a mature package by any means, but it’s working ok and others might be interested.

2 Likes

I love this idea. How deep can the tree get?

At the moment just one level, but I plan to make it arbitrary when I get some more free time to do a bit of coding. I want the structure to be reusable, so you can pretty easily make trees just by writing a function to create a list formatted as ‘(title (backlink backlink …) title2 (backlinks …)…) . It shouldn’t be tough to make the renderer take more levels, just need to find the time to do it.

I’ve made some significant changes to this package. It now works with arbitrary depth trees if you can provide the renderer with the data in the format it wants. I also wrote a “crosslinks” view that shows cross-references with other nodes, like searching for nodes that reference both “Pierre Bourdieu” and “Karl Marx”, as in this screenshot:

I use (setq! org-roam-mode-sections '(org-roam-tree-backlinks-section)), but it shows “Default section” when I start the view, and I have to mannually choose “backlinks tree” from the menu bar. Is there a way to config to show “backlinks tree” directly? Thanks!

Another issue is the menu icon itself. My environment is windows doom emacs, and It displays as below:

I have nerd icons installed, and ☰ (TRIGRAM FOR HEAVEN) can be displayed without problem.

Tried to ask AI and had no luck to solve it.

Hmm… when are you setting org-roam-mode-sections? My best guess that maybe you’re setting it before emacs loads org-roam, and org-roam then resets it to its default value? Does putting it in an after block fix it? (after! org-roam-tree (setq org-roam-mode-sections '(org-roam-tree-backlinks-section))

As for the icon… I’m not sure I can debug, I have no access to a windows system. What font are you using? TBF I didn’t use nerd icons for it, I just grabbed a unicode character. If you open the source file in emacs, does it render? It’s in variable org-roam-tree–header-buttons.

It looks like the symbol you suggest renders fine on my system, so I’ve swapped it in in the source. I probably won’t push to github for a few days while I’m testing a new tree view for unlinked references (which I’m personally finding super helpful!), but it shouldn’t bee too long.

For the icon, I guest it might not be a standard unicode char, or it is in an extended unicode set:

             position: 22506 of 24578 (92%), column: 32
            character:  (displayed as ) (codepoint 58834, #o162722, #xe5d2)
              charset: unicode-bmp (Unicode Basic Multilingual Plane (U+0000..U+FFFF))
code point in charset: 0xE5D2
               syntax: w 	which means: word
             category: L:Strong L2R, j:Japanese
             to input: type "C-x 8 RET e5d2"
          buffer code: #xEE #x97 #x92
            file code: #xEE #x97 #x92 (encoded by coding system utf-8-unix)
              display: no font available

Character code properties: customize what to show
  general-category: Co (Other, Private Use)
  decomposition: (58834) ('')

I would suggest to use:

             position: 22506 of 24578 (92%), column: 32
            character: ☰ (displayed as ☰) (codepoint 9776, #o23060, #x2630)
              charset: unicode-bmp (Unicode Basic Multilingual Plane (U+0000..U+FFFF))
code point in charset: 0x2630
               script: symbol
               syntax: w 	which means: word
             category: .:Base
             to input: type "C-x 8 RET 2630" or "C-x 8 RET TRIGRAM FOR HEAVEN"
          buffer code: #xE2 #x98 #xB0
            file code: #xE2 #x98 #xB0 (encoded by coding system utf-8-unix)
              display: by this font (glyph code):
    harfbuzz:-outline-等距更纱黑体 SC-regular-normal-normal-mono-36-*-*-*-c-*-iso8859-1 (#xA92)

Character code properties: customize what to show
  name: TRIGRAM FOR HEAVEN
  general-category: So (Symbol, Other)
  decomposition: (9776) ('☰')

For the default view, I use:

(use-package! org-roam-tree
  :after org-roam
  :config
  (setq! org-roam-mode-sections '(org-roam-tree-backlinks-section))
  (setq org-roam-tree-default-visible 2)
  )

Tried both setq and setq! and got same result.

I am able to change the icon, but the start view remains “Default section”:

(after! org-roam-tree
  (setq! org-roam-mode-sections '(org-roam-tree-backlinks-section))
  (setq org-roam-tree--header-buttons
        (list
         (org-roam-tree--make-button "☰" #'org-roam-tree--header-menu
          )))
  )

Hmm, this is very strange, I’m at a bit of a loss. Try starting a new emacs session, and open up your roam buffer but don’t change the view. What is the value of org-roam-mode-sections?

If it looks right, try M-: (org-roam-buffer-refresh) and see if that makes it display properly.

Thanks for the instruction. Now I found the cause that I also use org-roam-bibtex, where I configured:

(setf org-roam-mode-sections '(orb-section-reference
                               orb-section-abstract
                               org-roam-backlinks-section
                               org-roam-reflinks-section))

Now my questions is how to put ort and orb together? I’d love to have tree view as default and click to change to orb view.

Oh neat, I didn’t know about orb.

At the moment I’m not supporting mixing tree sections with other sections. You can try it but I’d be surprised if it works reliably.

What you can do is load -tree after your other package and its config, and it should save your sections as the “default” section so you cans switch to them quickly.

All right, thanks!