1 Return-Path: <imain@stemwinder.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id EC08F431FBC
\r
6 for <notmuch@notmuchmail.org>; Thu, 2 Oct 2014 13:23:56 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id QBC4wxPKbWQP for <notmuch@notmuchmail.org>;
\r
16 Thu, 2 Oct 2014 13:23:49 -0700 (PDT)
\r
17 Received: from cmta9.telus.net (cmta9.telus.net [209.171.16.82])
\r
18 by olra.theworths.org (Postfix) with ESMTP id B6311431FB6
\r
19 for <notmuch@notmuchmail.org>; Thu, 2 Oct 2014 13:23:49 -0700 (PDT)
\r
20 Received: from ovo.mains.priv ([207.102.88.62]) by cmta9.telus.net with TELUS
\r
21 id yLPo1o00R1LiWEf01LPoop; Thu, 02 Oct 2014 14:23:49 -0600
\r
22 X-Authority-Analysis: v=2.0 cv=KNmE+i5o c=1 sm=2
\r
23 a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=S-IsBHyFrF4A:10 a=tsa3CZZnAAAA:8
\r
24 a=QFmAR4G64Eb_gXI2RCcA:9 a=MjTX9qxYB3U_cAoe:21 a=YysiEKMxJFnvkd6R:21
\r
25 a=EcQDfIwDZEqJA1f7rVUV8Q==:117
\r
26 X-Telus-Outbound-IP: 207.102.88.62
\r
27 From: Ian Main <imain@stemwinder.org>
\r
28 To: notmuch@notmuchmail.org
\r
29 Subject: [PATCH] VIM: Add URI handling
\r
30 Date: Thu, 2 Oct 2014 13:23:43 -0700
\r
31 Message-Id: <1412281423-22441-1-git-send-email-imain@stemwinder.org>
\r
32 X-Mailer: git-send-email 1.9.3
\r
33 X-BeenThere: notmuch@notmuchmail.org
\r
34 X-Mailman-Version: 2.1.13
\r
36 List-Id: "Use and development of the notmuch mail system."
\r
37 <notmuch.notmuchmail.org>
\r
38 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
39 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
41 List-Post: <mailto:notmuch@notmuchmail.org>
\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
43 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
45 X-List-Received-Date: Thu, 02 Oct 2014 20:23:57 -0000
\r
47 This patch adds URI handling to the vim client. You can now press
\r
48 'u' by default and the client will parse the current line and find
\r
49 any URIs available. If there are more than one it opens the one
\r
50 under the cursor or else it opens the only one available. It also
\r
51 supports mailto: URI's and will compose a new message when activated.
\r
53 By default xdg-open is used for everything but mailto: which generally
\r
54 does the right thing afaict.
\r
58 vim/notmuch.txt | 1 +
\r
59 vim/notmuch.vim | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
\r
60 2 files changed, 53 insertions(+), 7 deletions(-)
\r
62 diff --git a/vim/notmuch.txt b/vim/notmuch.txt
\r
63 index 4374102..d336406 100644
\r
64 --- a/vim/notmuch.txt
\r
65 +++ b/vim/notmuch.txt
\r
66 @@ -72,6 +72,7 @@ q Quit view
\r
67 A Archive (-inbox -unread)
\r
68 I Mark as read (-unread)
\r
74 diff --git a/vim/notmuch.vim b/vim/notmuch.vim
\r
75 index 331e930..de82bb9 100644
\r
76 --- a/vim/notmuch.vim
\r
77 +++ b/vim/notmuch.vim
\r
78 @@ -12,7 +12,7 @@ let g:notmuch_folders_maps = {
\r
79 \ '<Enter>': 'folders_show_search()',
\r
80 \ 's': 'folders_search_prompt()',
\r
81 \ '=': 'folders_refresh()',
\r
82 - \ 'c': 'compose()',
\r
83 + \ 'c': 'compose("")',
\r
86 let g:notmuch_search_maps = {
\r
87 @@ -25,7 +25,7 @@ let g:notmuch_search_maps = {
\r
88 \ 's': 'search_search_prompt()',
\r
89 \ '=': 'search_refresh()',
\r
90 \ '?': 'search_info()',
\r
91 - \ 'c': 'compose()',
\r
92 + \ 'c': 'compose("")',
\r
95 let g:notmuch_show_maps = {
\r
96 @@ -37,10 +37,11 @@ let g:notmuch_show_maps = {
\r
97 \ 'e': 'show_extract_msg()',
\r
98 \ 's': 'show_save_msg()',
\r
99 \ 'p': 'show_save_patches()',
\r
100 + \ 'u': 'show_open_uri()',
\r
101 \ 'r': 'show_reply()',
\r
102 \ '?': 'show_info()',
\r
103 \ '<Tab>': 'show_next_msg()',
\r
104 - \ 'c': 'compose()',
\r
105 + \ 'c': 'compose("")',
\r
108 let g:notmuch_compose_maps = {
\r
109 @@ -59,6 +60,7 @@ let s:notmuch_datetime_format_default = '%d.%m.%y %H:%M:%S'
\r
110 let s:notmuch_reader_default = 'mutt -f %s'
\r
111 let s:notmuch_sendmail_default = 'sendmail'
\r
112 let s:notmuch_folders_count_threads_default = 0
\r
113 +let s:notmuch_open_uri_default = 'xdg-open'
\r
115 function! s:new_file_buffer(type, fname)
\r
116 exec printf('edit %s', a:fname)
\r
117 @@ -135,8 +137,8 @@ function! s:show_reply()
\r
121 -function! s:compose()
\r
122 - ruby open_compose
\r
123 +function! s:compose(to_email)
\r
124 + ruby open_compose(VIM::evaluate('a:to_email'))
\r
125 let b:compose_done = 0
\r
126 call s:set_map(g:notmuch_compose_maps)
\r
127 autocmd BufDelete <buffer> call s:on_compose_delete()
\r
128 @@ -159,6 +161,45 @@ ruby << EOF
\r
132 +function! s:show_open_uri()
\r
133 + let line = getline(".")
\r
134 + let pos = getpos(".")
\r
138 + line = VIM::evaluate('line')
\r
139 + col = VIM::evaluate('col') - 1
\r
140 + uris = URI.extract(line)
\r
142 + if uris.length == 1
\r
143 + wanted_uri = uris[0]
\r
145 + uris.each do |uri|
\r
146 + # Check to see the URI is at the present cursor location
\r
147 + idx = line.index(uri)
\r
148 + if col >= idx and col <= idx + uri.length
\r
156 + uri = URI.parse(wanted_uri)
\r
157 + if uri.class == URI::MailTo
\r
158 + vim_puts("Composing new email to #{uri.to}.")
\r
159 + VIM::command("call s:compose('#{uri.to}')")
\r
161 + vim_puts("Opening #{uri.to_s}.")
\r
162 + cmd = VIM::evaluate('g:notmuch_open_uri')
\r
163 + system(cmd, uri.to_s)
\r
166 + vim_puts('URI not found.')
\r
171 function! s:show_open_msg()
\r
174 @@ -404,6 +445,10 @@ function! s:set_defaults()
\r
178 + if !exists('g:notmuch_open_uri')
\r
179 + let g:notmuch_open_uri = s:notmuch_open_uri_default
\r
182 if !exists('g:notmuch_reader')
\r
183 if exists('g:notmuch_rb_reader')
\r
184 let g:notmuch_reader = g:notmuch_rb_reader
\r
185 @@ -611,11 +656,11 @@ ruby << EOF
\r
186 open_compose_helper(lines, cur)
\r
189 - def open_compose()
\r
190 + def open_compose(to_email)
\r
193 lines << "From: #{$email}"
\r
195 + lines << "To: #{to_email}"
\r