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

Re: Feature request: enable undo after reloading file

Expand Messages
  • Andy Wokula
    ... You can try a workaround with ... au FileChangedShell * call DiffSync() func! DiffSync() :DiffOrig vert new set buftype=nofile read # 0delete _ diffthis
    Message 1 of 9 , Nov 4, 2007
    • 0 Attachment
      Alexei Alexandrov schrieb:
      > Hi,
      >
      > I'd like to request a feature in Vim which would be useful not very often but
      > is very important I think.
      >
      > Usually I don't lose information in Vim. You can undo things, you can restore
      > the file from a backup etc. There is only one situation which led me to
      > information loss several times. This situation happens when I have a file with
      > modifications opened in Vim and then I also change this file by accident
      > outside of Vim. In this case Vim shows a message box with 2 buttons: reload
      > file or don't reload file. Several times I pressed "reload file" by accident.
      > And my changes in Vim were lost! Undo didn't work after that.
      >
      > I don't know if it's difficult to implement but it would be great if undo
      > worked after such reload. And this would be useful not only for "by accident"
      > cases - I could also press "reload" just to see what those external changes are
      > and then undo if I don't need them.
      >
      > P.S. Persistent undo would be great too. :)

      You can try a workaround with
      :h DiffOrig
      :h FileChangedShell

      au FileChangedShell * call DiffSync()

      func! DiffSync()
      " :DiffOrig
      vert new
      set buftype=nofile
      read #
      0delete _
      diffthis
      wincmd p
      diffthis

      wincmd p
      %diffput
      close

      diffoff
      endfunc

      Diffing against the changed file on disk adds the changes to the undo
      history.

      When writing the file you'll get a
      WARNING: The file has been changed since reading it!!!
      of course -- the function does not reload the file.

      As :h FileChangedShell states:
      | NOTE: The commands must not change the current
      | buffer, jump to another buffer or delete a
      | buffer. *E246*

      Trying the function I didn't get any errors though.

      --
      Andy


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Bram Moolenaar
      ... I ll put it in the todo list. However, don t expect it soon. I think the only right way to implement it is to do a diff between the buffer text and the
      Message 2 of 9 , Nov 4, 2007
      • 0 Attachment
        Alexei Alexandrov wrote:

        > I'd like to request a feature in Vim which would be useful not very often but
        > is very important I think.
        >
        > Usually I don't lose information in Vim. You can undo things, you can restore
        > the file from a backup etc. There is only one situation which led me to
        > information loss several times. This situation happens when I have a file with
        > modifications opened in Vim and then I also change this file by accident
        > outside of Vim. In this case Vim shows a message box with 2 buttons: reload
        > file or don't reload file. Several times I pressed "reload file" by accident.
        > And my changes in Vim were lost! Undo didn't work after that.
        >
        > I don't know if it's difficult to implement but it would be great if undo
        > worked after such reload. And this would be useful not only for "by accident"
        > cases - I could also press "reload" just to see what those external changes are
        > and then undo if I don't need them.

        I'll put it in the todo list. However, don't expect it soon. I think
        the only right way to implement it is to do a diff between the buffer
        text and the file that is to be loaded. The difference would then be
        stored as a change in the undo buffer.

        > P.S. Persistent undo would be great too. :)

        That's already in the todo list.

        --
        From "know your smileys":
        :~) A man with a tape recorder up his nose

        /// 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 ///

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_dev" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Andy Wokula
        ... Already there (todo.txt from 2007 Oct 30) as well: 8 See :e as a change operation, find the changes and add them to the undo info. Needed for when an
        Message 3 of 9 , Nov 4, 2007
        • 0 Attachment
          Bram Moolenaar schrieb:
          >
          > Alexei Alexandrov wrote:
          >
          >> I'd like to request a feature in Vim which would be useful not very often but
          >> is very important I think.
          >>
          >> Usually I don't lose information in Vim. You can undo things, you can restore
          >> the file from a backup etc. There is only one situation which led me to
          >> information loss several times. This situation happens when I have a file with
          >> modifications opened in Vim and then I also change this file by accident
          >> outside of Vim. In this case Vim shows a message box with 2 buttons: reload
          >> file or don't reload file. Several times I pressed "reload file" by accident.
          >> And my changes in Vim were lost! Undo didn't work after that.
          >>
          >> I don't know if it's difficult to implement but it would be great if undo
          >> worked after such reload. And this would be useful not only for "by accident"
          >> cases - I could also press "reload" just to see what those external changes are
          >> and then undo if I don't need them.
          >
          > I'll put it in the todo list. However, don't expect it soon. I think
          > the only right way to implement it is to do a diff between the buffer
          > text and the file that is to be loaded. The difference would then be
          > stored as a change in the undo buffer.

          Already there (todo.txt from 2007 Oct 30) as well:

          8 See ":e" as a change operation, find the changes and add them to the
          undo info. Needed for when an external tool changes the file.

          >> P.S. Persistent undo would be great too. :)
          >
          > That's already in the todo list.

          --
          Andy

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_dev" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Alexei Alexandrov
          ... Yes, this would be the most correct way. It is also not very easy to implement perhaps? ... I know actually - this is why the smile is there. Just making
          Message 4 of 9 , Nov 4, 2007
          • 0 Attachment
            On 11/4/07, Bram Moolenaar <Bram@...> wrote:
            >
            > I'll put it in the todo list. However, don't expect it soon. I think
            > the only right way to implement it is to do a diff between the buffer
            > text and the file that is to be loaded. The difference would then be
            > stored as a change in the undo buffer.

            Yes, this would be the most correct way. It is also not very easy to
            implement perhaps?

            >
            > > P.S. Persistent undo would be great too. :)
            >
            > That's already in the todo list.
            >
            I know actually - this is why the smile is there. Just making sure you
            know people need this feature :)

            --
            Alexei Alexandrov

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_dev" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • Bram Moolenaar
            ... It probably needs to depend on an external diff program. That s both a bit unreliable (esp. on MS-Windows where executing external programs is not simple)
            Message 5 of 9 , Nov 5, 2007
            • 0 Attachment
              Alexei Alexandrov wrote:

              > On 11/4/07, Bram Moolenaar <Bram@...> wrote:
              > >
              > > I'll put it in the todo list. However, don't expect it soon. I think
              > > the only right way to implement it is to do a diff between the buffer
              > > text and the file that is to be loaded. The difference would then be
              > > stored as a change in the undo buffer.
              >
              > Yes, this would be the most correct way. It is also not very easy to
              > implement perhaps?

              It probably needs to depend on an external diff program. That's both a
              bit unreliable (esp. on MS-Windows where executing external programs is
              not simple) and can be slow.

              I once looked into including diff code into Vim, but could only find
              code that is relatively complicated. If someone knows a nice,
              well-behaving, small diff algorithm implementation in C that would help
              a lot.

              --
              From "know your smileys":
              O:-) Saint

              /// 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 ///

              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_dev" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • James Longstreet
              ... It s a bit messy from first glance, but I was able to find some MIT-licensed diff code in C: http://www.ioplex.com/~miallen/libmba/dl/src/diff.c
              Message 6 of 9 , Nov 5, 2007
              • 0 Attachment
                On 11/5/07, Bram Moolenaar <Bram@...> wrote:
                > I once looked into including diff code into Vim, but could only find
                > code that is relatively complicated. If someone knows a nice,
                > well-behaving, small diff algorithm implementation in C that would help
                > a lot.

                It's a bit messy from first glance, but I was able to find some
                MIT-licensed diff code in C:
                http://www.ioplex.com/~miallen/libmba/dl/src/diff.c

                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_dev" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • Fan Decheng
                ... Hehe, a workaround: choose OK rather than Load . When you are ready to reload it, use :e . -- Fan Decheng dtsfan@citiz.net
                Message 7 of 9 , Nov 6, 2007
                • 0 Attachment
                  Alexei Alexandrov wrote:
                  > Hi,
                  >
                  > I'd like to request a feature in Vim which would be useful not very often but
                  > is very important I think.
                  >
                  > Usually I don't lose information in Vim. You can undo things, you can restore
                  > the file from a backup etc. There is only one situation which led me to
                  > information loss several times. This situation happens when I have a file with
                  > modifications opened in Vim and then I also change this file by accident
                  > outside of Vim. In this case Vim shows a message box with 2 buttons: reload
                  > file or don't reload file. Several times I pressed "reload file" by accident.
                  > And my changes in Vim were lost! Undo didn't work after that.
                  >
                  > I don't know if it's difficult to implement but it would be great if undo
                  > worked after such reload. And this would be useful not only for "by accident"
                  > cases - I could also press "reload" just to see what those external changes are
                  > and then undo if I don't need them.
                  >
                  > P.S. Persistent undo would be great too. :)
                  >
                  >
                  > >
                  >
                  >
                  >
                  Hehe, a workaround: choose "OK" rather than "Load". When you are ready
                  to reload it, use :e .

                  --
                  Fan Decheng
                  dtsfan@...



                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_dev" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • Bram Moolenaar
                  ... Thanks. This indeed looks short enough to include in Vim, and the MIT license is permissive. Now we need someone to integrate this with Vim. Volunteer?
                  Message 8 of 9 , Nov 6, 2007
                  • 0 Attachment
                    James Longstreet wrote:

                    > On 11/5/07, Bram Moolenaar <Bram@...> wrote:
                    > > I once looked into including diff code into Vim, but could only find
                    > > code that is relatively complicated. If someone knows a nice,
                    > > well-behaving, small diff algorithm implementation in C that would help
                    > > a lot.
                    >
                    > It's a bit messy from first glance, but I was able to find some
                    > MIT-licensed diff code in C:
                    > http://www.ioplex.com/~miallen/libmba/dl/src/diff.c

                    Thanks. This indeed looks short enough to include in Vim, and the MIT
                    license is permissive.

                    Now we need someone to integrate this with Vim. Volunteer?
                    The result should be that diff mode works faster and more reliable.
                    This means we don't need ":diffupdate" much.

                    And later we could use it to do this undo-after-file-load feature.

                    --
                    Warning label on a superhero Halloween costume:
                    "Caution: Cape does not enable user to fly."

                    /// 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 ///

                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_dev" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  Your message has been successfully submitted and would be delivered to recipients shortly.