From 34243a0a90e8e94cef7d87ccee159636d1fd983a Mon Sep 17 00:00:00 2001 From: matthuszagh Date: Sat, 9 Oct 2021 06:36:20 -0700 Subject: [PATCH] (feat): allow org-roam-node-display-template to be a closure (#1891) --- org-roam-node.el | 8 ++++++-- org-roam-utils.el | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/org-roam-node.el b/org-roam-node.el index 6cfd36c..8f84c04 100644 --- a/org-roam-node.el +++ b/org-roam-node.el @@ -60,9 +60,13 @@ field. If it's not specified, the field will be inserted as is, i.e. it won't be aligned nor trimmed. If it's an integer, the field will be aligned accordingly and all the exceeding characters will be trimmed out. If it's \"*\", the field will use -as many characters as possible and will be aligned accordingly." +as many characters as possible and will be aligned accordingly. + +A closure can also be assigned to this variable in which case the +closure is evaluated and the return value is used as the +template. The closure must evaluate to a valid template string." :group 'org-roam - :type 'string) + :type '(string function)) (defcustom org-roam-node-annotation-function #'org-roam-node-read--annotation "This function used to attach annotations for `org-roam-node-read'. diff --git a/org-roam-utils.el b/org-roam-utils.el index ae6cc89..7233d2b 100644 --- a/org-roam-utils.el +++ b/org-roam-utils.el @@ -129,7 +129,9 @@ value (possibly nil). Adapted from `s-format'." (funcall replacer var default-val)))) (if v (format "%s" v) (signal 'org-roam-format-resolve md))) (set-match-data replacer-match-data)))) - template + (if (functionp template) + (funcall template) + template) ;; Need literal to make sure it works t t) (set-match-data saved-match-data))))