(feat): allow org-roam-node-display-template to be a closure (#1891)

This commit is contained in:
matthuszagh
2021-10-09 06:36:20 -07:00
committed by GitHub
parent 54d17cc50f
commit 34243a0a90
2 changed files with 9 additions and 3 deletions

View File

@@ -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 i.e. it won't be aligned nor trimmed. If it's an integer, the
field will be aligned accordingly and all the exceeding field will be aligned accordingly and all the exceeding
characters will be trimmed out. If it's \"*\", the field will use 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 :group 'org-roam
:type 'string) :type '(string function))
(defcustom org-roam-node-annotation-function #'org-roam-node-read--annotation (defcustom org-roam-node-annotation-function #'org-roam-node-read--annotation
"This function used to attach annotations for `org-roam-node-read'. "This function used to attach annotations for `org-roam-node-read'.

View File

@@ -129,7 +129,9 @@ value (possibly nil). Adapted from `s-format'."
(funcall replacer var default-val)))) (funcall replacer var default-val))))
(if v (format "%s" v) (signal 'org-roam-format-resolve md))) (if v (format "%s" v) (signal 'org-roam-format-resolve md)))
(set-match-data replacer-match-data)))) (set-match-data replacer-match-data))))
template (if (functionp template)
(funcall template)
template)
;; Need literal to make sure it works ;; Need literal to make sure it works
t t) t t)
(set-match-data saved-match-data)))) (set-match-data saved-match-data))))