Re: [PATCH] Determining whether a window used :lcd
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
Bob Hiestand wrote: > 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? It was still in my pile of messages to read. 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? -- The only way the average employee can speak to an executive is by taking a second job as a golf caddie. (Scott Adams - The Dilbert principle) /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net \\\ ///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\download, build and distribute -- http://www.A-A-P.org/// \\\help me help AIDS victims -- http://ICCF-Holland.org///
Re: [PATCH] Determining whether a window used :lcd
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
> 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
On 4/20/07, Bram Moolenaar <[EMAIL PROTECTED]> wrote: 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"? If you agree, and nobody has something to say on this, can you change your patch? 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". with local directory alternatives as well? One could then change directory and simply pop the top of the cd stack when one is done. Of course, this could quite easily be implemented in VimScript if builtin commands could be overridden, like :cd and :lcd. Then one could maintain a stack with a VimScript list. An alternative, seeing as how we've already discussed overriding builtin commands and my side of the argument lost, would be to add a DirectoryChanged autocommand. Then one could at least implement :Cdprev and :Cdnext. I'm probably missing something here, but I can't see what it is. nikolai
Re: [PATCH] Determining whether a window used :lcd
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
Bob Hiestand wrote: > 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. Great thanks. Good to see a patch with documentation updates! -- A)bort, R)etry, B)ang it with a large hammer /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net \\\ ///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\download, build and distribute -- http://www.A-A-P.org/// \\\help me help AIDS victims -- http://ICCF-Holland.org///
Re: [PATCH] Determining whether a window used :lcd
Bob Hiestand wrote: > > > 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. Charles Campbell will send me an updated Vim syntax file later. I don't think this change is important enough to patch it right now. -- A)bort, R)etry, D)o it right this time /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net \\\ ///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\download, build and distribute -- http://www.A-A-P.org/// \\\help me help AIDS victims -- http://ICCF-Holland.org///
Re: [PATCH] Determining whether a window used :lcd
On 4/24/07, Bob Hiestand <[EMAIL PROTECTED]> wrote: 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. 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? nikolai
Re: [PATCH] Determining whether a window used :lcd
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
On 4/25/07, Bob Hiestand <[EMAIL PROTECTED]> wrote: 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. OK, I guess then I don't understand your todo entry and Yakov's need for it. 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. I figured that the todo was about having a way of changing directories and being able to go back. 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? nikolai
Re: [PATCH] Determining whether a window used :lcd
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
On 4/25/07, Bob Hiestand <[EMAIL PROTECTED]> wrote: 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. Ah, Yakov was only suggesting a way of doing it. I realize you didn't add it, I'm just using "your" here to separate it from "mine", that is, the one I suggested could be used for your need. > 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.) nikolai
Re: [PATCH] Determining whether a window used :lcd
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
Re: [PATCH] Determining whether a window used :lcd
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