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.

> 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.

-- 
The Law of VIM:
For each member b of the possible behaviour space B of program P, there exists
a finite time t before which at least one user u in the total user space U of
program P will request b becomes a member of the allowed behaviour space B'
(B' <= B).
In other words: Sooner or later everyone wants everything as an option.
                                        -- Vince Negri

 /// Bram Moolenaar -- [email protected] -- 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    ///

-- 
-- 
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.


Raspunde prin e-mail lui