On Wed, May 15, 2013 at 8:51 PM, Bram Moolenaar wrote:
>> >":python os.chdir('/tmp')" makes short buffer names invalid. (Xavier de
>> >Gaye)
>> >Check directory and call shorten_fnames()?
>>
>> Probably not only the python problem.
>
> I wonder if there is a hook inside Python, so that we can do the
> equivalent of ":cd" in Vim, handling the side effects.
Indeed, a hook to chdir can be made with the following code in
a module named vim_hook:
########### vim_hook.py ###########
import vim
import os
_chdir = os.chdir
def chdir(path):
_chdir(path)
vim.command("cd " + path)
os.chdir = chdir
###########
This module is imported on vim startup with:
PyRun_SimpleString("import vim_hook");
To test that this fixes os.chdir, run the following commands after
having copied the above vim_hook.py file in the current directory:
:py3 import sys; sys.path[:1] = ['.']; import vim_hook
:py3 import os; os.chdir("/tmp")
Note that we must add the current directory to sys.path in order to be
able to import vim_hook. I believe this is another bug.
--
Xavier
Les Chemins de Lokoti: http://lokoti.alwaysdata.net
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.