vim: have ? show details of what's under cursor in search/show views
authorBart Trojanowski <bart@jukie.net>
Sun, 22 Nov 2009 05:29:57 +0000 (00:29 -0500)
committerBart Trojanowski <bart@jukie.net>
Wed, 25 Nov 2009 05:48:54 +0000 (00:48 -0500)
vim/README
vim/plugin/notmuch.vim

index 91fc7a3..ff0828f 100644 (file)
@@ -36,6 +36,7 @@ Buffer types:
             +       - add tag(s) to selected message
             -       - remove tag(s) from selected message
             =       - refresh display
+            ?       - reveal the thread ID of what's under cursor
             ^]      - search using word under cursor
 
     [notmuch-show]
@@ -49,5 +50,6 @@ Buffer types:
             h       - toggle folding of extra header lines
             s       - toggle folding of signatures
             q       - return to search display
+            ?       - reveal the message and thread IDs of what's under cursor
             ^]      - search using word under cursor
 
index 15252d2..e13ea9f 100644 (file)
@@ -104,6 +104,7 @@ let g:notmuch_search_maps = {
         \ '+':          ':call <SID>NM_search_add_tags([])<CR>',
         \ '-':          ':call <SID>NM_search_remove_tags([])<CR>',
         \ '=':          ':call <SID>NM_search_refresh_view()<CR>',
+        \ '?':          ':echo <SID>NM_search_thread_id()<CR>',
         \ }
 
 " --- --- bindings for show screen {{{2
@@ -129,6 +130,7 @@ let g:notmuch_show_maps = {
         \
         \ 'r':          ':call <SID>NM_show_reply()<CR>',
         \ 'm':          ':call <SID>NM_new_mail()<CR>',
+        \ '?':          ':echo <SID>NM_show_thread_id() . '' '' . <SID>NM_show_message_id()<CR>',
         \ }
 
 
@@ -226,7 +228,7 @@ endfunction
 " --- --- search screen action functions {{{2
 
 function! s:NM_search_show_thread()
-        let id = <SID>NM_search_find_thread_id()
+        let id = <SID>NM_search_thread_id()
         if id != ''
                 call <SID>NM_cmd_show([id])
         endif
@@ -324,7 +326,7 @@ endfunction
 
 " --- --- search screen helper functions {{{2
 
-function! s:NM_search_find_thread_id()
+function! s:NM_search_thread_id()
         if !exists('b:nm_raw_lines')
                 echoe 'no b:nm_raw_lines'
                 return ''
@@ -363,6 +365,7 @@ function! s:NM_cmd_show(words)
         setlocal bufhidden=hide
         call <SID>NM_newBuffer('show', join(info['disp'], "\n"))
         setlocal bufhidden=delete
+        let b:nm_words = a:words
         let b:nm_raw_info = info
         let b:nm_prev_bufnr = prev_bufnr
 
@@ -475,7 +478,32 @@ function! s:NM_show_pipe_message()
         echo 'not implemented'
 endfunction
 
-" --- --- search screen helper functions {{{2
+" --- --- show screen helper functions {{{2
+
+function! s:NM_show_thread_id()
+        if !exists('b:nm_words')
+                echoe 'no b:nm_words'
+                return ''
+        endif
+        return b:nm_words[0]
+endfunction
+
+function! s:NM_show_message_id()
+        if !exists('b:nm_raw_info')
+                echoe 'no b:nm_raw_info'
+                return ''
+        endif
+        let info = b:nm_raw_info
+        let lnum = line('.')
+        for msg in info['msgs']
+                if lnum < msg['start']
+                        continue
+                endif
+
+                return msg['id']
+        endfor
+        return ''
+endfunction
 
 function! s:NM_show_fold_toggle(key, type, fold)
         let info = b:nm_raw_info
@@ -766,7 +794,7 @@ function! s:NM_search_expand(arg)
 endfunction
 
 function! s:NM_add_remove_tags(prefix, tags)
-        let id = <SID>NM_search_find_thread_id()
+        let id = <SID>NM_search_thread_id()
         if id == ''
                 echoe 'Eeek! I couldn''t find the thead id!'
         endif