Commits

Markus Braun committed 57bdf51

add possibility to modify autocommand event

Comments (0)

Files changed (2)

doc/localvimrc.txt

 Default: ".lvimrc"
 
 ------------------------------------------------------------------------------
+*g:localvimrc_event*
+
+List of autocommand events that trigger local vimrc file loading.
+
+Default: [ "BufWinEnter" ]
+
+NOTE: BufWinEnter is the default to enable lines like
+
+        setlocal colorcolumn=+1
+
+      in the local vimrc file. Settings "local to window" need to be set for
+      every time a buffer is displayed in a window.
+
+------------------------------------------------------------------------------
 *g:localvimrc_reverse*
 
 Reverse behavior of loading local vimrc files.

plugin/localvimrc.vim

   let s:localvimrc_name = g:localvimrc_name
 endif
 
+" define default "localvimrc_event" {{{2
+" copy to script local variable to prevent .lvimrc modifying the name option.
+if (!exists("g:localvimrc_event") || !(type(g:localvimrc_event) == type([])))
+  let s:localvimrc_event = [ "BufWinEnter" ]
+else
+  let s:localvimrc_event = g:localvimrc_event
+endif
+
 " define default "localvimrc_reverse" {{{2
 " copy to script local variable to prevent .lvimrc modifying the reverse
 " option.
   augroup localvimrc
     autocmd!
 
-    " call s:LocalVimRC() when creating ore reading any file
-    autocmd BufWinEnter * call s:LocalVimRC()
+    for event in s:localvimrc_event
+      " call s:LocalVimRC() when creating ore reading any file
+      exec "autocmd ".event." * call s:LocalVimRC()"
+    endfor
   augroup END
 endif