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>',
109 " --- --- bindings for show screen {{{2
110 let g:notmuch_show_maps = {
111 \ '<C-P>': ':call <SID>NM_show_previous(1)<CR>',
112 \ '<C-N>': ':call <SID>NM_show_next(1)<CR>',
113 \ '<C-]>': ':call <SID>NM_search_expand(''<cword>'')<CR>',
114 \ 'q': ':call <SID>NM_kill_this_buffer()<CR>',
116 \ 'b': ':call <SID>NM_show_fold_toggle(''b'', ''bdy'', !g:notmuch_show_fold_bodies)<CR>',
117 \ 'c': ':call <SID>NM_show_fold_toggle(''c'', ''cit'', !g:notmuch_show_fold_citations)<CR>',
118 \ 'h': ':call <SID>NM_show_fold_toggle(''h'', ''hdr'', !g:notmuch_show_fold_headers)<CR>',
119 \ 's': ':call <SID>NM_show_fold_toggle(''s'', ''sig'', !g:notmuch_show_fold_signatures)<CR>',
121 \ 'a': ':call <SID>NM_show_archive_thread()<CR>',
122 \ 'A': ':call <SID>NM_show_mark_read_then_archive_thread()<CR>',
123 \ 'N': ':call <SID>NM_show_mark_read_then_next_open_message()<CR>',
124 \ 'v': ':call <SID>NM_show_view_all_mime_parts()<CR>',
125 \ '+': ':call <SID>NM_show_add_tag()<CR>',
126 \ '-': ':call <SID>NM_show_remove_tag()<CR>',
127 \ '<Space>': ':call <SID>NM_show_advance_marking_read_and_archiving()<CR>',
128 \ '\|': ':call <SID>NM_show_pipe_message()<CR>',
130 \ 'r': ':call <SID>NM_show_reply()<CR>',
131 \ 'm': ':call <SID>NM_new_mail()<CR>',
135 " --- implement folders screen {{{1
137 function! s:NM_cmd_folders(words)
139 echoe 'Not exapecting any arguments for folders command.'
144 for entry in g:notmuch_folders
145 let [ name, search ] = entry
146 let data = s:NM_run(cmd + [search])
147 let cnt = matchlist(data, '\(\d\+\)')[1]
148 call add(disp, printf('%9d %-20s (%s)', cnt, name, search))
149 call add(searches, search)
152 call <SID>NM_newBuffer('folders', join(disp, "\n"))
153 let b:nm_searches = searches
154 let b:nm_timestamp = reltime()
156 call <SID>NM_cmd_folders_mksyntax()
157 call <SID>NM_set_map(g:notmuch_folders_maps)
162 function! s:NM_cmd_folders_mksyntax()
165 " --- --- folders screen action functions {{{2
167 function! s:NM_folders_refresh_view()
169 setlocal bufhidden=delete
170 call s:NM_cmd_folders([])
171 exec printf('norm %dG', lno)
174 function! s:NM_folders_show_search()
176 let search = b:nm_searches[line-1]
178 let prev_bufnr = bufnr('%')
179 setlocal bufhidden=hide
180 call <SID>NM_cmd_search([search])
181 setlocal bufhidden=delete
182 let b:nm_prev_bufnr = prev_bufnr
186 " --- implement search screen {{{1
188 function! s:NM_cmd_search(words)
190 if g:notmuch_search_newest_first
191 let cmd = cmd + ['--sort=newest-first']
193 let cmd = cmd + ['--sort=oldest-first']
195 let data = s:NM_run(cmd + a:words)
196 let lines = split(data, "\n")
197 let disp = copy(lines)
198 call map(disp, 's:NM_cmd_search_fmtline(v:val)')
200 call <SID>NM_newBuffer('search', join(disp, "\n"))
201 let b:nm_raw_lines = lines
202 let b:nm_search_words = a:words
204 call <SID>NM_cmd_search_mksyntax()
205 call <SID>NM_set_map(g:notmuch_search_maps)
209 function! s:NM_cmd_search_fmtline(line)
210 let m = matchlist(a:line, '^\(thread:\S\+\)\s\([^]]\+\]\) \([^;]\+\); \(.*\) (\([^(]*\))$')
212 return 'ERROR PARSING: ' . a:line
214 let max = g:notmuch_search_from_column_width
216 if strlen(from) >= max
217 let from = substitute(m[3][0:max-4], '[^A-Za-z1-9_]*$', '', '') . '...'
219 return printf('%s %-20s | %s (%s)', m[2], from, m[4], m[5])
221 function! s:NM_cmd_search_mksyntax()
222 syntax clear nmSearchFrom
223 exec printf('syntax match nmSearchFrom /\(\] \)\@<=.\{%d\}/ oneline contained', g:notmuch_search_from_column_width)
226 " --- --- search screen action functions {{{2
228 function! s:NM_search_show_thread()
229 let id = <SID>NM_search_find_thread_id()
231 call <SID>NM_cmd_show([id])
235 function! s:NM_search_prompt()
236 " TODO: input() can support completion
237 let text = input('NotMuch Search: ')
239 let tags = split(text)
241 let tags = s:notmuch_initial_search_words_defaults
243 if b:nm_type == 'search'
244 " TODO: we intend to replace the current buffer,
245 " ... maybe we could just clear it
246 let prev_bufnr = b:nm_prev_bufnr
247 setlocal bufhidden=delete
249 let prev_bufnr = bufnr('%')
250 setlocal bufhidden=hide
252 call <SID>NM_cmd_search(tags)
253 setlocal bufhidden=delete
254 let b:nm_prev_bufnr = prev_bufnr
257 function! s:NM_search_edit()
258 " TODO: input() can support completion
259 let text = input('NotMuch Search: ', join(b:nm_search_words, ' '))
261 call <SID>NM_cmd_search(split(text))
265 function! s:NM_search_archive_thread()
266 call <SID>NM_add_remove_tags_on_screen('-', ['inbox'])
267 call <SID>NM_add_remove_tags('-', ['inbox'])
271 function! s:NM_search_filter()
272 call <SID>NM_search_filter_helper('Filter: ', '')
275 function! s:NM_search_filter_by_tag()
276 call <SID>NM_search_filter_helper('Filter Tag(s): ', 'tag:')
279 function! s:NM_search_filter_helper(prompt, prefix)
280 " TODO: input() can support completion
281 let text = input(a:prompt)
286 let tags = split(text)
287 map(tags, 'and a:prefix . v:val')
288 let tags = b:nm_search_words + tags
291 let prev_bufnr = bufnr('%')
292 setlocal bufhidden=hide
293 call <SID>NM_cmd_search(tags)
294 setlocal bufhidden=delete
295 let b:nm_prev_bufnr = prev_bufnr
298 function! s:NM_search_toggle_order()
299 let g:notmuch_search_newest_first = !g:notmuch_search_newest_first
300 " FIXME: maybe this would be better done w/o reading re-reading the lines
301 " reversing the b:nm_raw_lines and the buffer lines would be better
302 call <SID>NM_search_refresh_view()
305 function! s:NM_search_reply_to_thread()
306 echo 'not implemented'
309 function! s:NM_search_add_tags(tags)
310 call <SID>NM_search_add_remove_tags('Add Tag(s): ', '+', a:tags)
313 function! s:NM_search_remove_tags(tags)
314 call <SID>NM_search_add_remove_tags('Remove Tag(s): ', '-', a:tags)
317 function! s:NM_search_refresh_view()
319 setlocal bufhidden=delete
320 call <SID>NM_cmd_search(b:nm_search_words)
321 " FIXME: should find the line of the thread we were on if possible
322 exec printf('norm %dG', lno)
325 " --- --- search screen helper functions {{{2
327 function! s:NM_search_find_thread_id()
328 if !exists('b:nm_raw_lines')
329 echoe 'no b:nm_raw_lines'
333 let info = b:nm_raw_lines[line-1]
334 let what = split(info, '\s\+')[0]
339 function! s:NM_search_add_remove_tags(prompt, prefix, intags)
340 if type(a:intags) != type([]) || len(a:intags) == 0
341 " TODO: input() can support completion
342 let text = input(a:prompt)
346 let tags = split(text, ' ')
350 call <SID>NM_add_remove_tags(a:prefix, tags)
351 call <SID>NM_add_remove_tags_on_screen(a:prefix, tags)
354 " --- implement show screen {{{1
356 function! s:NM_cmd_show(words)
357 let prev_bufnr = bufnr('%')
358 let data = s:NM_run(['show'] + a:words)
359 let lines = split(data, "\n")
361 let info = s:NM_cmd_show_parse(lines)
363 setlocal bufhidden=hide
364 call <SID>NM_newBuffer('show', join(info['disp'], "\n"))
365 setlocal bufhidden=delete
366 let b:nm_raw_info = info
367 let b:nm_prev_bufnr = prev_bufnr
369 call <SID>NM_cmd_show_mkfolds()
370 call <SID>NM_cmd_show_mksyntax()
371 call <SID>NM_set_map(g:notmuch_show_maps)
372 setlocal foldtext=NM_cmd_show_foldtext()
374 setlocal foldcolumn=6
378 function! s:NM_show_previous(can_change_thread)
379 let info = b:nm_raw_info
381 for msg in reverse(copy(info['msgs']))
382 if lnum <= msg['start']
386 exec printf('norm %dG', msg['start'])
387 " TODO: try to fit the message on screen
391 if !a:can_change_thread
394 call <SID>NM_kill_this_buffer()
395 if line('.') != line('0')
397 call <SID>NM_search_show_thread()
399 call <SID>NM_show_previous(0)
401 echo 'No more messages.'
405 function! s:NM_show_next(can_change_thread)
406 let info = b:nm_raw_info
408 for msg in info['msgs']
409 if lnum >= msg['start']
413 exec printf('norm %dG', msg['start'])
414 " TODO: try to fit the message on screen
418 if !a:can_change_thread
421 call <SID>NM_kill_this_buffer()
422 if line('.') != line('$')
424 call <SID>NM_search_show_thread()
426 echo 'No more messages.'
430 function! s:NM_show_archive_thread()
431 echo 'not implemented'
434 function! s:NM_show_mark_read_then_archive_thread()
435 echo 'not implemented'
438 function! s:NM_show_next_message()
439 echo 'not implemented'
442 function! s:NM_show_mark_read_then_next_open_message()
443 echo 'not implemented'
446 function! s:NM_show_previous_message()
447 echo 'not implemented'
450 function! s:NM_show_reply()
451 echo 'not implemented'
454 function! s:NM_show_view_all_mime_parts()
455 echo 'not implemented'
458 function! s:NM_show_view_raw_message()
459 echo 'not implemented'
462 function! s:NM_show_add_tag()
463 echo 'not implemented'
466 function! s:NM_show_remove_tag()
467 echo 'not implemented'
470 function! s:NM_show_advance_marking_read_and_archiving()
471 echo 'not implemented'
474 function! s:NM_show_pipe_message()
475 echo 'not implemented'
478 " --- --- search screen helper functions {{{2
480 function! s:NM_show_fold_toggle(key, type, fold)
481 let info = b:nm_raw_info
486 for fld in info['folds']
488 exec printf('%dfold%s', fld[1], act)
491 exec printf('nnoremap <buffer> %s :call <SID>NM_show_fold_toggle(''%s'', ''%s'', %d)<CR>', a:key, a:key, a:type, !a:fold)
495 " s:NM_cmd_show_parse returns the following dictionary:
496 " 'disp': lines to display
497 " 'msgs': message info dicts { start, end, id, depth, filename, descr, header }
498 " 'folds': fold info arrays [ type, start, end ]
499 " 'foldtext': fold text indexed by start line
500 function! s:NM_cmd_show_parse(inlines)
501 let info = { 'disp': [],
520 for line in a:inlines
521 let inlnum = inlnum + 1
527 if match(line, g:notmuch_show_part_end_regexp) != -1
528 let part_end = len(info['disp'])
530 call add(info['disp'], line)
533 if in_part == 'text/plain'
534 if !part_end && mode_type == ''
535 if match(line, g:notmuch_show_signature_regexp) != -1
536 let mode_type = 'sig'
537 let mode_start = len(info['disp'])
538 elseif match(line, g:notmuch_show_citation_regexp) != -1
539 let mode_type = 'cit'
540 let mode_start = len(info['disp'])
542 elseif mode_type == 'cit'
543 if part_end || match(line, g:notmuch_show_citation_regexp) == -1
544 let outlnum = len(info['disp'])
545 let foldinfo = [ mode_type, mode_start, outlnum-1,
546 \ printf('[ %d-line citation. Press "c" to show. ]', outlnum - mode_start) ]
549 elseif mode_type == 'sig'
550 let outlnum = len(info['disp'])
551 if (outlnum - mode_start) > g:notmuch_show_signature_lines_max
554 let foldinfo = [ mode_type, mode_start, outlnum-1,
555 \ printf('[ %d-line signature. Press "s" to show. ]', outlnum - mode_start) ]
562 " FIXME: this is a hack for handling two folds being added for one line
563 " we should handle addinga fold in a function
564 if len(foldinfo) && foldinfo[1] < foldinfo[2]
565 call add(info['folds'], foldinfo[0:2])
566 let info['foldtext'][foldinfo[1]] = foldinfo[3]
569 let foldinfo = [ 'text', part_start, part_end,
570 \ printf('[ %d-line %s. Press "p" to show. ]', part_end - part_start, in_part) ]
572 call add(info['disp'], '')
576 if !has_key(msg,'body_start')
577 let msg['body_start'] = len(info['disp']) + 1
579 if match(line, g:notmuch_show_body_end_regexp) != -1
580 let body_end = len(info['disp'])
581 let foldinfo = [ 'bdy', body_start, body_end,
582 \ printf('[ BODY %d - %d lines ]', len(info['msgs']), body_end - body_start) ]
586 elseif match(line, g:notmuch_show_part_begin_regexp) != -1
587 let m = matchlist(line, 'ID: \(\d\+\), Content-type: \(\S\+\)')
588 let in_part = 'unknown'
592 call add(info['disp'],
593 \ printf('--- %s ---', in_part))
594 let part_start = len(info['disp']) + 1
599 let msg['descr'] = line
600 call add(info['disp'], line)
602 let msg['hdr_start'] = len(info['disp']) + 1
605 if match(line, g:notmuch_show_header_end_regexp) != -1
606 let hdr_start = msg['hdr_start']+1
607 let hdr_end = len(info['disp'])
608 let foldinfo = [ 'hdr', hdr_start, hdr_end,
609 \ printf('[ %d-line headers. Press "h" to show. ]', hdr_end + 1 - hdr_start) ]
610 let msg['header'] = hdr
614 let m = matchlist(line, '^\(\w\+\):\s*\(.*\)$')
617 if match(g:notmuch_show_headers, m[1]) != -1
618 call add(info['disp'], line)
625 if match(line, g:notmuch_show_message_end_regexp) != -1
626 let msg['end'] = len(info['disp'])
627 call add(info['disp'], '')
629 let foldinfo = [ 'msg', msg['start'], msg['end'],
630 \ printf('[ MSG %d - %s ]', len(info['msgs']), msg['descr']) ]
632 call add(info['msgs'], msg)
639 elseif match(line, g:notmuch_show_header_begin_regexp) != -1
643 elseif match(line, g:notmuch_show_body_begin_regexp) != -1
644 let body_start = len(info['disp']) + 1
650 if match(line, g:notmuch_show_message_begin_regexp) != -1
651 let msg['start'] = len(info['disp']) + 1
653 let m = matchlist(line, g:notmuch_show_message_parse_regexp)
656 let msg['depth'] = m[2]
657 let msg['filename'] = m[3]
664 if len(foldinfo) && foldinfo[1] < foldinfo[2]
665 call add(info['folds'], foldinfo[0:2])
666 let info['foldtext'][foldinfo[1]] = foldinfo[3]
672 function! s:NM_cmd_show_mkfolds()
673 let info = b:nm_raw_info
675 for afold in info['folds']
676 exec printf('%d,%dfold', afold[1], afold[2])
677 if (afold[0] == 'sig' && g:notmuch_show_fold_signatures)
678 \ || (afold[0] == 'cit' && g:notmuch_show_fold_citations)
679 \ || (afold[0] == 'bdy' && g:notmuch_show_fold_bodies)
680 \ || (afold[0] == 'hdr' && g:notmuch_show_fold_headers)
681 exec printf('%dfoldclose', afold[1])
683 exec printf('%dfoldopen', afold[1])
688 function! s:NM_cmd_show_mksyntax()
689 let info = b:nm_raw_info
691 for msg in info['msgs']
693 let start = msg['start']
694 let hdr_start = msg['hdr_start']
695 let body_start = msg['body_start']
697 exec printf('syntax region nmShowMsg%dDesc start=''\%%%dl'' end=''\%%%dl'' contains=@nmShowMsgDesc', cnt, start, start+1)
698 exec printf('syntax region nmShowMsg%dHead start=''\%%%dl'' end=''\%%%dl'' contains=@nmShowMsgHead', cnt, hdr_start, body_start)
699 exec printf('syntax region nmShowMsg%dBody start=''\%%%dl'' end=''\%%%dl'' contains=@nmShowMsgBody', cnt, body_start, end)
703 function! NM_cmd_show_foldtext()
704 let foldtext = b:nm_raw_info['foldtext']
705 return foldtext[v:foldstart]
709 " --- notmuch helper functions {{{1
711 function! s:NM_newBuffer(type, content)
713 setlocal buftype=nofile readonly modifiable
716 setlocal nomodifiable
717 execute printf('set filetype=notmuch-%s', a:type)
718 execute printf('set syntax=notmuch-%s', a:type)
719 let b:nm_type = a:type
722 function! s:NM_run(args)
723 let cmd = g:notmuch_cmd . ' ' . join(a:args) . '< /dev/null'
725 let start = reltime()
726 let out = system(cmd)
727 let err = v:shell_error
728 let delta = reltime(start)
730 echo printf('[%s] {%s} %s', reltimestr(delta), string(err), string(cmd))
734 echo substitute(out, '\n*$', '', '')
742 " --- external mail handling helpers {{{1
744 function! s:NM_new_mail()
745 echo 'not implemented'
748 " --- other helpers {{{1
750 function! s:NM_kill_this_buffer()
751 if exists('b:nm_prev_bufnr')
752 setlocal bufhidden=delete
753 exec printf(":buffer %d", b:nm_prev_bufnr)
755 echo "Nothing to kill."
759 function! s:NM_search_expand(arg)
760 let word = expand(a:arg)
761 let prev_bufnr = bufnr('%')
762 setlocal bufhidden=hide
763 call <SID>NM_cmd_search([word])
764 setlocal bufhidden=delete
765 let b:nm_prev_bufnr = prev_bufnr
768 function! s:NM_add_remove_tags(prefix, tags)
769 let id = <SID>NM_search_find_thread_id()
771 echoe 'Eeek! I couldn''t find the thead id!'
773 call map(a:tags, 'a:prefix . v:val')
774 " TODO: handle errors
775 call <SID>NM_run(['tag'] + a:tags + ['--', id])
778 function! s:NM_add_remove_tags_on_screen(prefix, tags)
782 for tagname in a:tags
783 exec printf('silent %ss/(\([^)]*\)\<%s\>\([^)]*\))$/(\1\2)/', online, tagname)
786 for tagname in a:tags
787 exec printf('silent %ss/(\([^)]*\)\([^)]*\))$/(\1 %s)/', online, tagname)
790 setlocal nomodifiable
793 " --- process and set the defaults {{{1
795 function! NM_set_defaults(force)
796 for [key, dflt] in items(s:notmuch_defaults)
798 if !a:force && exists(key) && type(dflt) == type(eval(key))
800 elseif type(dflt) == type(0)
801 let cmd = printf('let %s = %d', key, dflt)
802 elseif type(dflt) == type('')
803 let cmd = printf('let %s = ''%s''', key, dflt)
804 " FIXME: not sure why this didn't work when dflt is an array
805 "elseif type(dflt) == type([])
806 " let cmd = printf('let %s = %s', key, string(dflt))
808 echoe printf('E: Unknown type in NM_set_defaults(%d) using [%s,%s]',
809 \ a:force, key, string(dflt))
815 call NM_set_defaults(0)
817 " for some reason NM_set_defaults() didn't work for arrays...
818 if !exists('g:notmuch_show_headers')
819 let g:notmuch_show_headers = s:notmuch_show_headers_defaults
821 if !exists('g:notmuch_initial_search_words')
822 let g:notmuch_initial_search_words = s:notmuch_initial_search_words_defaults
824 if !exists('g:notmuch_folders')
825 let g:notmuch_folders = s:notmuch_folders_defaults
829 " --- assign keymaps {{{1
831 function! s:NM_set_map(maps)
833 for [key, code] in items(a:maps)
834 exec printf('nnoremap <buffer> %s %s', key, code)
836 " --- this is a hack for development :)
837 nnoremap ,nmr :source ~/.vim/plugin/notmuch.vim<CR>:call NotMuch('')<CR>
840 " --- command handler {{{1
842 function! NotMuch(args)
848 let words = split(args)
849 if words[0] == 'folders'
850 let words = words[1:]
851 call <SID>NM_cmd_folders(words)
852 elseif words[0] == 'search'
854 let words = words[1:]
855 elseif exists('b:nm_search_words')
856 let words = b:nm_search_words
858 let words = g:notmuch_initial_search_words
860 call <SID>NM_cmd_search(words)
862 elseif words[0] == 'show'
863 echoe 'show is not yet implemented.'
866 function! CompleteNotMuch(arg_lead, cmd_line, cursor_pos)
873 command! -nargs=* -complete=customlist,CompleteNotMuch NotMuch call NotMuch(<q-args>)
874 cabbrev notmuch <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'NotMuch' : 'notmuch')<CR>
876 " vim: set ft=vim ts=8 sw=8 et foldmethod=marker :