Org-roam(v2) 以及 org-roam-ui 的使用姿势(已支持Emacs 29 内置的 sqlite)

  1. 首先是基础的设置,这里感谢论坛大佬的提醒,我也使用了built-in 的sqlite
     (setq org-roam-database-connector 'sqlite-builtin
     org-roam-mode-section-functions (list #'org-roam-backlinks-section
                                           #'org-roam-reflinks-section
                                           ;; #'org-roam-unlinked-references-section
                                           )
     org-roam-directory "~/Documents/emacs/orgmode/roam/"
     org-roam-dailies-directory "~/Documents/emacs/orgmode/roam"

     org-roam-db-gc-threshold most-positive-fixnum)

;; 使用侧边栏而不是完整buffer
      (add-to-list 'display-buffer-alist
                   '("\\*org-roam\\*"
                     (display-buffer-in-side-window)
                     (side . right)
                     (slot . 0)
                     (window-width . 0.25)
                     (window-parameters . ((no-other-window . t)
                                           (no-delete-other-windows . t)))))

  1. 标题链接,org-roam默认会把所有的标题链接和文件链接视为同一级,这样有时会因此重复索引或者不直观的特点,我从doom里面抄了一堆代码, 效果如第四个node那样(2021-0815是文件一级,而具体的标题一级是后面的链接)

代码


      ;; Codes blow are used to general a hierachy for title nodes that under a file
      (cl-defmethod org-roam-node-doom-filetitle ((node org-roam-node))
        "Return the value of \"#+title:\" (if any) from file that NODE resides in.
      If there's no file-level title in the file, return empty string."
        (or (if (= (org-roam-node-level node) 0)
                (org-roam-node-title node)
              (org-roam-get-keyword "TITLE" (org-roam-node-file node)))
            ""))
      (cl-defmethod org-roam-node-doom-hierarchy ((node org-roam-node))
        "Return hierarchy for NODE, constructed of its file title, OLP and direct title.
        If some elements are missing, they will be stripped out."
        (let ((title     (org-roam-node-title node))
              (olp       (org-roam-node-olp   node))
              (level     (org-roam-node-level node))
              (filetitle (org-roam-node-doom-filetitle node))
              (separator (propertize " > " 'face 'shadow)))
          (cl-case level
            ;; node is a top-level file
            (0 filetitle)
            ;; node is a level 1 heading
            (1 (concat (propertize filetitle 'face '(shadow italic))
                       separator title))
            ;; node is a heading with an arbitrary outline path
            (t (concat (propertize filetitle 'face '(shadow italic))
                       separator (propertize (string-join olp " > ") 'face '(shadow italic))
                       separator title)))))

     (setq org-roam-node-display-template (concat "${type:15} ${doom-hierarchy:80} " (propertize "${tags:*}" 'face 'org-tag)))

6 个赞