emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Advanced capture template using Elisp functions: void-function/void-


From: Karl Voit
Subject: [O] Advanced capture template using Elisp functions: void-function/void-variable
Date: Mon, 9 May 2016 15:40:52 +0200
User-agent: slrn/pre1.0.0-18 (Linux)

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]