From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: [CODE] org-open-link-from-string in a program Date: Thu, 08 Aug 2013 13:58:35 +0800 Message-ID: <87haf0soz8.fsf@ericabrahamsen.net> References: <87ehab5fgr.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7JEq-0003V9-Gt for emacs-orgmode@gnu.org; Thu, 08 Aug 2013 01:58:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V7JEk-0006qf-2c for emacs-orgmode@gnu.org; Thu, 08 Aug 2013 01:58:20 -0400 Received: from plane.gmane.org ([80.91.229.3]:32849) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7JEj-0006qN-SI for emacs-orgmode@gnu.org; Thu, 08 Aug 2013 01:58:14 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1V7JEi-0002sY-O9 for emacs-orgmode@gnu.org; Thu, 08 Aug 2013 07:58:12 +0200 Received: from 114.250.121.54 ([114.250.121.54]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 08 Aug 2013 07:58:12 +0200 Received: from eric by 114.250.121.54 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 08 Aug 2013 07:58:12 +0200 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 Eric Abrahamsen writes: > I'm trying to write a small function that programmatically follows a > link to a gnus message, then calls > `gnus-summary-wide-reply-with-original' to start a reply to that > message. Okay, this seems like a fair amount of code for something that doesn't actually do all that much, but here it is. I have one capture template that incorporates a link to a gnus message in the headline (for REPLY todos), and a different one that prompts for one or more mailto: or bbdb: links, and puts them in the headline (with an EMAIL todo). Sometimes I have mailto links and message links in the same header, so I can reply to a message and copy other people on the reply. The two main functions here (org-mail-handle-mail and org-mail-handle-mail-agenda) look at the headline under point and hopefully DTRT with the links they find there. Like I said, the whole point of this is single-key-in, single-key-out capturing and handling of email todos. Things that are weird: 1. I've used an "org-mail" prefix, which doesn't otherwise exist. 2. It assumes you're using gnus 3. It assumes you want to reply to messages using `gnus-wide-reply-with-original' 4. It still seems a wee bit fragile. Gnus doesn't take kindly to be operated non-interactively; I've used call-interactively where I can, just in case, but sometimes odd things happen. Anyway, there it is. I'd be happy to stick it on worg, put it in contrib, or just leave it here. If anyone wants it tweaked or expanded or generalized (it doesn't do org-contact contacts, for example), just let me know. (defvar org-mail-window-conf nil "Save org-buffer window configuration here, for later restoration.") (defun org-mail-restore-after-send () (gnus-summary-exit nil t) (when (window-configuration-p org-mail-window-conf) (set-window-configuration org-mail-window-conf)) (call-interactively 'org-agenda-todo)) (defun org-mail-handle-mail (&optional interactive-p) "Handle mail-related links for current headline." tC (interactive "p") (unless (org-back-to-heading t) (error "Not in an org item")) (when interactive-p (setq org-mail-window-conf (current-window-configuration))) (let ((todo-kwd (org-element-property :todo-keyword (org-element-at-point))) message mailto) (while (re-search-forward org-any-link-re (line-end-position) t) (let ((addr (or (match-string-no-properties 2) (match-string-no-properties 0)))) (cond ((string-match "^