From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthieu Lemerre Subject: [PATCH] Make org-capture more generic Date: Fri, 17 Jun 2011 00:50:26 +0200 Message-ID: <87ei2t75n1.fsf@free.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:33178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QXLOY-0000pF-QS for emacs-orgmode@gnu.org; Thu, 16 Jun 2011 18:50:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QXLOW-0006rR-7R for emacs-orgmode@gnu.org; Thu, 16 Jun 2011 18:50:38 -0400 Received: from smtp3-g21.free.fr ([212.27.42.3]:36784) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QXLOV-0006r8-8O for emacs-orgmode@gnu.org; Thu, 16 Jun 2011 18:50:36 -0400 Received: from matthieu-netbook (unknown [82.239.207.166]) by smtp3-g21.free.fr (Postfix) with ESMTP id 6BA6DA6229 for ; Fri, 17 Jun 2011 00:50:28 +0200 (CEST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-a-new-empty-entry-type-to-org-capture.patch >From 8fa638b36f477f2b81e131439729dda954d2e0ad Mon Sep 17 00:00:00 2001 From: Matthieu Lemerre 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0002-Allows-org-capture-template-to-be-a-function.patch >From 4d933ee2cc91f93c8e78a792175751e27c9d03e4 Mon Sep 17 00:00:00 2001 From: Matthieu Lemerre 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 --=-=-=--