all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Matthieu Lemerre <racin@free.fr>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Make org-capture more generic
Date: Fri, 17 Jun 2011 00:50:26 +0200	[thread overview]
Message-ID: <87ei2t75n1.fsf@free.fr> (raw)

[-- Attachment #1: Type: text/plain, Size: 1473 bytes --]


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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-a-new-empty-entry-type-to-org-capture.patch --]
[-- Type: text/x-diff, Size: 1015 bytes --]

From 8fa638b36f477f2b81e131439729dda954d2e0ad Mon Sep 17 00:00:00 2001
From: Matthieu Lemerre <matthieu.lemerre@gmail.com>
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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Allows-org-capture-template-to-be-a-function.patch --]
[-- Type: text/x-diff, Size: 1862 bytes --]

From 4d933ee2cc91f93c8e78a792175751e27c9d03e4 Mon Sep 17 00:00:00 2001
From: Matthieu Lemerre <matthieu.lemerre@gmail.com>
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	other threads:[~2011-06-16 22:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=87ei2t75n1.fsf@free.fr \
    --to=racin@free.fr \
    --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.