emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jambunathan K <kjambunathan@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Re: feature request: a basic conversation manager
Date: Sun, 29 Aug 2010 00:46:35 +0530	[thread overview]
Message-ID: <81lj7qh7jg.fsf@gmail.com> (raw)
In-Reply-To: <877hjn3fcp.wl%ucecesf@ucl.ac.uk> (Eric S. Fraga's message of "Wed, 18 Aug 2010 20:12:06 +0100")

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


Carsten & Others

    >> In the context of the original post, is there a possible way to do
    >> this.
    >> 
    >> 1. I mark a TODO entry in todo.org as done.
    >> 
    >> 2. An org-id (say ID-TODO) gets created for the TODO entry if
    >> there is none yet.
    >> 
    >> 3. The state transition to DONE triggers a capture rule. The
    >> conversation is collected in a capture buffer and filed as a
    >> heading under conversation.org.  An org-id (say ID-CONV) is
    >> generated for the captured entry.
    >> 
    >> 4. ID-TODO is noted in the conversation.org 5. ID-CONV is noted
    >> down in todo.org
    >> 
    >> Jambunathan K.

    Eric> I guess you could use the org-after-todo-state-change-hook
    Eric> together with the functionality of org-capture to implement
    Eric> this quite easily?  Of course, this requires some emacs lisp
    Eric> knowledge.

Thanks for accepting my earlier two patches on this thread.

I have identified couple of more things that are needed in org core to
support the above workflow. The changes required are minimal but enable
complex workflows.

[Context Switch]
Before I proceed further let me add this - 

The intention of this mail is to share my notes and influence you to
considering adding the needed support in the core. In effect the
attached patch is demo-only and not to be construed as a formal commit
request.
[Back to Original Context]

Needed features are:

1. Support for 'out-of-band' capture: Think of it as a
   org-add-log-setup for capture workflow. This is implemented as part
   of org-capture-setup in the enclosed patch.
 
   Note: Capture and Log Notes workflow are similar.
   + org-capture <=> org-add-log-note: Both of these routines pop-up
     notes buffers.

   + org-capture-finalize <=> org-store-log-note: Both dump the user
     notes to the user-specified position.

   + org-capture-setup <=> org-add-log-setup: Both make a note of the
     notes insertion position for later use. Note that they only setup
     the note taking process and don't by themselves collect or store
     notes.

   In some sense the addition of org-add-log-setup would make Log Notes
   and Org Capture closer together. ie., one can make org-capture
   supplant the simplistic Log Notes.
     
2. Support for chained captures: Think of it as per-capture-rule
   exit-hook. Unlike org-capture-before-finalize-hook (which gets
   invoked in the middle of the capture), this gets called right at
   the fag end of the capture after the capture buffer is saved or
   aborted and window configs are restored.
   
   This is implemented as part of a new :exit element in capture-plist
   in the attached patch.

What you need to do:

1. Apply the attached patch to org-mode.
1. Load conversation.el. 
2. Start with following todo.org entry.

# Sample ~/todo.org

* TODO Talk to someone
  SCHEDULED: <2010-09-08 Wed +1d>
  
3. Do a C-c C-t on the above entry
4. Do C-c C-t  once more.   

See the following magic happen

# TODO.org after 2 C-c C-t (s).

* TODO Talk to someone
  SCHEDULED: <2010-09-08 Wed +1d>
  :PROPERTIES:
  :ID:       47df1dd3-3101-4dda-95df-cac71ae7dcab
  :END:
   [[id:a9664246-f396-4084-abb0-0c2274e409cd][Conversation-199003770]] [2010-08-28 Sat 23:25]
   [[id:ee280862-750e-49ee-b3a4-2cebe655dae8][Conversation-446218316]] [2010-08-28 Sat 23:25]


# Conversation.org after 2 C-c C-t (s).
   
* Conversations

** Conversation-446218316
   :PROPERTIES:
   :ID:       ee280862-750e-49ee-b3a4-2cebe655dae8
   :END:
   TODO Context: [[id:47df1dd3-3101-4dda-95df-cac71ae7dcab][Talk to someone]]

** Conversation-199003770
   :PROPERTIES:
   :ID:       a9664246-f396-4084-abb0-0c2274e409cd
   :END:
   TODO Context: [[id:47df1dd3-3101-4dda-95df-cac71ae7dcab][Talk to someone]]
   
   
I have few more things to share. This after sometime or once you revert
with your comments.
   
Jambunathan K. 


Attachments:


[-- Attachment #2: Unit Test Code --]
[-- Type: text/plain, Size: 1964 bytes --]

;; Use ID for storing links
(setq org-link-to-org-use-id t)

;; trigger a capture on done
(add-hook 'org-after-todo-state-change-hook
	  'my-todo-state-change-hook)

;; DONE on a todo item triggers a capture rule "x"
(defun my-todo-state-change-hook () 
  ""
  (when (member state org-done-keywords)
    (org-capture-setup "x")))

;; org-capture-templates

;; Rule-x does this
;; - creates an entry in conversation.org
;; - saves a link to the parent TODO entry in the new conversation node
;; - exits with a call to my-update-todo-node defun

(setq org-capture-templates
      '(("x" "Create conversation node" entry
	 (file+headline "~/conversation.org" "Conversations")
	 "** Conversation-%(int-to-string (random))\n   TODO Context: %a\n   %?"
	 :prepend t :empty-lines 1
	 :exit (my-update-todo-node))))

;;  my-update-todo-node does this
;; - visits the last captured node (ie, the conversation node)
;; - installs a makeshift capture rule and invokes it
;;
;; makeshift capture rule installs a link to the newly created
;; conversation node in the todo node.

(defun my-update-todo-node ()
  (when (not org-note-abort)
    (let (org-capture-templates)

      (with-current-buffer (marker-buffer org-capture-last-stored-marker)
	(save-excursion
	  (goto-char (marker-position org-capture-last-stored-marker))

	  (setq org-capture-templates
		`(("*" "Makeshift" plain
		   (id ,(my-id-from-id-link (org-capture-get :annotation))) 
		   "   %a %U\n   %?")))
	  (org-capture nil "*"))))))


;; this is a library routine used by makeshift capture rule
(defun my-id-from-id-link (id-link)
  ""
  (let (link type path)

    (when (string-match org-bracket-link-regexp id-link)
      (setq link (match-string-no-properties 1  id-link)))

    (when (and link (string-match org-link-re-with-space3 link))
      (setq type (match-string 1 link) path (match-string 2 link)))

    path))

;; (setq hyperlink "[[id:1766a3bb-d717-4779-ac33-98510ada95aa][Conversations]]")

[-- Attachment #3: patch to org-mode --]
[-- Type: text/plain, Size: 3045 bytes --]

From 01210b9ecf8e72db462639a9f317408f1390e964 Mon Sep 17 00:00:00 2001
From: Jambunathan K <kjambunathan@gmail.com>
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


[-- Attachment #4: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

  reply	other threads:[~2010-08-28 19:16 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-27  2:44 feature request: a basic conversation manager Samuel Wales
2008-11-29 18:22 ` Ross Patterson
2008-12-10  5:00   ` Samuel Wales
2008-12-09 10:36 ` Carsten Dominik
2008-12-10  3:59   ` Samuel Wales
2010-08-18 19:01 ` Jambunathan K
2010-08-18 19:12   ` Eric S Fraga
2010-08-28 19:16     ` Jambunathan K [this message]
2010-08-22 22:37   ` [PATCH 1/2] org-store-link: Return link when invoked from within agenda buffer Jambunathan K
2010-08-23 10:18     ` [Accepted] [Orgmode, " Carsten Dominik
2010-08-22 22:37   ` [PATCH " Jambunathan K
2010-08-22 22:37   ` Jambunathan K
2010-08-22 23:11   ` [PATCH 2/2] org-store-link: Fix storing of links to headlines in indirect buffers Jambunathan K
2010-08-23 10:14     ` [Accepted] [Orgmode, " Carsten Dominik
2010-08-28 19:43   ` feature request: a basic conversation manager Samuel Wales
2010-08-28 19:50     ` Samuel Wales
2010-08-28 21:42       ` Jambunathan K
2010-08-28 22:08         ` Samuel Wales

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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=81lj7qh7jg.fsf@gmail.com \
    --to=kjambunathan@gmail.com \
    --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 public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).