Skip to content

Commit

Permalink
add VimagitLeaveCommit User autocmd and add tw example
Browse files Browse the repository at this point in the history
ref #140
  • Loading branch information
jreybert committed Aug 3, 2017
1 parent 38c6d12 commit aabe1b9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ absolute path.
*Note:* `g:magit_last_updated_buffer` will be updated and VimagitUpdateFile event will
be raised only if the buffer is currently opened in vim.

##### VimagitCommitEnter
##### VimagitEnterCommit

This event is raised when the commit section opens and the cursor is
placed in this section. For example, the user may want to go straight into
Expand All @@ -304,6 +304,17 @@ insert mode when committing, defining this autocmd in its vimrc:
autocmd User VimagitEnterCommit startinsert
```

##### VimagitLeaveCommit

This event is raised when the commit section is closed, because the user
finished to write its commit message or canceled it. For example, the user wants
to set the |textwidth| of the vimagit buffer while editing a commit message,
defining these |autocmd| in vimrc:
```
autocmd User VimagitEnterCommit setlocal textwidth=72
autocmd User VimagitLeaveCommit setlocal textwidth=0
```

#### Autocmd example

The following example calls the vim-gitgutter refresh function on a specific
Expand Down
15 changes: 13 additions & 2 deletions doc/vimagit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,26 @@ absolute path.
Note: |g:magit_last_updated_buffer| will be updated and VimagitUpdateFile event will
be raised only if the buffer is currently opened in vim.

VimagitCommitEnter *vimagit-VimagitCommitEnter*
VimagitEnterCommit *vimagit-VimagitEnterCommit*

This event is raised when the commit section opens and the cursor is
placed in this section. For example, the user may want to go straight into
insert mode when committing, defining this |autocmd| in its vimrc:
insert mode when committing, defining this |autocmd| in vimrc:
>
autocmd User VimagitEnterCommit startinsert
<

VimagitLeaveCommit *vimagit-VimagitLeaveCommit*

This event is raised when the commit section is closed, because the user
finished to write its commit message or canceled it. For example, the user
wants to set the |textwidth| of the vimagit buffer while editing a commit
message, defining these |autocmd| in vimrc:
>
autocmd User VimagitEnterCommit setlocal textwidth=72
autocmd User VimagitLeaveCommit setlocal textwidth=0
<

Autocmd example *vimagit-autocmd_example*
---------------

Expand Down
6 changes: 6 additions & 0 deletions plugin/magit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,9 @@ function! magit#commit_command(mode)
" when we do commit, it is prefered ot commit the way we prepared it
" (.i.e normal or amend), whatever we commit with CC or CA.
call <SID>mg_git_commit(b:magit_current_commit_mode)
if exists('#User#VimagitLeaveCommit')
doautocmd User VimagitLeaveCommit
endif
else
let b:magit_current_commit_mode=a:mode
let b:magit_commit_newly_open=1
Expand All @@ -1138,6 +1141,9 @@ function! magit#close_commit()

let b:magit_current_commit_mode=''
let b:magit_current_commit_msg=[]
if exists('#User#VimagitLeaveCommit')
doautocmd User VimagitLeaveCommit
endif
call magit#update_buffer()
endfunction

Expand Down

0 comments on commit aabe1b9

Please sign in to comment.