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

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