diff --git a/README.md b/README.md index 62d5d177b226039148d4bf6e689b5da51c6b1064..703b78f7da3b3c1655dc8f231cf89349b39ec4f4 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,9 @@ Following mappings are set locally, for magit buffer only, in normal mode. ##### CF * Amend the staged changes into the previous commit, without modifying previous commit message. +##### CU + * Close a commit section (If you need soon after open or editing commit message, pressing 'u' is good enough). + ##### I * Add the file under the cursor in .gitgnore diff --git a/doc/vimagit.txt b/doc/vimagit.txt index 144e49e42f1c6212a0a31e2b635f4e9c319ed622..94115a6f4007e4237ca25c382fe9954943851785 100644 --- a/doc/vimagit.txt +++ b/doc/vimagit.txt @@ -236,6 +236,11 @@ Following mappings are set locally, for magit buffer only, in normal mode. CF Amend the staged changes into the previous commit, without modifying previous commit message + *vimagit-CU* *magit#close_commit()* + *vimagit-g:magit_close_commit_mapping* + CU Close a commit section (If you need soon after open or editing + Ucommit message, pressing 'u' is good enough). + *vimagit-I* *magit#ignore_file()* *vimagit-g:magit_ignore_mapping* I Add the file under the cursor in .gitgnore diff --git a/plugin/magit.vim b/plugin/magit.vim index aa57aa3d4c1763fdd01f0583817a2898f24bcca6..243a1800646e1cc115c88444c1f315fc432a6c7c 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -27,6 +27,7 @@ let g:magit_discard_hunk_mapping = get(g:, 'magit_discard_hunk_mapping', let g:magit_commit_mapping = get(g:, 'magit_commit_mapping', 'CC' ) let g:magit_commit_amend_mapping = get(g:, 'magit_commit_amend_mapping', 'CA' ) let g:magit_commit_fixup_mapping = get(g:, 'magit_commit_fixup_mapping', 'CF' ) +let g:magit_close_commit_mapping = get(g:, 'magit_close_commit_mapping', 'CU' ) let g:magit_reload_mapping = get(g:, 'magit_reload_mapping', 'R' ) let g:magit_ignore_mapping = get(g:, 'magit_ignore_mapping', 'I' ) let g:magit_close_mapping = get(g:, 'magit_close_mapping', 'q' ) @@ -661,6 +662,7 @@ function! magit#show_magit(display, ...) execute "nnoremap <buffer> <silent> " . g:magit_commit_mapping . " :call magit#commit_command('CC')<cr>" execute "nnoremap <buffer> <silent> " . g:magit_commit_amend_mapping . " :call magit#commit_command('CA')<cr>" execute "nnoremap <buffer> <silent> " . g:magit_commit_fixup_mapping . " :call magit#commit_command('CF')<cr>" + execute "nnoremap <buffer> <silent> " . g:magit_close_commit_mapping . " :call magit#close_commit()<cr>" execute "nnoremap <buffer> <silent> " . g:magit_ignore_mapping . " :call magit#ignore_file()<cr>" execute "nnoremap <buffer> <silent> " . g:magit_close_mapping . " :call magit#close_magit()<cr>" execute "nnoremap <buffer> <silent> " . g:magit_toggle_help_mapping . " :call magit#toggle_help()<cr>" @@ -926,6 +928,24 @@ function! magit#commit_command(mode) call magit#update_buffer() endfunction +" magit#close_commit: cancel for commit mode +" close commit section if opened +function! magit#close_commit() + if ( b:magit_current_commit_mode == '' ) + return + endif + + let git_dir=magit#git#git_dir() + let commit_editmsg=git_dir . 'COMMIT_EDITMSG' + if ( filereadable(commit_editmsg) ) + let commit_msg=s:mg_get_commit_msg() + call writefile(commit_msg, commit_editmsg) + endif + + let b:magit_current_commit_mode='' + call magit#update_buffer() +endfunction + " magit#jump_hunk: function to jump among hunks " it closes the current fold (if any), jump to next hunk and unfold it " param[in] dir: can be 'N' (for next) or 'P' (for previous)