emacs-启用org-roam中的unlinked-section
1. 启用unlinked-section
在 org-roam
中进行如下设置:
(use-package org-roam :custom (org-roam-mode-sections (list #'org-roam-backlinks-section ;; #'org-roam-reflinks-section #'org-roam-unlinked-references-section )) )
2. 覆盖内置相关函数
(defun org-roam-unlinked-references--rg-command (titles) "Return the ripgrep command searching for TITLES." (concat "rg --follow --only-matching --vimgrep --pcre2 --ignore-case " (mapconcat (lambda (glob) (concat "--glob " glob)) (org-roam--list-files-search-globs org-roam-file-extensions) " ") (format " \"%s\" " (mapconcat (lambda (title) (format "(%s)" title)) titles "|")) (shell-quote-argument org-roam-directory))) (defun org-roam-unlinked-references-section (node) "The unlinked references section for NODE. References from FILE are excluded." (when (and (executable-find "rg") (org-roam-node-title node) (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 (org-roam-unlinked-references--rg-command titles)) (coding-system-for-read 'utf-8) (results (split-string (shell-command-to-string rg-command))) 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))) (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)))))
3. 提示
因为取消了 shell-quote-argument
,可能会导致形如 org-roam
这种连词失效,但是换来了中文及alias单词的可用性。