On Fri, May 17, 2013 at 3:28 PM, Bram Moolenaar wrote:
>
> Xavier de Gaye wrote:
>
>> 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")
>
> OK, but we want this to work without any commands being used in a
> script. It should be done when initalizing Python.This is what I meant. The attached patch does this. A new directory named 'python' is added to the vim runtime files. This directory contains at the moment a _vim_python.py file that is imported when initalizing Python after the python directory pathname has been added to sys.path. _vim_python.py is meant to contain (or to import the other components of) the python part of the vim-python interface. -- 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.
os_chdir.diff
Description: Binary data
