X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=vim%2Fplugin%2Fnotmuch.vim;h=7927dd62e77e3f685ddd3e9c3818729551337e1b;hp=8f6c7748ca5c1495c88c923f39cc9caa511bef93;hb=898b173a182ee37d6e54f5f09284f99a8aef8892;hpb=5a32a1d48f790d5bb63e5e7e70b989cd94692c0a diff --git a/vim/plugin/notmuch.vim b/vim/plugin/notmuch.vim index 8f6c7748..7927dd62 100644 --- a/vim/plugin/notmuch.vim +++ b/vim/plugin/notmuch.vim @@ -110,8 +110,8 @@ let g:notmuch_search_maps = { " --- --- bindings for show screen {{{2 let g:notmuch_show_maps = { - \ '': ':call NM_show_previous(1)', - \ '': ':call NM_show_next(1)', + \ '': ':call NM_show_previous(1, 0)', + \ '': ':call NM_show_next(1, 0)', \ '': ':call NM_search_expand('''')', \ 'q': ':call NM_kill_this_buffer()', \ @@ -276,8 +276,8 @@ function! s:NM_search_edit() endfunction function! s:NM_search_archive_thread() - call NM_add_remove_tags_on_screen('-', ['inbox']) - call NM_add_remove_tags('-', ['inbox']) + call NM_add_remove_tags_on_screen('', '-', ['inbox']) + call NM_add_remove_tags([], '-', ['inbox']) norm j endfunction @@ -370,8 +370,8 @@ function! s:NM_search_add_remove_tags(prompt, prefix, intags) else let tags = a:intags endif - call NM_add_remove_tags(a:prefix, tags) - call NM_add_remove_tags_on_screen(a:prefix, tags) + call NM_add_remove_tags([], a:prefix, tags) + call NM_add_remove_tags_on_screen('', a:prefix, tags) endfunction " --- implement show screen {{{1 @@ -399,49 +399,56 @@ function! s:NM_cmd_show(words) endfunction -function! s:NM_show_previous(can_change_thread) +function! s:NM_show_previous(can_change_thread, find_matching) let info = b:nm_raw_info let lnum = line('.') for msg in reverse(copy(info['msgs'])) + if a:find_matching && msg['match'] == '0' + continue + endif if lnum <= msg['start'] continue endif - exec printf('norm %dG', msg['start']) + exec printf('norm %dGzt', msg['start']) " TODO: try to fit the message on screen - norm zz return endfor if !a:can_change_thread return endif call NM_kill_this_buffer() - if line('.') != line('0') + if line('.') > 1 norm k call NM_search_show_thread() norm G - call NM_show_previous(0) + call NM_show_previous(0, a:find_matching) else echo 'No more messages.' endif endfunction -function! s:NM_show_next(can_change_thread) +function! s:NM_show_next(can_change_thread, find_matching) let info = b:nm_raw_info let lnum = line('.') for msg in info['msgs'] + if a:find_matching && msg['match'] == '0' + continue + endif if lnum >= msg['start'] continue endif - exec printf('norm %dG', msg['start']) + exec printf('norm %dGzt', msg['start']) " TODO: try to fit the message on screen - norm zz return endfor - if !a:can_change_thread - return + if a:can_change_thread + call NM_show_next_thread() endif +endfunction + +function! s:NM_show_next_thread() call NM_kill_this_buffer() if line('.') != line('$') norm j @@ -459,10 +466,6 @@ function! s:NM_show_mark_read_then_archive_thread() echo 'not implemented' endfunction -function! s:NM_show_next_message() - echo 'not implemented' -endfunction - function! s:NM_show_mark_read_then_next_open_message() echo 'not implemented' endfunction @@ -845,26 +848,31 @@ function! s:NM_search_expand(arg) let b:nm_prev_bufnr = prev_bufnr endfunction -function! s:NM_add_remove_tags(prefix, tags) - let id = NM_search_thread_id() - if id == '' +function! s:NM_add_remove_tags(filter, prefix, tags) + let filter = len(a:filter) ? a:filter : [NM_search_thread_id()] + if !len(filter) echoe 'Eeek! I couldn''t find the thead id!' endif + echo 'filter = ' . string(filter) . ' ... ' . string(type(filter)) call map(a:tags, 'a:prefix . v:val') " TODO: handle errors - call NM_run(['tag'] + a:tags + ['--', id]) + let args = ['tag'] + call extend(args, a:tags) + call add(args, '--') + call extend(args, filter) + echo 'NUM_run( ' . string(args) . ' )' + call NM_run(args) endfunction -function! s:NM_add_remove_tags_on_screen(prefix, tags) - let online = '' +function! s:NM_add_remove_tags_on_screen(online, prefix, tags) setlocal modifiable if a:prefix == '-' for tagname in a:tags - exec printf('silent %ss/(\([^)]*\)\<%s\>\([^)]*\))$/(\1\2)/', online, tagname) + exec printf('silent! %ss/(\([^)]*\)\<%s\>\([^)]*\))$/(\1\2)/', string(a:online), tagname) endfor else for tagname in a:tags - exec printf('silent %ss/(\([^)]*\)\([^)]*\))$/(\1 %s)/', online, tagname) + exec printf('silent! %ss/(\([^)]*\)\([^)]*\))$/(\1 %s)/', string(a:online), tagname) endfor endif setlocal nomodifiable