[Idle-dev] RE: Current Working Directory

Guido van Rossum guido@python.org
Fri, 30 May 2003 07:56:58 -0400


> [KBK]
> > [me]
> >> mmmm... right now if you have different py scripts
> >> opened in idlefork, next time you open the file
> >> browser the default dir corresponds to the file
> >> being edited. will that change?
> > 
> > Yes, that seems to be the way Windows does it.  Whatever
> > directory you open/save to last becomes the cwd.
> > 
> > This seems to be per application.  i.e. the cwd is local to the app.
> 
> I'm afraid that that would also change directory for
> "Save", "Save As", "Save Copy As" and "Find in Files", right?
> 
> The change you propose sounds good if you only work with one
> file at a time. But suppose you open a python library file
> just for the sake of cheeting some code, you are back
> to your working script and the cwd changed.
> 
> MHO is only change dir per explicit user request.
> Ideally, file operations ("Open", "Save", "Save As",
> "Save Copy As" and "Find in Files") in the Idlefork Shell window
> defaults to the current working directory.
> File operations in Idlefork Editor windows defaults to the
> absolute path of the editing file.
> "Run" operations uses the CWD application wide, of course.
> This picture completes with a "Change Current Dir" menu
> item under "File" (or under "Run"!) menu along with a way
> to see which is it and a "Shell Start Dir" user config option.
> 
> But that's my (an) opinion, NOT a feature request.
> (I haven't thought the case where Idlefork starts without a
> shell window neither)
> 
> regards,
> -Hernan

Here's the model I'd like to see.  It's similar to what Emacs does,
and it works very well for me there.  Each window has a directory
associated with it.  This is normally the directory containing the
file loaded in the window; if a window has no file loaded in it, it
should be the directory of the window from which this window was
created.  E.g. if I'm editing a file /foo/bar.py, and I hit ^N to
create a new window, the new window's directory should be /foo.  The
directory associated with a window should be used as the initial
directory for all Open and Save dialogs.  If you use Save As into a
different directory, the window's directory changes (but not so for
Save A Copy).  All this has nothing to do with the current directory
of the IDLE process itself, which is never changed.  If the initial
window has no file associated with it (e.g. it is a Python Shell
window) then it should be the startup directory of IDLE.

(I think this is pretty much already implemented except for file-less
windows, which seem to inherit IDLE's initial directory.)

The Run command should use the file's directory as the initial cwd of
the subprocess started, and this should also set directory associated
with the Python Shell window where the output is sent.

--Guido van Rossum (home page: http://www.python.org/~guido/)