From b7ea1a1bb227b177da1caf6bee1996b042d993df Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Tue, 6 Aug 2019 00:34:17 +0200 Subject: [PATCH] Add :SignifyPreviewHunk This is merely a first draft that needs to get refined further. --- autoload/sy/repo.vim | 43 +++++++++++++++++++++++++++++++++++++++++++ plugin/signify.vim | 1 + 2 files changed, 44 insertions(+) diff --git a/autoload/sy/repo.vim b/autoload/sy/repo.vim index e5eabee..2685d5f 100644 --- a/autoload/sy/repo.vim +++ b/autoload/sy/repo.vim @@ -61,6 +61,42 @@ function! sy#repo#job_exit_show_signs(bufnr, vcs, exitval, diff) abort call setbufvar(a:bufnr, 'sy_job_id_'.a:vcs, 0) endfunction +" Function: #job_exit_preview_hunk {{{1 +function! sy#repo#job_exit_preview_hunk(_bufnr, _vcs, _exitval, diff) abort + let in_hunk = 0 + let hunk = [] + + for line in a:diff + if in_hunk + if line[:2] == '@@ ' + silent! wincmd P + if !&previewwindow + noautocmd botright new + endif + call setline(1, hunk) + silent! %foldopen! + setlocal previewwindow filetype=diff buftype=nofile bufhidden=delete + noautocmd wincmd p + return + endif + call add(hunk, line) + elseif line[:2] == '@@ ' && s:is_line_in_hunk(line) + let in_hunk = 1 + endif + endfor +endfunction + +function! s:is_line_in_hunk(hunkline) + let curline = line('.') + let [old_line, new_line, old_count, new_count] = sy#sign#parse_hunk(a:hunkline) + + if curline >= new_line && curline <= (new_line + new_count) + return 1 + endif + + return 0 +endfunction + " Function: sy#get_diff_start {{{1 function! sy#repo#get_diff_start(vcs, func) abort call sy#verbose('sy#repoget_diff_start()', a:vcs) @@ -303,6 +339,13 @@ function! sy#repo#diffmode(do_tab) abort normal! ]czt endfunction +" Function: #preview_hunk {{{1 +function! sy#repo#preview_hunk() abort + if exists('b:sy') && has_key(b:sy, 'updated_by') + call sy#repo#get_diff_start(b:sy.updated_by, function('sy#repo#job_exit_preview_hunk')) + endif +endfunction + " Function: s:initialize_job {{{1 function! s:initialize_job(vcs) abort let vcs_cmd = s:expand_cmd(a:vcs, g:signify_vcs_cmds) diff --git a/plugin/signify.vim b/plugin/signify.vim index 3a13442..26e2e2b 100644 --- a/plugin/signify.vim +++ b/plugin/signify.vim @@ -67,6 +67,7 @@ command! -nargs=0 -bar SignifyList call sy#debug#list_active_bu 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 -bang SignifyDiff call sy#repo#diffmode(1) +command! -nargs=0 -bar SignifyPreviewHunk call sy#repo#preview_hunk() 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()