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

Re: Breaking undo in Insert mode

Expand Messages
  • dag.odenhall@gmail.com
    I d like to note that this trick never quite worked anyway. For example if you do i test .uu in a new buffer you end up with two empty lines even
    Message 1 of 18 , Jul 12, 2013

      I'd like to note that this trick never quite worked anyway. For example if you do i"test"<CR><Esc>.uu in a new buffer you end up with two empty lines even though you're at the “oldest” change. This could be another bug with setline(), I suppose.



      On Thu, Jul 11, 2013 at 6:57 PM, Ben Fritz <fritzophrenic@...> wrote:
      On Thursday, July 11, 2013 10:45:16 AM UTC-5, Christian Brabandt wrote:
      > On Thu, July 11, 2013 17:36, Ben Fritz wrote:
      >
      > > On Thursday, July 4, 2013 4:44:26 AM UTC-5, Bram Moolenaar wrote:
      >
      > >>
      >
      > >> Perhaps we can somehow detect that CTRL-R = had the side effect of
      >
      > >>
      >
      > >> changing the text and then split undo.  When it only returns the text to
      >
      > >>
      >
      > >> be inserted, there is no need to split undo.
      >
      > >>
      >
      > >
      >
      > > Even though it won't fix it all the way, I think this is a good idea. It
      >
      > > will make things a lot better at least.
      >
      > >
      >
      > > Then we can do this obviously simplified example without breaking undo:
      >
      > >
      >
      > > inoremap <Space> <C-R>="\<LT>Space>"<CR>
      >
      >
      >
      > Wouldn't in this example CTRL-R= also change the text and therefore break
      >
      > undo here as well?
      >

      It doesn't change the text directly, it only returns a value.

      Actually this mapping seems to work now that I try it again. I'm not sure what I did differently when it didn't work the first time I tried. Something is making me unable to use delimitMate, because even if set the option that makes the <Space> mapping simply return a space, the undo sequence breaks on every space insertion.

      This is closer to what is actually going on in delimitMate, but I still can't reproduce the issue. I will try again later to get a smaller example:

      function! Space()
        return "\<Space>"
      endfun

      inoremap flarbityflarb  <C-]><C-R>=Space()<CR>

      imap <Space> <C-]>flarbityflarb

      --
      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.



      --
      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
       
      ---
      You received this message because you are subscribed to the Google Groups "vim_dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
       
       
    • Thiago Alves
      Hi guys, I m the author of AutoClose and since almost a year ago I gave up trying to fix all sort of problems caused by inventive solutions to workaround the
      Message 2 of 18 , Jul 12, 2013
        Hi guys, I'm the author of AutoClose and since almost a year ago I gave up trying to fix all sort of problems caused by inventive solutions to "workaround" the undo break.

        I really like Bram's idea where <C-R>= would break the undo. If we have that auto complete plugins would be way more simple to implement.

        Is anyone working on this patch at this point?

        On Wednesday, July 3, 2013 1:45:32 PM UTC-7, Ben Fritz wrote:
        > I use the delimitMate plugin by Israel Chauca Fuentes:
        >
        >
        >
        > http://www.vim.org/scripts/script.php?script_id=2754
        >
        > https://github.com/Raimondi/delimitMate
        >
        >
        >
        > I found this plugin to be "the best" at automatically inserting the
        >
        > closing character for "paired" characters like (..), [..], etc. It is
        >
        > customizeable, and until recently, did not affect undo/redo/repeat.
        >
        >
        >
        > But, this plugin uses setline() internally, taking advantage of the
        >
        > "bug" fixed recently, that calling setline() in insert mode does not
        >
        > break the undo sequence. So, in Vim 7.3.1169, I can type the following:
        >
        >
        >
        > aone two three<Esc>
        >
        >
        >
        > Pressing 'u' would undo the entire insertion. With 7.3.1298, pressing
        >
        > 'u' removes each word individually, because <Space> triggers some logic
        >
        > in delimitMate.
        >
        >
        >
        > It is even more annoying when delimitMate actually inserts anything.
        >
        > Typing the following with delimitMate installed:
        >
        >
        >
        > aone two(three<Esc>
        >
        >
        >
        > Will actually insert the text:
        >
        >
        >
        > one two(three)
        >
        >
        >
        > So far, so good. Pressing '.' to repeat likewise still works. But when
        >
        > pressing 'u', in 1169 the entire insert is undone. In 1298, the first
        >
        > press gets rid of three) and the second press gets rid of the rest.
        >
        >
        >
        > Similar problems also occur when using the mapping to skip past an
        >
        > existing ) instead of inserting a new one when pressing ) in insert
        >
        > mode.
        >
        >
        >
        > I think, what is needed, is a method in insert mode, to insert text
        >
        > after the cursor and/or move the cursor, without breaking the undo
        >
        > sequence. The setline() thing was always a hack, I admit.
        >
        >
        >
        > Oddly it looks like Israel's name is on the 7.3.1200 issue description,
        >
        > so presumably he's aware of this. But the latest version of his plugin
        >
        > from GitHub breaks as described. And honestly I think it somewhat
        >
        > strange that I need a complicated plugin using setline(), etc. to avoid
        >
        > breaking undo/redo for something as simple as inserting an extra ) while
        >
        > typing in insert mode, or moving the cursor beyond the ) when typing a
        >
        > new one.

        --
        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_dev" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Thiago Alves
        Hi guys, I m the author of AutoClose and since almost a year ago I gave up trying to fix all sort of problems caused by inventive solutions to workaround the
        Message 3 of 18 , Jul 12, 2013
          Hi guys, I'm the author of AutoClose and since almost a year ago I gave up trying to fix all sort of problems caused by inventive solutions to "workaround" the undo break.
          I really like Bram's idea where <C-R>= would not break the undo. If we have that auto complete plugins would be way more simple to implement.

          Is anyone working on this patch at this point?

          On Tuesday, July 9, 2013 8:13:22 AM UTC-7, Bram Moolenaar wrote:
          > Ben Fritz wrote:
          >
          >
          >
          > > On Tue, Jul 9, 2013 at 5:54 AM, Bram Moolenaar <Bram@...> wrote:
          >
          > > >
          >
          > > > That can be done by returning cursor key sequences. No need for
          >
          > > > setline():
          >
          > > >
          >
          > > > imap ( <C-R>=LeftParen()<CR>
          >
          > > > fun! LeftParen()
          >
          > > > return "()\<Left>"
          >
          > > > endfun
          >
          > > > imap ) <C-R>=RightParen()<CR>
          >
          > > > fun! RightParen()
          >
          > > > return "\<Right>"
          >
          > > > endfun
          >
          > > >
          >
          > >
          >
          > > I don't remember how setline() solves the problem, but just returning
          >
          > > cursor sequences doesn't work, because it breaks undo/redo/repeat.
          >
          >
          >
          > Yeah, that's true. I suppose we could avoid saving for undo under
          >
          > certain conditions, but it's quite hard to decide what those conditions
          >
          > are. Perhaps "when inserting a register and the cursor remains within
          >
          > the inserted text"?
          >
          >
          >
          > > If I insert abc(123) with mappings like, then press '.' somewhere
          >
          > > else, I will only get the 123 inserted. Pressing 'u' after inserting
          >
          > > "abc(123) + 456" will only undo the " + 456".
          >
          > >
          >
          > > The mappings that used to work to get around this are complicated;
          >
          > > hence the reason I'm using a plugin instead of simple mappings; but
          >
          > > previously somehow using setline() allowed all of undo, redo, and
          >
          > > repeat to work as if there were not any mappings. Now only repeat
          >
          > > works.
          >
          >
          >
          > --
          >
          > "I love deadlines. I especially like the whooshing sound they
          >
          > make as they go flying by."
          >
          > -- Douglas Adams
          >
          >
          >
          > /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
          >
          > /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
          >
          > \\\ an exciting new programming language -- http://www.Zimbu.org ///
          >
          > \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

          --
          --
          You received this message from the "vim_dev" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_dev" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        Your message has been successfully submitted and would be delivered to recipients shortly.