emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [Orgmode] inserting files within remember templates


From: Adam Spiers
Subject: Re: [Orgmode] inserting files within remember templates
Date: Sat, 24 Nov 2007 14:52:27 +0000
User-agent: Mutt/1.5.14 (2007-02-12)

On Wed, Nov 07, 2007 at 09:42:55AM +0100, Carsten Dominik wrote:
> On 6 Nov 2007, at 11:39 PM, Adam Spiers wrote:
> > On Tue, Nov 06, 2007 at 04:36:47PM +0000, Adam Spiers wrote:
> > > This could easily be accomplished if remember templates allowed  
> > > syntax such as
> > > 
> > > ,------
> > > | * %T
> > > | %(shell-command-to-string "grep 'last full' 
> > > /proc/acpi/battery/BAT0/info")
> > > `------
> >
> > OK, it turns out that this was easy to implement, and I think the
> > patch is small enough that it could be accepted even though I haven't
> > got around to sending back the copyright assignment form yet (sorry -
> > this *will* happen at some point!)
> 
> I'll take this patch, thanks.

[snipped]

> >There might need to be some debate about how to handle read errors in
> >the case of invalid syntax.  Or perhaps some people already have
> >`%(...)' within their remember templates for some really unusual
> >reason, and don't want it interpreted?  Though in the latter case, one
> >could argue that it might make sense to require `%' always to be
> >escaped as `%%' if used literally, to be on the safe side.

Here's a better version.  Differences:

  - Supports insertion of the contents of another file via %[/path/to/file]

  - Embeds any errors within the template, making it clearer that an
    error occurred, and also exactly which bit of the template caused
    it.  This also lets the user manually correct the error and finish
    their remembering workflow before having to go back and fix the
    template, which is much more in keeping with the "remember this
    quick before I forget!" spirit of remember itself.

  - Patches texinfo file.

  - Respects Carsten's apparent preference for having indent-tabs-mode
    set (though this may make the below patch's indentation look
    strange due to the hard tabs).

diff -r 09b1470ac170 org.el
--- a/org.el    Wed Oct 31 09:46:35 2007 +0000
+++ b/org.el    Sat Nov 24 14:39:51 2007 +0000
@@ -12806,6 +12806,30 @@ to be run from that hook to fucntion pro
          (replace-match
           (or (eval (intern (concat "v-" (match-string 1)))) "")
           t t))
+       ;; %[] Insert contents of a file.
+       (goto-char (point-min))
+       (while (re-search-forward "%\\[\\(.+\\)\\]" nil t)
+         (let ((start (match-beginning 0))
+               (end (match-end 0))
+               (filename (expand-file-name (match-string 1))))
+           (goto-char start)
+           (delete-region start end)
+           (condition-case error
+               (insert-file-contents filename)
+             (error (insert (format "%%![Couldn't insert %s: %s]"
+                                    filename error))))))
+       ;; %() embedded elisp
+       (goto-char (point-min))
+       (while (re-search-forward "%\\((.+)\\)" nil t)
+         (goto-char (match-beginning 0))
+         (let ((template-start (point)))
+           (forward-char 1)
+           (let ((result
+                  (condition-case error
+                      (eval (read (current-buffer)))
+                    (error (format "%%![Error: %s]" error)))))
+             (delete-region template-start (point))
+             (insert result))))
        ;; From the property list
        (when plist-p
          (goto-char (point-min))
diff -r 09b1470ac170 org.texi
--- a/org.texi  Wed Oct 31 09:46:35 2007 +0000
+++ b/org.texi  Sat Nov 24 14:39:51 2007 +0000
@@ -4378,6 +4378,8 @@ insertion of content:
 %^g         @r{prompt for tags, with completion on tags in target file.}
 %^G         @r{prompt for tags, with completion all tags in all agenda files.}
 %:keyword   @r{specific information for certain link types, see below}
+%[pathname] @r{insert the contents of the file given by @code{pathname}}
+%(sexp)     @r{evaluate elisp @code{(sexp)} and replace with the result}
 @end example
 
 @noindent




reply via email to

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