Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (with-eval-after-load 'org-roam
- (defun org-roam-unlinked-references-section (node)
- "The unlinked references section for NODE.
- References from FILE are excluded."
- (when (and (executable-find "rg")
- (not (string-match "PCRE2 is not available"
- (shell-command-to-string "rg --pcre2-version"))))
- (let* ((titles (cons (org-roam-node-title node)
- (org-roam-node-aliases node)))
- (rg-command (concat "rg -L -o --vimgrep -P -i "
- (mapconcat (lambda (glob) (concat "-g " glob))
- (org-roam--list-files-search-globs org-roam-file-extensions)
- " ")
- (format " '\\[([^[]]++|(?R))*\\]%s' "
- (mapconcat (lambda (title)
- (format "|(\\b%s\\b)" (shell-quote-argument title)))
- titles ""))
- org-roam-directory))
- (results (split-string (shell-command-to-string rg-command) "\n"))
- f row col match)
- (magit-insert-section (unlinked-references)
- (magit-insert-heading "Unlinked References:")
- (dolist (line results)
- (save-match-data
- (when (string-match org-roam-unlinked-references-result-re line)
- (setq f (match-string 1 line)
- row (string-to-number (match-string 2 line))
- col (string-to-number (match-string 3 line))
- match (match-string 4 line))
- (when (and match
- (not (file-equal-p (org-roam-node-file node) f))
- (member (downcase match) (mapcar #'downcase titles))
- (not (s-contains? ":NOTER_PAGE:" line t))
- (not (s-contains? ":NOTER_DOCUMENT:" line t))
- )
- (magit-insert-section section (org-roam-grep-section)
- (oset section file f)
- (oset section row row)
- (oset section col col)
- (insert (propertize (format "%s:%s:%s"
- (truncate-string-to-width (file-name-base f) 15 nil nil t)
- row col) 'font-lock-face 'org-roam-dim)
- " "
- (org-roam-fontify-like-in-org-mode
- (org-roam-unlinked-references-preview-line f row))
- "\n"))))))
- (insert ?\n)))))
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement