[PATCH] Fwd: Determining whether a window used :lcd

2007-04-11 Thread Bob Hiestand

The attached patch very simply implements the following from the todo:

7   There is no way to change directory and go back without changing the local
   and/or global directory.  Add a way to find out if the current window uses
   a local directory.  Add cdcmd() that returns ":cd" or ":lcd"?

I personally would prefer the function be called something like 'isdirlocal()'.

I need this feature for my vcscommand.vim plugin, which changes
directory a fair amount, and can screw up the user environment if the
user makes use of :lcd.

Thank you,

bob


-- Forwarded message --
From: Bob Hiestand <[EMAIL PROTECTED]>
Date: Apr 11, 2007 4:06 PM
Subject: Re: Determining whether a window used :lcd
To: Yakov Lerner <[EMAIL PROTECTED]>
Cc: "vim@vim.org" 


On 4/11/07, Yakov Lerner <[EMAIL PROTECTED]> wrote:

I needed this once in of my script. I ended with some rude
simplification/workaround, lackng the direct simple solution.
I don't know your specific case, but you might find simlpistic workaround.

One weird attempt to determine this would be to (I did not do it):
  (1) get getcwd() in the window in quiestion
  (2) create temp new window with :new
  (3)  get getcwd() in the new temp window
  (4) compare cwd from step (3) against cwd from step(1)
  (5) :bw the temp window
This has lots of drawcacks:
- I am not sure this sequence works in the presence of :acd thought.
- I am not sure this sequence works at all, but I can't think of other
method either.
- This sequence won't detect one subtle case: case the :lcd is set, but is set
to directory X where X is same as current directory. (This case behaves
differently that case without  :lcd, but this difference might not
matter to you).


I don't think it works.  When you use :new, you inherit the :lcd, if
it was used.


Maybe vim needs new functions getlcwd(), hetgcwd(), or additional 2nd
param to getcwd() to return global/local dir.


After looking in the :help todo, it appears that others have requested
it.  I've thrown together a quick patch to implement the described
'cdcmd()' (I prefer a more direct 'isdirlocal()'), but that's fine.
I'll try submitting it.

Thank you,

bob


cdcmd.patch
Description: Binary data


Re: [PATCH] Determining whether a window used :lcd

2007-04-20 Thread Bob Hiestand

On 4/11/07, Bob Hiestand <[EMAIL PROTECTED]> wrote:

The attached patch very simply implements the following from the todo:

7   There is no way to change directory and go back without changing the local
and/or global directory.  Add a way to find out if the current window uses
a local directory.  Add cdcmd() that returns ":cd" or ":lcd"?

I personally would prefer the function be called something like 'isdirlocal()'.

I need this feature for my vcscommand.vim plugin, which changes
directory a fair amount, and can screw up the user environment if the
user makes use of :lcd.


Does anyone have any feedback on this?

Thank you,

bob


cdcmd.patch
Description: Binary data


Re: [PATCH] Determining whether a window used :lcd

2007-04-23 Thread Bob Hiestand

On 4/20/07, Bram Moolenaar <[EMAIL PROTECTED]> wrote:


It was still in my pile of messages to read.


I apologize for my impatience.


I agree that a different function would be more useful.  I prefer
haslocaldir().  This would return zero when the current window uses the
global directory, one when it has a local directory.  Later we could add
an argument for selecting the window.

If you agree, and nobody has something to say on this, can you change
your patch?


Done.  Please see attached.


haslocaldir.patch
Description: Binary data


Re: [PATCH] Determining whether a window used :lcd

2007-04-23 Thread Bob Hiestand

> I agree that a different function would be more useful.  I prefer
> haslocaldir().  This would return zero when the current window uses the
> global directory, one when it has a local directory.  Later we could add
> an argument for selecting the window.
>
> If you agree, and nobody has something to say on this, can you change
> your patch?

Done.  Please see attached.


On a patch that adds a builtin function, should I alter
runtime/syntax/vim.vim as well to recognize that function?  The
comment under the function syntax keyword specification indicates that
it is auto-generated, so I left it alone.

Thank you,

bob


Re: [PATCH] Determining whether a window used :lcd

2007-04-24 Thread Bob Hiestand

On 4/23/07, Nikolai Weibull <[EMAIL PROTECTED]> wrote:

> > The attached patch very simply implements the following from the todo:
Wait!  I have a comment!  Isn't this todo just a subset of

6   Add ":cdprev": go back to the previous directory.  Need to remember a
stack of previous directories.  We also need ":cdnext".


Not at all.  This patch merely exposes some information about the
current cd/lcd functionality.  It does not provide new directory
changing stack capability.

Thank you,

bob


Re: [PATCH] Determining whether a window used :lcd

2007-04-25 Thread Bob Hiestand

On 4/25/07, Nikolai Weibull <[EMAIL PROTECTED]> wrote:

> Not at all.  This patch merely exposes some information about the
> current cd/lcd functionality.  It does not provide new directory
> changing stack capability.

You misunderstand.  Isn't the functionality requested in "your" todo
entry just a subset of the one above?  I mean, can't the functionality
that your todo entry adds be made available with the addition of a
directory stack?


No, I understand your question, but I don't see any relationship, at
all, between the two items.  Adding current directory stacks has
nothing to do with allowing introspection of the state of a window
variable.  The two changes are completely orthogonal.

That said, for the purpose of my needs, I would be happy if I could
temporarily override the current directory of a window without having
to worry whether the directory was local or global.  An implementation
of either todo would be therefore sufficient for my plugin; I chose to
address the more obvious lacking functionality instead of adding
entirely new functionality.

Thank you,

bob


Re: [PATCH] Determining whether a window used :lcd

2007-04-25 Thread Bob Hiestand

On 4/25/07, Nikolai Weibull <[EMAIL PROTECTED]> wrote:


OK, I guess then I don't understand your todo entry and Yakov's need for it.


I should clarify, it is my need, and I have no idea who added the
todo.  I found it while trying to discern if the functionality I
needed was provided already.


The todo entry is

   There is no way to change directory and go back without changing the local
   and/or global directory.  Add a way to find out if the current window uses
   a local directory.  Add cdcmd() that returns ":cd" or ":lcd"?

I guess I'm just confused about how the first two sentences relate.
Ah, the first sentence is simply a statement that really has very
little to do with the actual todo entry.


True.


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.

In either case, I have adversely and unexpectedly altered the environment.

The patch as it stands lets me check to see if the current window has
a local directory, and therefore which version of the change directory
command to use.

Thank you,

bob


Re: [PATCH] Determining whether a window used :lcd

2007-04-26 Thread Bob Hiestand

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