]> git.notmuchmail.org Git - notmuch/blobdiff - vim/plugin/notmuch.vim
vim: fix a case where we started with :NotMuch search
[notmuch] / vim / plugin / notmuch.vim
index e1822a41c241978bb086b43e03734393019f6360..e41daed162a6981759b1b1425fcff9b14a6bc78d 100644 (file)
@@ -254,7 +254,7 @@ function! s:NM_search_prompt()
                 let tags = s:notmuch_initial_search_words_defaults
         endif
         let prev_bufnr = bufnr('%')
-        if b:nm_type == 'search'
+        if b:nm_type == 'search' && exists('b:nm_prev_bufnr')
                 " TODO: we intend to replace the current buffer,
                 "       ... maybe we could just clear it
                 let prev_bufnr = b:nm_prev_bufnr
@@ -351,12 +351,15 @@ function! s:NM_search_thread_id()
         if !exists('b:nm_raw_lines')
                 echoe 'no b:nm_raw_lines'
                 return ''
-        else
-                let line = line('.')
-                let info = b:nm_raw_lines[line-1]
-                let what = split(info, '\s\+')[0]
-                return what
         endif
+        let mnum = line('.') - 1
+        if len(b:nm_raw_lines) <= mnum
+                return ''
+        endif
+        echo 'len=' . string(len(b:nm_raw_lines)) . '  mnum=' . string(mnum)
+        let info = b:nm_raw_lines[mnum]
+        let what = split(info, '\s\+')[0]
+        return what
 endfunction
 
 function! s:NM_search_add_remove_tags(prompt, prefix, intags)
@@ -997,6 +1000,7 @@ function! NotMuch(args)
         if words[0] == 'folders'
                 let words = words[1:]
                 call <SID>NM_cmd_folders(words)
+
         elseif words[0] == 'search'
                 if len(words) > 1
                         let words = words[1:]