Saturday, January 17, 2015

Re: Any automatic bracket-insertion plugins not breaking undo?



2015-01-17 1:55 GMT+03:00 Christian Brabandt <cblists@256bit.org>:
Hi Bram!

On Fr, 16 Jan 2015, Bram Moolenaar wrote:

>
> Christian Brabandt wrote:
>
> > On Fr, 16 Jan 2015, Ben Fritz wrote:
> >
> > > The problem is, there is no way to move the cursor in insert mode,
> > > without breaking the undo sequence. Such a capability would allow both
> > > of these mappings:
> > >
> > > inore ( ()<Left> inore <expr> ) GetNextChar()==")" ? "\<Right>" : ")"
> > >
> > > Alternatively, there is no way in insert mode to insert a character
> > > after the cursor, or delete the character after the cursor. Such a
> > > capability would allow:
> > >
> > > inore <expr> ( ")".PutCharAfter(")") inore <expr> ) GetNextChar()==")"
> > > ? DeleteNextChar().")" : ")"
> > >
> > > At one point, there was a workaround that exploited a bug in setline()
> > > that allowed the undo/redo to work. You could use setline() to change
> > > the line without breaking undo sequence. I don't remember how repeat
> > > worked, but I think it involved an <Esc> mapping.
> > >
> > > If either the abilities above (moving the cursor without breaking
> > > undo, or insert/delete after the cursor) were implemented as Vim
> > > insert-mode commands, I would consider dropping the use of a plugin
> > > and just writing my own mappings.
> > >
> > > As it is, I tried the pull request I mentioned on delimitMate, and it
> > > seems to work for simple cases, but either visual-block mode messes it
> > > up. I have an unsatisfactory workaround I posted as a comment on that
> > > pull request that I'm using for the present.
> >
> > Hm, we already have special cases <C-[Left|Right]> and <S-[Left|Right]>
> > to move by word|WORD. So how about making <M-Left> and <M-Right> move
> > without breaking undo?
> > https://github.com/chrisbra/vim-mq-patches/blob/master/move_cursor_without_breaking_undo
>
> It's very likely there will be a request for other movements, e.g. a
> word back.

<C-Right> and <S-Right> does this already.

> How about a prefix for movement commands?  Something
> starting with CTRL-G.  It's several keys to type, but I assume this will
> mostly be used in mappings.

I thought about that. But my fear is, that this will allow to jump
anywhere in insert mode and I think this would probably break undo (a
problem we have just fixed with <c-r>= in insert mode before 7.4).
So I did intentionally just allow <M-Left> and <M-Right> in the hope,
that this will still allow proper undo and will cover most of the snip
plugin use-cases.

Just `w` and `b` with left and right will already allow to go anywhere, regardless of &whichwrap option.

But if you are going to use the same code for <M-Left> as for <Left> then adding `[` and `]` &whichwrap is just enough for <M-Left> and <M-Right> to go anywhere as well. If you want to restrict motions to a single line <M-Left>/<M-Right> should ignore &whichwrap. Also given that they will be used mostly in mappings which can use <expr> allowing <M-Left>/<M-Right> is just as good as allowing going anywhere in the line plugins wants to go and it may be easier to create code that does random motion after pressing <C-g>, but intentionally breaks undo if this motion happens to end on the other line.
 

Best,
Christian
--
Es ist ebenso fehlerhaft, nicht überall die Sinnlichkeit, als überall
ihren Sieg voranzusetzen.
                -- Jean Paul (eig. Johann Paul Friedrich Richter)

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: