Tuesday, August 19, 2014

Re: Peculiar spell-check replacement behavior (bug?)

On Di, 19 Aug 2014, Tim Chase wrote:

> Playing around with the most recent vimgolf challenge, I was
> surprised by the following. To replicate the issue in a document with
> multiple different misspelled words:
>
> - :set spell
>
>
> - On a misspelled word (in the vimgolf case, this is "Mosst") use
>
> 1z=
>
> to select the first replacement. Good (it now reads "Most")
>
> - use "]s" to jump to the next (different) misspelled word (in the
> vimgolf case, this is "heirarchies")
>
> - use "." to repeat the "1z=" action
>
> Expected behavior: the period repeat executes the "z=" action using
> the previous count (1) to choose the first replacement for the word
> under the cursor (in this case, it should be "hierarchies")
>
> Current (well, 7.3.547 on Debian Stable) behavior: the period repeat
> replaces the word under the cursor with the replacement used in the
> previous "1z=" (in this case, it changed "heirarchies" to "Most")
>
> More peculiarly, if you use "2." to choose the 2nd replacement
> choice, it swallowed the space after "heirarchies" but still replaced
> it with "Most", and "3." swallowed the trailing space AND the
> following word.
>
> I found it surprising, but am not sure whether this is a bug (and if
> so, to what degree) or just a mismatch between my expectations and
> reality (tweaking documentation on "." to clarify what qualifies as a
> "simple change" might help clear up my misunderstanding).
>
> Thoughts from others here?

I wasn't aware of this one as well. I looked it up in the source, and
internally Vim is handling it like doing a ciw<replaced_word>
so that explains it.

It should however be possible to make it work as expected. I think, this
patch does it:

diff --git a/src/spell.c b/src/spell.c
--- a/src/spell.c
+++ b/src/spell.c
@@ -10383,6 +10383,8 @@ spell_suggest(count)
+ stp->st_wordlen + 1);
if (p != NULL)
{
+ char_u numbuf[10];
+
c = (int)(sug.su_badptr - line);
mch_memmove(p, line, c);
STRCPY(p + c, stp->st_word);
@@ -10392,10 +10394,11 @@ spell_suggest(count)

/* For redo we use a change-word command. */
ResetRedobuff();
- AppendToRedobuff((char_u *)"ciw");
- AppendToRedobuffLit(p + c,
- stp->st_wordlen + sug.su_badlen - stp->st_orglen);
- AppendCharToRedobuff(ESC);
+ AppendToRedobuff((char_u *)"z=");
+ vim_snprintf((char *)numbuf, sizeof(numbuf), "%*ld ", count ? count
+ : selected, count ? (long)count : (long)selected);
+ AppendToRedobuffLit(numbuf, -1);
+ AppendCharToRedobuff(NL);

/* After this "p" may be invalid. */
changed_bytes(curwin->w_cursor.lnum, c);


Best,
Christian
--
Dass das Bedingte zugleich unbedingt sei. Welches unbegreiflich
ist, ob wir es gleich alle Tage erfahren.
-- Goethe, Maximen und Reflektionen, Nr. 1322

--
--
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: