diff plugin/lawrencium.vim @ 9:82a49134a85c

Added keyboard shortcuts to Hgstatus window.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 12 Dec 2011 10:59:46 -0800
parents 1e155bfa94ad
children 7d16084d40a9
line wrap: on
line diff
--- a/plugin/lawrencium.vim	Sun Dec 11 23:04:36 2011 -0800
+++ b/plugin/lawrencium.vim	Mon Dec 12 10:59:46 2011 -0800
@@ -287,16 +287,15 @@
     nnoremap <buffer> <silent> <C-N> :call search('^[MARC\!\?I ]\s.', 'We')<cr>
     nnoremap <buffer> <silent> <C-P> :call search('^[MARC\!\?I ]\s.','Wbe')<cr>
     nnoremap <buffer> <silent> <cr>  :execute <SID>HgStatus_FileEdit()<cr>
+    nnoremap <buffer> <silent> <C-D> :execute <SID>HgStatus_FileDiff(0)<cr>
+    nnoremap <buffer> <silent> <C-V> :execute <SID>HgStatus_FileDiff(1)<cr>
     nnoremap <buffer> <silent> q     :bdelete<cr>
 endfunction
 
 function! s:HgStatus_FileEdit() abort
-    let l:repo = s:hg_repo()
-    let l:line = getline('.')
-    " Yay, awesome, Vim's regex syntax is fucked up like shit, especially for
-    " look-aheads and look-behinds. See for yourself:
-    let l:filename = matchstr(l:line, '\([MARC\!\?I ]\s\)\@<=.*')
-    let l:filename = l:repo.GetFullPath(l:filename)
+    " Get the path of the file the cursor is on.
+    let l:filename = s:HgStatus_GetSelectedPath()
+    
     " Go back to the previous window and open the file there, or open an
     " existing buffer.
     wincmd p
@@ -307,6 +306,25 @@
     endif
 endfunction
 
+function! s:HgStatus_FileDiff(vertical) abort
+    " Get the path of the file the cursor is on.
+    let l:filename = s:HgStatus_GetSelectedPath()
+    
+    " Go back to the previous window and call HgDiff.
+    wincmd p
+    call s:HgDiff(l:filename, a:vertical)
+endfunction
+
+function! s:HgStatus_GetSelectedPath() abort
+    let l:repo = s:hg_repo()
+    let l:line = getline('.')
+    " Yay, awesome, Vim's regex syntax is fucked up like shit, especially for
+    " look-aheads and look-behinds. See for yourself:
+    let l:filename = matchstr(l:line, '\([MARC\!\?I ]\s\)\@<=.*')
+    let l:filename = l:repo.GetFullPath(l:filename)
+    return l:filename
+endfunction
+
 call s:AddMainCommand("Hgstatus :execute s:HgStatus()")
 
 " }}}