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

Suggestion: Rewind-mode instead of undo-tree

Expand Messages
  • David Schweikert
    Hi, We did speak about implementing a undo-tree in the Vim 7 BOF at the SANE 2004 conference and I tried to explain one possible simplified interface that
    Message 1 of 8 , Sep 30 5:30 AM
      Hi,

      We did speak about implementing a "undo-tree" in the Vim 7 BOF at the
      SANE 2004 conference and I tried to explain one possible simplified
      interface that could be a way to do it. Here is a better explanation and
      some refinement that I worked out later:

      1. The Problem

      Sometimes I use undo to see how I did some work that I then changed
      later. Usually I then copy a paragraph and go forward again with redo,
      so that I can put that paragraph in the current version.

      If I make a mistake and do a change before the redo, I loose all the
      changes that I did since then. That can be pretty bad.

      This could be solved by having a "undo-tree" functionality (whishlist
      #15), which would not discard the old branch when making a change while
      traversing the undo tree.

      Implementing that is pretty easy, since you just need to store the
      undo actions in a tree instead of a list. The problematic part is how to
      use it. How to let the user know that he is on a branching point, how
      choose an alternative, etc. It can get pretty confusing.

      2. Rewind mode

      My proposal is as follows: instead of implementing an interface to
      navigate the undo tree, simply implement a special "rewind" (or
      "time-shift") mode, which walks the history backwards showing what was
      in the buffer before, independently of undo or redo actions. For
      example, if I type:

      iaaa <esc>
      ibbb <esc>
      u
      iccc <esc>
      u
      iddd <esc>

      Then in in rewind-mode, every time I press the rewind-key, I would get :

      0: aaa ddd
      1: aaa
      2: aaa ccc
      3: aaa
      4: aaa bbb
      5: aaa

      3. Possible implementation

      It could be implemented for example by having a separate undo list,
      (let's call it the rewind list), which records the undo and redo actions
      as forwarding-going changes. Nothing gets deleted from that list.

      What if you do a change while rewinding? If that is possible, then it's
      just another undo, with the same problems... In order for this to work,
      this shouldn't be allowed. Rewind-mode should allow you to look at the
      past in a read-only mode, so that you can for example copy out what you
      need, without taking branches.

      It would be great to also show in the status bar at which time the
      buffer had this content (and also help give a feeling of "rewinding",
      thus understanding what it is about).

      Such a rewind-mode would solve for me in a satisfactory way the same
      problem that undo-tree would, while keeping a very simple user
      interface. It happens maybe once or twice a year that I need it, it's
      not worth learning a complex interface for it.

      Cheers
      David
      --
      David Schweikert | phone: +41 44 632 7019
      System manager ISG.EE | walk: ETH Zentrum, ETL F24.1
      ETH Zurich, Switzerland | web: http://people.ee.ethz.ch/dws
    • Bram Moolenaar
      ... Thanks for writing this down. ... I think this is not a mode, we need commands to go backward and forward in time. This doesn t change the state of Vim,
      Message 2 of 8 , Oct 2, 2004
        David Schweikert wrote:

        > We did speak about implementing a "undo-tree" in the Vim 7 BOF at the
        > SANE 2004 conference and I tried to explain one possible simplified
        > interface that could be a way to do it. Here is a better explanation and
        > some refinement that I worked out later:

        Thanks for writing this down.

        > Then in in rewind-mode, every time I press the rewind-key, I would get :
        >
        > 0: aaa ddd
        > 1: aaa
        > 2: aaa ccc
        > 3: aaa
        > 4: aaa bbb
        > 5: aaa

        I think this is not a mode, we need commands to go backward and forward
        in time. This doesn't change the state of Vim, only the text.

        We might skip over some parts of the tree when going backward in time,
        especially sequences of undo commands, because they only take you back
        to situations that you have seen before.

        --
        hundred-and-one symptoms of being an internet addict:
        39. You move into a new house and decide to Netscape before you landscape.

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
        \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///
      • David Schweikert
        ... OK. It should be clearly marked in the GUI however, so that the user knows, that it is in this time-shifting or review mode , where he can t change
        Message 3 of 8 , Oct 4, 2004
          On Sat, Oct 02, 2004 at 17:29:48 +0200, Bram Moolenaar wrote:
          > I think this is not a mode, we need commands to go backward and forward
          > in time. This doesn't change the state of Vim, only the text.

          OK. It should be clearly marked in the GUI however, so that the user
          knows, that it is in this time-shifting or review "mode", where he can't
          change anything and can walk backwards and forwards in time.

          > We might skip over some parts of the tree when going backward in time,
          > especially sequences of undo commands, because they only take you back
          > to situations that you have seen before.

          Yes, I agree...

          Cheers
          David
          --
          David Schweikert | phone: +41 44 632 7019
          System manager ISG.EE | walk: ETH Zentrum, ETL F24.1
          ETH Zurich, Switzerland | web: http://people.ee.ethz.ch/dws
        • Bram Moolenaar
          ... But you _can_ make changes. As soon as you do this a new branch in the tree is created. Just like what happens when you make a change after pressing u
          Message 4 of 8 , Oct 4, 2004
            David Schweikert wrote:

            > On Sat, Oct 02, 2004 at 17:29:48 +0200, Bram Moolenaar wrote:
            > > I think this is not a mode, we need commands to go backward and forward
            > > in time. This doesn't change the state of Vim, only the text.
            >
            > OK. It should be clearly marked in the GUI however, so that the user
            > knows, that it is in this time-shifting or review "mode", where he can't
            > change anything and can walk backwards and forwards in time.

            But you _can_ make changes. As soon as you do this a new branch in the
            tree is created. Just like what happens when you make a change after
            pressing "u" a few times. The idea is that you can go back to a
            previous state of the text and continue editing there.

            The only "mode" involved is the position in the undo tree. Like the
            position you get with undo/redo, but measuring in a different way. This
            position is used for the "go to older state" and "go to newer state"
            commands that are to be added.

            --
            hundred-and-one symptoms of being an internet addict:
            61. Your best friends know your e-mail address, but neither your phone number
            nor the address where you live.

            /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
            /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
            \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
            \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///
          • David Schweikert
            ... What s the difference to undo then? I think that in order to implement such a time shifting functionality, it should be forbidden to make changes and thus
            Message 5 of 8 , Oct 4, 2004
              On Mon, Oct 04, 2004 at 10:59:45 +0200, Bram Moolenaar wrote:
              > > OK. It should be clearly marked in the GUI however, so that the user
              > > knows, that it is in this time-shifting or review "mode", where he can't
              > > change anything and can walk backwards and forwards in time.
              >
              > But you _can_ make changes. As soon as you do this a new branch in the
              > tree is created. Just like what happens when you make a change after
              > pressing "u" a few times. The idea is that you can go back to a
              > previous state of the text and continue editing there.

              What's the difference to undo then? I think that in order to implement
              such a time shifting functionality, it should be forbidden to make
              changes and thus create branches, otherwise you have the same problem
              like with undo...

              Let's say it's 17:00 now and you go back to 13:00 with "rewind".
              You make a change... What are you going to see if you press repeatedly
              the 'rewind' key again?

              1. the state of 13:00 plus the change (shown as 17:10)
              2. the state of 17:00
              3. the state of 13:00

              Feasible, but a little bit confusing in my opinion. Maybe you can
              provide a configurable option to force read-only mode when traversing
              the undo tree with rewind (or how you will call it)...

              Cheers
              David
              --
              David Schweikert | phone: +41 44 632 7019
              System manager ISG.EE | walk: ETH Zentrum, ETL F24.1
              ETH Zurich, Switzerland | web: http://people.ee.ethz.ch/dws
            • Edward L. Fox
              It seems to be too expensive comparing with the benefit, in my opinion.
              Message 6 of 8 , Oct 4, 2004
                It seems to be too expensive comparing with the benefit, in my opinion.

                On Mon, 4 Oct 2004 18:05:02 +0200, David Schweikert <dws@...> wrote:
                > On Mon, Oct 04, 2004 at 10:59:45 +0200, Bram Moolenaar wrote:
                > > > OK. It should be clearly marked in the GUI however, so that the user
                > > > knows, that it is in this time-shifting or review "mode", where he can't
                > > > change anything and can walk backwards and forwards in time.
                > >
                > > But you _can_ make changes. As soon as you do this a new branch in the
                > > tree is created. Just like what happens when you make a change after
                > > pressing "u" a few times. The idea is that you can go back to a
                > > previous state of the text and continue editing there.
                >
                > What's the difference to undo then? I think that in order to implement
                > such a time shifting functionality, it should be forbidden to make
                > changes and thus create branches, otherwise you have the same problem
                > like with undo...
                >
                > Let's say it's 17:00 now and you go back to 13:00 with "rewind".
                > You make a change... What are you going to see if you press repeatedly
                > the 'rewind' key again?
                >
                > 1. the state of 13:00 plus the change (shown as 17:10)
                > 2. the state of 17:00
                > 3. the state of 13:00
                >
                > Feasible, but a little bit confusing in my opinion. Maybe you can
                > provide a configurable option to force read-only mode when traversing
                > the undo tree with rewind (or how you will call it)...
                >
                > Cheers
                > David
                > --
                > David Schweikert | phone: +41 44 632 7019
                > System manager ISG.EE | walk: ETH Zentrum, ETL F24.1
                > ETH Zurich, Switzerland | web: http://people.ee.ethz.ch/dws
                >
              • Bram Moolenaar
                ... This part is just like undo. But the states of the text you can go to are different. undo/redo walks one line, from root to the end of one branch, in the
                Message 7 of 8 , Oct 4, 2004
                  David Schweikert wrote:

                  > On Mon, Oct 04, 2004 at 10:59:45 +0200, Bram Moolenaar wrote:
                  > > > OK. It should be clearly marked in the GUI however, so that the user
                  > > > knows, that it is in this time-shifting or review "mode", where he
                  > > > can't change anything and can walk backwards and forwards in time.
                  > >
                  > > But you _can_ make changes. As soon as you do this a new branch in the
                  > > tree is created. Just like what happens when you make a change after
                  > > pressing "u" a few times. The idea is that you can go back to a
                  > > previous state of the text and continue editing there.
                  >
                  > What's the difference to undo then? I think that in order to implement
                  > such a time shifting functionality, it should be forbidden to make
                  > changes and thus create branches, otherwise you have the same problem
                  > like with undo...

                  This part is just like undo. But the states of the text you can go to
                  are different. undo/redo walks one line, from root to the end of one
                  branch, in the undo tree. The "timeshift" commands walk all branches in
                  the undo tree.

                  > Let's say it's 17:00 now and you go back to 13:00 with "rewind".
                  > You make a change... What are you going to see if you press repeatedly
                  > the 'rewind' key again?
                  >
                  > 1. the state of 13:00 plus the change (shown as 17:10)
                  > 2. the state of 17:00
                  > 3. the state of 13:00
                  >
                  > Feasible, but a little bit confusing in my opinion. Maybe you can
                  > provide a configurable option to force read-only mode when traversing
                  > the undo tree with rewind (or how you will call it)...

                  If you go back to the state of 13:00 and you make a new change at 17:00,
                  you get a new state marked with 17:00. Thus this is a new branch,
                  linked to the state at 13:00. If you "undo" you get to the 13.00 state
                  again. If you go back in time, you get to the state before the previous
                  change, which is probably somewhere else.

                  In a picture:

                  12:50
                  / \
                  / \
                  14:00 13:00
                  / / \
                  / / \
                  14:10 13:10 17:00
                  / /
                  / /
                  14:20 13:20

                  Assume you were at 14:20, go back in time to 13:00, then make a
                  change this becomes a new branch 17:00. Using undo to go from 13:20
                  to 13:00 it's exactly the same.

                  Thus when you use "timeshift" commands you can go back in time, and
                  forward again. This remembers the time of the current text state. As
                  soon as you make a change you get a text state with the current time as
                  the timestamp. Thus you can walk from 14:20 to 14:10 ... 13:00 to
                  12:50, each with one "backward" command. Then go forward from 12:50 to
                  13:00 with a "forward" command. If you then make a change you create a
                  new stat 17:00. Now a "backward" command would take you to 14:20. But
                  an undo would take you to 13:00 and then "backward" to 12:50


                  Perhaps it would be useful to set time-marks, in case you want to jump
                  back or forward to a specific text state. That might be complicated
                  though, just remembering the time is a lot simpler.

                  --
                  "Thou shalt not follow the Null Pointer, for at its end Chaos and
                  Madness lie."

                  /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                  /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
                  \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
                  \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///
                • David Schweikert
                  ... I understand now. Thanks for the explanation! Somehow I was stuck on thinking about an implementation with a list instead of a tree and there it would have
                  Message 8 of 8 , Oct 4, 2004
                    On Mon, Oct 04, 2004 at 20:05:04 +0200, Bram Moolenaar wrote:
                    > [ explanation of the timeshift functionality with the undo tree ]

                    I understand now. Thanks for the explanation! Somehow I was stuck on
                    thinking about an implementation with a list instead of a tree and there
                    it would have had some issues. Like you describe it it makes perfect
                    sense to me... I think it would be a great addition to Vim.

                    Maybe you could put some text of your mail in the appriopriate help
                    file: it might help others to understand how it works.

                    > Perhaps it would be useful to set time-marks, in case you want to jump
                    > back or forward to a specific text state. That might be complicated
                    > though, just remembering the time is a lot simpler.

                    Wouldn't such a marker be just a pointer to the corresponding node in
                    the tree? Sounds cool, but maybe not really that useful.

                    Cheers
                    David
                    --
                    David Schweikert | phone: +41 44 632 7019
                    System manager ISG.EE | walk: ETH Zentrum, ETL F24.1
                    ETH Zurich, Switzerland | web: http://people.ee.ethz.ch/dws
                  Your message has been successfully submitted and would be delivered to recipients shortly.