[PATCH 7/9] CLI: add properties to dump output
[notmuch-archives.git] / 1a / 9885c348d2a6ca7972b1901a0ccf581b2c2345
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 C3ACD431FC9\r
6         for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 09:11:52 -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\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 H7LNOwSoA-gx for <notmuch@notmuchmail.org>;\r
16         Fri, 24 Oct 2014 09:11:45 -0700 (PDT)\r
17 Received: from cmta10.telus.net (cmta10.telus.net [209.171.16.83])\r
18         by olra.theworths.org (Postfix) with ESMTP id C6392431FBD\r
19         for <notmuch@notmuchmail.org>; Fri, 24 Oct 2014 09:11:44 -0700 (PDT)\r
20 Received: from ovo.mains.priv ([207.102.88.62]) by cmta10.telus.net with TELUS\r
21         id 74Bj1p00j1LiWEf014BjuR; Fri, 24 Oct 2014 10:11:44 -0600\r
22 X-Authority-Analysis: v=2.0 cv=PP7RD4WC c=1 sm=2\r
23         a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=tsa3CZZnAAAA:8 a=pLijyACDi_T6FvlSOQQA:9\r
24         a=5qZx4DuJvQdhHk7O:21 a=DutyRs6kb4brqzYA: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 v3] VIM: Add URI handling\r
30 Date: Fri, 24 Oct 2014 09:11:34 -0700\r
31 Message-Id: <1414167094-31566-1-git-send-email-imain@stemwinder.org>\r
32 X-Mailer: git-send-email 1.9.3\r
33 In-Reply-To: <1414102794-12094-1-git-send-email-imain@stemwinder.org>\r
34 References: <1414102794-12094-1-git-send-email-imain@stemwinder.org>\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.13\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Fri, 24 Oct 2014 16:11:52 -0000\r
48 \r
49 This patch adds URI handling to the vim client.  You can now press\r
50 'enter' by default and the client will parse the current line and find\r
51 any 'Part's or URIs available for opening.  If there are more than one\r
52 it opens the one under the cursor or else it opens the only one\r
53 available.  It also supports mailto: URI's and will compose a new\r
54 message when activated.\r
55 \r
56 By default xdg-open is used for everything but mailto: which generally\r
57 does the right thing afaict.\r
58 \r
59 Note that this is now dependant on the attachment patch in order to\r
60 make the nice 'enter' behavior work for both.\r
61 \r
62     Ian\r
63 ---\r
64 \r
65 Fix commit message formatting.\r
66 \r
67  vim/notmuch.txt |  3 ++-\r
68  vim/notmuch.vim | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++------\r
69  2 files changed, 70 insertions(+), 9 deletions(-)\r
70 \r
71 diff --git a/vim/notmuch.txt b/vim/notmuch.txt\r
72 index 838a904..5d84fde 100644\r
73 --- a/vim/notmuch.txt\r
74 +++ b/vim/notmuch.txt\r
75 @@ -74,7 +74,8 @@ I     Mark as read (-unread)\r
76  t      Tag (prompted)\r
77  e       Extract attachment on the current 'Attachment' line or all\r
78         attachments if the cursor is elsewhere.\r
79 -v       View attachment on the current 'Attachment' line.\r
80 +<enter> View email part on the current 'Part' line, or open URI under cursor\r
81 +        or on line.\r
82  s      Search\r
83  p      Save patches\r
84  r      Reply\r
85 diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
86 index 1466e50..2f76f55 100644\r
87 --- a/vim/notmuch.vim\r
88 +++ b/vim/notmuch.vim\r
89 @@ -12,7 +12,7 @@ let g:notmuch_folders_maps = {\r
90         \ '<Enter>':    'folders_show_search()',\r
91         \ 's':          'folders_search_prompt()',\r
92         \ '=':          'folders_refresh()',\r
93 -       \ 'c':          'compose()',\r
94 +       \ 'c':          'compose("")',\r
95         \ }\r
96  \r
97  let g:notmuch_search_maps = {\r
98 @@ -25,7 +25,7 @@ let g:notmuch_search_maps = {\r
99         \ 's':          'search_search_prompt()',\r
100         \ '=':          'search_refresh()',\r
101         \ '?':          'search_info()',\r
102 -       \ 'c':          'compose()',\r
103 +       \ 'c':          'compose("")',\r
104         \ }\r
105  \r
106  let g:notmuch_show_maps = {\r
107 @@ -35,13 +35,13 @@ let g:notmuch_show_maps = {\r
108         \ 't':          'show_tag("")',\r
109         \ 'o':          'show_open_msg()',\r
110         \ 'e':          'show_extract_msg()',\r
111 -       \ '<Enter>':    'show_view_attachment()',\r
112 +       \ '<Enter>':    'show_view_magic()',\r
113         \ 's':          'show_save_msg()',\r
114         \ 'p':          'show_save_patches()',\r
115         \ 'r':          'show_reply()',\r
116         \ '?':          'show_info()',\r
117         \ '<Tab>':      'show_next_msg()',\r
118 -       \ 'c':          'compose()',\r
119 +       \ 'c':          'compose("")',\r
120         \ }\r
121  \r
122  let g:notmuch_compose_maps = {\r
123 @@ -63,6 +63,7 @@ let s:notmuch_view_attachment_default = 'xdg-open'\r
124  let s:notmuch_attachment_tmpdir_default = '~/.notmuch/tmp'\r
125  let s:notmuch_folders_count_threads_default = 0\r
126  let s:notmuch_compose_start_insert_default = 1\r
127 +let s:notmuch_open_uri_default = 'xdg-open'\r
128  \r
129  function! s:new_file_buffer(type, fname)\r
130         exec printf('edit %s', a:fname)\r
131 @@ -141,8 +142,8 @@ function! s:show_reply()\r
132         end\r
133  endfunction\r
134  \r
135 -function! s:compose()\r
136 -       ruby open_compose\r
137 +function! s:compose(to_email)\r
138 +       ruby open_compose(VIM::evaluate('a:to_email'))\r
139         let b:compose_done = 0\r
140         call s:set_map(g:notmuch_compose_maps)\r
141         autocmd BufDelete <buffer> call s:on_compose_delete()\r
142 @@ -155,6 +156,22 @@ function! s:show_info()\r
143         ruby vim_puts get_message.inspect\r
144  endfunction\r
145  \r
146 +function! s:show_view_magic()\r
147 +       let line = getline(".")\r
148 +\r
149 +ruby << EOF\r
150 +       line = VIM::evaluate('line')\r
151 +\r
152 +       # Easiest to check for 'Part' types first..\r
153 +       match = line.match(/^Part (\d*):/)\r
154 +       if match and match.length == 2\r
155 +               VIM::command('call s:show_view_attachment()')\r
156 +       else\r
157 +               VIM::command('call s:show_open_uri()')\r
158 +       end\r
159 +EOF\r
160 +endfunction\r
161 +\r
162  function! s:show_view_attachment()\r
163         let line = getline(".")\r
164  ruby << EOF\r
165 @@ -226,6 +243,45 @@ ruby << EOF\r
166  EOF\r
167  endfunction\r
168  \r
169 +function! s:show_open_uri()\r
170 +       let line = getline(".")\r
171 +       let pos = getpos(".")\r
172 +       let col = pos[2]\r
173 +ruby << EOF\r
174 +       m = get_message\r
175 +       line = VIM::evaluate('line')\r
176 +       col = VIM::evaluate('col') - 1\r
177 +       uris = URI.extract(line)\r
178 +       wanted_uri = nil\r
179 +       if uris.length == 1\r
180 +               wanted_uri = uris[0]\r
181 +       else\r
182 +               uris.each do |uri|\r
183 +                       # Check to see the URI is at the present cursor location\r
184 +                       idx = line.index(uri)\r
185 +                       if col >= idx and col <= idx + uri.length\r
186 +                               wanted_uri = uri\r
187 +                               break\r
188 +                       end\r
189 +               end\r
190 +       end\r
191 +\r
192 +       if wanted_uri\r
193 +               uri = URI.parse(wanted_uri)\r
194 +               if uri.class == URI::MailTo\r
195 +                       vim_puts("Composing new email to #{uri.to}.")\r
196 +                       VIM::command("call s:compose('#{uri.to}')")\r
197 +               else\r
198 +                       vim_puts("Opening #{uri.to_s}.")\r
199 +                       cmd = VIM::evaluate('g:notmuch_open_uri')\r
200 +                       system(cmd, uri.to_s)\r
201 +               end\r
202 +       else\r
203 +               vim_puts('URI not found.')\r
204 +       end\r
205 +EOF\r
206 +endfunction\r
207 +\r
208  function! s:show_open_msg()\r
209  ruby << EOF\r
210         m = get_message\r
211 @@ -481,6 +537,10 @@ function! s:set_defaults()\r
212                 endif\r
213         endif\r
214  \r
215 +       if !exists('g:notmuch_open_uri')\r
216 +               let g:notmuch_open_uri = s:notmuch_open_uri_default\r
217 +       endif\r
218 +\r
219         if !exists('g:notmuch_reader')\r
220                 if exists('g:notmuch_rb_reader')\r
221                         let g:notmuch_reader = g:notmuch_rb_reader\r
222 @@ -693,11 +753,11 @@ ruby << EOF\r
223                 open_compose_helper(lines, cur)\r
224         end\r
225  \r
226 -       def open_compose()\r
227 +       def open_compose(to_email)\r
228                 lines = []\r
229  \r
230                 lines << "From: #{$email}"\r
231 -               lines << "To: "\r
232 +               lines << "To: #{to_email}"\r
233                 cur = lines.count\r
234  \r
235                 lines << "Cc: "\r
236 -- \r
237 1.9.3\r
238 \r