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:

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.  haslocaldir() has the
advantage of (imo) being simpler.

Thank you,

bob

Reply via email to