From 01210b9ecf8e72db462639a9f317408f1390e964 Mon Sep 17 00:00:00 2001 From: Jambunathan K Date: Sat, 28 Aug 2010 23:17:39 +0530 Subject: [PATCH] Support for chained captures and 'out of band' captures. * lisp/org-capture.el (org-capture-setup): Added. Use this to install a catpture rule that needs to be invoked as part of post-command-hook. Similar to org-add-log-setup. (org-capture-last-setup-marker): (org-capture-last-setup-keys): Added. Installed by org-capture-setup and used within org-capture. (org-capture): Modified. Check for a pending org-capture-setup and do the needful. (org-capture-finalize): Modified. Check for :exit properties and invoke the same. Think of it as a per-capture-rule exit hook. --- lisp/org-capture.el | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index e544964..def9975 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -76,6 +76,12 @@ :tag "Org Capture" :group 'org) +(defvar org-capture-last-setup-marker (make-marker) + "Marker position installed with `org-capture-setup'.") + +(defvar org-capture-last-setup-keys nil + "Capture keys installed with `org-capture-setup'.") + ;;;###autoload (defcustom org-capture-templates nil "Templates for the creation of new entries. @@ -370,6 +376,20 @@ Lisp programs can set KEYS to a string associated with a template in `org-capture-templates'. In this case, interactive selection will be bypassed." (interactive "P") + + (let ((setup-buf (marker-buffer org-capture-last-setup-marker)) + (setup-pos (marker-position org-capture-last-setup-marker))) + + (when setup-buf + (remove-hook 'post-command-hook 'org-capture) + + (with-current-buffer setup-buf + (goto-char setup-pos) + (setq keys org-capture-last-setup-keys)) + + (move-marker org-capture-last-setup-marker nil) + (setq org-capture-last-setup-keys nil))) + (cond ((equal goto '(4)) (org-capture-goto-target)) ((equal goto '(16)) (org-capture-goto-last-stored)) @@ -525,6 +545,9 @@ bypassed." (kill-buffer (current-buffer)) ;; Restore the window configuration before capture (set-window-configuration return-wconf)) + + (eval (or (org-capture-get :exit))) + (when abort-note (cond ((equal abort-note 'clean) @@ -901,6 +924,16 @@ already gone." (org-table-current-dline)))) (t (error "This should not happen")))) +(defun org-capture-setup (keys &optional buffer pos) + "Install position and keys for later capture. +The advised action is invoked as part of `post-command-hook'." + + (move-marker org-capture-last-setup-marker (or pos (point)) buffer) + (setq org-capture-last-setup-keys keys) + + (add-hook 'post-command-hook 'org-capture 'append) + ) + (defun org-capture-bookmark-last-stored-position () "Bookmark the last-captured position." (let* ((where (org-capture-get :position-for-last-stored 'local)) -- 1.7.0.4