emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Patch] Capture: %[FILE] and %(SEXP) (again)
@ 2010-07-17 11:44 Sebastian Rose
  2010-07-17 17:03 ` Johan Friis
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Rose @ 2010-07-17 11:44 UTC (permalink / raw)
  To: Emacs-orgmode mailing list

[-- Attachment #1: Type: text/plain, Size: 465 bytes --]

Hi,



currently, WE CANNOT EDIT FULL FLEDGED TEMPLATES IN SEPARATE FILE IN ORG
MODE.

Sorry for being back with this issue again and again, but I got no
feedback for the last two times I tried, did I?



I just found, that something like my proposed patch in is implemented in
org-capture (see
http://thread.gmane.org/gmane.emacs.orgmode/26441/focus=26484a).


But let's see...



This is supposed to be one of the entries in my `org-capture-templates'
variable:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-verbatim, Size: 166 bytes --]

   ("L" "Lauf" entry (file+headline "notes/Laufen/Training.org" "Training")
     "%[~/emacs/org/capture-templates/training.org]"
     :empty-lines 1
     :prepend t)

[-- Attachment #3: Type: text/plain, Size: 75 bytes --]



The file "~/emacs/org/capture-templates/training.org" looks like this:



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: Type: text/x-verbatim, Size: 200 bytes --]

* DONE %u  (%^{Run or what|run|run|bike|swim|wout})  %^{Distance}  X:XX
  :PROPERTIES:
  :kcal:     XXX%^{meters}p%^{start}p%^{time}p%^{type}p%^{rpuls}p
  :END:
*** Weather
    %?

*** Track

...etc.

[-- Attachment #5: Type: text/plain, Size: 2251 bytes --]




Everything worked, except the "%u" elements (and all the others like
"%u") which I expect to expand to inactive timestamps (w.o. time).

If I switched the second line of my template to

    "%(org-file-contents \"~/emacs/org/capture-templates/training.org\")"

I encountered the same bahaviour.



In my opinion, this is because `%[FILE]' and `%(SEXP)' are is
implemented the wrong way or at least, the aim of the implementation is
vague and the documentation is not appropriate.


EITHER (a)

  the user wants to insert the contents of file (or the result of a
  sexp) without special template parsing.  In that case the "^{PROP}"
  substitution should not work as well, or the docs should reflect the
  facts, that "^{PROP}"-subtitution takes place after expansion of "%[]"
  and "%()", "%()"-substitution takes place after "%[]"-substitution
  (i.e. in the results of that substitution).  "%[]"- and
  "%()"-substitutions takes place after simple substitution.

  Currently, the docs do not reflect the fact, that the user may not use
  arbitrary text in "%[]" files.  Some expansions take place (the
  complex ones), some don't (the simple ones "%\\(uUtT...\\)" --- !??).

  Alternatively, the code vor "%()" and "%[]" should go to separate
  variables, that are inserted into the template after all expansion is
  done, i.e. the end of `org-capture-fill-template'.

OR (b)

  the user wants the contents of the file (or the result of a sexp) to
  be used as a template with all bells and wistles (why? he would simply
  use `C-x i' otherwise).  In that case, the evaluation of `%[FILE]' and
  `%(SEXP)' should be done, as my patch proposed, at the start of
  `org-capture-set-plist'.  There, the value of the local `txt' variable
  should be set to the contents of the file (or the result of the sexp.
  Now it would work reliably for ever (assuming `org-capture-set-plist'
  is and will be the unique entry point to template parsing).

OR (c)

  (a) and (b) are true and (b) is the special case, where the template
  consists of either a single entry "%[FILE]" or the contents of the
  local variable `txt' in `org-capture-set-plist' is the name of an
  existing file (+1).




I'll keep rebasing my org-capture branch, which now does this:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #6: org-capture-file-templates-old.patch --]
[-- Type: text/x-diff, Size: 651 bytes --]

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index afb56ba..421e098 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -982,6 +982,8 @@ Point will remain at the first line after the inserted text."
   (org-capture-put :key (car entry) :description (nth 1 entry)
 		   :target (nth 3 entry))
   (let ((txt (nth 4 entry)) (type (or (nth 2 entry) 'entry)))
+    (when (file-exists-p txt)
+	(setq txt (org-file-contents txt)))
     (when (or (not txt) (and (stringp txt) (not (string-match "\\S-" txt))))
       ;; The template may be empty or omitted for special types.
       ;; Here we insert the default templates for such cases.

[-- Attachment #7: Type: text/plain, Size: 110 bytes --]



This let's you edit full fledged templates in separate file in Org mode! Yeah!




I thought of this here:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #8: org-capture-file-templates.patch --]
[-- Type: text/x-diff, Size: 1077 bytes --]

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index afb56ba..eb05c7a 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -982,6 +982,18 @@ Point will remain at the first line after the inserted text."
   (org-capture-put :key (car entry) :description (nth 1 entry)
 		   :target (nth 3 entry))
   (let ((txt (nth 4 entry)) (type (or (nth 2 entry) 'entry)))
+
+  ;; Special case:
+  ;; The template consists of exactly one element out of "%[FILE]" or "%(SEXP)".
+  ;; In this case, insert the contents/reulsts to allow full fledged templates.
+  (cond
+    ;; %[] Insert contents of a file:
+    ((string-match "^%\\[\\(.+\\)\\]$" txt)
+      (setq txt (org-file-contents (expand-file-name (match-string 1 txt)))))
+    ;; %() Insert contents of a sexp:
+    ((string-match "^%\\((.+)\\)$" txt)
+      (setq txt (eval (read (match-string 1 txt))))))
+
     (when (or (not txt) (and (stringp txt) (not (string-match "\\S-" txt))))
       ;; The template may be empty or omitted for special types.
       ;; Here we insert the default templates for such cases.

[-- Attachment #9: Type: text/plain, Size: 392 bytes --]


But I don't like this "special" case the patch provides.


I hope it's somewhat clear what I'm asking for...



In my opinion, the current implementation of "%[FILE]" templates is
complicated and useless.  Why would I want to use a "%[FILE]" template,
if no simple expansions ("%\\(uUtT....\\)") take place?  The file would
not even adjust to the current date.




Best wishes

   Sebastian

[-- Attachment #10: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: [Patch] Capture: %[FILE] and %(SEXP) (again)
  2010-07-17 11:44 [Patch] Capture: %[FILE] and %(SEXP) (again) Sebastian Rose
@ 2010-07-17 17:03 ` Johan Friis
  2010-07-17 20:23   ` Sebastian Rose
  0 siblings, 1 reply; 4+ messages in thread
From: Johan Friis @ 2010-07-17 17:03 UTC (permalink / raw)
  To: emacs-orgmode

I have this in my org-capture-templates, and it works just fine. The
note.org file is of course an org-mode file, with normal syntax.

  ("j" "Journal" entry (file "~/note/journal.org") (file "~/note/template/journal.org"))

I am not sure if I misunderstood what you want to do, just wanted to
state that the above works great for me (it expands what it is supposed to)

- Johan

  

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

* Re: Re: [Patch] Capture: %[FILE] and %(SEXP) (again)
  2010-07-17 17:03 ` Johan Friis
@ 2010-07-17 20:23   ` Sebastian Rose
  2010-07-18  5:40     ` Carsten Dominik
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Rose @ 2010-07-17 20:23 UTC (permalink / raw)
  To: Johan Friis; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 784 bytes --]

Johan Friis <mail@alterecco.net> writes:
> I have this in my org-capture-templates, and it works just fine. The
> note.org file is of course an org-mode file, with normal syntax.
>
>   ("j" "Journal" entry (file "~/note/journal.org") (file "~/note/template/journal.org"))
>
> I am not sure if I misunderstood what you want to do, just wanted to
> state that the above works great for me (it expands what it is supposed to)



Ahhhh!

This does what I expect, but it is not documented.

Thanks Johan!

That's why I wrote my previous mail?  I simply could not figure out, how
to achieve that and I did not know about (file "filename").  Where is
this in the docs?

But, OK, forget it.  I now know that I have to use the (file "...")
syntax.


So this is one of the neccessary patches:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org.texi-document-template-files.patch --]
[-- Type: text/x-diff, Size: 688 bytes --]

diff --git a/doc/org.texi b/doc/org.texi
index f1f894a..e5d0a3b 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6109,7 +6109,9 @@ file and location.
 The template for creating the capture item.  If you leave this
 empty, an appropriate default template will be used.  Otherwise this is a
 string with  escape codes, which will be replaced depending on time
-and context of the capture call.  See below for more details.
+and context of the capture call.  The string with escapes may be loaded
+from a template file, using the special syntax `(file
+``path-to-template'')'.  See below for more details.
 
 @item properties
 The rest of the entry is a property list of additional options.

[-- Attachment #3: Type: text/plain, Size: 161 bytes --]





Still, as I said in my previous mail, the way "%[FILE]" and "%(SEXP)"
work is not quite right and the docs are still incomplete.


Best wishes

   Sebastian

[-- Attachment #4: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: Re: [Patch] Capture: %[FILE] and %(SEXP) (again)
  2010-07-17 20:23   ` Sebastian Rose
@ 2010-07-18  5:40     ` Carsten Dominik
  0 siblings, 0 replies; 4+ messages in thread
From: Carsten Dominik @ 2010-07-18  5:40 UTC (permalink / raw)
  To: Sebastian Rose; +Cc: emacs-orgmode, Johan Friis

Hi Sebastian,

I have rejected both of your patches an instead changed the order of  
evaluation
of escapes in `org-capture-fill-template'.  Inserting file contents and
evaluating sexp entries now happens first, so that the parser looking
for other escapes also sees the stuff inserted by these escapes.

Hope this fixes the issues you where having.

Cheers

- Carsten

On Jul 17, 2010, at 10:23 PM, Sebastian Rose wrote:

> Johan Friis <mail@alterecco.net> writes:
>> I have this in my org-capture-templates, and it works just fine. The
>> note.org file is of course an org-mode file, with normal syntax.
>>
>>  ("j" "Journal" entry (file "~/note/journal.org") (file "~/note/ 
>> template/journal.org"))
>>
>> I am not sure if I misunderstood what you want to do, just wanted to
>> state that the above works great for me (it expands what it is  
>> supposed to)
>
>
>
> Ahhhh!
>
> This does what I expect, but it is not documented.
>
> Thanks Johan!
>
> That's why I wrote my previous mail?  I simply could not figure out,  
> how
> to achieve that and I did not know about (file "filename").  Where is
> this in the docs?
>
> But, OK, forget it.  I now know that I have to use the (file "...")
> syntax.
>
>
> So this is one of the neccessary patches:
>
> diff --git a/doc/org.texi b/doc/org.texi
> index f1f894a..e5d0a3b 100644
> --- a/doc/org.texi
> +++ b/doc/org.texi
> @@ -6109,7 +6109,9 @@ file and location.
> The template for creating the capture item.  If you leave this
> empty, an appropriate default template will be used.  Otherwise this  
> is a
> string with  escape codes, which will be replaced depending on time
> -and context of the capture call.  See below for more details.
> +and context of the capture call.  The string with escapes may be  
> loaded
> +from a template file, using the special syntax `(file
> +``path-to-template'')'.  See below for more details.
>
> @item properties
> The rest of the entry is a property list of additional options.
>
>
>
>
> Still, as I said in my previous mail, the way "%[FILE]" and "%(SEXP)"
> work is not quite right and the docs are still incomplete.
>
>
> Best wishes
>
>   Sebastian
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

- Carsten

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

end of thread, other threads:[~2010-07-18  5:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-17 11:44 [Patch] Capture: %[FILE] and %(SEXP) (again) Sebastian Rose
2010-07-17 17:03 ` Johan Friis
2010-07-17 20:23   ` Sebastian Rose
2010-07-18  5:40     ` Carsten Dominik

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).