Re: [PATCH] VIM: Add URI handling
[notmuch-archives.git] / 29 / 8ac074c4138d22124640012b0cc5c2aba5dae7
1 Return-Path: <tomi.ollila@iki.fi>\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 216F2431FB6\r
6         for <notmuch@notmuchmail.org>; Mon, 20 Oct 2014 11:53:41 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 UyJG36pqWdGg for <notmuch@notmuchmail.org>;\r
16         Mon, 20 Oct 2014 11:53:37 -0700 (PDT)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id 8182D431FAF\r
19         for <notmuch@notmuchmail.org>; Mon, 20 Oct 2014 11:53:37 -0700 (PDT)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id BD66D10008C;\r
22         Mon, 20 Oct 2014 21:53:14 +0300 (EEST)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: Ian Main <imain@stemwinder.org>, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH] VIM: Add URI handling\r
26 In-Reply-To: <1412281423-22441-1-git-send-email-imain@stemwinder.org>\r
27 References: <1412281423-22441-1-git-send-email-imain@stemwinder.org>\r
28 User-Agent: Notmuch/0.18.1+130~ga61922f (http://notmuchmail.org) Emacs/24.3.1\r
29         (x86_64-unknown-linux-gnu)\r
30 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
31         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
32         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
33 Date: Mon, 20 Oct 2014 21:53:14 +0300\r
34 Message-ID: <m2y4sar2sl.fsf@guru.guru-group.fi>\r
35 MIME-Version: 1.0\r
36 Content-Type: text/plain\r
37 X-BeenThere: notmuch@notmuchmail.org\r
38 X-Mailman-Version: 2.1.13\r
39 Precedence: list\r
40 List-Id: "Use and development of the notmuch mail system."\r
41         <notmuch.notmuchmail.org>\r
42 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
43         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
45 List-Post: <mailto:notmuch@notmuchmail.org>\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
47 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
49 X-List-Received-Date: Mon, 20 Oct 2014 18:53:41 -0000\r
50 \r
51 On Thu, Oct 02 2014, Ian Main <imain@stemwinder.org> wrote:\r
52 \r
53 > This patch adds URI handling to the vim client.  You can now press\r
54 > 'u' by default and the client will parse the current line and find\r
55 > any URIs available.  If there are more than one it opens the one\r
56 > under the cursor or else it opens the only one available.  It also\r
57 > supports mailto: URI's and will compose a new message when activated.\r
58 >\r
59 > By default xdg-open is used for everything but mailto: which generally\r
60 > does the right thing afaict.\r
61 \r
62 This patch LGTM.\r
63 \r
64 >\r
65 >     Ian\r
66 \r
67 Tomi\r
68 \r
69 > ---\r
70 >  vim/notmuch.txt |  1 +\r
71 >  vim/notmuch.vim | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-------\r
72 >  2 files changed, 53 insertions(+), 7 deletions(-)\r
73 >\r
74 > diff --git a/vim/notmuch.txt b/vim/notmuch.txt\r
75 > index 4374102..d336406 100644\r
76 > --- a/vim/notmuch.txt\r
77 > +++ b/vim/notmuch.txt\r
78 > @@ -72,6 +72,7 @@ q   Quit view\r
79 >  A    Archive (-inbox -unread)\r
80 >  I    Mark as read (-unread)\r
81 >  t    Tag (prompted)\r
82 > +u    Open URI\r
83 >  s    Search\r
84 >  p    Save patches\r
85 >  r    Reply\r
86 > diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
87 > index 331e930..de82bb9 100644\r
88 > --- a/vim/notmuch.vim\r
89 > +++ b/vim/notmuch.vim\r
90 > @@ -12,7 +12,7 @@ let g:notmuch_folders_maps = {\r
91 >       \ '<Enter>':    'folders_show_search()',\r
92 >       \ 's':          'folders_search_prompt()',\r
93 >       \ '=':          'folders_refresh()',\r
94 > -     \ 'c':          'compose()',\r
95 > +     \ 'c':          'compose("")',\r
96 >       \ }\r
97 >  \r
98 >  let g:notmuch_search_maps = {\r
99 > @@ -25,7 +25,7 @@ let g:notmuch_search_maps = {\r
100 >       \ 's':          'search_search_prompt()',\r
101 >       \ '=':          'search_refresh()',\r
102 >       \ '?':          'search_info()',\r
103 > -     \ 'c':          'compose()',\r
104 > +     \ 'c':          'compose("")',\r
105 >       \ }\r
106 >  \r
107 >  let g:notmuch_show_maps = {\r
108 > @@ -37,10 +37,11 @@ let g:notmuch_show_maps = {\r
109 >       \ 'e':          'show_extract_msg()',\r
110 >       \ 's':          'show_save_msg()',\r
111 >       \ 'p':          'show_save_patches()',\r
112 > +     \ 'u':          'show_open_uri()',\r
113 >       \ 'r':          'show_reply()',\r
114 >       \ '?':          'show_info()',\r
115 >       \ '<Tab>':      'show_next_msg()',\r
116 > -     \ 'c':          'compose()',\r
117 > +     \ 'c':          'compose("")',\r
118 >       \ }\r
119 >  \r
120 >  let g:notmuch_compose_maps = {\r
121 > @@ -59,6 +60,7 @@ let s:notmuch_datetime_format_default = '%d.%m.%y %H:%M:%S'\r
122 >  let s:notmuch_reader_default = 'mutt -f %s'\r
123 >  let s:notmuch_sendmail_default = 'sendmail'\r
124 >  let s:notmuch_folders_count_threads_default = 0\r
125 > +let s:notmuch_open_uri_default = 'xdg-open'\r
126 >  \r
127 >  function! s:new_file_buffer(type, fname)\r
128 >       exec printf('edit %s', a:fname)\r
129 > @@ -135,8 +137,8 @@ function! s:show_reply()\r
130 >       startinsert!\r
131 >  endfunction\r
132 >  \r
133 > -function! s:compose()\r
134 > -     ruby open_compose\r
135 > +function! s:compose(to_email)\r
136 > +     ruby open_compose(VIM::evaluate('a:to_email'))\r
137 >       let b:compose_done = 0\r
138 >       call s:set_map(g:notmuch_compose_maps)\r
139 >       autocmd BufDelete <buffer> call s:on_compose_delete()\r
140 > @@ -159,6 +161,45 @@ ruby << EOF\r
141 >  EOF\r
142 >  endfunction\r
143 >  \r
144 > +function! s:show_open_uri()\r
145 > +     let line = getline(".")\r
146 > +     let pos = getpos(".")\r
147 > +     let col = pos[2]\r
148 > +ruby << EOF\r
149 > +     m = get_message\r
150 > +     line = VIM::evaluate('line')\r
151 > +     col = VIM::evaluate('col') - 1\r
152 > +     uris = URI.extract(line)\r
153 > +     wanted_uri = nil\r
154 > +     if uris.length == 1\r
155 > +             wanted_uri = uris[0]\r
156 > +     else\r
157 > +             uris.each do |uri|\r
158 > +                     # Check to see the URI is at the present cursor location\r
159 > +                     idx = line.index(uri)\r
160 > +                     if col >= idx and col <= idx + uri.length\r
161 > +                             wanted_uri = uri\r
162 > +                             break\r
163 > +                     end\r
164 > +             end\r
165 > +     end\r
166 > +\r
167 > +     if wanted_uri\r
168 > +             uri = URI.parse(wanted_uri)\r
169 > +             if uri.class == URI::MailTo\r
170 > +                     vim_puts("Composing new email to #{uri.to}.")\r
171 > +                     VIM::command("call s:compose('#{uri.to}')")\r
172 > +             else\r
173 > +                     vim_puts("Opening #{uri.to_s}.")\r
174 > +                     cmd = VIM::evaluate('g:notmuch_open_uri')\r
175 > +                     system(cmd, uri.to_s)\r
176 > +             end\r
177 > +     else\r
178 > +             vim_puts('URI not found.')\r
179 > +     end\r
180 > +EOF\r
181 > +endfunction\r
182 > +\r
183 >  function! s:show_open_msg()\r
184 >  ruby << EOF\r
185 >       m = get_message\r
186 > @@ -404,6 +445,10 @@ function! s:set_defaults()\r
187 >               endif\r
188 >       endif\r
189 >  \r
190 > +     if !exists('g:notmuch_open_uri')\r
191 > +             let g:notmuch_open_uri = s:notmuch_open_uri_default\r
192 > +     endif\r
193 > +\r
194 >       if !exists('g:notmuch_reader')\r
195 >               if exists('g:notmuch_rb_reader')\r
196 >                       let g:notmuch_reader = g:notmuch_rb_reader\r
197 > @@ -611,11 +656,11 @@ ruby << EOF\r
198 >               open_compose_helper(lines, cur)\r
199 >       end\r
200 >  \r
201 > -     def open_compose()\r
202 > +     def open_compose(to_email)\r
203 >               lines = []\r
204 >  \r
205 >               lines << "From: #{$email}"\r
206 > -             lines << "To: "\r
207 > +             lines << "To: #{to_email}"\r
208 >               cur = lines.count\r
209 >  \r
210 >               lines << "Cc: "\r
211 > -- \r
212 > 1.9.3\r
213 >\r
214 > _______________________________________________\r
215 > notmuch mailing list\r
216 > notmuch@notmuchmail.org\r
217 > http://notmuchmail.org/mailman/listinfo/notmuch\r