--- /dev/null
+Return-Path: <imain@stemwinder.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id B5ECD431FD7\r
+ for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 15:20:07 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id RXyZj0Z+QjP8 for <notmuch@notmuchmail.org>;\r
+ Thu, 23 Oct 2014 15:20:00 -0700 (PDT)\r
+Received: from cmta11.telus.net (cmta11.telus.net [209.171.16.84])\r
+ by olra.theworths.org (Postfix) with ESMTP id 5CF59431FBD\r
+ for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 15:20:00 -0700 (PDT)\r
+Received: from ovo.mains.priv ([207.102.88.62]) by cmta11.telus.net with TELUS\r
+ id 6mKy1p0051LiWEf01mKygu; Thu, 23 Oct 2014 16:19:58 -0600\r
+X-Authority-Analysis: v=2.0 cv=daReKwre c=1 sm=2\r
+ a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=tsa3CZZnAAAA:8 a=r_jncFobP5VkJRuen9wA:9\r
+ a=-tTqbyaxCRf-iLxf:21 a=0_Bxu91NZpkSn-c3:21\r
+ a=EcQDfIwDZEqJA1f7rVUV8Q==:117\r
+X-Telus-Outbound-IP: 207.102.88.62\r
+From: Ian Main <imain@stemwinder.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2] VIM: Add URI handling\r
+Date: Thu, 23 Oct 2014 15:19:54 -0700\r
+Message-Id: <1414102794-12094-1-git-send-email-imain@stemwinder.org>\r
+X-Mailer: git-send-email 1.9.3\r
+In-Reply-To: <1412281423-22441-1-git-send-email-imain@stemwinder.org>\r
+References: <1412281423-22441-1-git-send-email-imain@stemwinder.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 23 Oct 2014 22:20:07 -0000\r
+\r
+Add URI handling to the vim client. You can now press 'enter' by default and\r
+the client will parse the current line and find any 'Part's or URIs available\r
+for opening. If there are more than one it opens the one under the cursor or\r
+else it opens the only one available. It also supports mailto: URI's and will\r
+compose a new message when activated.\r
+\r
+By default xdg-open is used for everything but mailto: which generally\r
+does the right thing afaict.\r
+\r
+Note that this is now dependant on the attachment patch in order to make\r
+the nice 'enter' behavior work for both.\r
+\r
+ Ian\r
+---\r
+ vim/notmuch.txt | 3 ++-\r
+ vim/notmuch.vim | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++------\r
+ 2 files changed, 70 insertions(+), 9 deletions(-)\r
+\r
+diff --git a/vim/notmuch.txt b/vim/notmuch.txt\r
+index 838a904..5d84fde 100644\r
+--- a/vim/notmuch.txt\r
++++ b/vim/notmuch.txt\r
+@@ -74,7 +74,8 @@ I Mark as read (-unread)\r
+ t Tag (prompted)\r
+ e Extract attachment on the current 'Attachment' line or all\r
+ attachments if the cursor is elsewhere.\r
+-v View attachment on the current 'Attachment' line.\r
++<enter> View email part on the current 'Part' line, or open URI under cursor\r
++ or on line.\r
+ s Search\r
+ p Save patches\r
+ r Reply\r
+diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
+index 1466e50..2f76f55 100644\r
+--- a/vim/notmuch.vim\r
++++ b/vim/notmuch.vim\r
+@@ -12,7 +12,7 @@ let g:notmuch_folders_maps = {\r
+ \ '<Enter>': 'folders_show_search()',\r
+ \ 's': 'folders_search_prompt()',\r
+ \ '=': 'folders_refresh()',\r
+- \ 'c': 'compose()',\r
++ \ 'c': 'compose("")',\r
+ \ }\r
+ \r
+ let g:notmuch_search_maps = {\r
+@@ -25,7 +25,7 @@ let g:notmuch_search_maps = {\r
+ \ 's': 'search_search_prompt()',\r
+ \ '=': 'search_refresh()',\r
+ \ '?': 'search_info()',\r
+- \ 'c': 'compose()',\r
++ \ 'c': 'compose("")',\r
+ \ }\r
+ \r
+ let g:notmuch_show_maps = {\r
+@@ -35,13 +35,13 @@ let g:notmuch_show_maps = {\r
+ \ 't': 'show_tag("")',\r
+ \ 'o': 'show_open_msg()',\r
+ \ 'e': 'show_extract_msg()',\r
+- \ '<Enter>': 'show_view_attachment()',\r
++ \ '<Enter>': 'show_view_magic()',\r
+ \ 's': 'show_save_msg()',\r
+ \ 'p': 'show_save_patches()',\r
+ \ 'r': 'show_reply()',\r
+ \ '?': 'show_info()',\r
+ \ '<Tab>': 'show_next_msg()',\r
+- \ 'c': 'compose()',\r
++ \ 'c': 'compose("")',\r
+ \ }\r
+ \r
+ let g:notmuch_compose_maps = {\r
+@@ -63,6 +63,7 @@ let s:notmuch_view_attachment_default = 'xdg-open'\r
+ let s:notmuch_attachment_tmpdir_default = '~/.notmuch/tmp'\r
+ let s:notmuch_folders_count_threads_default = 0\r
+ let s:notmuch_compose_start_insert_default = 1\r
++let s:notmuch_open_uri_default = 'xdg-open'\r
+ \r
+ function! s:new_file_buffer(type, fname)\r
+ exec printf('edit %s', a:fname)\r
+@@ -141,8 +142,8 @@ function! s:show_reply()\r
+ end\r
+ endfunction\r
+ \r
+-function! s:compose()\r
+- ruby open_compose\r
++function! s:compose(to_email)\r
++ ruby open_compose(VIM::evaluate('a:to_email'))\r
+ let b:compose_done = 0\r
+ call s:set_map(g:notmuch_compose_maps)\r
+ autocmd BufDelete <buffer> call s:on_compose_delete()\r
+@@ -155,6 +156,22 @@ function! s:show_info()\r
+ ruby vim_puts get_message.inspect\r
+ endfunction\r
+ \r
++function! s:show_view_magic()\r
++ let line = getline(".")\r
++\r
++ruby << EOF\r
++ line = VIM::evaluate('line')\r
++\r
++ # Easiest to check for 'Part' types first..\r
++ match = line.match(/^Part (\d*):/)\r
++ if match and match.length == 2\r
++ VIM::command('call s:show_view_attachment()')\r
++ else\r
++ VIM::command('call s:show_open_uri()')\r
++ end\r
++EOF\r
++endfunction\r
++\r
+ function! s:show_view_attachment()\r
+ let line = getline(".")\r
+ ruby << EOF\r
+@@ -226,6 +243,45 @@ ruby << EOF\r
+ EOF\r
+ endfunction\r
+ \r
++function! s:show_open_uri()\r
++ let line = getline(".")\r
++ let pos = getpos(".")\r
++ let col = pos[2]\r
++ruby << EOF\r
++ m = get_message\r
++ line = VIM::evaluate('line')\r
++ col = VIM::evaluate('col') - 1\r
++ uris = URI.extract(line)\r
++ wanted_uri = nil\r
++ if uris.length == 1\r
++ wanted_uri = uris[0]\r
++ else\r
++ uris.each do |uri|\r
++ # Check to see the URI is at the present cursor location\r
++ idx = line.index(uri)\r
++ if col >= idx and col <= idx + uri.length\r
++ wanted_uri = uri\r
++ break\r
++ end\r
++ end\r
++ end\r
++\r
++ if wanted_uri\r
++ uri = URI.parse(wanted_uri)\r
++ if uri.class == URI::MailTo\r
++ vim_puts("Composing new email to #{uri.to}.")\r
++ VIM::command("call s:compose('#{uri.to}')")\r
++ else\r
++ vim_puts("Opening #{uri.to_s}.")\r
++ cmd = VIM::evaluate('g:notmuch_open_uri')\r
++ system(cmd, uri.to_s)\r
++ end\r
++ else\r
++ vim_puts('URI not found.')\r
++ end\r
++EOF\r
++endfunction\r
++\r
+ function! s:show_open_msg()\r
+ ruby << EOF\r
+ m = get_message\r
+@@ -481,6 +537,10 @@ function! s:set_defaults()\r
+ endif\r
+ endif\r
+ \r
++ if !exists('g:notmuch_open_uri')\r
++ let g:notmuch_open_uri = s:notmuch_open_uri_default\r
++ endif\r
++\r
+ if !exists('g:notmuch_reader')\r
+ if exists('g:notmuch_rb_reader')\r
+ let g:notmuch_reader = g:notmuch_rb_reader\r
+@@ -693,11 +753,11 @@ ruby << EOF\r
+ open_compose_helper(lines, cur)\r
+ end\r
+ \r
+- def open_compose()\r
++ def open_compose(to_email)\r
+ lines = []\r
+ \r
+ lines << "From: #{$email}"\r
+- lines << "To: "\r
++ lines << "To: #{to_email}"\r
+ cur = lines.count\r
+ \r
+ lines << "Cc: "\r
+-- \r
+1.9.3\r
+\r