emacs-orgmode
[Top][All Lists]
Advanced

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

[Orgmode] [Patch] Capture: %[FILE] and %(SEXP) (again)


From: Sebastian Rose
Subject: [Orgmode] [Patch] Capture: %[FILE] and %(SEXP) (again)
Date: Sat, 17 Jul 2010 13:44:53 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

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:

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

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


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


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:

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.

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




I thought of this here:

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

reply via email to

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