From 65955a32398e67d8049989a1a23d391bfe830840 Mon Sep 17 00:00:00 2001 From: somini Date: Sat, 23 Jun 2018 17:45:14 +0100 Subject: [PATCH 1/4] Use the correct Fugitive API (cherry picked from commit 0127bbb5ae5c2fcc1e54d455179246f81c6c5927) --- plugin/gv.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/gv.vim b/plugin/gv.vim index 672e7f9..5a019a3 100644 --- a/plugin/gv.vim +++ b/plugin/gv.vim @@ -249,7 +249,7 @@ function! s:list(fugitive_repo, log_opts) let git_args = ['log'] + default_opts + a:log_opts let git_log_cmd = call(a:fugitive_repo.git_command, git_args, a:fugitive_repo) - let repo_short_name = fnamemodify(substitute(a:fugitive_repo.dir(), '[\\/]\.git[\\/]\?$', '', ''), ':t') + let repo_short_name = fnamemodify(a:fugitive_repo.tree(), ':t') let bufname = repo_short_name.' '.join(a:log_opts) silent exe (bufexists(bufname) ? 'buffer' : 'file') fnameescape(bufname) From 99e1c46eacb8deb651c87328301ab106f50ee537 Mon Sep 17 00:00:00 2001 From: Farhan Mustar Date: Tue, 23 Feb 2021 00:20:22 +0800 Subject: [PATCH 2/4] Update to use existing tab and clear buffer before update. --- plugin/gv.vim | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/plugin/gv.vim b/plugin/gv.vim index 5a019a3..bd0cefc 100644 --- a/plugin/gv.vim +++ b/plugin/gv.vim @@ -190,8 +190,13 @@ function! s:maps() xmap [[ogv endfunction -function! s:setup(git_dir, git_origin) - call s:tabnew() +function! s:setup(bufname, git_dir, git_origin) + let winid = s:find_winid(a:bufname) + if winid != -1 + call win_gotoid(winid) + else + call s:tabnew() + endif call s:scratch() if exists('g:fugitive_github_domains') @@ -211,14 +216,29 @@ function! s:setup(git_dir, git_origin) let b:git_dir = a:git_dir endfunction +function! s:find_winid(bufname) + let bufid = buffer_number(a:bufname) + let winid = -1 + if bufid != -1 + let winidlist = win_findbuf(bufid) + if !empty(winidlist) + let winid = winidlist[0] + endif + endif + return winid +endfunction + function! s:scratch() setlocal buftype=nofile bufhidden=wipe noswapfile nomodeline endfunction function! s:fill(cmd) setlocal modifiable + let cursor_line = line('.') + silent normal! gg"_dG silent execute 'read' escape('!'.a:cmd, '%') normal! gg"_dd + execute cursor_line setlocal nomodifiable endfunction @@ -244,14 +264,12 @@ function! s:log_opts(fugitive_repo, bang, visual, line1, line2) return [['--graph'], []] endfunction -function! s:list(fugitive_repo, log_opts) +function! s:list(bufname, fugitive_repo, log_opts) let default_opts = ['--color=never', '--date=short', '--format=%cd %h%d %s (%an)'] let git_args = ['log'] + default_opts + a:log_opts let git_log_cmd = call(a:fugitive_repo.git_command, git_args, a:fugitive_repo) - let repo_short_name = fnamemodify(a:fugitive_repo.tree(), ':t') - let bufname = repo_short_name.' '.join(a:log_opts) - silent exe (bufexists(bufname) ? 'buffer' : 'file') fnameescape(bufname) + silent exe (bufexists(a:bufname) ? 'buffer' : 'file') fnameescape(a:bufname) call s:fill(git_log_cmd) setlocal nowrap tabstop=8 cursorline iskeyword+=# @@ -354,8 +372,11 @@ function! s:gv(bang, visual, line1, line2, args) abort let [opts1, paths1] = s:log_opts(fugitive_repo, a:bang, a:visual, a:line1, a:line2) let [opts2, paths2] = s:split_pathspec(gv#shellwords(a:args)) let log_opts = opts1 + opts2 + paths1 + paths2 - call s:setup(git_dir, fugitive_repo.config('remote.origin.url')) - call s:list(fugitive_repo, log_opts) + let repo_short_name = fnamemodify(fugitive_repo.tree(), ':t') + let bufname = repo_short_name.' '.join(log_opts) + + call s:setup(bufname, git_dir, fugitive_repo.config('remote.origin.url')) + call s:list(bufname, fugitive_repo, log_opts) call FugitiveDetect(@#) endif catch From 0dc9e2f0ab07a30e945037e0ce24151b992235cc Mon Sep 17 00:00:00 2001 From: Farhan Mustar Date: Tue, 23 Feb 2021 00:28:47 +0800 Subject: [PATCH 3/4] Refactor code. --- plugin/gv.vim | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugin/gv.vim b/plugin/gv.vim index bd0cefc..fd59eba 100644 --- a/plugin/gv.vim +++ b/plugin/gv.vim @@ -218,14 +218,14 @@ endfunction function! s:find_winid(bufname) let bufid = buffer_number(a:bufname) - let winid = -1 - if bufid != -1 - let winidlist = win_findbuf(bufid) - if !empty(winidlist) - let winid = winidlist[0] - endif + if bufid == -1 + return -1 + endif + let winidlist = win_findbuf(bufid) + if empty(winidlist) + return -1 endif - return winid + return winidlist[0] endfunction function! s:scratch() From a1519fc9fb2137f3c54bf01d19d2775c19acd462 Mon Sep 17 00:00:00 2001 From: Farhan Mustar Date: Sun, 7 Mar 2021 23:09:58 +0800 Subject: [PATCH 4/4] Update use winsaveview to get current windows state, fix only restore cursor line position. --- plugin/gv.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/gv.vim b/plugin/gv.vim index fd59eba..34c11a4 100644 --- a/plugin/gv.vim +++ b/plugin/gv.vim @@ -234,11 +234,11 @@ endfunction function! s:fill(cmd) setlocal modifiable - let cursor_line = line('.') + let win_state = winsaveview() silent normal! gg"_dG silent execute 'read' escape('!'.a:cmd, '%') normal! gg"_dd - execute cursor_line + call winrestview(win_state) setlocal nomodifiable endfunction