Advertisement
Guest User

Untitled

a guest
May 18th, 2022
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 2.65 KB | None | 0 0
  1. (with-eval-after-load 'org-roam
  2. (defun org-roam-unlinked-references-section (node)
  3.   "The unlinked references section for NODE.
  4. References from FILE are excluded."
  5.   (when (and (executable-find "rg")
  6.              (not (string-match "PCRE2 is not available"
  7.                                 (shell-command-to-string "rg --pcre2-version"))))
  8.     (let* ((titles (cons (org-roam-node-title node)
  9.                          (org-roam-node-aliases node)))
  10.            (rg-command (concat "rg -L -o --vimgrep -P -i "
  11.                                (mapconcat (lambda (glob) (concat "-g " glob))
  12.                                           (org-roam--list-files-search-globs org-roam-file-extensions)
  13.                                           " ")
  14.                                (format " '\\[([^[]]++|(?R))*\\]%s' "
  15.                                        (mapconcat (lambda (title)
  16.                                                     (format "|(\\b%s\\b)" (shell-quote-argument title)))
  17.                                                   titles ""))
  18.                                org-roam-directory))
  19.            (results (split-string (shell-command-to-string rg-command) "\n"))
  20.            f row col match)
  21.       (magit-insert-section (unlinked-references)
  22.         (magit-insert-heading "Unlinked References:")
  23.         (dolist (line results)
  24.           (save-match-data
  25.             (when (string-match org-roam-unlinked-references-result-re line)
  26.               (setq f (match-string 1 line)
  27.                     row (string-to-number (match-string 2 line))
  28.                     col (string-to-number (match-string 3 line))
  29.                     match (match-string 4 line))
  30.               (when (and match
  31.                          (not (file-equal-p (org-roam-node-file node) f))
  32.                          (member (downcase match) (mapcar #'downcase titles))
  33.                          (not (s-contains? ":NOTER_PAGE:" line t))
  34.                          (not (s-contains? ":NOTER_DOCUMENT:" line t))
  35. )
  36.                 (magit-insert-section section (org-roam-grep-section)
  37.                   (oset section file f)
  38.                   (oset section row row)
  39.                   (oset section col col)
  40.                   (insert (propertize (format "%s:%s:%s"
  41.                                               (truncate-string-to-width (file-name-base f) 15 nil nil t)
  42.                                               row col) 'font-lock-face 'org-roam-dim)
  43.                           " "
  44.                           (org-roam-fontify-like-in-org-mode
  45.                            (org-roam-unlinked-references-preview-line f row))
  46.                           "\n"))))))
  47.         (insert ?\n)))))
  48.                 )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement