From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sebastian Rose Subject: [Patch] Capture: %[FILE] and %(SEXP) (again) Date: Sat, 17 Jul 2010 13:44:53 +0200 Message-ID: <87fwzi1gei.fsf@gmx.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from [140.186.70.92] (port=46109 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oa5p3-0005O9-6m for emacs-orgmode@gnu.org; Sat, 17 Jul 2010 07:44:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oa5oy-0007Ls-Vd for emacs-orgmode@gnu.org; Sat, 17 Jul 2010 07:44:48 -0400 Received: from mail.gmx.net ([213.165.64.20]:47836) by eggs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1Oa5oy-0007Lb-Jy for emacs-orgmode@gnu.org; Sat, 17 Jul 2010 07:44:44 -0400 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Emacs-orgmode mailing list --=-=-= 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: --=-=-= Content-Type: text/x-verbatim Content-Disposition: inline ("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: --=-=-= Content-Type: text/x-verbatim Content-Disposition: inline * 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=org-capture-file-templates-old.patch 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=org-capture-file-templates.patch 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 --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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 --=-=-=--