From 46699b1df656171342d50a35ed847311f47e38e8 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Wed, 11 Apr 2018 16:23:43 +0200 Subject: [PATCH] SignifyDiff: initial support for :SignifyDiff Currently this only works for git and is not documented. --- autoload/sy/repo.vim | 40 ++++++++++++++++++++++++++++++++++++++++ plugin/signify.vim | 1 + 2 files changed, 41 insertions(+) diff --git a/autoload/sy/repo.vim b/autoload/sy/repo.vim index 5a1d5eb..08d2362 100644 --- a/autoload/sy/repo.vim +++ b/autoload/sy/repo.vim @@ -244,6 +244,33 @@ function! sy#repo#debug_detection() endfor endfunction +" Function: #diffmode {{{1 +function! sy#repo#diffmode() abort + if !exists('b:sy') + echomsg 'signify: I cannot detect any changes!' + return + endif + let vcs = b:sy.updated_by + if !has_key(g:signify_vcs_cmds_diffmode, vcs) + echomsg 'SignifyDiff has no support for: '. vcs + echomsg 'Open an issue for it at: https://github.com/mhinz/vim-signify/issues' + return + endif + let cmd = s:expand_cmd_diffmode(vcs) + let ft = &filetype + tabedit % + diffthis + leftabove vnew + silent put =system(cmd) + silent 1delete + diffthis + set buftype=nofile bufhidden=wipe nomodified + let &filetype = ft + wincmd p + silent! %foldopen! + normal! ]czt +endfunction + " Function: s:initialize_job {{{1 function! s:initialize_job(vcs) abort let vcs_cmd = s:expand_cmd(a:vcs) @@ -279,6 +306,15 @@ function! s:expand_cmd(vcs) abort return cmd endfunction +" Function: s:expand_cmd_diffmode {{{1 +function! s:expand_cmd_diffmode(vcs) abort + let cmd = g:signify_vcs_cmds_diffmode[a:vcs] + let cmd = s:replace(cmd, '%f', s:get_vcs_path(a:vcs)) + let cmd = s:replace(cmd, '%d', s:difftool) + let cmd = s:replace(cmd, '%n', s:devnull) + return cmd +endfunction + " Function: s:run {{{1 function! s:run(vcs) let [cwd, chdir] = sy#util#chdir() @@ -436,5 +472,9 @@ else let g:signify_vcs_cmds = s:vcs_cmds endif +let g:signify_vcs_cmds_diffmode = { + \ 'git': 'git show HEAD:./%f', + \ } + let s:difftool = sy#util#escape(s:difftool) let s:devnull = has('win32') || has ('win64') ? 'NUL' : '/dev/null' diff --git a/plugin/signify.vim b/plugin/signify.vim index d7d0888..e08316a 100644 --- a/plugin/signify.vim +++ b/plugin/signify.vim @@ -66,6 +66,7 @@ augroup END command! -nargs=0 -bar SignifyList call sy#debug#list_active_buffers() command! -nargs=0 -bar SignifyDebug call sy#repo#debug_detection() command! -nargs=0 -bar -bang SignifyFold call sy#fold#dispatch(1) +command! -nargs=0 -bar SignifyDiff call sy#repo#diffmode() command! -nargs=0 -bar SignifyRefresh call sy#util#refresh_windows() command! -nargs=0 -bar SignifyEnable call sy#enable() command! -nargs=0 -bar SignifyDisable call sy#disable()