add org-roam-capture-new-node-hook

This commit is contained in:
Jethro Kuan
2021-04-23 13:49:02 +08:00
parent d53f0e60bf
commit e6acc40e79

View File

@@ -334,6 +334,11 @@ streamlined user experience in Org-roam."
((const :format "%v " :table-line-pos) (string)) ((const :format "%v " :table-line-pos) (string))
((const :format "%v " :kill-buffer) (const t)))))))) ((const :format "%v " :kill-buffer) (const t))))))))
(defvar org-roam-capture-new-node-hook (list #'org-roam-capture--insert-ref)
"Normal-mode hooks (list of functions) run when a new Org-roam node is created.
The current point is the point of the new node.
The hooks must not move the point.")
(defcustom org-roam-capture-ref-templates (defcustom org-roam-capture-ref-templates
'(("r" "ref" plain "%?" '(("r" "ref" plain "%?"
:if-new (file+head "${slug}.org" :if-new (file+head "${slug}.org"
@@ -495,6 +500,11 @@ run Org-capture's template expansion."
(plist-put org-roam-capture--info ksym r) (plist-put org-roam-capture--info ksym r)
r)))))))) r))))))))
(defun org-roam-capture--insert-ref ()
"Insert the ref if any."
(when-let ((ref (plist-get org-roam-capture--info :ref)))
(org-roam-ref-add ref)))
(defun org-roam-capture--goto-location () (defun org-roam-capture--goto-location ()
"Initialize the buffer, and goto the location of the new capture. "Initialize the buffer, and goto the location of the new capture.
Return the ID of the location." Return the ID of the location."
@@ -551,8 +561,7 @@ Return the ID of the location."
(setq id (org-roam-node-id node))))) (setq id (org-roam-node-id node)))))
(save-excursion (save-excursion
(goto-char p) (goto-char p)
(when-let ((ref (plist-get org-roam-capture--info :ref))) (run-hooks 'org-roam-capture-new-node-hook)
(org-roam-ref-add ref))
(org-id-get-create)))) (org-id-get-create))))
(defun org-roam-capture-find-or-create-olp (olp) (defun org-roam-capture-find-or-create-olp (olp)