From b4f14eebae91069da0fd8b2ae398fe0dbedcd09b Mon Sep 17 00:00:00 2001 From: lafirest Date: Tue, 15 Mar 2022 14:24:55 +0800 Subject: [PATCH] (feat)capture: add org-roam-post-node-insert-hook (#2125) * (feat): add org-roam-post-node-insert-hook Co-authored-by: Jethro Kuan --- org-roam-capture.el | 11 ++++++++--- org-roam-node.el | 10 +++++++--- org-roam.el | 6 ++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/org-roam-capture.el b/org-roam-capture.el index 47e9a9f..8c25bbd 100644 --- a/org-roam-capture.el +++ b/org-roam-capture.el @@ -744,12 +744,17 @@ This function is to be called in the Org-capture finalization process." (delete-region (car region) (cdr region)) (set-marker (car region) nil) (set-marker (cdr region) nil)) - (let ((link (org-link-make-string (concat "id:" (org-roam-capture--get :id)) - (org-roam-capture--get :link-description)))) + (let* ((id (org-roam-capture--get :id)) + (description (org-roam-capture--get :link-description)) + (link (org-link-make-string (concat "id:" id) + description))) (if (eq (point) (marker-position mkr)) (insert link) (org-with-point-at mkr - (insert link))))))) + (insert link))) + (run-hook-with-args 'org-roam-post-node-insert-hook + id + description))))) ;;;; Processing of the capture templates (defun org-roam-capture--fill-template (template &optional ensure-newline) diff --git a/org-roam-node.el b/org-roam-node.el index 217f6b9..e8189e7 100644 --- a/org-roam-node.el +++ b/org-roam-node.el @@ -688,9 +688,13 @@ The INFO, if provided, is passed to the underlying `org-roam-capture-'." (delete-region beg end) (set-marker beg nil) (set-marker end nil)) - (insert (org-link-make-string - (concat "id:" (org-roam-node-id node)) - description))) + (let ((id (org-roam-node-id node))) + (insert (org-link-make-string + (concat "id:" id) + description)) + (run-hook-with-args 'org-roam-post-node-insert-hook + id + description))) (org-roam-capture- :node node :info info diff --git a/org-roam.el b/org-roam.el index 1cf0828..529cb60 100644 --- a/org-roam.el +++ b/org-roam.el @@ -122,6 +122,12 @@ All Org files, at any level of nesting, are considered part of the Org-roam." :group 'org-roam :type 'hook) +(defcustom org-roam-post-node-insert-hook nil + "Hook run when an Org-roam node is inserted as an Org link. +Each function takes two arguments: the id of the node, and the link description." + :group 'org-roam + :type 'hook) + (defcustom org-roam-file-extensions '("org") "List of file extensions to be included by Org-Roam. While a file extension different from \".org\" may be used, the