From: Sebastian Rose <sebastian_rose@gmx.de>
To: Emacs-orgmode mailing list <emacs-orgmode@gnu.org>
Subject: [Patch] Capture: %[FILE] and %(SEXP) (again)
Date: Sat, 17 Jul 2010 13:44:53 +0200 [thread overview]
Message-ID: <87fwzi1gei.fsf@gmx.de> (raw)
[-- 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
next reply other threads:[~2010-07-17 11:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-17 11:44 Sebastian Rose [this message]
2010-07-17 17:03 ` [Patch] Capture: %[FILE] and %(SEXP) (again) Johan Friis
2010-07-17 20:23 ` Sebastian Rose
2010-07-18 5:40 ` Carsten Dominik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fwzi1gei.fsf@gmx.de \
--to=sebastian_rose@gmx.de \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.