X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=vim%2Fplugin%2Fnotmuch.vim;h=dfa4c432faca9d12c8693063f5ec2382e45fc862;hp=9e5ee39a9fa1daaa817b52bcfd71ad04bcca32f4;hb=9e3cc68875602c72109c2e27ba07a193865560fd;hpb=75ae11ebd222cbbc19817be0cc6998cb6b1456d4 diff --git a/vim/plugin/notmuch.vim b/vim/plugin/notmuch.vim index 9e5ee39a..dfa4c432 100644 --- a/vim/plugin/notmuch.vim +++ b/vim/plugin/notmuch.vim @@ -90,8 +90,8 @@ let g:notmuch_search_maps = { " --- --- bindings for show screen {{{2 let g:notmuch_show_maps = { - \ '': ':call NM_show_prev()', - \ '': ':call NM_show_next()', + \ '': ':call NM_show_previous(1)', + \ '': ':call NM_show_next(1)', \ 'q': ':call NM_kill_this_buffer()', \ \ 'b': ':call NM_show_fold_toggle(''b'', ''bdy'', !g:notmuch_show_fold_bodies)', @@ -123,11 +123,8 @@ function! s:NM_cmd_search(words) let cmd = cmd + ['--sort=oldest-first'] endif let data = s:NM_run(cmd + a:words) - "let data = substitute(data, '27/27', '25/27', '') - "let data = substitute(data, '\[4/4\]', '[0/4]', '') let lines = split(data, "\n") let disp = copy(lines) - "call map(disp, 'substitute(v:val, "^thread:\\S* ", "", "")' ) call map(disp, 's:NM_cmd_search_fmtline(v:val)') call NM_newBuffer('search', join(disp, "\n")) @@ -189,11 +186,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']) - " TODO: this could be made better and more generic - setlocal modifiable - s/(\([^)]*\)\\([^)]*\))$/(\1\2)/ - setlocal nomodifiable norm j endfunction @@ -272,21 +266,12 @@ function! s:NM_search_add_remove_tags(prompt, prefix, intags) if !strlen(text) return endif - call NM_add_remove_tags(a:prefix, split(text, ' ')) + let tags = split(text, ' ') else - call NM_add_remove_tags(a:prefix, a:intags) - endif - call NM_search_refresh_view() -endfunction - -function! s:NM_add_remove_tags(prefix, tags) - let id = NM_search_find_thread_id() - if id == '' - echoe 'Eeek! I couldn''t find the thead id!' + let tags = a:intags endif - call map(a:tags, 'a:prefix . v:val') - " TODO: handle errors - call NM_run(['tag'] + a:tags + ['--', id]) + call NM_add_remove_tags(a:prefix, tags) + call NM_add_remove_tags_on_screen(a:prefix, tags) endfunction " --- implement show screen {{{1 @@ -313,26 +298,56 @@ function! s:NM_cmd_show(words) endfunction -function! s:NM_show_prev() - echoe "not implemented" +function! s:NM_show_previous(can_change_thread) + let info = b:nm_raw_info + let lnum = line('.') + for msg in reverse(copy(info['msgs'])) + if lnum <= msg['start'] + continue + endif + + exec printf('norm %dG', 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') + norm k + call NM_search_show_thread() + norm G + call NM_show_previous(0) + else + echo 'No more messages.' + endif endfunction -function! s:NM_show_next() +function! s:NM_show_next(can_change_thread) let info = b:nm_raw_info let lnum = line('.') - let cnt = 0 for msg in info['msgs'] - let cnt = cnt + 1 if lnum >= msg['start'] continue endif exec printf('norm %dG', msg['start']) + " TODO: try to fit the message on screen norm zz return endfor - norm qj - call NM_search_show_thread() + if !a:can_change_thread + return + endif + call NM_kill_this_buffer() + if line('.') != line('$') + norm j + call NM_search_show_thread() + else + echo 'No more messages.' + endif endfunction function! s:NM_show_archive_thread() @@ -450,8 +465,10 @@ function! s:NM_cmd_show_parse(inlines) elseif mode_type == 'cit' if part_end || match(line, g:notmuch_show_citation_regexp) == -1 let outlnum = len(info['disp']) - let foldinfo = [ mode_type, mode_start, outlnum-1, - \ printf('[ %d-line citation. Press "c" to show. ]', outlnum - mode_start) ] + if mode_start != outlnum + let foldinfo = [ mode_type, mode_start, outlnum-1, + \ printf('[ %d-line citation. Press "c" to show. ]', outlnum - mode_start) ] + endif let mode_type = '' endif elseif mode_type == 'sig' @@ -459,8 +476,10 @@ function! s:NM_cmd_show_parse(inlines) if (outlnum - mode_start) > g:notmuch_show_signature_lines_max let mode_type = '' elseif part_end - let foldinfo = [ mode_type, mode_start, outlnum, - \ printf('[ %d-line signature. Press "s" to show. ]', outlnum - mode_start) ] + if mode_start != outlnum + let foldinfo = [ mode_type, mode_start, outlnum-1, + \ printf('[ %d-line signature. Press "s" to show. ]', outlnum - mode_start) ] + endif let mode_type = '' endif endif @@ -514,7 +533,7 @@ function! s:NM_cmd_show_parse(inlines) let hdr_start = msg['hdr_start']+1 let hdr_end = len(info['disp']) let foldinfo = [ 'hdr', hdr_start, hdr_end, - \ printf('[ %d-line headers. Press "h" to show. ]', hdr_end - hdr_start) ] + \ printf('[ %d-line headers. Press "h" to show. ]', hdr_end + 1 - hdr_start) ] let msg['header'] = hdr let in_header = 0 let hdr = {} @@ -628,8 +647,15 @@ endfunction function! s:NM_run(args) let cmd = g:notmuch_cmd . ' ' . join(a:args) . '< /dev/null' + + let start = reltime() let out = system(cmd) - if v:shell_error + let err = v:shell_error + let delta = reltime(start) + + echo printf('[%s] {%s} %s', reltimestr(delta), string(err), string(cmd)) + + if err echohl Error echo substitute(out, '\n*$', '', '') echohl None @@ -656,6 +682,31 @@ function! s:NM_kill_this_buffer() endif endfunction +function! s:NM_add_remove_tags(prefix, tags) + let id = NM_search_find_thread_id() + if id == '' + echoe 'Eeek! I couldn''t find the thead id!' + endif + call map(a:tags, 'a:prefix . v:val') + " TODO: handle errors + call NM_run(['tag'] + a:tags + ['--', id]) +endfunction + +function! s:NM_add_remove_tags_on_screen(prefix, tags) + let online = '' + setlocal modifiable + if a:prefix == '-' + for tagname in a:tags + exec printf('silent %ss/(\([^)]*\)\<%s\>\([^)]*\))$/(\1\2)/', online, tagname) + endfor + else + for tagname in a:tags + exec printf('silent %ss/(\([^)]*\)\([^)]*\))$/(\1 %s)/', online, tagname) + endfor + endif + setlocal nomodifiable +endfunction + " --- process and set the defaults {{{1 function! NM_set_defaults(force) @@ -691,9 +742,12 @@ endif " --- assign keymaps {{{1 function! s:NM_set_map(maps) + nmapclear for [key, code] in items(a:maps) exec printf('nnoremap %s %s', key, code) endfor + " --- this is a hack for development :) + nnoremap ,nmr :source ~/.vim/plugin/notmuch.vim:call NotMuch('') endfunction " --- command handler {{{1 @@ -724,8 +778,4 @@ endfunction command! -nargs=* -complete=customlist,CompleteNotMuch NotMuch call NotMuch() cabbrev notmuch =(getcmdtype()==':' && getcmdpos()==1 ? 'NotMuch' : 'notmuch') -" --- hacks, only for development :) {{{1 - -nnoremap ,nmr :source ~/.vim/plugin/notmuch.vim:call NotMuch('') - " vim: set ft=vim ts=8 sw=8 et foldmethod=marker :