]> git.notmuchmail.org Git - notmuch/blobdiff - vim/plugin/notmuch.vim
don't fold single lines
[notmuch] / vim / plugin / notmuch.vim
index 2ddc8160417b5552e77274c057d8819474e658e6..09df1ed9aea3e5ca8a15d6aba755e1264482a662 100644 (file)
@@ -189,11 +189,8 @@ function! s:NM_search_edit()
 endfunction
 
 function! s:NM_search_archive_thread()
+        call <SID>NM_add_remove_tags_on_screen('-', ['inbox'])
         call <SID>NM_add_remove_tags('-', ['inbox'])
-        " TODO: this could be made better and more generic
-        setlocal modifiable
-        s/(\([^)]*\)\<inbox\>\([^)]*\))$/(\1\2)/
-        setlocal nomodifiable
         norm j
 endfunction
 
@@ -272,21 +269,12 @@ function! s:NM_search_add_remove_tags(prompt, prefix, intags)
                 if !strlen(text)
                         return
                 endif
-                call <SID>NM_add_remove_tags(a:prefix, split(text, ' '))
+                let tags = split(text, ' ')
         else
-                call <SID>NM_add_remove_tags(a:prefix, a:intags)
+                let tags = a:intags
         endif
-        call <SID>NM_search_refresh_view()
-endfunction
-
-function! s:NM_add_remove_tags(prefix, tags)
-        let id = <SID>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 <SID>NM_run(['tag'] + a:tags + ['--', id])
+        call <SID>NM_add_remove_tags(a:prefix, tags)
+        call <SID>NM_add_remove_tags_on_screen(a:prefix, tags)
 endfunction
 
 " --- implement show screen {{{1
@@ -480,8 +468,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'
@@ -658,8 +648,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
@@ -686,6 +683,31 @@ function! s:NM_kill_this_buffer()
         endif
 endfunction
 
+function! s:NM_add_remove_tags(prefix, tags)
+        let id = <SID>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 <SID>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)