From 2e4c9236d6a23784ef6980000bee92d8ec74e6d2 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sun, 27 Feb 2011 13:58:05 -0500 Subject: [PATCH] Implement :Gwq --- doc/fugitive.txt | 7 +++++++ plugin/fugitive.vim | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/doc/fugitive.txt b/doc/fugitive.txt index 5a10ba2..39f3dd2 100644 --- a/doc/fugitive.txt +++ b/doc/fugitive.txt @@ -118,6 +118,13 @@ that are part of Git repositories). :0:foo.txt or even :0 to write to just that stage in the index. + *fugitive-:Gwq* +:Gwq [path] Like |:Gwrite| followed by |:quit| if the write + succeeded. + +:Gwq! [path] Like |:Gwrite|! followed by |:quit|! if the write + succeeded. + *fugitive-:Gdiff* :Gdiff [revision] Perform a |vimdiff| against the current file in the given revision. With no argument, the version in the diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 13b6279..4130bb2 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -903,6 +903,8 @@ call s:command("-bar -bang -nargs=? -count -complete=customlist,s:EditComplete G " Gwrite, Gwq {{{1 call s:command("-bar -bang -nargs=? -complete=customlist,s:EditComplete Gwrite :execute s:Write(0,)") +call s:command("-bar -bang -nargs=? -complete=customlist,s:EditComplete Gw :execute s:Write(0,)") +call s:command("-bar -bang -nargs=? -complete=customlist,s:EditComplete Gwq :execute s:Wq(0,)") function! s:Write(force,...) abort if exists('b:fugitive_commit_arguments') @@ -1022,6 +1024,19 @@ function! s:Write(force,...) abort return 'checktime' endfunction +function! s:Wq(force,...) abort + let bang = a:force ? '!' : '' + if exists('b:fugitive_commit_arguments') + return 'wq'.bang + endif + let result = call(s:function('s:Write'),[a:force]+a:000) + if result =~# '^\%(write\|wq\|echoerr\)' + return s:sub(result,'^write','wq') + else + return result.'|quit'.bang + endif +endfunction + " }}}1 " Gdiff {{{1