Over at the Emacs StackExchange, Raam Dev asked how to define functions for
org-capture-templates that could take arguments. For example, it would be useful to have a function that creates a Ledger entry for the specified account. Functions used in
org-capture-templates can’t take any arguments, but you can use property lists instead. Here’s the answer I posted.
You can specify your own properties in the property list for the template, and then you can access those properties with
org-capture-plist. Here’s a brief example:
Here’s a brief example:(defun my/expense-template () (format "Hello world %s" (plist-get org-capture-plist :account))) (setq org-capture-templates '(("x" "Test entry 1" plain (file "~/tmp/test.txt") (function my/expense-template) :account "Account:Bank") ("y" "Test entry 2" plain (file "~/tmp/test.txt") (function my/expense-template) :account "Account:AnotherBank")))
I hope that helps!
- 16 June 2015 at 9:06am
- Sacha on Supplying an Argument to a Capture Template Function | Irreal
[…] Sacha Chua has our backs with a neat hack to supply an argument to a template ...