lang/org: Add +roam2 flag for org-roam v2
This commit is contained in:
parent
46732c0ada
commit
5ef733b488
8 changed files with 278 additions and 9 deletions
122
modules/lang/org/contrib/roam2.el
Normal file
122
modules/lang/org/contrib/roam2.el
Normal file
|
@ -0,0 +1,122 @@
|
|||
;;; lang/org/contrib/roam2.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +roam2)
|
||||
|
||||
(defvar +org-roam-open-buffer-on-find-file t
|
||||
"If non-nil, open the org-roam buffer when opening an org roam file.")
|
||||
|
||||
(defvar +org-roam-link-to-org-use-id 'create-if-interactive
|
||||
"`org-roam-directory' local value for `org-id-link-to-org-use-id'.
|
||||
It's not recommended to set this to nil in order for other parts
|
||||
of org-mode to properly utilize ID links.")
|
||||
|
||||
|
||||
;;
|
||||
;;; Packages
|
||||
|
||||
(use-package! org-roam
|
||||
:hook (org-load . +org-init-roam-h)
|
||||
:preface
|
||||
;; Set this to nil so we can later detect if the user has set custom values
|
||||
;; for these variables. If not, default values will be set in the :config
|
||||
;; section.
|
||||
(defvar org-roam-directory nil)
|
||||
(defvar org-roam-db-location nil)
|
||||
|
||||
:init
|
||||
(doom-load-packages-incrementally
|
||||
'(ansi-color dash f rx seq magit-section))
|
||||
|
||||
(map! :after org
|
||||
:map org-mode-map
|
||||
:localleader
|
||||
:prefix ("m" . "org-roam")
|
||||
"D" #'org-roam-demote-entire-buffer
|
||||
"f" #'org-roam-node-find
|
||||
"F" #'org-roam-ref-find
|
||||
"g" #'org-roam-graph
|
||||
"i" #'org-roam-node-insert
|
||||
"I" #'org-id-get-create
|
||||
"m" #'org-roam-buffer-toggle
|
||||
"M" #'org-roam-buffer
|
||||
"n" #'org-roam-capture
|
||||
"r" #'org-roam-refile
|
||||
"R" #'org-roam-link-replace-all
|
||||
(:prefix ("d" . "by date")
|
||||
:desc "Goto previous note" "b" #'org-roam-dailies-goto-previous-note
|
||||
:desc "Goto date" "d" #'org-roam-dailies-goto-date
|
||||
:desc "Capture date" "D" #'org-roam-dailies-capture-date
|
||||
:desc "Goto next note" "f" #'org-roam-dailies-goto-next-note
|
||||
:desc "Goto tomorrow" "m" #'org-roam-dailies-goto-tomorrow
|
||||
:desc "Capture tomorrow" "M" #'org-roam-dailies-capture-tomorrow
|
||||
:desc "Capture today" "n" #'org-roam-dailies-capture-today
|
||||
:desc "Goto today" "t" #'org-roam-dailies-goto-today
|
||||
:desc "Capture today" "T" #'org-roam-dailies-capture-today
|
||||
:desc "Goto yesterday" "y" #'org-roam-dailies-goto-yesterday
|
||||
:desc "Capture yesterday" "Y" #'org-roam-dailies-capture-yesterday
|
||||
:desc "Find directory" "-" #'org-roam-dailies-find-directory)
|
||||
(:prefix ("o" . "node properties")
|
||||
"a" #'org-roam-alias-add
|
||||
"A" #'org-roam-alias-remove
|
||||
"t" #'org-roam-tag-add
|
||||
"T" #'org-roam-tag-remove
|
||||
"r" #'org-roam-ref-add
|
||||
"R" #'org-roam-ref-remove))
|
||||
|
||||
;; Don't display warning message dedicated for v1 users. Need to be set early.
|
||||
(setq org-roam-v2-ack t)
|
||||
|
||||
:config
|
||||
(defun +org-init-roam-h ()
|
||||
"Setup `org-roam' but don't immediately initialize its database.
|
||||
Instead, initialize it when it will be actually needed."
|
||||
(letf! ((#'org-roam-db-sync #'ignore))
|
||||
(org-roam-setup))
|
||||
(defadvice! +org-roam-init-db-a (&rest _)
|
||||
"Initialize org-roam database when it's first time queried to."
|
||||
:before #'org-roam-db-query
|
||||
(advice-remove 'org-roam-db-query #'+org-roam-init-db-a)
|
||||
(message "Initializing org-roam database...")
|
||||
(org-roam-db-sync)))
|
||||
|
||||
(setq org-roam-directory
|
||||
(thread-first (or org-roam-directory "roam")
|
||||
(expand-file-name org-directory)
|
||||
(file-truename)
|
||||
(file-name-as-directory))
|
||||
org-roam-db-location
|
||||
(or org-roam-db-location
|
||||
(concat doom-etc-dir "org-roam.db"))
|
||||
org-roam-node-display-template
|
||||
"${doom-hierarchy:*} ${doom-tags:35} ${doom-subdirs}"
|
||||
org-roam-completion-everywhere t
|
||||
org-roam-mode-section-functions
|
||||
#'(org-roam-backlinks-section
|
||||
org-roam-reflinks-section))
|
||||
|
||||
(setq-hook! 'org-roam-find-file-hook
|
||||
org-id-link-to-org-use-id +org-roam-link-to-org-use-id)
|
||||
|
||||
;; Normally, the org-roam buffer doesn't open until you explicitly call
|
||||
;; `org-roam'. If `+org-roam-open-buffer-on-find-file' is non-nil, the
|
||||
;; org-roam buffer will be opened for you whenever you visit a file in
|
||||
;; `org-roam-directory'.
|
||||
(add-hook! 'org-roam-find-file-hook :append
|
||||
(defun +org-roam-open-with-buffer-maybe-h ()
|
||||
(and +org-roam-open-buffer-on-find-file
|
||||
(not org-roam-capture--node) ; don't proc for capture buffers
|
||||
(not (eq 'visible (org-roam-buffer--visibility)))
|
||||
(org-roam-buffer-toggle))))
|
||||
|
||||
(set-popup-rules!
|
||||
`((,(regexp-quote org-roam-buffer) ; persistent org-roam buffer
|
||||
:side right :width .33 :height .5 :ttl nil :modeline nil :quit nil :slot 1)
|
||||
("^org-roam:" ; node dedicated org-roam buffer
|
||||
:side right :width .33 :height .5 :ttl nil :modeline nil :quit nil :slot 2)))
|
||||
|
||||
(add-hook 'org-roam-mode-hook #'turn-on-visual-line-mode))
|
||||
|
||||
|
||||
;; Since the org module lazy loads org-protocol (waits until an org URL is
|
||||
;; detected), we can safely chain `org-roam-protocol' to it.
|
||||
(use-package! org-roam-protocol
|
||||
:after org-protocol)
|
Loading…
Add table
Add a link
Reference in a new issue