Skip to content

Commit

Permalink
Auto-close magit buffer/window on clean state
Browse files Browse the repository at this point in the history
Option is by default false

fix #132
  • Loading branch information
jreybert committed Nov 6, 2017
1 parent 8a54c76 commit 54a428a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,14 @@ or a hunk is staged/unstaged).
Default value is 1.
> let g:magit_refresh_gitgutter=[01]
#### g:magit_auto_close

When set to 1, magit buffer automatically closes after a commit if there is
nothing else to stage (which means that both Staged and Unstaged sections are
empty).
Default value is 0.
> let g:magit_auto_close=[01]
## Requirements

This part must be refined, I don't see any minimal version for git and vim, but for sure there should be one.
Expand Down
7 changes: 7 additions & 0 deletions doc/vimagit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,13 @@ or a hunk is staged/unstaged).
Default value is 1.
let g:magit_refresh_gitgutter=[01]

*vimagit-g:magit_auto_close*
When set to 1, magit buffer automatically closes after a commit if there is
nothing else to stage (which means that both Staged and Unstaged sections are
empty).
Default value is 0.
let g:magit_auto_close=[01]

===============================================================================
6. FAQ *vimagit-FAQ*

13 changes: 13 additions & 0 deletions plugin/magit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ let g:magit_enabled = get(g:, 'magit_enabled',
let g:magit_show_help = get(g:, 'magit_show_help', 0)
let g:magit_default_show_all_files = get(g:, 'magit_default_show_all_files', 1)
let g:magit_default_fold_level = get(g:, 'magit_default_fold_level', 1)
let g:magit_auto_close = get(g:, 'magit_auto_close', 0)
let g:magit_auto_foldopen = get(g:, 'magit_auto_foldopen', 1)
let g:magit_default_sections = get(g:, 'magit_default_sections', ['info', 'global_help', 'commit', 'staged', 'unstaged'])
let g:magit_discard_untracked_do_delete = get(g:, 'magit_discard_untracked_do_delete', 0)
Expand Down Expand Up @@ -374,6 +375,7 @@ function! s:mg_git_commit(mode) abort
let b:magit_current_commit_mode=''
let b:magit_current_commit_msg=[]
endif
let b:magit_just_commited = 1
endfunction

" s:mg_select_file_block: select the whole diff file, relative to the current
Expand Down Expand Up @@ -593,6 +595,15 @@ function! magit#update_buffer(...)

call b:state.update()

if ( g:magit_auto_close == 1 &&
\ b:magit_just_commited == 1 &&
\ empty(b:state.get_filenames('staged')) &&
\ empty(b:state.get_filenames('unstaged')) )
let b:magit_just_commited = 0
call magit#close_magit()
return
endif

for section in g:magit_default_sections
try
let func = s:mg_display_functions[section]
Expand Down Expand Up @@ -798,6 +809,8 @@ function! magit#show_magit(display, ...)

let b:magit_diff_context=3

let b:magit_just_commited = 0

call magit#utils#setbufnr(bufnr(buffer_name))
call magit#sign#init()

Expand Down

0 comments on commit 54a428a

Please sign in to comment.