From 9eaf91b801a4d5a47d1b7fc862b6c8c65bd4bc92 Mon Sep 17 00:00:00 2001 From: Ahmed Shariff Date: Thu, 14 Apr 2022 12:50:47 -0400 Subject: [PATCH] (fix)capture: Process fn capture templates before whitespace-content (#2157) * [Fix #2156] Expand fn templates in fill-template before whitespace-content * Update change log and adding tests related to #2157 --- CHANGELOG.md | 1 + org-roam-capture.el | 5 ++++- tests/test-org-roam-capture.el | 7 ++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f71df5..2d462a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Fixed - [#2130](https://github.com/org-roam/org-roam/pull/2130) buffer: unlinked-references section now also searches within symlinked directories - [#2152](https://github.com/org-roam/org-roam/pull/2152) org-roam-preview-default-function: doesn't copy copy content of next heading node when current node's content is empty +- [#2156](https://github.com/org-roam/org-roam/pull/2157) capture: templates with functions are handled correctly to avoid signaling `char-or-string-p` ### Changed diff --git a/org-roam-capture.el b/org-roam-capture.el index 0f9ba74..c3c90db 100644 --- a/org-roam-capture.el +++ b/org-roam-capture.el @@ -762,7 +762,10 @@ This function is to be called in the Org-capture finalization process." It expands ${var} occurrences in TEMPLATE, and then runs org-capture's template expansion. When ENSURE-NEWLINE, always ensure there's a newline behind." - (let ((template-whitespace-content (org-roam-whitespace-content template))) + (let* ((template (if (functionp template) + (funcall template) + template)) + (template-whitespace-content (org-roam-whitespace-content template))) (setq template (org-roam-format-template template diff --git a/tests/test-org-roam-capture.el b/tests/test-org-roam-capture.el index 34f37bb..ef20605 100644 --- a/tests/test-org-roam-capture.el +++ b/tests/test-org-roam-capture.el @@ -46,6 +46,11 @@ :to-equal "foo\n\n") (expect (org-roam-capture--fill-template "foo\n\t\n") - :to-equal "foo\n\t\n"))) + :to-equal "foo\n\t\n")) + + (it "expands templates when it's a function" + (expect + (org-roam-capture--fill-template (lambda () "foo")) + :to-equal "foo"))) (provide 'test-org-roam-capture)