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

[patch] Persistent Undo

Expand Messages
  • Jordan Lewis
    This patch implements persistent undo. It is against SVN revision 1365. I d like to submit it to the list to see what people think. More specifically, here are
    Message 1 of 4 , Feb 20 1:20 PM
    • 0 Attachment
      This patch implements persistent undo. It is against SVN revision
      1365. I'd like to submit it to the list to see what people think.

      More specifically, here are the changes:
      1. Added commands :wundo and :rundo that write and read undo files
      respectively. An undo file is a binary file that contains an undo
      tree. One of these will exist for every file whose undo tree is saved.
      2. Added 'undofile'/'udf' option that toggles automatic undo file
      writing and reading. If a file's checksum changed since the last time
      it had an undo file written for it, Vim will silently (or loudly, with
      verbose > 0) ignore the undo file when editing the file.
      3. Added 'undodir'/'udir' option that defines a list of directories in
      which to save the undo files. I copied the per-OS default values for
      this option based on the swapfile 'dir' option.
      4. Added simple crc32 checksum based on the crc32 crypto in misc2.c
      and a function to checksum a buffer.
      5. Made the get2c, get3c, and get4c functions in spell.c not static
      since they were useful to me. Perhaps these belong in one of the
      misc.c files now?
      6. Added calls to u_wundo and u_rundo where files get written/read if
      undofile is set. It seems like I had to put these calls in too many
      places, perhaps there is a better place for them?

      To test it, you'll need to:
      1. set the 'undofile' or 'udf' option in your .vimrc
      2. mkdir .vim/undo, or set undodir to something else and mkdir it
      3. change a file, :wq, reload, and your undo tree should be loaded


      Things to note:
      1. I have only tested this patch on Linux (32- and 64-bit) and OS X
      machines.
      2. If the checksum of a file changes in between edits, the patch will
      not load the undo file. A message will get displayed about this if
      your verbose is greater than 0.
      3. The undo files are saved in a binary format. I have put some simple
      safety checks in the unserialization function, but if you edit the
      undo file, there is a high likelihood that Vim will choke.
      4. I didn't give error numbers to the new error messages I defined. I
      suspect that this is important, but I wasn't sure how the numbering
      scheme works.


      Known bug:
      If you edit a file inside of a zip archive and save changes, Vim will
      segfault when you re-edit it later and it tries to load the undofile.
      I suspect this is because Vim seems to have two different types of
      canonical name for files within zip archives, and the undo file
      mechanism somehow mismatches these representations. I am unfamiliar
      with the mechanics of Vim's zip file support, so I thought I would ask
      the list for advice on how to fix this issue.


      Comments and suggestions would be greatly appreciated.

      - Jordan Lewis


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Andreas Bernauer
      Hi Jordan, just my thoughts: ... Why do you use checksum? For large files, this could take very long. How about mtime or some other timestamp of the
      Message 2 of 4 , Feb 23 2:51 AM
      • 0 Attachment
        Hi Jordan,

        just my thoughts:

        Jordan Lewis wrote:
        > 2. Added 'undofile'/'udf' option that toggles automatic undo file
        > writing and reading. If a file's checksum changed since the last time
        > it had an undo file written for it, Vim will silently (or loudly, with
        > verbose > 0) ignore the undo file when editing the file.

        Why do you use checksum? For large files, this could take very long. How about
        mtime or some other timestamp of the filesystem?

        Is it possible to exclude some files from undo saving?

        > Things to note:
        > 3. The undo files are saved in a binary format. I have put some simple
        > safety checks in the unserialization function, but if you edit the
        > undo file, there is a high likelihood that Vim will choke.

        Reasoning for using a binary format? If the undo file is shared between systems
        that use different binary representation, things will probably go havoc.

        Without having looked into it, I guess the undo parts contain text that has been
        undone plus some extra information such as location and time, all of which could
        be represented in a text format.

        Cheers,

        --
        Andreas.

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_dev" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Jordan Lewis
        ... Good point, aside from some kind of rare race condition it seems like using mtime would offer only advantages over checksumming. I ll try to make this
        Message 3 of 4 , Feb 27 3:28 PM
        • 0 Attachment
          On Feb 23, 4:51 am, Andreas Bernauer <vim-de...@...> wrote:
          > > 2. Added 'undofile'/'udf' option that toggles automatic undo file  
          > > writing and reading. If a file's checksum changed since the last time  
          > > it had an undo file written for it, Vim will silently (or loudly, with  
          > > verbose > 0) ignore the undo file when editing the file.
          >
          > Why do you use checksum? For large files, this could take very long. How about
          > mtime or some other timestamp of the filesystem?

          Good point, aside from some kind of rare race condition it seems like
          using mtime would offer only advantages over checksumming. I'll try to
          make this change sometime soon and resubmit the patch.

          > Is it possible to exclude some files from undo saving?

          I was thinking that there could be an option containing a list of
          filename patterns that would cause undo saves not to happen, a la
          cvsignore.

          > Reasoning for using a binary format?

          I designed the file format in an ad-hoc fashion, and it is a lot
          easier to simply write out numbers than to convert everything into
          strings, and design a nice format, etc. Some (possibly negligible)
          advantages to using a binary format:

          1. No need to do difficult parsing or include an XML library or
          anything.
          2. No difficulties with an 'end-of-string' marker heuristic: can just
          use a null byte instead of having to pick a marker and hack to make
          sure that no one can accidentally include it in their text file
          3. Smaller files
          4. Swap files and spell files are already in a binary format, so it
          shouldn't come as a surprise for people to see a new one.

          On the other hand, it would be nice to have a human-readable format.

          > If the undo file is shared between systems
          > that use different binary representation, things will probably go havoc.

          Yep, probably.

          > Without having looked into it, I guess the undo parts contain text that has been
          > undone plus some extra information such as location and time, all of which could
          > be represented in a text format.

          There's significantly more metadata than just the things that you
          mentioned, but yes, it would probably be possible to represent the
          file textually.



          - Jordan
          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_dev" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Jordan Lewis
          ... to ... I ve replaced the checksum operation with a simple mtime check. This allowed me to remove the extra checksumming functions I wrote from misc2.c.
          Message 4 of 4 , Mar 1, 2009
          • 0 Attachment
            On Feb 27, 5:28 pm, Jordan Lewis <jordanthele...@...> wrote:
            > Good point, aside from some kind of rare race condition it seems like
            > using mtime would offer only advantages over checksumming. I'll try
            to
            > make this change sometime soon and resubmit the patch.

            I've replaced the checksum operation with a simple mtime check. This
            allowed me to remove the extra checksumming functions I wrote from
            misc2.c.

            This patch is now against SVN revision 1390.


            --~--~---------~--~----~------------~-------~--~----~
            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.