I'm using org-capture to insert expenses into a Ledger file with this template, along with auto-completion for the various expense categories:
(setq ledger-expense-completions
(list
"" ;; needed for first | for mapconcat
"Expenses:Food" "Expenses:Food:Restaurants" "Expenses:Food:Groceries"
))
(setq capture-expense-template
"%%(org-read-date) * %%^{Description}
%%^{Expense%s} %%^{Amount}
Account:Cash")
(defun return-capture-expense-template ()
(let ((compstring
(mapconcat 'identity ledger-expense-completions "|" )))
(format capture-expense-template compstring)))
(setq org-capture-templates
(append '(("l" "Ledger entries")
("lc" "Cash" plain
(file "~/Documents/journal.ledger")
(function return-capture-expense-template)
:empty-lines-before 1
:empty-lines-after 1))
org-capture-templates))
This works fine, however I'd like to modify return-capture-expense-template
to make it a bit more dynamic so that I can pass in the account, e.g., "Account:Bank"
or "Account:Cash"
, to support variations of this template without creating a separate capture-expense-template
for each variation.
So here's how I modified things:
(setq ledger-expense-completions
(list
"" ;; needed for first | for mapconcat
"Expenses:Food" "Expenses:Food:Restaurants" "Expenses:Food:Groceries"
))
(setq capture-expense-template
"%%(org-read-date) * %%^{Description}
%%^{Expense%s} %%^{Amount}
%s")
(defun return-capture-expense-template (account)
(let ((compstring
(mapconcat 'identity ledger-expense-completions "|" )))
(format capture-expense-template compstring account)))
(setq org-capture-templates nil)
(setq org-capture-templates
(append '(("l" "Ledger entries")
("lc" "Cash" plain
(file "~/Documents/journal.ledger")
(function return-capture-expense-template "Account:Bank")
:empty-lines-before 1
:empty-lines-after 1))
org-capture-templates))
When I try evaluating (return-capture-expense-template "Account:Bank")
on a separate line, that gives me the template output that I would expect (with "Account:Bank"
dynamically inserted into the capture template), however when I run org-capture, I get Wrong number of arguments
because the "Account:Bank"
is not getting passed to return-capture-expense-template
on this line: (function return-capture-expense-template "Account:Bank")
.
I reviewed the docs for Anonymous Functions and tried writing that line in various ways, but nothing I do seems to be working.
Is it not possible to pass a variable to a function when using the special form function
?
"Account:Bank"
into the function.