* Advanced capture template using Elisp functions: void-function/void-variable
@ 2016-05-09 13:40 Karl Voit
2016-05-09 15:24 ` Karl Voit
0 siblings, 1 reply; 2+ messages in thread
From: Karl Voit @ 2016-05-09 13:40 UTC (permalink / raw)
To: emacs-orgmode
Hi!
I came across this great blog post[1] that introduced me to the idea
of including Elisp functions to capture templates. With this trick,
it is possible to re-use some user-entry.
So far so good. However, when I am using this capture definition, I end up with
lots of "void-function" and "void-variable". Probably I have an escaping issue.
Do you have an idea how to fix my error(s)?
The whole story: (sorry for some long lines)
I took David's code and renamed according my name schema:
,----
| (defvar my-capture-promt-history nil
| "History of prompt answers for org capture.")
| (defun my-capture-prompt (prompt variable)
| "PROMPT for string, save it to VARIABLE and insert it."
| (make-local-variable variable)
| (set variable (read-string (concat prompt ": ") nil my-capture-promt-history)))
| (defun my-capture-insert (variable)
| "Insert content of VARIABLE."
| (symbol-value variable))
| (defun my-capture-optional (what text)
| "Ask user to include WHAT. If user agrees return TEXT."
| (when (y-or-n-p (concat "Include " what "?"))
| text))
`----
Then I created a variable holding the complex template string:
,----
| (setq my-capture-template-r6story "** TODO [[IPD:%(my-capture-promt \"IPD number\" 'my-ipd)]] %(my-capture-promt \"Story title\" 'my-title) [1/11] :US_%(my-capture-promt \"Short title\" 'my-short-title):
| :PROPERTIES:
| :CREATED: [%(format-time-string \"%Y-%m-%d %a %H:%M\")]
| :ID: %(format-time-string \"%Y-%m-%d\")-Story-%(my-capture-insert 'my-short-title)
| :END:
|
| | *IPD* | *Confluence* | *Champ* |
| | [[IPD:%(my-capture-insert 'my-ipd)][%(my-capture-insert 'my-ipd)]] | %(my-capture-insert 'my-title) | |
|
| [...]
| ")
|
`----
,----[ my capture template definition ]
| (setq org-capture-templates
| `(
| ("u" "Userstory" entry (file+headline "~/stories.org" "New Stories")
| ,my-capture-template-r6story :empty-lines 1)
| ))
`----
So far so good. However, when I am using this capture definition, I end up with
lots of "void-function" and "void-variable":
,----
| * TODO [[IPD:%![Error: (void-function my-capture-promt)]]] %![Error: (void-function my-capture-promt)] [1/11] :US_%![Error: (void-function my-capture-promt)]:
| :PROPERTIES:
| :CREATED: [2016-05-09 [[file:c:/Users/karl/org/project.org::*2del][2del]] 15:27]
| :ID: 2016-05-09-Story-%![Error: (void-variable my-short-title)]
| :END:
|
| | *IPD* | *Confluence* | *Champ* |
| | [[IPD:%![Error: (void-variable my-ipd)]][%![Error: (void-variable my-ipd)]]] | %![Error: (void-variable my-title)] | |
|
| [...]
`----
Note that "2del" is the current super-heading, 15:27 is current time, and
c:/Users/karl/org/project.org is the current Org-mode file. None of them are
supposed to be in my Org-mode file. They are interpreted by org-capture instead
of the Elisp function. I tend to think that this is a hint that I've got an
issue with wrong escaping.
Bonus for everybody who read so far and is still interested to read more:
So far, I was using yasnippet but unfortunately, I've got severe issues with
yasnippet and Emacs endless-loops/crashes. Since I was not able to fix
yasnippet even with posting in Newsgroups, I want to replace my complex
yasnippet templates with capture+Elisp. Isn't it awesome funny, how
yasnippet is printed four times in a row according to my alignment on pure
coincidence? ;-)
[1] http://storax.github.io/blog/2016/05/02/org-capture-tricks/
--
mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML to Org-mode:
> get Memacs from https://github.com/novoid/Memacs <
https://github.com/novoid/extract_pdf_annotations_to_orgmode + more on github
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Advanced capture template using Elisp functions: void-function/void-variable
2016-05-09 13:40 Advanced capture template using Elisp functions: void-function/void-variable Karl Voit
@ 2016-05-09 15:24 ` Karl Voit
0 siblings, 0 replies; 2+ messages in thread
From: Karl Voit @ 2016-05-09 15:24 UTC (permalink / raw)
To: emacs-orgmode
Hi!
Phil obviously did not want to embarrass me in public so he wrote me
an email which pointed me to my simple error: a typo "promt" instead
of "prompt" in the function name.
* Karl Voit <devnull@Karl-Voit.at> wrote:
>
> However, when I am using this capture definition, I end up with
> lots of "void-function" and "void-variable". Probably I have an escaping issue.
>
> ,----
>| (defun my-capture-prompt (prompt variable)
>| "PROMPT for string, save it to VARIABLE and insert it."
>| (make-local-variable variable)
>| (set variable (read-string (concat prompt ": ") nil my-capture-promt-history)))
At this point, I know how to type "prompt" in a proper way.
>| (defun my-capture-insert (variable)
>| "Insert content of VARIABLE."
>| (symbol-value variable))
Phil remarks that this is equivalent to eval() which I can't confirm
with my limited Elisp knowledge.
> Then I created a variable holding the complex template string:
>
> ,----
>| (setq my-capture-template-r6story "** TODO [[IPD:%(my-capture-promt \"IPD number\" 'my-ipd)]] %(my-capture-promt \"Story title\" 'my-title) [1/11] :US_%(my-capture-promt \"Short title\" 'my-short-title):
[...]
prompt, prompt, prompt, prompt, prompt, prompt.
Sorry for the fuzz. However, you might be pointed to a clever way
for capture templates.
--
mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML to Org-mode:
> get Memacs from https://github.com/novoid/Memacs <
https://github.com/novoid/extract_pdf_annotations_to_orgmode + more on github
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-05-09 15:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-09 13:40 Advanced capture template using Elisp functions: void-function/void-variable Karl Voit
2016-05-09 15:24 ` Karl Voit
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.