Skip to content

Commit f9228ce

Browse files
authored
(feat): add support for filtering backlinks. (#2247)
* Add support for filtering backlinks. See #1043. * Add documentation for backlinks filter
1 parent 25c4767 commit f9228ce

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

doc/org-roam.org

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,19 @@ rendering reference links), set ~org-roam-mode-sections~ as follows:
644644
org-roam-reflinks-section))
645645
#+end_src
646646

647+
The backlinks section ~org-roam-backlinks-section~ also supports a
648+
predicate to filter backlinks, ~:show-backlink-p~. This can be used
649+
as follows:
650+
651+
#+begin_src emacs-lisp
652+
(defun my-org-roam-show-backlink-p (backlink)
653+
(not (member "daily" (org-roam-node-tags (org-roam-backlink-source-node backlink)))))
654+
655+
(setq org-roam-mode-sections
656+
'((org-roam-backlinks-section :unique t :show-backlink-p my/org-roam-show-backlink-p)
657+
org-roam-reflinks-section))
658+
#+end_src
659+
647660
** Configuring the Org-roam buffer display
648661

649662
Org-roam does not control how the pop-up buffer is displayed: this is left to

org-roam-mode.el

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,19 +514,25 @@ Sorts by title."
514514
(string< (org-roam-node-title (org-roam-backlink-source-node a))
515515
(org-roam-node-title (org-roam-backlink-source-node b))))
516516

517-
(cl-defun org-roam-backlinks-section (node &key (unique nil))
517+
(cl-defun org-roam-backlinks-section (node &key (unique nil) (show-backlink-p nil))
518518
"The backlinks section for NODE.
519519
520520
When UNIQUE is nil, show all positions where references are found.
521-
When UNIQUE is t, limit to unique sources."
521+
When UNIQUE is t, limit to unique sources.
522+
523+
When SHOW-BACKLINK-P is not null, only show backlinks for which
524+
this predicate is not nil."
522525
(when-let ((backlinks (seq-sort #'org-roam-backlinks-sort (org-roam-backlinks-get node :unique unique))))
523526
(magit-insert-section (org-roam-backlinks)
524527
(magit-insert-heading "Backlinks:")
525528
(dolist (backlink backlinks)
526-
(org-roam-node-insert-section
527-
:source-node (org-roam-backlink-source-node backlink)
528-
:point (org-roam-backlink-point backlink)
529-
:properties (org-roam-backlink-properties backlink)))
529+
(when (or (null show-backlink-p)
530+
(and (not (null show-backlink-p))
531+
(funcall show-backlink-p backlink)))
532+
(org-roam-node-insert-section
533+
:source-node (org-roam-backlink-source-node backlink)
534+
:point (org-roam-backlink-point backlink)
535+
:properties (org-roam-backlink-properties backlink))))
530536
(insert ?\n))))
531537

532538
;;;; Reflinks

0 commit comments

Comments
 (0)