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 \ 'a': ':call <SID>NM_search_archive_thread()<CR>',
95 \ 'f': ':call <SID>NM_search_filter()<CR>',
96 \ 'm': ':call <SID>NM_new_mail()<CR>',
97 \ 'o': ':call <SID>NM_search_toggle_order()<CR>',
98 \ 'r': ':call <SID>NM_search_reply_to_thread()<CR>',
99 \ 's': ':call <SID>NM_search_prompt()<CR>',
100 \ 'S': ':call <SID>NM_search_edit()<CR>',
101 \ 't': ':call <SID>NM_search_filter_by_tag()<CR>',
102 \ 'q': ':call <SID>NM_kill_this_buffer()<CR>',
103 \ '+': ':call <SID>NM_search_add_tags([])<CR>',
104 \ '-': ':call <SID>NM_search_remove_tags([])<CR>',
105 \ '=': ':call <SID>NM_search_refresh_view()<CR>',
108 " --- --- bindings for show screen {{{2
109 let g:notmuch_show_maps = {
110 \ '<C-P>': ':call <SID>NM_show_previous(1)<CR>',
111 \ '<C-N>': ':call <SID>NM_show_next(1)<CR>',
112 \ 'q': ':call <SID>NM_kill_this_buffer()<CR>',
114 \ 'b': ':call <SID>NM_show_fold_toggle(''b'', ''bdy'', !g:notmuch_show_fold_bodies)<CR>',
115 \ 'c': ':call <SID>NM_show_fold_toggle(''c'', ''cit'', !g:notmuch_show_fold_citations)<CR>',
116 \ 'h': ':call <SID>NM_show_fold_toggle(''h'', ''hdr'', !g:notmuch_show_fold_headers)<CR>',
117 \ 's': ':call <SID>NM_show_fold_toggle(''s'', ''sig'', !g:notmuch_show_fold_signatures)<CR>',
119 \ 'a': ':call <SID>NM_show_archive_thread()<CR>',
120 \ 'A': ':call <SID>NM_show_mark_read_then_archive_thread()<CR>',
121 \ 'N': ':call <SID>NM_show_mark_read_then_next_open_message()<CR>',
122 \ 'v': ':call <SID>NM_show_view_all_mime_parts()<CR>',
123 \ '+': ':call <SID>NM_show_add_tag()<CR>',
124 \ '-': ':call <SID>NM_show_remove_tag()<CR>',
125 \ '<Space>': ':call <SID>NM_show_advance_marking_read_and_archiving()<CR>',
126 \ '\|': ':call <SID>NM_show_pipe_message()<CR>',
128 \ 'r': ':call <SID>NM_show_reply()<CR>',
129 \ 'm': ':call <SID>NM_new_mail()<CR>',
133 " --- implement folders screen {{{1
135 function! s:NM_cmd_folders(words)
137 echoe 'Not exapecting any arguments for folders command.'
142 for entry in g:notmuch_folders
143 let [ name, search ] = entry
144 let data = s:NM_run(cmd + [search])
145 let cnt = matchlist(data, '\(\d\+\)')[1]
146 call add(disp, printf('%9d %-20s (%s)', cnt, name, search))
147 call add(searches, search)
150 call <SID>NM_newBuffer('folders', join(disp, "\n"))
151 let b:nm_searches = searches
152 let b:nm_timestamp = reltime()
154 call <SID>NM_cmd_folders_mksyntax()
155 call <SID>NM_set_map(g:notmuch_folders_maps)
160 function! s:NM_cmd_folders_mksyntax()
163 " --- --- folders screen action functions {{{2
165 function! s:NM_folders_refresh_view()
167 setlocal bufhidden=delete
168 call s:NM_cmd_folders([])
169 exec printf('norm %dG', lno)
172 function! s:NM_folders_show_search()
174 let search = b:nm_searches[line-1]
176 let prev_bufnr = bufnr('%')
177 setlocal bufhidden=hide
178 call <SID>NM_cmd_search([search])
179 setlocal bufhidden=delete
180 let b:nm_prev_bufnr = prev_bufnr
184 " --- implement search screen {{{1
186 function! s:NM_cmd_search(words)
188 if g:notmuch_search_newest_first
189 let cmd = cmd + ['--sort=newest-first']
191 let cmd = cmd + ['--sort=oldest-first']
193 let data = s:NM_run(cmd + a:words)
194 let lines = split(data, "\n")
195 let disp = copy(lines)
196 call map(disp, 's:NM_cmd_search_fmtline(v:val)')
198 call <SID>NM_newBuffer('search', join(disp, "\n"))
199 let b:nm_raw_lines = lines
200 let b:nm_search_words = a:words
202 call <SID>NM_cmd_search_mksyntax()
203 call <SID>NM_set_map(g:notmuch_search_maps)
207 function! s:NM_cmd_search_fmtline(line)
208 let m = matchlist(a:line, '^\(thread:\S\+\)\s\([^]]\+\]\) \([^;]\+\); \(.*\) (\([^(]*\))$')
210 return 'ERROR PARSING: ' . a:line
212 let max = g:notmuch_search_from_column_width
214 if strlen(from) >= max
215 let from = substitute(m[3][0:max-4], '[^A-Za-z1-9_]*$', '', '') . '...'
217 return printf('%s %-20s | %s (%s)', m[2], from, m[4], m[5])
219 function! s:NM_cmd_search_mksyntax()
220 syntax clear nmSearchFrom
221 exec printf('syntax match nmSearchFrom /\(\] \)\@<=.\{%d\}/ oneline contained', g:notmuch_search_from_column_width)
224 " --- --- search screen action functions {{{2
226 function! s:NM_search_show_thread()
227 let id = <SID>NM_search_find_thread_id()
229 call <SID>NM_cmd_show([id])
233 function! s:NM_search_prompt()
234 " TODO: input() can support completion
235 let text = input('NotMuch Search: ')
237 let tags = split(text)
239 let tags = s:notmuch_initial_search_words_defaults
241 if b:nm_type == 'search'
242 " TODO: we intend to replace the current buffer,
243 " ... maybe we could just clear it
244 let prev_bufnr = b:nm_prev_bufnr
245 setlocal bufhidden=delete
247 let prev_bufnr = bufnr('%')
248 setlocal bufhidden=hide
250 call <SID>NM_cmd_search(tags)
251 setlocal bufhidden=delete
252 let b:nm_prev_bufnr = prev_bufnr
255 function! s:NM_search_edit()
256 " TODO: input() can support completion
257 let text = input('NotMuch Search: ', join(b:nm_search_words, ' '))
259 call <SID>NM_cmd_search(split(text))
263 function! s:NM_search_archive_thread()
264 call <SID>NM_add_remove_tags_on_screen('-', ['inbox'])
265 call <SID>NM_add_remove_tags('-', ['inbox'])
269 function! s:NM_search_filter()
270 call <SID>NM_search_filter_helper('Filter: ', '')
273 function! s:NM_search_filter_by_tag()
274 call <SID>NM_search_filter_helper('Filter Tag(s): ', 'tag:')
277 function! s:NM_search_filter_helper(prompt, prefix)
278 " TODO: input() can support completion
279 let text = input(a:prompt)
284 let tags = split(text)
285 map(tags, 'and a:prefix . v:val')
286 let tags = b:nm_search_words + tags
289 let prev_bufnr = bufnr('%')
290 setlocal bufhidden=hide
291 call <SID>NM_cmd_search(tags)
292 setlocal bufhidden=delete
293 let b:nm_prev_bufnr = prev_bufnr
296 function! s:NM_search_toggle_order()
297 let g:notmuch_search_newest_first = !g:notmuch_search_newest_first
298 " FIXME: maybe this would be better done w/o reading re-reading the lines
299 " reversing the b:nm_raw_lines and the buffer lines would be better
300 call <SID>NM_search_refresh_view()
303 function! s:NM_search_reply_to_thread()
304 echo 'not implemented'
307 function! s:NM_search_add_tags(tags)
308 call <SID>NM_search_add_remove_tags('Add Tag(s): ', '+', a:tags)
311 function! s:NM_search_remove_tags(tags)
312 call <SID>NM_search_add_remove_tags('Remove Tag(s): ', '-', a:tags)
315 function! s:NM_search_refresh_view()
317 setlocal bufhidden=delete
318 call <SID>NM_cmd_search(b:nm_search_words)
319 " FIXME: should find the line of the thread we were on if possible
320 exec printf('norm %dG', lno)
323 " --- --- search screen helper functions {{{2
325 function! s:NM_search_find_thread_id()
326 if !exists('b:nm_raw_lines')
327 echoe 'no b:nm_raw_lines'
331 let info = b:nm_raw_lines[line-1]
332 let what = split(info, '\s\+')[0]
337 function! s:NM_search_add_remove_tags(prompt, prefix, intags)
338 if type(a:intags) != type([]) || len(a:intags) == 0
339 " TODO: input() can support completion
340 let text = input(a:prompt)
344 let tags = split(text, ' ')
348 call <SID>NM_add_remove_tags(a:prefix, tags)
349 call <SID>NM_add_remove_tags_on_screen(a:prefix, tags)
352 " --- implement show screen {{{1
354 function! s:NM_cmd_show(words)
355 let prev_bufnr = bufnr('%')
356 let data = s:NM_run(['show'] + a:words)
357 let lines = split(data, "\n")
359 let info = s:NM_cmd_show_parse(lines)
361 setlocal bufhidden=hide
362 call <SID>NM_newBuffer('show', join(info['disp'], "\n"))
363 setlocal bufhidden=delete
364 let b:nm_raw_info = info
365 let b:nm_prev_bufnr = prev_bufnr
367 call <SID>NM_cmd_show_mkfolds()
368 call <SID>NM_cmd_show_mksyntax()
369 call <SID>NM_set_map(g:notmuch_show_maps)
370 setlocal foldtext=NM_cmd_show_foldtext()
372 setlocal foldcolumn=6
376 function! s:NM_show_previous(can_change_thread)
377 let info = b:nm_raw_info
379 for msg in reverse(copy(info['msgs']))
380 if lnum <= msg['start']
384 exec printf('norm %dG', msg['start'])
385 " TODO: try to fit the message on screen
389 if !a:can_change_thread
392 call <SID>NM_kill_this_buffer()
393 if line('.') != line('0')
395 call <SID>NM_search_show_thread()
397 call <SID>NM_show_previous(0)
399 echo 'No more messages.'
403 function! s:NM_show_next(can_change_thread)
404 let info = b:nm_raw_info
406 for msg in info['msgs']
407 if lnum >= msg['start']
411 exec printf('norm %dG', msg['start'])
412 " TODO: try to fit the message on screen
416 if !a:can_change_thread
419 call <SID>NM_kill_this_buffer()
420 if line('.') != line('$')
422 call <SID>NM_search_show_thread()
424 echo 'No more messages.'
428 function! s:NM_show_archive_thread()
429 echo 'not implemented'
432 function! s:NM_show_mark_read_then_archive_thread()
433 echo 'not implemented'
436 function! s:NM_show_next_message()
437 echo 'not implemented'
440 function! s:NM_show_mark_read_then_next_open_message()
441 echo 'not implemented'
444 function! s:NM_show_previous_message()
445 echo 'not implemented'
448 function! s:NM_show_reply()
449 echo 'not implemented'
452 function! s:NM_show_view_all_mime_parts()
453 echo 'not implemented'
456 function! s:NM_show_view_raw_message()
457 echo 'not implemented'
460 function! s:NM_show_add_tag()
461 echo 'not implemented'
464 function! s:NM_show_remove_tag()
465 echo 'not implemented'
468 function! s:NM_show_advance_marking_read_and_archiving()
469 echo 'not implemented'
472 function! s:NM_show_pipe_message()
473 echo 'not implemented'
476 " --- --- search screen helper functions {{{2
478 function! s:NM_show_fold_toggle(key, type, fold)
479 let info = b:nm_raw_info
484 for fld in info['folds']
486 exec printf('%dfold%s', fld[1], act)
489 exec printf('nnoremap <buffer> %s :call <SID>NM_show_fold_toggle(''%s'', ''%s'', %d)<CR>', a:key, a:key, a:type, !a:fold)
493 " s:NM_cmd_show_parse returns the following dictionary:
494 " 'disp': lines to display
495 " 'msgs': message info dicts { start, end, id, depth, filename, descr, header }
496 " 'folds': fold info arrays [ type, start, end ]
497 " 'foldtext': fold text indexed by start line
498 function! s:NM_cmd_show_parse(inlines)
499 let info = { 'disp': [],
518 for line in a:inlines
519 let inlnum = inlnum + 1
525 if match(line, g:notmuch_show_part_end_regexp) != -1
526 let part_end = len(info['disp'])
528 call add(info['disp'], line)
531 if in_part == 'text/plain'
532 if !part_end && mode_type == ''
533 if match(line, g:notmuch_show_signature_regexp) != -1
534 let mode_type = 'sig'
535 let mode_start = len(info['disp'])
536 elseif match(line, g:notmuch_show_citation_regexp) != -1
537 let mode_type = 'cit'
538 let mode_start = len(info['disp'])
540 elseif mode_type == 'cit'
541 if part_end || match(line, g:notmuch_show_citation_regexp) == -1
542 let outlnum = len(info['disp'])
543 if mode_start != outlnum
544 let foldinfo = [ mode_type, mode_start, outlnum-1,
545 \ 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 if mode_start != outlnum
555 let foldinfo = [ mode_type, mode_start, outlnum-1,
556 \ printf('[ %d-line signature. Press "s" to show. ]', outlnum - mode_start) ]
564 " FIXME: this is a hack for handling two folds being added for one line
565 " we should handle addinga fold in a function
567 call add(info['folds'], foldinfo[0:2])
568 let info['foldtext'][foldinfo[1]] = foldinfo[3]
571 let foldinfo = [ 'text', part_start, part_end,
572 \ printf('[ %d-line %s. Press "p" to show. ]', part_end - part_start, in_part) ]
574 call add(info['disp'], '')
578 if !has_key(msg,'body_start')
579 let msg['body_start'] = len(info['disp']) + 1
581 if match(line, g:notmuch_show_body_end_regexp) != -1
582 let body_end = len(info['disp'])
583 let foldinfo = [ 'bdy', body_start, body_end,
584 \ printf('[ BODY %d - %d lines ]', len(info['msgs']), body_end - body_start) ]
588 elseif match(line, g:notmuch_show_part_begin_regexp) != -1
589 let m = matchlist(line, 'ID: \(\d\+\), Content-type: \(\S\+\)')
590 let in_part = 'unknown'
594 call add(info['disp'],
595 \ printf('--- %s ---', in_part))
596 let part_start = len(info['disp']) + 1
601 let msg['descr'] = line
602 call add(info['disp'], line)
604 let msg['hdr_start'] = len(info['disp']) + 1
607 if match(line, g:notmuch_show_header_end_regexp) != -1
608 let hdr_start = msg['hdr_start']+1
609 let hdr_end = len(info['disp'])
610 let foldinfo = [ 'hdr', hdr_start, hdr_end,
611 \ printf('[ %d-line headers. Press "h" to show. ]', hdr_end + 1 - hdr_start) ]
612 let msg['header'] = hdr
616 let m = matchlist(line, '^\(\w\+\):\s*\(.*\)$')
619 if match(g:notmuch_show_headers, m[1]) != -1
620 call add(info['disp'], line)
627 if match(line, g:notmuch_show_message_end_regexp) != -1
628 let msg['end'] = len(info['disp'])
629 call add(info['disp'], '')
631 let foldinfo = [ 'msg', msg['start'], msg['end'],
632 \ printf('[ MSG %d - %s ]', len(info['msgs']), msg['descr']) ]
634 call add(info['msgs'], msg)
641 elseif match(line, g:notmuch_show_header_begin_regexp) != -1
645 elseif match(line, g:notmuch_show_body_begin_regexp) != -1
646 let body_start = len(info['disp']) + 1
652 if match(line, g:notmuch_show_message_begin_regexp) != -1
653 let msg['start'] = len(info['disp']) + 1
655 let m = matchlist(line, g:notmuch_show_message_parse_regexp)
658 let msg['depth'] = m[2]
659 let msg['filename'] = m[3]
667 call add(info['folds'], foldinfo[0:2])
668 let info['foldtext'][foldinfo[1]] = foldinfo[3]
674 function! s:NM_cmd_show_mkfolds()
675 let info = b:nm_raw_info
677 for afold in info['folds']
678 exec printf('%d,%dfold', afold[1], afold[2])
679 if (afold[0] == 'sig' && g:notmuch_show_fold_signatures)
680 \ || (afold[0] == 'cit' && g:notmuch_show_fold_citations)
681 \ || (afold[0] == 'bdy' && g:notmuch_show_fold_bodies)
682 \ || (afold[0] == 'hdr' && g:notmuch_show_fold_headers)
683 exec printf('%dfoldclose', afold[1])
685 exec printf('%dfoldopen', afold[1])
690 function! s:NM_cmd_show_mksyntax()
691 let info = b:nm_raw_info
693 for msg in info['msgs']
695 let start = msg['start']
696 let hdr_start = msg['hdr_start']
697 let body_start = msg['body_start']
699 exec printf('syntax region nmShowMsg%dDesc start=''\%%%dl'' end=''\%%%dl'' contains=@nmShowMsgDesc', cnt, start, start+1)
700 exec printf('syntax region nmShowMsg%dHead start=''\%%%dl'' end=''\%%%dl'' contains=@nmShowMsgHead', cnt, hdr_start, body_start)
701 exec printf('syntax region nmShowMsg%dBody start=''\%%%dl'' end=''\%%%dl'' contains=@nmShowMsgBody', cnt, body_start, end)
705 function! NM_cmd_show_foldtext()
706 let foldtext = b:nm_raw_info['foldtext']
707 return foldtext[v:foldstart]
711 " --- notmuch helper functions {{{1
713 function! s:NM_newBuffer(type, content)
715 setlocal buftype=nofile readonly modifiable
718 setlocal nomodifiable
719 execute printf('set filetype=notmuch-%s', a:type)
720 execute printf('set syntax=notmuch-%s', a:type)
721 let b:nm_type = a:type
724 function! s:NM_run(args)
725 let cmd = g:notmuch_cmd . ' ' . join(a:args) . '< /dev/null'
727 let start = reltime()
728 let out = system(cmd)
729 let err = v:shell_error
730 let delta = reltime(start)
732 echo printf('[%s] {%s} %s', reltimestr(delta), string(err), string(cmd))
736 echo substitute(out, '\n*$', '', '')
744 " --- external mail handling helpers {{{1
746 function! s:NM_new_mail()
747 echo 'not implemented'
750 " --- other helpers {{{1
752 function! s:NM_kill_this_buffer()
753 if exists('b:nm_prev_bufnr')
754 setlocal bufhidden=delete
755 exec printf(":buffer %d", b:nm_prev_bufnr)
757 echo "Nothing to kill."
761 function! s:NM_add_remove_tags(prefix, tags)
762 let id = <SID>NM_search_find_thread_id()
764 echoe 'Eeek! I couldn''t find the thead id!'
766 call map(a:tags, 'a:prefix . v:val')
767 " TODO: handle errors
768 call <SID>NM_run(['tag'] + a:tags + ['--', id])
771 function! s:NM_add_remove_tags_on_screen(prefix, tags)
775 for tagname in a:tags
776 exec printf('silent %ss/(\([^)]*\)\<%s\>\([^)]*\))$/(\1\2)/', online, tagname)
779 for tagname in a:tags
780 exec printf('silent %ss/(\([^)]*\)\([^)]*\))$/(\1 %s)/', online, tagname)
783 setlocal nomodifiable
786 " --- process and set the defaults {{{1
788 function! NM_set_defaults(force)
789 for [key, dflt] in items(s:notmuch_defaults)
791 if !a:force && exists(key) && type(dflt) == type(eval(key))
793 elseif type(dflt) == type(0)
794 let cmd = printf('let %s = %d', key, dflt)
795 elseif type(dflt) == type('')
796 let cmd = printf('let %s = ''%s''', key, dflt)
797 " FIXME: not sure why this didn't work when dflt is an array
798 "elseif type(dflt) == type([])
799 " let cmd = printf('let %s = %s', key, string(dflt))
801 echoe printf('E: Unknown type in NM_set_defaults(%d) using [%s,%s]',
802 \ a:force, key, string(dflt))
808 call NM_set_defaults(0)
810 " for some reason NM_set_defaults() didn't work for arrays...
811 if !exists('g:notmuch_show_headers')
812 let g:notmuch_show_headers = s:notmuch_show_headers_defaults
814 if !exists('g:notmuch_initial_search_words')
815 let g:notmuch_initial_search_words = s:notmuch_initial_search_words_defaults
817 if !exists('g:notmuch_folders')
818 let g:notmuch_folders = s:notmuch_folders_defaults
822 " --- assign keymaps {{{1
824 function! s:NM_set_map(maps)
826 for [key, code] in items(a:maps)
827 exec printf('nnoremap <buffer> %s %s', key, code)
829 " --- this is a hack for development :)
830 nnoremap ,nmr :source ~/.vim/plugin/notmuch.vim<CR>:call NotMuch('')<CR>
833 " --- command handler {{{1
835 function! NotMuch(args)
841 let words = split(args)
842 if words[0] == 'folders'
843 let words = words[1:]
844 call <SID>NM_cmd_folders(words)
845 elseif words[0] == 'search'
847 let words = words[1:]
848 elseif exists('b:nm_search_words')
849 let words = b:nm_search_words
851 let words = g:notmuch_initial_search_words
853 call <SID>NM_cmd_search(words)
855 elseif words[0] == 'show'
856 echoe 'show is not yet implemented.'
859 function! CompleteNotMuch(arg_lead, cmd_line, cursor_pos)
866 command! -nargs=* -complete=customlist,CompleteNotMuch NotMuch call NotMuch(<q-args>)
867 cabbrev notmuch <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'NotMuch' : 'notmuch')<CR>
869 " vim: set ft=vim ts=8 sw=8 et foldmethod=marker :