]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0081: Failed "z=" does not reset 'nospell' setting v9.2.0081
authorLuuk van Baal <luukvbaal@gmail.com>
Sat, 28 Feb 2026 17:40:32 +0000 (17:40 +0000)
committerChristian Brabandt <cb@256bit.org>
Sat, 28 Feb 2026 17:40:32 +0000 (17:40 +0000)
Problem:  When z= fails due to no word being found, 'spelllang' being
          unset or a multiline visual selection, 'nospell' is not
          restored.
Solution: Jump to where the user configured value of 'spell' is restored
          instead of returning early (Luuk van Baal).

closes: #19525

Signed-off-by: Luuk van Baal <luukvbaal@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/spellsuggest.c
src/testdir/test_spell.vim
src/testdir/test_spell_utf8.vim
src/version.c

index 87efd0d5b2697d21d4d533eb637b72ea806c3f0f..866eedf31b4ee522ff2a6d03abf7eabf4adbde84 100644 (file)
@@ -463,7 +463,7 @@ spell_check_sps(void)
     void
 spell_suggest(int count)
 {
-    char_u     *line;
+    char_u     *line = NULL;
     pos_T      prev_cursor = curwin->w_cursor;
     char_u     wcopy[MAXWLEN + 2];
     char_u     *p;
@@ -488,7 +488,7 @@ spell_suggest(int count)
     if (*curwin->w_s->b_p_spl == NUL)
     {
        emsg(_(e_spell_checking_is_not_possible));
-       return;
+       goto skip;
     }
 
     if (VIsual_active)
@@ -498,7 +498,7 @@ spell_suggest(int count)
        if (curwin->w_cursor.lnum != VIsual.lnum)
        {
            vim_beep(BO_SPELL);
-           return;
+           goto skip;
        }
        badlen = (int)curwin->w_cursor.col - (int)VIsual.col;
        if (badlen < 0)
@@ -518,11 +518,11 @@ spell_suggest(int count)
        // No bad word or it starts after the cursor: use the word under the
        // cursor.
        curwin->w_cursor = prev_cursor;
-       line = ml_get_curline();
-       p = line + curwin->w_cursor.col;
+       char_u *curline = ml_get_curline();
+       p = curline + curwin->w_cursor.col;
        // Backup to before start of word.
-       while (p > line && spell_iswordp_nmw(p, curwin))
-           MB_PTR_BACK(line, p);
+       while (p > curline && spell_iswordp_nmw(p, curwin))
+           MB_PTR_BACK(curline, p);
        // Forward to start of word.
        while (*p != NUL && !spell_iswordp_nmw(p, curwin))
            MB_PTR_ADV(p);
@@ -530,9 +530,9 @@ spell_suggest(int count)
        if (!spell_iswordp_nmw(p, curwin))              // No word found.
        {
            beep_flush();
-           return;
+           goto skip;
        }
-       curwin->w_cursor.col = (colnr_T)(p - line);
+       curwin->w_cursor.col = (colnr_T)(p - curline);
     }
 
     // Get the word and its length.
index 170ea57926ac2b4e934c3a99eda64d326d99d401..58a2d58707e7b3599a5945ee2afb6d9fc8d08eac 100644 (file)
@@ -1567,4 +1567,18 @@ let g:test_data_aff_sal = [
       \"SAL Z                    S",
       \ ]
 
+func Test_suggest_spell_restore()
+  norm! z=
+  call assert_equal(0, &spell)
+  set spelllang=
+  sil! norm! z=
+  call assert_equal(0, &spell)
+  set spelllang=en
+  call setline(1, ['1','2'])
+  norm! vjz=
+  call assert_equal(0, &spell)
+  set spelllang&
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 2a5e8091f41c7c6cbf356a95959e0fc030e56838..fa9284be15e9722d7dd9bbc6eddc9ccc44d70895 100644 (file)
@@ -808,13 +808,14 @@ endfunc
 
 func Test_check_empty_line()
   " This was using freed memory
+  set spell
   enew
   spellgood! fl
   norm z=
   norm yy
   sil! norm P]svc
   norm P]s
-
+  set spell&
   bwipe!
 endfunc
 
index 5e72c784242228709634a4cd97ed4313794ddbe9..d74162d43e1307f9d6ed1c62f6598e7485bdc78d 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    81,
 /**/
     80,
 /**/