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 if b:nm_type == 'search'
246 " TODO: we intend to replace the current buffer,
247 " ... maybe we could just clear it
248 let prev_bufnr = b:nm_prev_bufnr
249 setlocal bufhidden=delete
251 let prev_bufnr = bufnr('%')
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:')
281 function! s:NM_search_filter_helper(prompt, prefix)
282 " TODO: input() can support completion
283 let text = input(a:prompt)
288 let tags = split(text)
289 map(tags, 'and a:prefix . v:val')
290 let tags = b:nm_search_words + tags
293 let prev_bufnr = bufnr('%')
294 setlocal bufhidden=hide
295 call <SID>NM_cmd_search(tags)
296 setlocal bufhidden=delete
297 let b:nm_prev_bufnr = prev_bufnr
300 function! s:NM_search_toggle_order()
301 let g:notmuch_search_newest_first = !g:notmuch_search_newest_first
302 " FIXME: maybe this would be better done w/o reading re-reading the lines
303 " reversing the b:nm_raw_lines and the buffer lines would be better
304 call <SID>NM_search_refresh_view()
307 function! s:NM_search_reply_to_thread()
308 echo 'not implemented'
311 function! s:NM_search_add_tags(tags)
312 call <SID>NM_search_add_remove_tags('Add Tag(s): ', '+', a:tags)
315 function! s:NM_search_remove_tags(tags)
316 call <SID>NM_search_add_remove_tags('Remove Tag(s): ', '-', a:tags)
319 function! s:NM_search_refresh_view()
321 setlocal bufhidden=delete
322 call <SID>NM_cmd_search(b:nm_search_words)
323 " FIXME: should find the line of the thread we were on if possible
324 exec printf('norm %dG', lno)
327 " --- --- search screen helper functions {{{2
329 function! s:NM_search_thread_id()
330 if !exists('b:nm_raw_lines')
331 echoe 'no b:nm_raw_lines'
335 let info = b:nm_raw_lines[line-1]
336 let what = split(info, '\s\+')[0]
341 function! s:NM_search_add_remove_tags(prompt, prefix, intags)
342 if type(a:intags) != type([]) || len(a:intags) == 0
343 " TODO: input() can support completion
344 let text = input(a:prompt)
348 let tags = split(text, ' ')
352 call <SID>NM_add_remove_tags(a:prefix, tags)
353 call <SID>NM_add_remove_tags_on_screen(a:prefix, tags)
356 " --- implement show screen {{{1
358 function! s:NM_cmd_show(words)
359 let prev_bufnr = bufnr('%')
360 let data = s:NM_run(['show'] + a:words)
361 let lines = split(data, "\n")
363 let info = s:NM_cmd_show_parse(lines)
365 setlocal bufhidden=hide
366 call <SID>NM_newBuffer('show', join(info['disp'], "\n"))
367 setlocal bufhidden=delete
368 let b:nm_words = a:words
369 let b:nm_raw_info = info
370 let b:nm_prev_bufnr = prev_bufnr
372 call <SID>NM_cmd_show_mkfolds()
373 call <SID>NM_cmd_show_mksyntax()
374 call <SID>NM_set_map(g:notmuch_show_maps)
375 setlocal foldtext=NM_cmd_show_foldtext()
377 setlocal foldcolumn=6
381 function! s:NM_show_previous(can_change_thread)
382 let info = b:nm_raw_info
384 for msg in reverse(copy(info['msgs']))
385 if lnum <= msg['start']
389 exec printf('norm %dG', msg['start'])
390 " TODO: try to fit the message on screen
394 if !a:can_change_thread
397 call <SID>NM_kill_this_buffer()
398 if line('.') != line('0')
400 call <SID>NM_search_show_thread()
402 call <SID>NM_show_previous(0)
404 echo 'No more messages.'
408 function! s:NM_show_next(can_change_thread)
409 let info = b:nm_raw_info
411 for msg in info['msgs']
412 if lnum >= msg['start']
416 exec printf('norm %dG', msg['start'])
417 " TODO: try to fit the message on screen
421 if !a:can_change_thread
424 call <SID>NM_kill_this_buffer()
425 if line('.') != line('$')
427 call <SID>NM_search_show_thread()
429 echo 'No more messages.'
433 function! s:NM_show_archive_thread()
434 echo 'not implemented'
437 function! s:NM_show_mark_read_then_archive_thread()
438 echo 'not implemented'
441 function! s:NM_show_next_message()
442 echo 'not implemented'
445 function! s:NM_show_mark_read_then_next_open_message()
446 echo 'not implemented'
449 function! s:NM_show_previous_message()
450 echo 'not implemented'
453 function! s:NM_show_reply()
454 echo 'not implemented'
457 function! s:NM_show_view_all_mime_parts()
458 echo 'not implemented'
461 function! s:NM_show_view_raw_message()
462 echo 'not implemented'
465 function! s:NM_show_add_tag()
466 echo 'not implemented'
469 function! s:NM_show_remove_tag()
470 echo 'not implemented'
473 function! s:NM_show_advance_marking_read_and_archiving()
474 echo 'not implemented'
477 function! s:NM_show_pipe_message()
478 echo 'not implemented'
481 " --- --- show screen helper functions {{{2
483 function! s:NM_show_thread_id()
484 if !exists('b:nm_words')
485 echoe 'no b:nm_words'
491 function! s:NM_show_message_id()
492 if !exists('b:nm_raw_info')
493 echoe 'no b:nm_raw_info'
496 let info = b:nm_raw_info
498 for msg in info['msgs']
499 if lnum >= msg['start']
508 function! s:NM_show_fold_toggle(key, type, fold)
509 let info = b:nm_raw_info
514 for fld in info['folds']
516 exec printf('%dfold%s', fld[1], act)
519 exec printf('nnoremap <buffer> %s :call <SID>NM_show_fold_toggle(''%s'', ''%s'', %d)<CR>', a:key, a:key, a:type, !a:fold)
523 " s:NM_cmd_show_parse returns the following dictionary:
524 " 'disp': lines to display
525 " 'msgs': message info dicts { start, end, id, depth, filename, descr, header }
526 " 'folds': fold info arrays [ type, start, end ]
527 " 'foldtext': fold text indexed by start line
528 function! s:NM_cmd_show_parse(inlines)
529 let info = { 'disp': [],
548 for line in a:inlines
549 let inlnum = inlnum + 1
555 if match(line, g:notmuch_show_part_end_regexp) != -1
556 let part_end = len(info['disp'])
558 call add(info['disp'], line)
561 if in_part == 'text/plain'
562 if !part_end && mode_type == ''
563 if match(line, g:notmuch_show_signature_regexp) != -1
564 let mode_type = 'sig'
565 let mode_start = len(info['disp'])
566 elseif match(line, g:notmuch_show_citation_regexp) != -1
567 let mode_type = 'cit'
568 let mode_start = len(info['disp'])
570 elseif mode_type == 'cit'
571 if part_end || match(line, g:notmuch_show_citation_regexp) == -1
572 let outlnum = len(info['disp'])
573 let foldinfo = [ mode_type, mode_start, outlnum-1,
574 \ printf('[ %d-line citation. Press "c" to show. ]', outlnum - mode_start) ]
577 elseif mode_type == 'sig'
578 let outlnum = len(info['disp'])
579 if (outlnum - mode_start) > g:notmuch_show_signature_lines_max
582 let foldinfo = [ mode_type, mode_start, outlnum-1,
583 \ printf('[ %d-line signature. Press "s" to show. ]', outlnum - mode_start) ]
590 " FIXME: this is a hack for handling two folds being added for one line
591 " we should handle addinga fold in a function
592 if len(foldinfo) && foldinfo[1] < foldinfo[2]
593 call add(info['folds'], foldinfo[0:2])
594 let info['foldtext'][foldinfo[1]] = foldinfo[3]
597 let foldinfo = [ 'text', part_start, part_end,
598 \ printf('[ %d-line %s. Press "p" to show. ]', part_end - part_start, in_part) ]
600 call add(info['disp'], '')
604 if !has_key(msg,'body_start')
605 let msg['body_start'] = len(info['disp']) + 1
607 if match(line, g:notmuch_show_body_end_regexp) != -1
608 let body_end = len(info['disp'])
609 let foldinfo = [ 'bdy', body_start, body_end,
610 \ printf('[ BODY %d - %d lines ]', len(info['msgs']), body_end - body_start) ]
614 elseif match(line, g:notmuch_show_part_begin_regexp) != -1
615 let m = matchlist(line, 'ID: \(\d\+\), Content-type: \(\S\+\)')
616 let in_part = 'unknown'
620 call add(info['disp'],
621 \ printf('--- %s ---', in_part))
622 let part_start = len(info['disp']) + 1
627 let msg['descr'] = line
628 call add(info['disp'], line)
630 let msg['hdr_start'] = len(info['disp']) + 1
633 if match(line, g:notmuch_show_header_end_regexp) != -1
634 let hdr_start = msg['hdr_start']+1
635 let hdr_end = len(info['disp'])
636 let foldinfo = [ 'hdr', hdr_start, hdr_end,
637 \ printf('[ %d-line headers. Press "h" to show. ]', hdr_end + 1 - hdr_start) ]
638 let msg['header'] = hdr
642 let m = matchlist(line, '^\(\w\+\):\s*\(.*\)$')
645 if match(g:notmuch_show_headers, m[1]) != -1
646 call add(info['disp'], line)
653 if match(line, g:notmuch_show_message_end_regexp) != -1
654 let msg['end'] = len(info['disp'])
655 call add(info['disp'], '')
657 let foldinfo = [ 'msg', msg['start'], msg['end'],
658 \ printf('[ MSG %d - %s ]', len(info['msgs']), msg['descr']) ]
660 call add(info['msgs'], msg)
667 elseif match(line, g:notmuch_show_header_begin_regexp) != -1
671 elseif match(line, g:notmuch_show_body_begin_regexp) != -1
672 let body_start = len(info['disp']) + 1
678 if match(line, g:notmuch_show_message_begin_regexp) != -1
679 let msg['start'] = len(info['disp']) + 1
681 let m = matchlist(line, g:notmuch_show_message_parse_regexp)
684 let msg['depth'] = m[2]
685 let msg['filename'] = m[3]
692 if len(foldinfo) && foldinfo[1] < foldinfo[2]
693 call add(info['folds'], foldinfo[0:2])
694 let info['foldtext'][foldinfo[1]] = foldinfo[3]
700 function! s:NM_cmd_show_mkfolds()
701 let info = b:nm_raw_info
703 for afold in info['folds']
704 exec printf('%d,%dfold', afold[1], afold[2])
705 if (afold[0] == 'sig' && g:notmuch_show_fold_signatures)
706 \ || (afold[0] == 'cit' && g:notmuch_show_fold_citations)
707 \ || (afold[0] == 'bdy' && g:notmuch_show_fold_bodies)
708 \ || (afold[0] == 'hdr' && g:notmuch_show_fold_headers)
709 exec printf('%dfoldclose', afold[1])
711 exec printf('%dfoldopen', afold[1])
716 function! s:NM_cmd_show_mksyntax()
717 let info = b:nm_raw_info
719 for msg in info['msgs']
721 let start = msg['start']
722 let hdr_start = msg['hdr_start']
723 let body_start = msg['body_start']
725 exec printf('syntax region nmShowMsg%dDesc start=''\%%%dl'' end=''\%%%dl'' contains=@nmShowMsgDesc', cnt, start, start+1)
726 exec printf('syntax region nmShowMsg%dHead start=''\%%%dl'' end=''\%%%dl'' contains=@nmShowMsgHead', cnt, hdr_start, body_start)
727 exec printf('syntax region nmShowMsg%dBody start=''\%%%dl'' end=''\%%%dl'' contains=@nmShowMsgBody', cnt, body_start, end)
731 function! NM_cmd_show_foldtext()
732 let foldtext = b:nm_raw_info['foldtext']
733 return foldtext[v:foldstart]
737 " --- notmuch helper functions {{{1
739 function! s:NM_newBuffer(type, content)
741 setlocal buftype=nofile readonly modifiable
744 setlocal nomodifiable
745 execute printf('set filetype=notmuch-%s', a:type)
746 execute printf('set syntax=notmuch-%s', a:type)
747 let b:nm_type = a:type
750 function! s:NM_run(args)
751 let cmd = g:notmuch_cmd . ' ' . join(a:args) . '< /dev/null'
753 let start = reltime()
754 let out = system(cmd)
755 let err = v:shell_error
756 let delta = reltime(start)
758 echo printf('[%s] {%s} %s', reltimestr(delta), string(err), string(cmd))
762 echo substitute(out, '\n*$', '', '')
770 " --- external mail handling helpers {{{1
772 function! s:NM_new_mail()
773 echo 'not implemented'
776 " --- other helpers {{{1
778 function! s:NM_kill_this_buffer()
779 if exists('b:nm_prev_bufnr')
780 setlocal bufhidden=delete
781 exec printf(":buffer %d", b:nm_prev_bufnr)
783 echo "Nothing to kill."
787 function! s:NM_search_expand(arg)
788 let word = expand(a:arg)
789 let prev_bufnr = bufnr('%')
790 setlocal bufhidden=hide
791 call <SID>NM_cmd_search([word])
792 setlocal bufhidden=delete
793 let b:nm_prev_bufnr = prev_bufnr
796 function! s:NM_add_remove_tags(prefix, tags)
797 let id = <SID>NM_search_thread_id()
799 echoe 'Eeek! I couldn''t find the thead id!'
801 call map(a:tags, 'a:prefix . v:val')
802 " TODO: handle errors
803 call <SID>NM_run(['tag'] + a:tags + ['--', id])
806 function! s:NM_add_remove_tags_on_screen(prefix, tags)
810 for tagname in a:tags
811 exec printf('silent %ss/(\([^)]*\)\<%s\>\([^)]*\))$/(\1\2)/', online, tagname)
814 for tagname in a:tags
815 exec printf('silent %ss/(\([^)]*\)\([^)]*\))$/(\1 %s)/', online, tagname)
818 setlocal nomodifiable
821 " --- process and set the defaults {{{1
823 function! NM_set_defaults(force)
824 for [key, dflt] in items(s:notmuch_defaults)
826 if !a:force && exists(key) && type(dflt) == type(eval(key))
828 elseif type(dflt) == type(0)
829 let cmd = printf('let %s = %d', key, dflt)
830 elseif type(dflt) == type('')
831 let cmd = printf('let %s = ''%s''', key, dflt)
832 " FIXME: not sure why this didn't work when dflt is an array
833 "elseif type(dflt) == type([])
834 " let cmd = printf('let %s = %s', key, string(dflt))
836 echoe printf('E: Unknown type in NM_set_defaults(%d) using [%s,%s]',
837 \ a:force, key, string(dflt))
843 call NM_set_defaults(0)
845 " for some reason NM_set_defaults() didn't work for arrays...
846 if !exists('g:notmuch_show_headers')
847 let g:notmuch_show_headers = s:notmuch_show_headers_defaults
849 if !exists('g:notmuch_initial_search_words')
850 let g:notmuch_initial_search_words = s:notmuch_initial_search_words_defaults
852 if !exists('g:notmuch_folders')
853 let g:notmuch_folders = s:notmuch_folders_defaults
857 " --- assign keymaps {{{1
859 function! s:NM_set_map(maps)
861 for [key, code] in items(a:maps)
862 exec printf('nnoremap <buffer> %s %s', key, code)
864 " --- this is a hack for development :)
865 nnoremap ,nmr :source ~/.vim/plugin/notmuch.vim<CR>:call NotMuch('')<CR>
868 " --- command handler {{{1
870 function! NotMuch(args)
876 let words = split(args)
877 if words[0] == 'folders'
878 let words = words[1:]
879 call <SID>NM_cmd_folders(words)
880 elseif words[0] == 'search'
882 let words = words[1:]
883 elseif exists('b:nm_search_words')
884 let words = b:nm_search_words
886 let words = g:notmuch_initial_search_words
888 call <SID>NM_cmd_search(words)
890 elseif words[0] == 'show'
891 echoe 'show is not yet implemented.'
894 function! CompleteNotMuch(arg_lead, cmd_line, cursor_pos)
901 command! -nargs=* -complete=customlist,CompleteNotMuch NotMuch call NotMuch(<q-args>)
902 cabbrev notmuch <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'NotMuch' : 'notmuch')<CR>
904 " vim: set ft=vim ts=8 sw=8 et foldmethod=marker :