emacs-orgmode
[Top][All Lists]
Advanced

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

[O] [PATCH] Make org-capture more generic


From: Matthieu Lemerre
Subject: [O] [PATCH] Make org-capture more generic
Date: Fri, 17 Jun 2011 00:50:26 +0200
User-agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.2.1 (i686-pc-linux-gnu)

Hi,

I really like org-capture, and especially the "hierarchical" interface
for selecting possible capture templates, but I think it needs to be
extended slightly so that it can be used to archive anything.

Some of the things I would like to do when capturing are:
 1. Just jump to some location without inserting anything so that I can
    edit things by myself (for instance, jump to the location where my
    org-capture-template is defined to manually add new templates)
 2. Copying some file to some location (no org involved)
 3. Extract some files from my mail to attach them to some org item
 4. Insert some parametrized code at point (e.g. for repetitive
    projects, like planning a business trip, I would like to insert
    a predefined project at point, so I don't have to do all the 
    planning every time I do it)

Item 1. is feasible if I remember to use C-u before calling
org-template, but this is a ugly workaround. Another way that I tried
was to using "" as a template with an unnarrowed buffer, but this
triggers a default template instead.

My first patch just extends org-capture to allow empty template, using a
new entry type, 'empty.

The second allows to use functions to define template. Together with an
empty template, it should allow implementing my 2, and may be useful to
implement 3 and 4.

I don't think these patches will be definitive; I mostly would like to
discuss org-capture evolution with org-mode gurus ;)

Regards
Matthieu

>From 8fa638b36f477f2b81e131439729dda954d2e0ad Mon Sep 17 00:00:00 2001
From: Matthieu Lemerre <address@hidden>
Date: Fri, 17 Jun 2011 00:04:40 +0200
Subject: [PATCH 1/2] Add a new "empty" entry-type to org-capture.

This special empty entry type allows to not insert any text in a
template. This can be used e.g. to only jump to a location, so that
the user can edit it by hand.
---
 lisp/org-capture.el |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 7d3f630..7e055f9 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1178,6 +1178,7 @@ Point will remain at the first line after the inserted 
text."
        ((eq type 'item) (setq txt "- %?"))
        ((eq type 'checkitem) (setq txt "- [ ] %?"))
        ((eq type 'table-line) (setq txt "| %? |"))
+       ((eq type 'empty) (setq txt ""))
        ((member type '(nil entry)) (setq txt "* %?\n  %a"))))
     (org-capture-put :template txt :type type)))
 
-- 
1.7.4.1

>From 4d933ee2cc91f93c8e78a792175751e27c9d03e4 Mon Sep 17 00:00:00 2001
From: Matthieu Lemerre <address@hidden>
Date: Fri, 17 Jun 2011 00:19:40 +0200
Subject: [PATCH 2/2] Allows org-capture template to be a function.

The function should return a string, which is used as a template.
---
 lisp/org-capture.el |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 7e055f9..368532f 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1171,15 +1171,17 @@ 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 (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.
-      (cond
-       ((eq type 'item) (setq txt "- %?"))
-       ((eq type 'checkitem) (setq txt "- [ ] %?"))
-       ((eq type 'table-line) (setq txt "| %? |"))
-       ((eq type 'empty) (setq txt ""))
-       ((member type '(nil entry)) (setq txt "* %?\n  %a"))))
+    (if (functionp txt)
+       (setq txt (funcall 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.
+       (cond
+        ((eq type 'item) (setq txt "- %?"))
+        ((eq type 'checkitem) (setq txt "- [ ] %?"))
+        ((eq type 'table-line) (setq txt "| %? |"))
+        ((eq type 'empty) (setq txt ""))
+        ((member type '(nil entry)) (setq txt "* %?\n  %a")))))
     (org-capture-put :template txt :type type)))
 
 (defun org-capture-goto-target (&optional template-key)
-- 
1.7.4.1


reply via email to

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