On 4/26/07, Bob Hiestand <[EMAIL PROTECTED]> wrote:
On 4/26/07, Nikolai Weibull <[EMAIL PROTECTED]> wrote:
> > > Either way, wouldn't it be more useful to alter getcwd() to take an
> > > optional argument stating whether we want the local or global cwd?
>
> > The problem is that my plugin needs to change the current working
> > directory, perform an action, and then restore the previous working
> > directory.  I need to know whether to use :lcd or :cd to do that.  If
> > I use :cd in a window that had previously used :lcd, then I clobbered
> > the :lcd usage and that window is now stuck to the global directory;
> > additionally, the global directory is changed to whatever the prior
> > value.  If I instead use :lcd always, and the window wasn't previously
> > using a local directory, it now is.
>
> let saved_cwd = getcwd('local')
> let cd_cmd = (saved_cwd != getcwd('global')) ? 'lcd' : 'cd'
> exec cd_cmd '…'
> ⋮
> exec cd_cmd saved_cwd
>
> (assuming getcwd('local') returns the local directory, if there is
> one, or whatever getcwd('global') would, if not.)

While, again, that functionality would suit my plugin's need, I can't
help but feel that that's a pretty inefficient way of checking
compared to:

As in, what, perhaps 8 ms instead of 6 ms?

let cd_cmd = haslocaldir() ? 'lcd' : 'cd'

In the larger picture, I don't know why you'd want to distinguish
between local and global directory normally, other than to determine
the correct ':l?cd' to use, so I don't think that specifying a
parameter to getcwd() to be very useful.

Say that you want to change the local directory to the global directory:

:exec 'cd' getcwd('local')

haslocaldir() has the advantage of (imo) being simpler.

And the disadvantage of being incredibly specific, adding another
function, and more documentation.

And still, wouldn't it be a lot cleaner to have something like
:pushd/:popd for a directory stack.  Then one could write

:pushd ...
⋮
:popd

That way one can easily change directories and later get back to the
state one was in.

It would have to keep track of global and local changes somehow, but
that shouldn't be impossible.

 nikolai

Reply via email to