Skip to content

Commit

Permalink
rework autocommand code, add configuration variable and documentation.
Browse files Browse the repository at this point in the history
embear committed Feb 6, 2017
1 parent 821c2d3 commit 52ecd1e
Showing 3 changed files with 79 additions and 6 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -241,12 +241,31 @@ let g:localvimrc_blacklist=['/share/projects/.*', '/usr/share/other-projects/.*'

- Default: No blacklist

### The `g:localvimrc_autocmd` setting

Emit autocommands |LocalVimRCPre| before and |LocalVimRC| and |LocalVimRCPost|
after sourcing every local vimrc file.

- Default: `1`

### The `g:localvimrc_debug` setting

Debug level for this script.

- Default: `0`

## Autocommands

If enabled localvimrc emits autocommands before and after sourcing an local vimrc file.

### The `LocalVimRCPre` autocommand

This autocommand is emitted right before sourcing each local vimrc file.

### The `LocalVimRC` and `LocalVimRCPost` autocommand

These autocommands are emitted right after sourcing each local vimrc file.

## Contribute

To contact the author (Markus Braun), please send an email to <markus.braun@krawel.de>
@@ -261,6 +280,7 @@ send a pull request or just tell me your ideas.
- Daniel Hahler for various patches
- Justin M. Keyes for ideas to improve this plugin
- Lars Winderling for whitelist/blacklist patch
- Michon van Dooren for autocommands patch

## Changelog

@@ -269,6 +289,7 @@ vX.X.X : XXXX-XX-XX
- |g:localvimrc_whitelist| and |g:localvimrc_blacklist| now takes optionally a list of regular expressions.
- add convenience variables |g:localvimrc_script_unresolved| and |g:localvimrc_script_dir_unresolved|.
- add ability to view local vimrc before sourcing when |g:localvimrc_ask| is enabled.
- emit autocommands before and after sourcing files.

v2.4.0 : 2016-02-05

42 changes: 37 additions & 5 deletions doc/localvimrc.txt
Original file line number Diff line number Diff line change
@@ -27,11 +27,15 @@ Contents ~
8. The |g:localvimrc_persistence_file| setting
9. The |g:localvimrc_whitelist| setting
10. The |g:localvimrc_blacklist| setting
11. The |g:localvimrc_debug| setting
5. Contribute |localvimrc-contribute|
6. Credits |localvimrc-credits|
7. Changelog |localvimrc-changelog|
8. References |localvimrc-references|
11. The |g:localvimrc_autocmd| setting
12. The |g:localvimrc_debug| setting
5. Autocommands |localvimrc-autocommands|
1. The |LocalVimRCPre| autocommand
2. The |LocalVimRC| and |LocalVimRCPost| autocommand
6. Contribute |localvimrc-contribute|
7. Credits |localvimrc-credits|
8. Changelog |localvimrc-changelog|
9. References |localvimrc-references|

===============================================================================
*localvimrc-introduction*
@@ -290,13 +294,38 @@ Example:
<
- Default: No blacklist

-------------------------------------------------------------------------------
The *g:localvimrc_autocmd* setting

Emit autocommands |LocalVimRCPre| before and |LocalVimRC| and |LocalVimRCPost|
after sourcing every local vimrc file.

- Default: '1'

-------------------------------------------------------------------------------
The *g:localvimrc_debug* setting

Debug level for this script.

- Default: '0'

===============================================================================
*localvimrc-autocommands*
Autocommands ~

If enabled localvimrc emits autocommands before and after sourcing an local
vimrc file.

-------------------------------------------------------------------------------
The *LocalVimRCPre* autocommand

This autocommand is emitted right before sourcing each local vimrc file.

-------------------------------------------------------------------------------
The LocalVimRC and *LocalVimRCPost* autocommand

These autocommands are emitted right after sourcing each local vimrc file.

===============================================================================
*localvimrc-contribute*
Contribute ~
@@ -316,6 +345,7 @@ Credits ~
- Daniel Hahler for various patches
- Justin M. Keyes for ideas to improve this plugin
- Lars Winderling for whitelist/blacklist patch
- Michon van Dooren for autocommands patch

===============================================================================
*localvimrc-changelog*
@@ -332,6 +362,8 @@ vX.X.X : XXXX-XX-XX
- add ability to view local vimrc before sourcing when |g:localvimrc_ask| is
enabled.

- emit autocommands before and after sourcing files.

v2.4.0 : 2016-02-05

- add setting |g:localvimrc_event| which defines the autocommand events that
22 changes: 21 additions & 1 deletion plugin/localvimrc.vim
Original file line number Diff line number Diff line change
@@ -126,6 +126,14 @@ else
let s:localvimrc_persistence_file = g:localvimrc_persistence_file
endif

" define default "localvimrc_autocmd" {{{2
" enable emitting of autocommands before and after sourcing a .lvimrc file
if (!exists("g:localvimrc_autocmd"))
let s:localvimrc_autocmd = 1
else
let s:localvimrc_autocmd = g:localvimrc_autocmd
endif

" define default "localvimrc_debug" {{{2
if (!exists("g:localvimrc_debug"))
let g:localvimrc_debug = 0
@@ -471,10 +479,22 @@ function! s:LocalVimRC()
endif
endtry
else
" emit an autocommands before sourcing
if (s:localvimrc_autocmd == 1)
silent doautocmd User LocalVimRCPre
call s:LocalVimRCDebug(1, "pre sourcing autocommand emitted")
endif

" execute the command
exec l:command
call s:LocalVimRCDebug(1, "sourced " . l:rcfile)
silent doautocmd User LocalVimRCSourced

" emit an autocommands after sourcing
if (s:localvimrc_autocmd == 1)
silent doautocmd User LocalVimRCPost
silent doautocmd User LocalVimRC
call s:LocalVimRCDebug(1, "post sourcing autocommand emitted")
endif
endif

" remove global variables again

0 comments on commit 52ecd1e

Please sign in to comment.