Adding a PwdChanged hook for autocmds

22 weergaven
Naar het eerste ongelezen bericht

Rich Healey

ongelezen,
10 dec 2011, 09:45:5110-12-2011
aan vim...@googlegroups.com
I attempted to add a new hook to the autocmd subsystem to allow me to bind
actions to the current working directory changing.

Attached is my attempt, I also tried patching ex_cd in desperation while it
wasn't working. I think my issue is in the way I'm invoking apply_autocmds, but
this seems to be the right approach. I would appreciate pointers in the right
direction.

Thanks.

Rich

pwd_changed_hook.patch

Bram Moolenaar

ongelezen,
11 dec 2011, 08:45:2211-12-2011
aan Rich Healey, vim...@googlegroups.com

Rich Healey wrote:

The problem with an autocommand like this is that it can perform any Vim
command. Callers of vim_chdir() are most likely not prepared for that
and may use invalid pointers, causing Vim to crash.

There is no generic way to solve this. It requires thinking of all the
nasty things that the autocommand might do and checking that all of them
are handled correctly in all places from where the autocommand can be
triggered. That's tough.

--
"Time flies like an arrow". So I put an arrow on my desk, now
awaiting one of these time flies showing up.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Rich Healey

ongelezen,
11 dec 2011, 08:51:1211-12-2011
aan vim...@googlegroups.com, Rich Healey
I'm not completely sure I understand, (Please forgive my ignorance) the caller of vim_chdir should not be obviously aware of the existance of the hook surely? The actions take place just before returning.

Obviously the user adding a hook to PwdChanged that attempts to invoke :chdir would problematic, but I'm not sure I understand your meaning. I was aware that there was probably a good reason this has not been done before, because it seemed like a very useful feature I was surprised not to find already there.

Finally, my original question may have been poorly phrased, I was posting to the list purely because the hook did not seem to work correctly..

I could add actions with

autocmd PwdChanged call SomeFunction()

And verifiy that they are set with

autocmd PwdChanged

Which seems to imply that the changes to fileio.c and vim.h were all that's required to create the new type, but the actions associated with PwdChanged were never executed. I tried to follow this up by adding a different type of hook to my .vimrc and changing the event called in misc2.c which also did not cause any actions to take place, at which point I became stumped and resorted to posting here.

Thanks for your time, and for vim.

Kent Sibilev

ongelezen,
11 dec 2011, 23:41:3911-12-2011
aan vim...@googlegroups.com
On Sun, Dec 11, 2011 at 8:51 AM, Rich Healey <heale...@gmail.com> wrote:
> I'm not completely sure I understand, (Please forgive my ignorance) the
> caller of vim_chdir should not be obviously aware of the existance of the
> hook surely? The actions take place just before returning.
>
> Obviously the user adding a hook to PwdChanged that attempts to invoke
> :chdir would problematic, but I'm not sure I understand your meaning. I was
> aware that there was probably a good reason this has not been done before,
> because it seemed like a very useful feature I was surprised not to find
> already there.
>

I'm not sure how it's possible to reliably implement this feature
given that I can easily chdir with Vim being unaware , for example:

:ruby Dir.chdir '..'


--
Kent

Allen beantwoorden
Auteur beantwoorden
Doorsturen
0 nieuwe berichten