Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically track links in org-mode to gnus messages?

I use org-mode + gnus + Gmail for my daily GTD routine. The concept is that treating all incoming messages as tasks, and converting all messages in INBOX into org-mode's tasks using org-capture. Once all new messages are converted into tasks, archive them, and hopefully INBOX is kept zero.

My workflow is as follows:

  1. Open the summary view of gnus INBOX, and select a new message
  2. Capture the message with org-store-link (C-c l)
  3. Open my todo file (todo.org), and create a new task for it, and paste the captured link to the task's body with org-insert-link (C-c C-l)
  4. Go back to gnus summary view and archive the message (B del)

The problem is that when moving a message into the archive folder, the captured link becomes broken, and I cannot follow the link anymore. This is because the captured link includes the IMAP folders' name and archiving message changes the message's IMAP folder name. E.g.,

  • Captured link: [[gnus:nnimap%2Blocalhost:%5BGmail%5D.Important#1364607772002.9702fb8c@Nodemailer][Email from Geeklist Team: Geekli.st Suggestions & Activi]] (IMAP folder name is "[Gmail]Important")
  • Link to archived message: [[gnus:nnimap%2Blocalhost:%5BGmail%5D.All Mail#1364607772002.9702fb8c@Nodemailer][Email from Geeklist Team: Geekli.st Suggestions & Activi]] (IMAP folder name is "[Gmail]All Mail")

So my question is: how can I update the captured link automatically when the message is moved to other folders? I guess there are some hooks to do this, but I could not find a good sample for this purpose. Or any simpler solutions for this kind of routine are welcome. TIA.

like image 657
Yasuhito Takamiya Avatar asked Apr 01 '13 01:04

Yasuhito Takamiya


People also ask

How do you add a link in Org mode?

Links in Org are plain text, and you can type or paste them straight into the buffer. By using this command, the links are automatically enclosed in double brackets, and you will be asked for the optional descriptive text.

What is org capture?

org-capture is a way to take notes in Emacs in an unobstructive way. It allows you to open a buffer to enter a note and it'll store it in the correct place based on the type of note you've selected. I must say that I took the term note from it's documentation, but I think that it's a very loose definition of the word.

How do you make a table in Org mode?

The easiest way to create a table is to directly type the "|" character at the beginning of a line, or after any amount of white space. This will put you in the first field of an atomic table. Once you've finished editing this cell, you can jump to the next one by pressing TAB .


1 Answers

I do not use 'org-store-link' and 'org-insert-link' but a capture template, that automatically generates a link to the message (%a below). So you do not have to switch buffers to store a TODO entry:

(setq org-capture-templates
  '(
    ("m" "TODO from Mail" entry (file+headline "~/gitfiles/org/gtd.org" "Inbox") 
     "* TODO %?, Link: %a")))

Since all my emails arrive in the INBOX and are archived in the folder "Archive" I can just use the following function which replaces the string 'INBOX' by 'Archive' in the Org mode link in the capture buffer:

 (defun hs/replace ()
   (interactive)
   (goto-char 1)
   (replace-string "INBOX" "Archive"))

This hook calls the function when I hit C-c C-c to file the capture entry:

(add-hook 'org-capture-prepare-finalize-hook 'hs/replace)

So, my workflow is as follows:

  • Select a message in Summary buffer
  • Hit C-c c m to capture a TODO item with Link to message and write a description (since the message is still in the inbox, the generated link contains the group "INBOX")
  • Hit C-c C-c to file the TODO entry (this calls the function 'hs/replace' which replaces the string INBOX by Archive)
  • Archive the email in the archive folder.

HTH

like image 51
karl Avatar answered Oct 23 '22 05:10

karl