1 " notmuch.vim plugin --- run notmuch within vim
3 " Copyright © Carl Worth
5 " This file is part of Notmuch.
7 " Notmuch is free software: you can redistribute it and/or modify it
8 " under the terms of the GNU General Public License as published by
9 " the Free Software Foundation, either version 3 of the License, or
10 " (at your option) any later version.
12 " Notmuch is distributed in the hope that it will be useful, but
13 " WITHOUT ANY WARRANTY; without even the implied warranty of
14 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 " General Public License for more details.
17 " You should have received a copy of the GNU General Public License
18 " along with Notmuch. If not, see <http://www.gnu.org/licenses/>.
20 " Authors: Bart Trojanowski <bart@jukie.net>
22 " --- configuration defaults {{{1
24 let s:notmuch_defaults = {
25 \ 'g:notmuch_cmd': 'notmuch' ,
27 \ 'g:notmuch_search_newest_first': 1 ,
28 \ 'g:notmuch_search_from_column_width': 20 ,
30 \ 'g:notmuch_show_fold_signatures': 1 ,
31 \ 'g:notmuch_show_fold_citations': 1 ,
32 \ 'g:notmuch_show_fold_bodies': 0 ,
33 \ 'g:notmuch_show_fold_headers': 1 ,
35 \ 'g:notmuch_show_message_begin_regexp': '^
\fmessage{' ,
36 \ 'g:notmuch_show_message_end_regexp': '^
\fmessage}' ,
37 \ 'g:notmuch_show_header_begin_regexp': '^
\fheader{' ,
38 \ 'g:notmuch_show_header_end_regexp': '^
\fheader}' ,
39 \ 'g:notmuch_show_body_begin_regexp': '^
\fbody{' ,
40 \ 'g:notmuch_show_body_end_regexp': '^
\fbody}' ,
41 \ 'g:notmuch_show_attachment_begin_regexp': '^
\fattachment{' ,
42 \ 'g:notmuch_show_attachment_end_regexp': '^
\fattachment}' ,
43 \ 'g:notmuch_show_part_begin_regexp': '^
\fpart{' ,
44 \ 'g:notmuch_show_part_end_regexp': '^
\fpart}' ,
45 \ 'g:notmuch_show_marker_regexp': '^
\f\\(message\\|header\\|body\\|attachment\\|part\\)[{}].*$',
47 \ 'g:notmuch_show_message_parse_regexp': '\(id:[^ ]*\) depth:\([0-9]*\) filename:\(.*\)$',
48 \ 'g:notmuch_show_tags_regexp': '(\([^)]*\))$' ,
50 \ 'g:notmuch_show_signature_regexp': '^\(-- \?\|_\+\)$' ,
51 \ 'g:notmuch_show_signature_lines_max': 12 ,
53 \ 'g:notmuch_show_citation_regexp': '^\s*>' ,
56 " defaults for g:notmuch_initial_search_words
57 " override with: let g:notmuch_initial_search_words = [ ... ]
58 let s:notmuch_initial_search_words_defaults = [
59 \ 'tag:inbox and tag:unread',
62 " defaults for g:notmuch_show_headers
63 " override with: let g:notmuch_show_headers = [ ... ]
64 let s:notmuch_show_headers_defaults = [
72 " defaults for g:notmuch_folders
73 " override with: let g:notmuch_folders = [ ... ]
74 let s:notmuch_folders_defaults = [
75 \ [ 'new', 'tag:inbox and tag:unread' ],
76 \ [ 'inbox', 'tag:inbox' ],
77 \ [ 'unread', 'tag:unread' ],
80 " --- keyboard mapping definitions {{{1
82 " --- --- bindings for folders mode {{{2
84 let g:notmuch_folders_maps = {
85 \ 's': ':call <SID>NM_search_prompt()<CR>',
86 \ 'q': ':call <SID>NM_kill_this_buffer()<CR>',
87 \ '=': ':call <SID>NM_folders_refresh_view()<CR>',
88 \ '<Enter>': ':call <SID>NM_folders_show_search()<CR>',
91 " --- --- bindings for search screen {{{2
92 let g:notmuch_search_maps = {
93 \ '<Enter>': ':call <SID>NM_search_show_thread()<CR>',
94 \ '<C-]>': ':call <SID>NM_search_expand(''<cword>'')<CR>',
95 \ 'a': ':call <SID>NM_search_archive_thread()<CR>',
96 \ 'f': ':call <SID>NM_search_filter()<CR>',
97 \ 'm': ':call <SID>NM_new_mail()<CR>',
98 \ 'o': ':call <SID>NM_search_toggle_order()<CR>',
99 \ 'r': ':call <SID>NM_search_reply_to_thread()<CR>',
100 \ 's': ':call <SID>NM_search_prompt()<CR>',
101 \ ',s': ':call <SID>NM_search_edit()<CR>',
102 \ 't': ':call <SID>NM_search_filter_by_tag()<CR>',
103 \ 'q': ':call <SID>NM_kill_this_buffer()<CR>',
104 \ '+': ':call <SID>NM_search_add_tags([])<CR>',
105 \ '-': ':call <SID>NM_search_remove_tags([])<CR>',
106 \ '=': ':call <SID>NM_search_refresh_view()<CR>',
107 \ '?': ':echo <SID>NM_search_thread_id()<CR>',
110 " --- --- bindings for show screen {{{2
111 let g:notmuch_show_maps = {
112 \ '<C-P>': ':call <SID>NM_show_previous(1)<CR>',
113 \ '<C-N>': ':call <SID>NM_show_next(1)<CR>',
114 \ '<C-]>': ':call <SID>NM_search_expand(''<cword>'')<CR>',
115 \ 'q': ':call <SID>NM_kill_this_buffer()<CR>',
117 \ 'b': ':call <SID>NM_show_fold_toggle(''b'', ''bdy'', !g:notmuch_show_fold_bodies)<CR>',
118 \ 'c': ':call <SID>NM_show_fold_toggle(''c'', ''cit'', !g:notmuch_show_fold_citations)<CR>',
119 \ 'h': ':call <SID>NM_show_fold_toggle(''h'', ''hdr'', !g:notmuch_show_fold_headers)<CR>',
120 \ 's': ':call <SID>NM_show_fold_toggle(''s'', ''sig'', !g:notmuch_show_fold_signatures)<CR>',
122 \ 'a': ':call <SID>NM_show_archive_thread()<CR>',
123 \ 'A': ':call <SID>NM_show_mark_read_then_archive_thread()<CR>',
124 \ 'N': ':call <SID>NM_show_mark_read_then_next_open_message()<CR>',
125 \ 'v': ':call <SID>NM_show_view_all_mime_parts()<CR>',
126 \ '+': ':call <SID>NM_show_add_tag()<CR>',
127 \ '-': ':call <SID>NM_show_remove_tag()<CR>',
128 \ '<Space>': ':call <SID>NM_show_advance_marking_read_and_archiving()<CR>',
129 \ '\|': ':call <SID>NM_show_pipe_message()<CR>',
131 \ 'r': ':call <SID>NM_show_reply()<CR>',
132 \ 'm': ':call <SID>NM_new_mail()<CR>',
133 \ '?': ':echo <SID>NM_show_thread_id() . '' '' . <SID>NM_show_message_id()<CR>',
137 " --- implement folders screen {{{1
139 function! s:NM_cmd_folders(words)
141 echoe 'Not exapecting any arguments for folders command.'
146 for entry in g:notmuch_folders
147 let [ name, search ] = entry
148 let data = s:NM_run(cmd + [search])
149 let cnt = matchlist(data, '\(\d\+\)')[1]
150 call add(disp, printf('%9d %-20s (%s)', cnt, name, search))
151 call add(searches, search)
154 call <SID>NM_newBuffer('folders', join(disp, "\n"))
155 let b:nm_searches = searches
156 let b:nm_timestamp = reltime()
158 call <SID>NM_cmd_folders_mksyntax()
159 call <SID>NM_set_map(g:notmuch_folders_maps)
164 function! s:NM_cmd_folders_mksyntax()
167 " --- --- folders screen action functions {{{2
169 function! s:NM_folders_refresh_view()
171 setlocal bufhidden=delete
172 call s:NM_cmd_folders([])
173 exec printf('norm %dG', lno)
176 function! s:NM_folders_show_search()
178 let search = b:nm_searches[line-1]
180 let prev_bufnr = bufnr('%')
181 setlocal bufhidden=hide
182 call <SID>NM_cmd_search([search])
183 setlocal bufhidden=delete
184 let b:nm_prev_bufnr = prev_bufnr
188 " --- implement search screen {{{1
190 function! s:NM_cmd_search(words)
192 if g:notmuch_search_newest_first
193 let cmd = cmd + ['--sort=newest-first']
195 let cmd = cmd + ['--sort=oldest-first']
197 let data = s:NM_run(cmd + a:words)
198 let lines = split(data, "\n")
199 let disp = copy(lines)
200 call map(disp, 's:NM_cmd_search_fmtline(v:val)')
202 call <SID>NM_newBuffer('search', join(disp, "\n"))
203 let b:nm_raw_lines = lines
204 let b:nm_search_words = a:words
206 call <SID>NM_cmd_search_mksyntax()
207 call <SID>NM_set_map(g:notmuch_search_maps)
211 function! s:NM_cmd_search_fmtline(line)
212 let m = matchlist(a:line, '^\(thread:\S\+\)\s\([^]]\+\]\) \([^;]\+\); \(.*\) (\([^(]*\))$')
214 return 'ERROR PARSING: ' . a:line
216 let max = g:notmuch_search_from_column_width
218 if strlen(from) >= max
219 let from = substitute(m[3][0:max-4], '[^A-Za-z1-9_]*$', '', '') . '...'
221 return printf('%s %-20s | %s (%s)', m[2], from, m[4], m[5])
223 function! s:NM_cmd_search_mksyntax()
224 syntax clear nmSearchFrom
225 exec printf('syntax match nmSearchFrom /\(\] \)\@<=.\{%d\}/ oneline contained', g:notmuch_search_from_column_width)
228 " --- --- search screen action functions {{{2
230 function! s:NM_search_show_thread()
231 let id = <SID>NM_search_thread_id()
233 call <SID>NM_cmd_show([id])
237 function! s:NM_search_prompt()
238 " TODO: input() can support completion
239 let text = input('NotMuch Search: ')
241 let tags = split(text)
243 let tags = s:notmuch_initial_search_words_defaults
245 let prev_bufnr = bufnr('%')
246 if b:nm_type == 'search'
247 " TODO: we intend to replace the current buffer,
248 " ... maybe we could just clear it
249 let prev_bufnr = b:nm_prev_bufnr
250 setlocal bufhidden=delete
252 setlocal bufhidden=hide
254 call <SID>NM_cmd_search(tags)
255 setlocal bufhidden=delete
256 let b:nm_prev_bufnr = prev_bufnr
259 function! s:NM_search_edit()
260 " TODO: input() can support completion
261 let text = input('NotMuch Search: ', join(b:nm_search_words, ' '))
263 call <SID>NM_cmd_search(split(text))
267 function! s:NM_search_archive_thread()
268 call <SID>NM_add_remove_tags_on_screen('-', ['inbox'])
269 call <SID>NM_add_remove_tags('-', ['inbox'])
273 function! s:NM_search_filter()
274 call <SID>NM_search_filter_helper('Filter: ', '', '')
277 function! s:NM_search_filter_by_tag()
278 call <SID>NM_search_filter_helper('Filter Tag(s): ', 'tag:', 'and')
281 function! s:NM_search_filter_helper(prompt, prefix, joiner)
282 " TODO: input() can support completion
283 let text = input(a:prompt)
288 let tags = split(text)
290 call map(tags, 'a:prefix . v:val')
293 let idx = len(tags) - 1
295 call insert(tags, a:joiner, idx)
299 let tags = b:nm_search_words + ['and', '''('] + tags + [')''']
301 let prev_bufnr = bufnr('%')
302 setlocal bufhidden=hide
303 call <SID>NM_cmd_search(tags)
304 setlocal bufhidden=delete
305 let b:nm_prev_bufnr = prev_bufnr
308 function! s:NM_search_toggle_order()
309 let g:notmuch_search_newest_first = !g:notmuch_search_newest_first
310 " FIXME: maybe this would be better done w/o reading re-reading the lines
311 " reversing the b:nm_raw_lines and the buffer lines would be better
312 call <SID>NM_search_refresh_view()
315 function! s:NM_search_reply_to_thread()
316 echo 'not implemented'
319 function! s:NM_search_add_tags(tags)
320 call <SID>NM_search_add_remove_tags('Add Tag(s): ', '+', a:tags)
323 function! s:NM_search_remove_tags(tags)
324 call <SID>NM_search_add_remove_tags('Remove Tag(s): ', '-', a:tags)
327 function! s:NM_search_refresh_view()
329 let prev_bufnr = b:nm_prev_bufnr
330 setlocal bufhidden=delete
331 call <SID>NM_cmd_search(b:nm_search_words)
332 let b:nm_prev_bufnr = prev_bufnr
333 " FIXME: should find the line of the thread we were on if possible
334 exec printf('norm %dG', lno)
337 " --- --- search screen helper functions {{{2
339 function! s:NM_search_thread_id()
340 if !exists('b:nm_raw_lines')
341 echoe 'no b:nm_raw_lines'
345 let info = b:nm_raw_lines[line-1]
346 let what = split(info, '\s\+')[0]
351 function! s:NM_search_add_remove_tags(prompt, prefix, intags)
352 if type(a:intags) != type([]) || len(a:intags) == 0
353 " TODO: input() can support completion
354 let text = input(a:prompt)
358 let tags = split(text, ' ')
362 call <SID>NM_add_remove_tags(a:prefix, tags)
363 call <SID>NM_add_remove_tags_on_screen(a:prefix, tags)
366 " --- implement show screen {{{1
368 function! s:NM_cmd_show(words)
369 let prev_bufnr = bufnr('%')
370 let data = s:NM_run(['show'] + a:words)
371 let lines = split(data, "\n")
373 let info = s:NM_cmd_show_parse(lines)
375 setlocal bufhidden=hide
376 call <SID>NM_newBuffer('show', join(info['disp'], "\n"))
377 setlocal bufhidden=delete
378 let b:nm_words = a:words
379 let b:nm_raw_info = info
380 let b:nm_prev_bufnr = prev_bufnr
382 call <SID>NM_cmd_show_mkfolds()
383 call <SID>NM_cmd_show_mksyntax()
384 call <SID>NM_set_map(g:notmuch_show_maps)
385 setlocal foldtext=NM_cmd_show_foldtext()
387 setlocal foldcolumn=6
391 function! s:NM_show_previous(can_change_thread)
392 let info = b:nm_raw_info
394 for msg in reverse(copy(info['msgs']))
395 if lnum <= msg['start']
399 exec printf('norm %dG', msg['start'])
400 " TODO: try to fit the message on screen
404 if !a:can_change_thread
407 call <SID>NM_kill_this_buffer()
408 if line('.') != line('0')
410 call <SID>NM_search_show_thread()
412 call <SID>NM_show_previous(0)
414 echo 'No more messages.'
418 function! s:NM_show_next(can_change_thread)
419 let info = b:nm_raw_info
421 for msg in info['msgs']
422 if lnum >= msg['start']
426 exec printf('norm %dG', msg['start'])
427 " TODO: try to fit the message on screen
431 if !a:can_change_thread
434 call <SID>NM_kill_this_buffer()
435 if line('.') != line('$')
437 call <SID>NM_search_show_thread()
439 echo 'No more messages.'
443 function! s:NM_show_archive_thread()
444 echo 'not implemented'
447 function! s:NM_show_mark_read_then_archive_thread()
448 echo 'not implemented'
451 function! s:NM_show_next_message()
452 echo 'not implemented'
455 function! s:NM_show_mark_read_then_next_open_message()
456 echo 'not implemented'
459 function! s:NM_show_previous_message()
460 echo 'not implemented'
463 function! s:NM_show_reply()
464 echo 'not implemented'
467 function! s:NM_show_view_all_mime_parts()
468 echo 'not implemented'
471 function! s:NM_show_view_raw_message()
472 echo 'not implemented'
475 function! s:NM_show_add_tag()
476 echo 'not implemented'
479 function! s:NM_show_remove_tag()
480 echo 'not implemented'
483 function! s:NM_show_advance_marking_read_and_archiving()
484 echo 'not implemented'
487 function! s:NM_show_pipe_message()
488 echo 'not implemented'
491 " --- --- show screen helper functions {{{2
493 function! s:NM_show_thread_id()
494 if !exists('b:nm_words')
495 echoe 'no b:nm_words'
501 function! s:NM_show_message_id()
502 if !exists('b:nm_raw_info')
503 echoe 'no b:nm_raw_info'
506 let info = b:nm_raw_info
508 for msg in info['msgs']
509 if lnum >= msg['start']
518 function! s:NM_show_fold_toggle(key, type, fold)
519 let info = b:nm_raw_info
524 for fld in info['folds']
526 exec printf('%dfold%s', fld[1], act)
529 exec printf('nnoremap <buffer> %s :call <SID>NM_show_fold_toggle(''%s'', ''%s'', %d)<CR>', a:key, a:key, a:type, !a:fold)
533 " s:NM_cmd_show_parse returns the following dictionary:
534 " 'disp': lines to display
535 " 'msgs': message info dicts { start, end, id, depth, filename, descr, header }
536 " 'folds': fold info arrays [ type, start, end ]
537 " 'foldtext': fold text indexed by start line
538 function! s:NM_cmd_show_parse(inlines)
539 let info = { 'disp': [],
558 for line in a:inlines
559 let inlnum = inlnum + 1
565 if match(line, g:notmuch_show_part_end_regexp) != -1
566 let part_end = len(info['disp'])
568 call add(info['disp'], line)
571 if in_part == 'text/plain'
572 if !part_end && mode_type == ''
573 if match(line, g:notmuch_show_signature_regexp) != -1
574 let mode_type = 'sig'
575 let mode_start = len(info['disp'])
576 elseif match(line, g:notmuch_show_citation_regexp) != -1
577 let mode_type = 'cit'
578 let mode_start = len(info['disp'])
580 elseif mode_type == 'cit'
581 if part_end || match(line, g:notmuch_show_citation_regexp) == -1
582 let outlnum = len(info['disp'])
583 let foldinfo = [ mode_type, mode_start, outlnum-1,
584 \ printf('[ %d-line citation. Press "c" to show. ]', outlnum - mode_start) ]
587 elseif mode_type == 'sig'
588 let outlnum = len(info['disp'])
589 if (outlnum - mode_start) > g:notmuch_show_signature_lines_max
592 let foldinfo = [ mode_type, mode_start, outlnum-1,
593 \ printf('[ %d-line signature. Press "s" to show. ]', outlnum - mode_start) ]
600 " FIXME: this is a hack for handling two folds being added for one line
601 " we should handle addinga fold in a function
602 if len(foldinfo) && foldinfo[1] < foldinfo[2]
603 call add(info['folds'], foldinfo[0:2])
604 let info['foldtext'][foldinfo[1]] = foldinfo[3]
607 let foldinfo = [ 'text', part_start, part_end,
608 \ printf('[ %d-line %s. Press "p" to show. ]', part_end - part_start, in_part) ]
610 call add(info['disp'], '')
614 if !has_key(msg,'body_start')
615 let msg['body_start'] = len(info['disp']) + 1
617 if match(line, g:notmuch_show_body_end_regexp) != -1
618 let body_end = len(info['disp'])
619 let foldinfo = [ 'bdy', body_start, body_end,
620 \ printf('[ BODY %d - %d lines ]', len(info['msgs']), body_end - body_start) ]
624 elseif match(line, g:notmuch_show_part_begin_regexp) != -1
625 let m = matchlist(line, 'ID: \(\d\+\), Content-type: \(\S\+\)')
626 let in_part = 'unknown'
630 call add(info['disp'],
631 \ printf('--- %s ---', in_part))
632 let part_start = len(info['disp']) + 1
637 let msg['descr'] = line
638 call add(info['disp'], line)
640 let msg['hdr_start'] = len(info['disp']) + 1
643 if match(line, g:notmuch_show_header_end_regexp) != -1
644 let hdr_start = msg['hdr_start']+1
645 let hdr_end = len(info['disp'])
646 let foldinfo = [ 'hdr', hdr_start, hdr_end,
647 \ printf('[ %d-line headers. Press "h" to show. ]', hdr_end + 1 - hdr_start) ]
648 let msg['header'] = hdr
652 let m = matchlist(line, '^\(\w\+\):\s*\(.*\)$')
655 if match(g:notmuch_show_headers, m[1]) != -1
656 call add(info['disp'], line)
663 if match(line, g:notmuch_show_message_end_regexp) != -1
664 let msg['end'] = len(info['disp'])
665 call add(info['disp'], '')
667 let foldinfo = [ 'msg', msg['start'], msg['end'],
668 \ printf('[ MSG %d - %s ]', len(info['msgs']), msg['descr']) ]
670 call add(info['msgs'], msg)
677 elseif match(line, g:notmuch_show_header_begin_regexp) != -1
681 elseif match(line, g:notmuch_show_body_begin_regexp) != -1
682 let body_start = len(info['disp']) + 1
688 if match(line, g:notmuch_show_message_begin_regexp) != -1
689 let msg['start'] = len(info['disp']) + 1
691 let m = matchlist(line, g:notmuch_show_message_parse_regexp)
694 let msg['depth'] = m[2]
695 let msg['filename'] = m[3]
702 if len(foldinfo) && foldinfo[1] < foldinfo[2]
703 call add(info['folds'], foldinfo[0:2])
704 let info['foldtext'][foldinfo[1]] = foldinfo[3]
710 function! s:NM_cmd_show_mkfolds()
711 let info = b:nm_raw_info
713 for afold in info['folds']
714 exec printf('%d,%dfold', afold[1], afold[2])
715 if (afold[0] == 'sig' && g:notmuch_show_fold_signatures)
716 \ || (afold[0] == 'cit' && g:notmuch_show_fold_citations)
717 \ || (afold[0] == 'bdy' && g:notmuch_show_fold_bodies)
718 \ || (afold[0] == 'hdr' && g:notmuch_show_fold_headers)
719 exec printf('%dfoldclose', afold[1])
721 exec printf('%dfoldopen', afold[1])
726 function! s:NM_cmd_show_mksyntax()
727 let info = b:nm_raw_info
729 for msg in info['msgs']
731 let start = msg['start']
732 let hdr_start = msg['hdr_start']
733 let body_start = msg['body_start']
735 exec printf('syntax region nmShowMsg%dDesc start=''\%%%dl'' end=''\%%%dl'' contains=@nmShowMsgDesc', cnt, start, start+1)
736 exec printf('syntax region nmShowMsg%dHead start=''\%%%dl'' end=''\%%%dl'' contains=@nmShowMsgHead', cnt, hdr_start, body_start)
737 exec printf('syntax region nmShowMsg%dBody start=''\%%%dl'' end=''\%%%dl'' contains=@nmShowMsgBody', cnt, body_start, end)
741 function! NM_cmd_show_foldtext()
742 let foldtext = b:nm_raw_info['foldtext']
743 return foldtext[v:foldstart]
747 " --- notmuch helper functions {{{1
749 function! s:NM_newBuffer(type, content)
751 setlocal buftype=nofile readonly modifiable
754 setlocal nomodifiable
755 execute printf('set filetype=notmuch-%s', a:type)
756 execute printf('set syntax=notmuch-%s', a:type)
757 let b:nm_type = a:type
760 function! s:NM_run(args)
761 let cmd = g:notmuch_cmd . ' ' . join(a:args) . '< /dev/null'
763 let start = reltime()
764 let out = system(cmd)
765 let err = v:shell_error
766 let delta = reltime(start)
768 echo printf('[%s] {%s} %s', reltimestr(delta), string(err), string(cmd))
772 echo substitute(out, '\n*$', '', '')
780 " --- external mail handling helpers {{{1
782 function! s:NM_new_mail()
783 echo 'not implemented'
786 " --- other helpers {{{1
788 function! s:NM_kill_this_buffer()
789 if exists('b:nm_prev_bufnr')
790 setlocal bufhidden=delete
791 exec printf(":buffer %d", b:nm_prev_bufnr)
793 echo "This is the last buffer; use :q<CR> to quit."
797 function! s:NM_search_expand(arg)
798 let word = expand(a:arg)
799 let prev_bufnr = bufnr('%')
800 setlocal bufhidden=hide
801 call <SID>NM_cmd_search([word])
802 setlocal bufhidden=delete
803 let b:nm_prev_bufnr = prev_bufnr
806 function! s:NM_add_remove_tags(prefix, tags)
807 let id = <SID>NM_search_thread_id()
809 echoe 'Eeek! I couldn''t find the thead id!'
811 call map(a:tags, 'a:prefix . v:val')
812 " TODO: handle errors
813 call <SID>NM_run(['tag'] + a:tags + ['--', id])
816 function! s:NM_add_remove_tags_on_screen(prefix, tags)
820 for tagname in a:tags
821 exec printf('silent %ss/(\([^)]*\)\<%s\>\([^)]*\))$/(\1\2)/', online, tagname)
824 for tagname in a:tags
825 exec printf('silent %ss/(\([^)]*\)\([^)]*\))$/(\1 %s)/', online, tagname)
828 setlocal nomodifiable
831 " --- process and set the defaults {{{1
833 function! NM_set_defaults(force)
834 for [key, dflt] in items(s:notmuch_defaults)
836 if !a:force && exists(key) && type(dflt) == type(eval(key))
838 elseif type(dflt) == type(0)
839 let cmd = printf('let %s = %d', key, dflt)
840 elseif type(dflt) == type('')
841 let cmd = printf('let %s = ''%s''', key, dflt)
842 " FIXME: not sure why this didn't work when dflt is an array
843 "elseif type(dflt) == type([])
844 " let cmd = printf('let %s = %s', key, string(dflt))
846 echoe printf('E: Unknown type in NM_set_defaults(%d) using [%s,%s]',
847 \ a:force, key, string(dflt))
853 call NM_set_defaults(0)
855 " for some reason NM_set_defaults() didn't work for arrays...
856 if !exists('g:notmuch_show_headers')
857 let g:notmuch_show_headers = s:notmuch_show_headers_defaults
859 if !exists('g:notmuch_initial_search_words')
860 let g:notmuch_initial_search_words = s:notmuch_initial_search_words_defaults
862 if !exists('g:notmuch_folders')
863 let g:notmuch_folders = s:notmuch_folders_defaults
867 " --- assign keymaps {{{1
869 function! s:NM_set_map(maps)
871 for [key, code] in items(a:maps)
872 exec printf('nnoremap <buffer> %s %s', key, code)
874 " --- this is a hack for development :)
875 nnoremap ,nmr :source ~/.vim/plugin/notmuch.vim<CR>:call NotMuch('')<CR>
878 " --- command handler {{{1
880 function! NotMuch(args)
886 let words = split(args)
887 if words[0] == 'folders'
888 let words = words[1:]
889 call <SID>NM_cmd_folders(words)
890 elseif words[0] == 'search'
892 let words = words[1:]
893 elseif exists('b:nm_search_words')
894 let words = b:nm_search_words
896 let words = g:notmuch_initial_search_words
898 call <SID>NM_cmd_search(words)
900 elseif words[0] == 'show'
901 echoe 'show is not yet implemented.'
904 function! CompleteNotMuch(arg_lead, cmd_line, cursor_pos)
911 command! -nargs=* -complete=customlist,CompleteNotMuch NotMuch call NotMuch(<q-args>)
912 cabbrev notmuch <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'NotMuch' : 'notmuch')<CR>
914 " vim: set ft=vim ts=8 sw=8 et foldmethod=marker :