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 setlocal bufhidden=delete
330 call <SID>NM_cmd_search(b:nm_search_words)
331 " FIXME: should find the line of the thread we were on if possible
332 exec printf('norm %dG', lno)
335 " --- --- search screen helper functions {{{2
337 function! s:NM_search_thread_id()
338 if !exists('b:nm_raw_lines')
339 echoe 'no b:nm_raw_lines'
343 let info = b:nm_raw_lines[line-1]
344 let what = split(info, '\s\+')[0]
349 function! s:NM_search_add_remove_tags(prompt, prefix, intags)
350 if type(a:intags) != type([]) || len(a:intags) == 0
351 " TODO: input() can support completion
352 let text = input(a:prompt)
356 let tags = split(text, ' ')
360 call <SID>NM_add_remove_tags(a:prefix, tags)
361 call <SID>NM_add_remove_tags_on_screen(a:prefix, tags)
364 " --- implement show screen {{{1
366 function! s:NM_cmd_show(words)
367 let prev_bufnr = bufnr('%')
368 let data = s:NM_run(['show'] + a:words)
369 let lines = split(data, "\n")
371 let info = s:NM_cmd_show_parse(lines)
373 setlocal bufhidden=hide
374 call <SID>NM_newBuffer('show', join(info['disp'], "\n"))
375 setlocal bufhidden=delete
376 let b:nm_words = a:words
377 let b:nm_raw_info = info
378 let b:nm_prev_bufnr = prev_bufnr
380 call <SID>NM_cmd_show_mkfolds()
381 call <SID>NM_cmd_show_mksyntax()
382 call <SID>NM_set_map(g:notmuch_show_maps)
383 setlocal foldtext=NM_cmd_show_foldtext()
385 setlocal foldcolumn=6
389 function! s:NM_show_previous(can_change_thread)
390 let info = b:nm_raw_info
392 for msg in reverse(copy(info['msgs']))
393 if lnum <= msg['start']
397 exec printf('norm %dG', msg['start'])
398 " TODO: try to fit the message on screen
402 if !a:can_change_thread
405 call <SID>NM_kill_this_buffer()
406 if line('.') != line('0')
408 call <SID>NM_search_show_thread()
410 call <SID>NM_show_previous(0)
412 echo 'No more messages.'
416 function! s:NM_show_next(can_change_thread)
417 let info = b:nm_raw_info
419 for msg in info['msgs']
420 if lnum >= msg['start']
424 exec printf('norm %dG', msg['start'])
425 " TODO: try to fit the message on screen
429 if !a:can_change_thread
432 call <SID>NM_kill_this_buffer()
433 if line('.') != line('$')
435 call <SID>NM_search_show_thread()
437 echo 'No more messages.'
441 function! s:NM_show_archive_thread()
442 echo 'not implemented'
445 function! s:NM_show_mark_read_then_archive_thread()
446 echo 'not implemented'
449 function! s:NM_show_next_message()
450 echo 'not implemented'
453 function! s:NM_show_mark_read_then_next_open_message()
454 echo 'not implemented'
457 function! s:NM_show_previous_message()
458 echo 'not implemented'
461 function! s:NM_show_reply()
462 echo 'not implemented'
465 function! s:NM_show_view_all_mime_parts()
466 echo 'not implemented'
469 function! s:NM_show_view_raw_message()
470 echo 'not implemented'
473 function! s:NM_show_add_tag()
474 echo 'not implemented'
477 function! s:NM_show_remove_tag()
478 echo 'not implemented'
481 function! s:NM_show_advance_marking_read_and_archiving()
482 echo 'not implemented'
485 function! s:NM_show_pipe_message()
486 echo 'not implemented'
489 " --- --- show screen helper functions {{{2
491 function! s:NM_show_thread_id()
492 if !exists('b:nm_words')
493 echoe 'no b:nm_words'
499 function! s:NM_show_message_id()
500 if !exists('b:nm_raw_info')
501 echoe 'no b:nm_raw_info'
504 let info = b:nm_raw_info
506 for msg in info['msgs']
507 if lnum >= msg['start']
516 function! s:NM_show_fold_toggle(key, type, fold)
517 let info = b:nm_raw_info
522 for fld in info['folds']
524 exec printf('%dfold%s', fld[1], act)
527 exec printf('nnoremap <buffer> %s :call <SID>NM_show_fold_toggle(''%s'', ''%s'', %d)<CR>', a:key, a:key, a:type, !a:fold)
531 " s:NM_cmd_show_parse returns the following dictionary:
532 " 'disp': lines to display
533 " 'msgs': message info dicts { start, end, id, depth, filename, descr, header }
534 " 'folds': fold info arrays [ type, start, end ]
535 " 'foldtext': fold text indexed by start line
536 function! s:NM_cmd_show_parse(inlines)
537 let info = { 'disp': [],
556 for line in a:inlines
557 let inlnum = inlnum + 1
563 if match(line, g:notmuch_show_part_end_regexp) != -1
564 let part_end = len(info['disp'])
566 call add(info['disp'], line)
569 if in_part == 'text/plain'
570 if !part_end && mode_type == ''
571 if match(line, g:notmuch_show_signature_regexp) != -1
572 let mode_type = 'sig'
573 let mode_start = len(info['disp'])
574 elseif match(line, g:notmuch_show_citation_regexp) != -1
575 let mode_type = 'cit'
576 let mode_start = len(info['disp'])
578 elseif mode_type == 'cit'
579 if part_end || match(line, g:notmuch_show_citation_regexp) == -1
580 let outlnum = len(info['disp'])
581 let foldinfo = [ mode_type, mode_start, outlnum-1,
582 \ printf('[ %d-line citation. Press "c" to show. ]', outlnum - mode_start) ]
585 elseif mode_type == 'sig'
586 let outlnum = len(info['disp'])
587 if (outlnum - mode_start) > g:notmuch_show_signature_lines_max
590 let foldinfo = [ mode_type, mode_start, outlnum-1,
591 \ printf('[ %d-line signature. Press "s" to show. ]', outlnum - mode_start) ]
598 " FIXME: this is a hack for handling two folds being added for one line
599 " we should handle addinga fold in a function
600 if len(foldinfo) && foldinfo[1] < foldinfo[2]
601 call add(info['folds'], foldinfo[0:2])
602 let info['foldtext'][foldinfo[1]] = foldinfo[3]
605 let foldinfo = [ 'text', part_start, part_end,
606 \ printf('[ %d-line %s. Press "p" to show. ]', part_end - part_start, in_part) ]
608 call add(info['disp'], '')
612 if !has_key(msg,'body_start')
613 let msg['body_start'] = len(info['disp']) + 1
615 if match(line, g:notmuch_show_body_end_regexp) != -1
616 let body_end = len(info['disp'])
617 let foldinfo = [ 'bdy', body_start, body_end,
618 \ printf('[ BODY %d - %d lines ]', len(info['msgs']), body_end - body_start) ]
622 elseif match(line, g:notmuch_show_part_begin_regexp) != -1
623 let m = matchlist(line, 'ID: \(\d\+\), Content-type: \(\S\+\)')
624 let in_part = 'unknown'
628 call add(info['disp'],
629 \ printf('--- %s ---', in_part))
630 let part_start = len(info['disp']) + 1
635 let msg['descr'] = line
636 call add(info['disp'], line)
638 let msg['hdr_start'] = len(info['disp']) + 1
641 if match(line, g:notmuch_show_header_end_regexp) != -1
642 let hdr_start = msg['hdr_start']+1
643 let hdr_end = len(info['disp'])
644 let foldinfo = [ 'hdr', hdr_start, hdr_end,
645 \ printf('[ %d-line headers. Press "h" to show. ]', hdr_end + 1 - hdr_start) ]
646 let msg['header'] = hdr
650 let m = matchlist(line, '^\(\w\+\):\s*\(.*\)$')
653 if match(g:notmuch_show_headers, m[1]) != -1
654 call add(info['disp'], line)
661 if match(line, g:notmuch_show_message_end_regexp) != -1
662 let msg['end'] = len(info['disp'])
663 call add(info['disp'], '')
665 let foldinfo = [ 'msg', msg['start'], msg['end'],
666 \ printf('[ MSG %d - %s ]', len(info['msgs']), msg['descr']) ]
668 call add(info['msgs'], msg)
675 elseif match(line, g:notmuch_show_header_begin_regexp) != -1
679 elseif match(line, g:notmuch_show_body_begin_regexp) != -1
680 let body_start = len(info['disp']) + 1
686 if match(line, g:notmuch_show_message_begin_regexp) != -1
687 let msg['start'] = len(info['disp']) + 1
689 let m = matchlist(line, g:notmuch_show_message_parse_regexp)
692 let msg['depth'] = m[2]
693 let msg['filename'] = m[3]
700 if len(foldinfo) && foldinfo[1] < foldinfo[2]
701 call add(info['folds'], foldinfo[0:2])
702 let info['foldtext'][foldinfo[1]] = foldinfo[3]
708 function! s:NM_cmd_show_mkfolds()
709 let info = b:nm_raw_info
711 for afold in info['folds']
712 exec printf('%d,%dfold', afold[1], afold[2])
713 if (afold[0] == 'sig' && g:notmuch_show_fold_signatures)
714 \ || (afold[0] == 'cit' && g:notmuch_show_fold_citations)
715 \ || (afold[0] == 'bdy' && g:notmuch_show_fold_bodies)
716 \ || (afold[0] == 'hdr' && g:notmuch_show_fold_headers)
717 exec printf('%dfoldclose', afold[1])
719 exec printf('%dfoldopen', afold[1])
724 function! s:NM_cmd_show_mksyntax()
725 let info = b:nm_raw_info
727 for msg in info['msgs']
729 let start = msg['start']
730 let hdr_start = msg['hdr_start']
731 let body_start = msg['body_start']
733 exec printf('syntax region nmShowMsg%dDesc start=''\%%%dl'' end=''\%%%dl'' contains=@nmShowMsgDesc', cnt, start, start+1)
734 exec printf('syntax region nmShowMsg%dHead start=''\%%%dl'' end=''\%%%dl'' contains=@nmShowMsgHead', cnt, hdr_start, body_start)
735 exec printf('syntax region nmShowMsg%dBody start=''\%%%dl'' end=''\%%%dl'' contains=@nmShowMsgBody', cnt, body_start, end)
739 function! NM_cmd_show_foldtext()
740 let foldtext = b:nm_raw_info['foldtext']
741 return foldtext[v:foldstart]
745 " --- notmuch helper functions {{{1
747 function! s:NM_newBuffer(type, content)
749 setlocal buftype=nofile readonly modifiable
752 setlocal nomodifiable
753 execute printf('set filetype=notmuch-%s', a:type)
754 execute printf('set syntax=notmuch-%s', a:type)
755 let b:nm_type = a:type
758 function! s:NM_run(args)
759 let cmd = g:notmuch_cmd . ' ' . join(a:args) . '< /dev/null'
761 let start = reltime()
762 let out = system(cmd)
763 let err = v:shell_error
764 let delta = reltime(start)
766 echo printf('[%s] {%s} %s', reltimestr(delta), string(err), string(cmd))
770 echo substitute(out, '\n*$', '', '')
778 " --- external mail handling helpers {{{1
780 function! s:NM_new_mail()
781 echo 'not implemented'
784 " --- other helpers {{{1
786 function! s:NM_kill_this_buffer()
787 if exists('b:nm_prev_bufnr')
788 setlocal bufhidden=delete
789 exec printf(":buffer %d", b:nm_prev_bufnr)
791 echo "This is the last buffer; use :q<CR> to quit."
795 function! s:NM_search_expand(arg)
796 let word = expand(a:arg)
797 let prev_bufnr = bufnr('%')
798 setlocal bufhidden=hide
799 call <SID>NM_cmd_search([word])
800 setlocal bufhidden=delete
801 let b:nm_prev_bufnr = prev_bufnr
804 function! s:NM_add_remove_tags(prefix, tags)
805 let id = <SID>NM_search_thread_id()
807 echoe 'Eeek! I couldn''t find the thead id!'
809 call map(a:tags, 'a:prefix . v:val')
810 " TODO: handle errors
811 call <SID>NM_run(['tag'] + a:tags + ['--', id])
814 function! s:NM_add_remove_tags_on_screen(prefix, tags)
818 for tagname in a:tags
819 exec printf('silent %ss/(\([^)]*\)\<%s\>\([^)]*\))$/(\1\2)/', online, tagname)
822 for tagname in a:tags
823 exec printf('silent %ss/(\([^)]*\)\([^)]*\))$/(\1 %s)/', online, tagname)
826 setlocal nomodifiable
829 " --- process and set the defaults {{{1
831 function! NM_set_defaults(force)
832 for [key, dflt] in items(s:notmuch_defaults)
834 if !a:force && exists(key) && type(dflt) == type(eval(key))
836 elseif type(dflt) == type(0)
837 let cmd = printf('let %s = %d', key, dflt)
838 elseif type(dflt) == type('')
839 let cmd = printf('let %s = ''%s''', key, dflt)
840 " FIXME: not sure why this didn't work when dflt is an array
841 "elseif type(dflt) == type([])
842 " let cmd = printf('let %s = %s', key, string(dflt))
844 echoe printf('E: Unknown type in NM_set_defaults(%d) using [%s,%s]',
845 \ a:force, key, string(dflt))
851 call NM_set_defaults(0)
853 " for some reason NM_set_defaults() didn't work for arrays...
854 if !exists('g:notmuch_show_headers')
855 let g:notmuch_show_headers = s:notmuch_show_headers_defaults
857 if !exists('g:notmuch_initial_search_words')
858 let g:notmuch_initial_search_words = s:notmuch_initial_search_words_defaults
860 if !exists('g:notmuch_folders')
861 let g:notmuch_folders = s:notmuch_folders_defaults
865 " --- assign keymaps {{{1
867 function! s:NM_set_map(maps)
869 for [key, code] in items(a:maps)
870 exec printf('nnoremap <buffer> %s %s', key, code)
872 " --- this is a hack for development :)
873 nnoremap ,nmr :source ~/.vim/plugin/notmuch.vim<CR>:call NotMuch('')<CR>
876 " --- command handler {{{1
878 function! NotMuch(args)
884 let words = split(args)
885 if words[0] == 'folders'
886 let words = words[1:]
887 call <SID>NM_cmd_folders(words)
888 elseif words[0] == 'search'
890 let words = words[1:]
891 elseif exists('b:nm_search_words')
892 let words = b:nm_search_words
894 let words = g:notmuch_initial_search_words
896 call <SID>NM_cmd_search(words)
898 elseif words[0] == 'show'
899 echoe 'show is not yet implemented.'
902 function! CompleteNotMuch(arg_lead, cmd_line, cursor_pos)
909 command! -nargs=* -complete=customlist,CompleteNotMuch NotMuch call NotMuch(<q-args>)
910 cabbrev notmuch <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'NotMuch' : 'notmuch')<CR>
912 " vim: set ft=vim ts=8 sw=8 et foldmethod=marker :