]> git.notmuchmail.org Git - notmuch/blobdiff - vim/plugin/notmuch.vim
vim: don't use scrolloff/sidesscrolloff in notmuch buffers
[notmuch] / vim / plugin / notmuch.vim
index f0106604f081a5a296c126a5157f59feb36c8f36..b4eeb416ce608ad58b31883639d1f8a03bd76141 100644 (file)
@@ -110,8 +110,8 @@ let g:notmuch_search_maps = {
 
 " --- --- bindings for show screen {{{2
 let g:notmuch_show_maps = {
 
 " --- --- bindings for show screen {{{2
 let g:notmuch_show_maps = {
-        \ '<C-P>':      ':call <SID>NM_show_previous(1)<CR>',
-        \ '<C-N>':      ':call <SID>NM_show_next(1)<CR>',
+        \ '<C-P>':      ':call <SID>NM_show_previous(1, 0)<CR>',
+        \ '<C-N>':      ':call <SID>NM_show_next(1, 0)<CR>',
         \ '<C-]>':      ':call <SID>NM_search_expand(''<cword>'')<CR>',
         \ 'q':          ':call <SID>NM_kill_this_buffer()<CR>',
         \
         \ '<C-]>':      ':call <SID>NM_search_expand(''<cword>'')<CR>',
         \ 'q':          ':call <SID>NM_kill_this_buffer()<CR>',
         \
@@ -399,49 +399,56 @@ function! s:NM_cmd_show(words)
 
 endfunction
 
 
 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']))
         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
 
                 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
                 " TODO: try to fit the message on screen
-                norm zz
                 return
         endfor
         if !a:can_change_thread
                 return
         endif
         call <SID>NM_kill_this_buffer()
                 return
         endfor
         if !a:can_change_thread
                 return
         endif
         call <SID>NM_kill_this_buffer()
-        if line('.') != line('0')
+        if line('.') > 1
                 norm k
                 call <SID>NM_search_show_thread()
                 norm G
                 norm k
                 call <SID>NM_search_show_thread()
                 norm G
-                call <SID>NM_show_previous(0)
+                call <SID>NM_show_previous(0, a:find_matching)
         else
                 echo 'No more messages.'
         endif
 endfunction
 
         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']
         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
 
                 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
                 " TODO: try to fit the message on screen
-                norm zz
                 return
         endfor
                 return
         endfor
-        if !a:can_change_thread
-                return
+        if a:can_change_thread
+                call <SID>NM_show_next_thread()
         endif
         endif
+endfunction
+
+function! s:NM_show_next_thread()
         call <SID>NM_kill_this_buffer()
         if line('.') != line('$')
                 norm j
         call <SID>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
 
         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
 function! s:NM_show_mark_read_then_next_open_message()
         echo 'not implemented'
 endfunction
@@ -514,22 +517,25 @@ endfunction
 
 " --- --- show screen helper functions {{{2
 
 
 " --- --- show screen helper functions {{{2
 
+function! s:NM_show_get_message_for_line(line)
+        for msg in b:nm_raw_info['msgs']
+                if a:line > msg['end']
+                        continue
+                endif
+                return msg
+        endfor
+        return {}
+endfunction
+
 function! s:NM_show_message_id()
         if !exists('b:nm_raw_info')
                 echoe 'no b:nm_raw_info'
                 return ''
         endif
 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['end']
-                        continue
-                endif
-                if has_key(msg,'id')
-                        return msg['id']
-                endif
-                return ''
-        endfor
+        let msg = <SID>NM_show_get_message_for_line(line('.'))
+        if has_key(msg,'id')
+                return msg['id']
+        endif
         return ''
 endfunction
 
         return ''
 endfunction
 
@@ -785,6 +791,8 @@ function! s:NM_newBuffer(type, content)
         silent put=a:content
         keepjumps 0d
         setlocal nomodifiable
         silent put=a:content
         keepjumps 0d
         setlocal nomodifiable
+        set scrolloff=0
+        set sidescrolloff=0
         execute printf('set filetype=notmuch-%s', a:type)
         execute printf('set syntax=notmuch-%s', a:type)
         let b:nm_type = a:type
         execute printf('set filetype=notmuch-%s', a:type)
         execute printf('set syntax=notmuch-%s', a:type)
         let b:nm_type = a:type