Skip to content

Commit

Permalink
Fix error of autocommands
Browse files Browse the repository at this point in the history
Previously all autocommands of the used autocommandgroup where removed
which causes several side effects. Now a flag is used to determine if
the autocommands of this plugin should be executed or not
  • Loading branch information
mantiz committed Jan 25, 2012
1 parent 5401081 commit 2f9b10d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 42 deletions.
29 changes: 23 additions & 6 deletions autoload/dirsettings.vim
Expand Up @@ -20,12 +20,29 @@
"
" Author: Christian Hammerl <info@christian-hammerl.de>
"
function!dirsettings#init(event, ...)
let fname = a:0 > 0 ? a:1 : '.vimdir'
let augroup = a:0 > 1 ? a:2 : 'dirsettings'
execute 'autocmd! ' . augroup
call dirsettings#load(fname)
execute 'doautocmd ' . a:event . ' *'

let s:dirsettings_performing_autocommand = 0

function! dirsettings#install(...)
let s:fname = a:0 > 0 ? a:1 : '.vimdir'
let s:augroup = a:0 > 1 ? a:2 : 'dirsettings'

execute 'augroup ' . s:augroup
au BufNewFile * call dirsettings#init('BufNewFile', s:fname)
au BufEnter * call dirsettings#init('BufEnter', s:fname)
augroup END
endfunction

function! dirsettings#init(event, fname)
try
if (s:dirsettings_performing_autocommand == 0)
let s:dirsettings_performing_autocommand = 1
call dirsettings#load(a:fname)
execute 'doautocmd ' . a:event . ' <buffer>'
endif
finally
let s:dirsettings_performing_autocommand = 0
endtry
endfunction

function! dirsettings#load(fname, ...)
Expand Down
29 changes: 0 additions & 29 deletions plugin/dirsettings.vim

This file was deleted.

23 changes: 16 additions & 7 deletions readme.rst
Expand Up @@ -17,20 +17,29 @@ With pathogen:

git clone <github-url> ./dirsettings.git

2. Create a symbolic link to the autoload vimscript provided by this package::

ln -s <path-of-this-package>/autoload/dirsettings.vim ~/.vim/autoload/

Or copy the provided autoload vimscript into your autoload directory::

cp <path-of-this-package>/autoload/dirsettings.vim ~/.vim/autoload/

2. Add the following content at the top of your ``.vimrc`` (if you want to be
able to modify the runtimepath before pathogen is invoked, it is important
that this statement is executed before ``pathogen#infect`` is executed)::

execute 'source ' . expand("<sfile>:p:h") . '/../bundle/dirsettings.git/plugin/dirsettings.vim'
call dirsettings#install()

The plugin places two autocommands (``BufNewFile, BufEnter``) with the
autocommand group `dirsettings`. It calls an internally used function to load
directory specific settings, deletes all autocommands of the group dirsettings
and recalls the event (``BufNewFile or BufEnter``) which then calls other
defined autocommands. This is because this has to be included at the very first
in your ``.vimrc``. These autocommands should be the very first which get
executed, otherwise it could happen that previously defined autocommands are
called twice.
directory specific settings, and sets a flag for the own autocommands so that
they are not executed twice which would result in an endless recursion. After
the flag was set, the current event is recalled which resets the flag (for
another event) and calls all other defined autocommands. This is because this
has to be included at the very first in your ``.vimrc``. These autocommands
should be the very first which get executed, otherwise it could happen that
previously defined autocommands are called twice.

===========
``.vimdir``
Expand Down

0 comments on commit 2f9b10d

Please sign in to comment.