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

Peculiar spell-check replacement behavior (bug?)

Expand Messages
  • Tim Chase
    Playing around with the most recent vimgolf challenge, I was surprised by the following. To replicate the issue in a document with multiple different
    Message 1 of 4 , Aug 19, 2014
      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?

      -tim



      --
      --
      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@....
      For more options, visit https://groups.google.com/d/optout.
    • Christian Brabandt
      ... 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 so that explains it. It
      Message 2 of 4 , Aug 19, 2014
        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@....
        For more options, visit https://groups.google.com/d/optout.
      • Bram Moolenaar
        ... It s documented: When a word was replaced the redo command . will repeat the word replacement. This works like ciw , the good word and . This
        Message 3 of 4 , Aug 19, 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?

          It's documented:

          When a word was replaced the redo command "." will
          repeat the word replacement. This works like "ciw",
          the good word and <Esc>. This does NOT work for Thai
          and other languages without spaces between words.

          It's one of those choices where there are always some users who expect
          it to work otherwise. Anyway, you can easily map "1z=" to some key,
          while making a map that repeats replacing with the same word is much
          harder.

          --
          Bumper sticker: Honk if you love peace and quiet.

          /// 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_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@....
          For more options, visit https://groups.google.com/d/optout.
        • Tim Chase
          ... Okay, as long as it s documented, it s just my misunderstanding then (though Christian s patch makes it look like it might be a straight-forward change, I
          Message 4 of 4 , Aug 19, 2014
            On 2014-08-19 22:01, Bram Moolenaar wrote:
            > > 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).
            >
            > It's documented:
            >
            > When a word was replaced the redo command "." will repeat the
            > word replacement. This works like "ciw", the good word and <Esc>.
            > This does NOT work for Thai and other languages without spaces
            > between words.
            >
            > It's one of those choices where there are always some users who
            > expect it to work otherwise.

            Okay, as long as it's documented, it's just my misunderstanding then
            (though Christian's patch makes it look like it might be a
            straight-forward change, I haven't tested it--particularly to ensure
            that it doesn't break repeating the no-count case). If Christian's
            solution works and fixes the odd Thai edge-case, it would be worth
            the subtle change as I still think the current behavior is
            unintuitive, even if understandable & documented.

            > Anyway, you can easily map "1z=" to some key, while making a map
            > that repeats replacing with the same word is much harder.

            I only encountered it while playing VimGolf where keystroke-count
            matters (and creating mappings costs keystrokes), so it's not the
            sort of thing I'd have bumped against in my normal editing.

            -tim



            --
            --
            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@....
            For more options, visit https://groups.google.com/d/optout.
          Your message has been successfully submitted and would be delivered to recipients shortly.