To: Devin Weaver <
[email protected]>
In-Reply-To: <
[email protected]>
Cc:
[email protected]
Subject: Patch 5.5b.2 (was: cindent deleting }'s bug)
Fcc: outbox
From: Bram Moolenaar <
[email protected]>
------------
Devin Weaver wrote:
> This one's a bit odd although not detremental. unfortunaltly I haven't browsed
> vim's source enough to know where to look and make a patch.
>
> Bug: when using C indenting in insert mode using the following keystrokes
> causes the second brace to dissapper.
> I've check this with vim 5.5b using 'vim -u NONE -U NONE -i NONE'
> I ':set cin', then 'i' for insert. typed '{', enter, '}'.
> Then I opened the middle line by pressing CTRL-O and Shift-O.
> (Heres the fun part) pressed Esc to jump to normal mode, 'j' to move down a
> line. then 'o' to open the next line.
> You'll notice that the closing brace has been deleted.
>
> Maybe one of you guru's with more free time then I would like to tackle this
> one?
I can reproduce it. It's a bug. There is a flag that remembers that an
indent has been inserted, and the indent should be deleted if nothing else is
typed on the line. Somehow recursively calling Insert mode (which is what
CTRL-O O does) messes this up, the flag is still set after moving to another
line, and it deletes the characters in the wrong line.
It looks like problems like this can be caused by any Normal mode command that
starts inserting, and is used by CTRL-O from Insert mode. There is a mixup of
starting the new insert command, and restarting the previous insert.
For now, I'll disallow nesting Insert mode. In the future, it should be
possible to nest it for mappings. Nesting it for interactive commands doesn't
appear to be useful, and can be confusing (hitting <Esc> would need to be done
once for every nested insert command). This was already in the todo list.
Patch 5.5b.2
Problem: When using "CTRL-O O" in Insert mode which inserts an auto-indent,
hit <Esc> and then "o" in another line truncates that line.
(Devin Weaver)
Solution: When using a command that starts Insert mode from CTRL-O, reset
"restart_edit" first. This avoids that edit() is called with a
mix of starting a new edit command and restarting a previous one.
Files: src/normal.c
*** ../vim-5.5b.1/src/normal.c Tue Sep 14 12:44:51 1999
--- src/normal.c Tue Sep 14 12:26:57 1999
***************
*** 1793,1799 ****
vim_beep();
else
{
! /* don't restart edit after typing <Esc> in edit() */
restart_edit = 0;
*command_busy = op_change(oap); /* will call edit() */
}
--- 1793,1800 ----
vim_beep();
else
{
! /* This is a new edit command, not a restart. We don't edit
! * recursively. */
restart_edit = 0;
*command_busy = op_change(oap); /* will call edit() */
}
***************
*** 1859,1865 ****
#ifdef VISUALEXTRA
else
{
! /* don't restart edit after typing <Esc> in edit() */
restart_edit = 0;
op_insert(oap); /* handles insert & append; will call edit() */
}
--- 1860,1867 ----
#ifdef VISUALEXTRA
else
{
! /* This is a new edit command, not a restart. We don't edit
! * recursively. */
restart_edit = 0;
op_insert(oap); /* handles insert & append; will call edit() */
}
***************
*** 4554,4560 ****
--- 4556,4567 ----
else if (!checkclearopq(cap->oap))
{
if (u_save_cursor() == OK)
+ {
+ /* This is a new edit command, not a restart. We don't edit
+ * recursively. */
+ restart_edit = 0;
command_busy = edit('R', FALSE, cap->count1);
+ }
}
return command_busy;
}
***************
*** 4577,4583 ****
--- 4584,4595 ----
else if (!checkclearopq(cap->oap))
{
if (u_save_cursor() == OK)
+ {
+ /* This is a new edit command, not a restart. We don't edit
+ * recursively. */
+ restart_edit = 0;
command_busy = edit('V', FALSE, cap->count1);
+ }
}
return command_busy;
}
***************
*** 4605,4610 ****
--- 4617,4625 ----
cap->extra_char = get_literal();
stuffcharReadbuff(cap->extra_char);
stuffcharReadbuff(ESC);
+ /* This is a new edit command, not a restart. We don't edit
+ * recursively. */
+ restart_edit = 0;
command_busy = edit('v', FALSE, cap->count1);
}
}
***************
*** 5209,5215 ****
--- 5224,5235 ----
if (!checkclearopq(oap))
{
if (u_save_cursor() == OK)
+ {
+ /* This is a new edit command, not a restart. We don't edit
+ * recursively. */
+ restart_edit = 0;
command_busy = edit('g', FALSE, cap->count1);
+ }
}
break;
***************
*** 5348,5354 ****
--- 5368,5379 ----
) == OK
&& open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD,
TRUE, FALSE, 0))
+ {
+ /* This is a new edit command, not a restart. We don't edit
+ * recursively. */
+ restart_edit = 0;
command_busy = edit(cap->cmdchar, TRUE, cap->count1);
+ }
#ifdef COMMENTS
fo_do_comments = FALSE;
#endif
***************
*** 5713,5718 ****
--- 5738,5746 ----
inc_cursor();
break;
}
+ /* This is a new edit command, not a restart. We don't edit
+ * recursively. */
+ restart_edit = 0;
return edit(cap->cmdchar, FALSE, cap->count1);
}
return FALSE;
*** ../vim-5.5b.1/src/version.c Tue Sep 14 12:44:52 1999
--- src/version.c Tue Sep 14 12:46:38 1999
***************
*** 420,420 ****
--- 420,421 ----
{ /* Add new patch number below this line */
+ 2,
--
Give a man a computer program and you give him a headache,
but teach him to program computers and you give him the power
to create headaches for others for the rest of his life...
R. B. Forest
--/-/---- Bram Moolenaar ----
[email protected] ----
[email protected] ---\-\--
\ \ www.vim.org/iccf www.moolenaar.net www.vim.org / /