Loading ...
Sorry, an error occurred while loading the content.

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

Expand Messages
  • 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
    Message 1 of 13 , Apr 11, 2007
    • 0 Attachment
      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 <bob.hiestand@...>
      Date: Apr 11, 2007 4:06 PM
      Subject: Re: Determining whether a window used :lcd
      To: Yakov Lerner <iler.ml@...>
      Cc: "vim@..." <vim@...>


      On 4/11/07, Yakov Lerner <iler.ml@...> 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
    • Bob Hiestand
      ... Does anyone have any feedback on this? Thank you, bob
      Message 2 of 13 , Apr 20, 2007
      • 0 Attachment
        On 4/11/07, Bob Hiestand <bob.hiestand@...> 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
      • Bram Moolenaar
        ... 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
        Message 3 of 13 , Apr 20, 2007
        • 0 Attachment
          Bob Hiestand wrote:

          > On 4/11/07, Bob Hiestand <bob.hiestand@...> 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 -- Bram@... -- 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 ///
        • Bob Hiestand
          ... I apologize for my impatience. ... Done. Please see attached.
          Message 4 of 13 , Apr 23, 2007
          • 0 Attachment
            On 4/20/07, Bram Moolenaar <Bram@...> 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.
          • Bob Hiestand
            ... 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
            Message 5 of 13 , Apr 23, 2007
            • 0 Attachment
              > > 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
            • Nikolai Weibull
              ... 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
              Message 6 of 13 , Apr 23, 2007
              • 0 Attachment
                On 4/20/07, Bram Moolenaar <Bram@...> wrote:

                > On 4/11/07, Bob Hiestand <bob.hiestand@...> 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
              • Bram Moolenaar
                ... Great thanks. Good to see a patch with documentation updates! -- A)bort, R)etry, B)ang it with a large hammer /// Bram Moolenaar -- Bram@Moolenaar.net --
                Message 7 of 13 , Apr 24, 2007
                • 0 Attachment
                  Bob Hiestand wrote:

                  > On 4/20/07, Bram Moolenaar <Bram@...> 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 -- Bram@... -- 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 ///
                • Bram Moolenaar
                  ... 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,
                  Message 8 of 13 , Apr 24, 2007
                  • 0 Attachment
                    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 -- Bram@... -- 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 ///
                  • Bob Hiestand
                    ... 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
                    Message 9 of 13 , Apr 25, 2007
                    • 0 Attachment
                      On 4/25/07, Nikolai Weibull <now@...> 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
                    • Bob Hiestand
                      ... 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
                      Message 10 of 13 , Apr 25, 2007
                      • 0 Attachment
                        On 4/25/07, Nikolai Weibull <now@...> 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
                      • Nikolai Weibull
                        ... 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
                        Message 11 of 13 , Apr 26, 2007
                        • 0 Attachment
                          On 4/25/07, Bob Hiestand <bob.hiestand@...> wrote:

                          > On 4/25/07, Nikolai Weibull <now@...> 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
                        • Bob Hiestand
                          ... 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
                          Message 12 of 13 , Apr 26, 2007
                          • 0 Attachment
                            On 4/26/07, Nikolai Weibull <now@...> 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
                          • Nikolai Weibull
                            ... As in, what, perhaps 8 ms instead of 6 ms? ... And the disadvantage of being incredibly specific, adding another function, and more documentation. And
                            Message 13 of 13 , Apr 26, 2007
                            • 0 Attachment
                              On 4/26/07, Bob Hiestand <bob.hiestand@...> wrote:
                              > On 4/26/07, Nikolai Weibull <now@...> 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
                            Your message has been successfully submitted and would be delivered to recipients shortly.