emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* sexp in org remember templates
@ 2009-10-26 22:06 Richard Riley
  2009-10-26 22:25 ` Richard Riley
  2009-10-26 22:31 ` Nick Dokos
  0 siblings, 2 replies; 4+ messages in thread
From: Richard Riley @ 2009-10-26 22:06 UTC (permalink / raw)
  To: emacs-orgmode


Not being much of an elisp programmer and just returning to try and
integrate with org-learn a little :-

This 

	      ("vocab"?v "* Learn TODO %(format '%s' rgr/orig-word)
	      :VOCAB:\n:PROPERTIES:\n:orig:\t%(format '%s'
	      rgr/orig-word)\n:trans:\t%(format '%s'
	      rgr/trans-word)\n:END:%!" nil bottom nil)

fails me by outputting:

,----
| * Learn TODO [Error: (wrong-type-argument stringp %s)]		      :VOCAB:
| :PROPERTIES:
| :orig:	%![Error: (wrong-type-argument stringp %s)]
| :trans:	%![Error: (wrong-type-argument stringp %s)]
| :END:%!
`----

both rgr/orig-word and rgr/trans-word are set as strings.

Q1 : can I use an elisp var directly as opposed to simulating a func like
above?
Q2 : What is wrong with the above? Whats wrong with that format of a
sexp?
Q3 : how can I specify in the template to auto schedule a TODO for "n"
days in advance?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sexp in org remember templates
  2009-10-26 22:06 sexp in org remember templates Richard Riley
@ 2009-10-26 22:25 ` Richard Riley
  2009-10-26 22:31 ` Nick Dokos
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Riley @ 2009-10-26 22:25 UTC (permalink / raw)
  To: emacs-orgmode

Richard Riley <rileyrgdev@gmail.com> writes:

> Not being much of an elisp programmer and just returning to try and
> integrate with org-learn a little :-
>
> This 
>
> 	      ("vocab"?v "* Learn TODO %(format '%s' rgr/orig-word)
> 	      :VOCAB:\n:PROPERTIES:\n:orig:\t%(format '%s'
> 	      rgr/orig-word)\n:trans:\t%(format '%s'
> 	      rgr/trans-word)\n:END:%!" nil bottom nil)
>
> fails me by outputting:

Just to follow up to my own post I now see a ginle function call will
work e.g

 	      ("vocab"?v "* Learn TODO %(rgr/orig-word)
 	      :VOCAB:\n:PROPERTIES:\n:orig:\t%(rgr/orig-word)\n:trans:\t%(rgr/trans-word)\n:END:%!"
 	      nil bottom nil)

Possibly me not knowing enough elisp but possibly also could support my
initial attempt? Thanks for any explanation.

>
> ,----
> | * Learn TODO [Error: (wrong-type-argument stringp %s)]		      :VOCAB:
> | :PROPERTIES:
> | :orig:	%![Error: (wrong-type-argument stringp %s)]
> | :trans:	%![Error: (wrong-type-argument stringp %s)]
> | :END:%!
> `----
>
> both rgr/orig-word and rgr/trans-word are set as strings.
>
> Q1 : can I use an elisp var directly as opposed to simulating a func like
> above?
> Q2 : What is wrong with the above? Whats wrong with that format of a
> sexp?
> Q3 : how can I specify in the template to auto schedule a TODO for "n"
> days in advance?
>
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>

-- 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sexp in org remember templates
  2009-10-26 22:06 sexp in org remember templates Richard Riley
  2009-10-26 22:25 ` Richard Riley
@ 2009-10-26 22:31 ` Nick Dokos
  2009-10-26 23:04   ` Richard Riley
  1 sibling, 1 reply; 4+ messages in thread
From: Nick Dokos @ 2009-10-26 22:31 UTC (permalink / raw)
  To: Richard Riley; +Cc: emacs-orgmode

Richard Riley <rileyrgdev@gmail.com> wrote:

> 
> Not being much of an elisp programmer and just returning to try and
> integrate with org-learn a little :-
> 
> This 
> 
> 	      ("vocab"?v "* Learn TODO %(format '%s' rgr/orig-word)
> 	      :VOCAB:\n:PROPERTIES:\n:orig:\t%(format '%s'
> 	      rgr/orig-word)\n:trans:\t%(format '%s'
> 	      rgr/trans-word)\n:END:%!" nil bottom nil)
> 
> fails me by outputting:
> 

At the very least, you need to avoid single quotes for quoting strings -
a single quote has a very special meaning to lisp in general: it inhibits
evaluation of the following sexp.

Try something like this instead:

("vocab"?v "* Learn TODO %(format \"%s\" rgr/orig-word)
 	      :VOCAB:\n:PROPERTIES:\n:orig:\t%(format \"%s\"
 	      rgr/orig-word)\n:trans:\t%(format \"%s\"
 	      rgr/trans-word)\n:END:%!" nil bottom nil)

However, no guarantees: when (or even whether) the format calls will be executed
(let alone whether they'll produce the correct result) depends on the
code that handles this construct. There have been a couple of questions
on the mailing list about such evaluations in the context of
org-remember-templates, and IIRC, Carsten had added an evaluation
mechanism there - see e.g. the thread at

   http://thread.gmane.org/gmane.emacs.orgmode/14521

and another thread referenced therein for some details. But I don't know
if this will do what you need it to do.

HTH,
Nick

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sexp in org remember templates
  2009-10-26 22:31 ` Nick Dokos
@ 2009-10-26 23:04   ` Richard Riley
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Riley @ 2009-10-26 23:04 UTC (permalink / raw)
  To: emacs-orgmode

Nick Dokos <nicholas.dokos@hp.com> writes:

> Richard Riley <rileyrgdev@gmail.com> wrote:
>
>> 
>> Not being much of an elisp programmer and just returning to try and
>> integrate with org-learn a little :-
>> 
>> This 
>> 
>> 	      ("vocab"?v "* Learn TODO %(format '%s' rgr/orig-word)
>> 	      :VOCAB:\n:PROPERTIES:\n:orig:\t%(format '%s'
>> 	      rgr/orig-word)\n:trans:\t%(format '%s'
>> 	      rgr/trans-word)\n:END:%!" nil bottom nil)
>> 
>> fails me by outputting:
>> 
>
> At the very least, you need to avoid single quotes for quoting strings -
> a single quote has a very special meaning to lisp in general: it inhibits
> evaluation of the following sexp.
>
> Try something like this instead:
>
> ("vocab"?v "* Learn TODO %(format \"%s\" rgr/orig-word)
>  	      :VOCAB:\n:PROPERTIES:\n:orig:\t%(format \"%s\"
>  	      rgr/orig-word)\n:trans:\t%(format \"%s\"
>  	      rgr/trans-word)\n:END:%!" nil bottom nil)
>
> However, no guarantees: when (or even whether) the format calls will be executed
> (let alone whether they'll produce the correct result) depends on the
> code that handles this construct. There have been a couple of questions
> on the mailing list about such evaluations in the context of
> org-remember-templates, and IIRC, Carsten had added an evaluation
> mechanism there - see e.g. the thread at
>
>    http://thread.gmane.org/gmane.emacs.orgmode/14521
>
> and another thread referenced therein for some details. But I don't know
> if this will do what you need it to do.
>
> HTH,
> Nick

Thanks for the info. In the meantime I had just created two functions
with no parameters to return the values and this worked. 

Trying now to auto remember. I have some code like this:-

,----
| (defun rgr/context-babel()
|   (interactive)
|   (save-window-excursion(unwind-protect
| 			    (let* ((default (region-or-word-at-point)))
| 			      (setq default (read-string (format "Translate \"%s\" :" default) nil nil default))
| 			      (when (length default) (setq
|   rgr/trans-word (babel default nil t))(setq rgr/orig-word
|   default)(org-remember nil ?v)(message "%s" rgr/trans-word))))))
`----

Thanks. I had already create two funcs to call so my template is now:-

,----
| 	      ("vocab"?v "* TODO Learn %(rgr/orig-word)
| 	      :VOCAB:\n:PROPERTIES:\n:orig:\t%(rgr/orig-word)\n:trans:\t%(rgr/trans-word)\n:END:%!"
| 	      nil bottom nil)
`----

and the translate code I call does this:

,----
| ;;;###autoload
| (defun rgr/context-babel()
|   (interactive)
|   (save-window-excursion(unwind-protect
| 			    (let* ((default (region-or-word-at-point)))
| 			      (setq default (read-string (format "Translate \"%s\" :" default) nil nil default))
| 			      (when (length default) (setq rgr/trans-word (babel default nil t))(setq rgr/orig-word default)(org-remember nil ?v)(message "%s" rgr/trans-word))))))
`----

and now I have my translate hot key auto creating VOCAB TODOs. The only
thing I need to know now is how to auto schedule them.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-10-26 23:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-26 22:06 sexp in org remember templates Richard Riley
2009-10-26 22:25 ` Richard Riley
2009-10-26 22:31 ` Nick Dokos
2009-10-26 23:04   ` Richard Riley

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).