]> granicus.if.org Git - vim/commitdiff
patch 8.2.0945: cannot use "z=" when 'spell' is off v8.2.0945
authorBram Moolenaar <Bram@vim.org>
Wed, 10 Jun 2020 13:32:08 +0000 (15:32 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 10 Jun 2020 13:32:08 +0000 (15:32 +0200)
Problem:    Cannot use "z=" when 'spell' is off.
Solution:   Make "z=" work even when 'spell' is off. (Christian Brabandt,
            Gary Johnson, closes #6227)

runtime/doc/eval.txt
src/evalfunc.c
src/globals.h
src/spell.c
src/spellsuggest.c
src/testdir/test_spell.vim
src/version.c

index f3e240aa0b0f54155e63b813947b14d42e681cc4..78588bfd3ca8db6fc482eeca746479146764c5de 100644 (file)
@@ -9537,9 +9537,8 @@ spellbadword([{sentence}])
                        echo spellbadword("the quik brown fox")
 <                      ['quik', 'bad'] ~
 
-               The spelling information for the current window is used.  The
-               'spell' option must be set and the value of 'spelllang' is
-               used.
+               The spelling information for the current window and the value
+               of 'spelllang' are used.
 
                Can also be used as a |method|: >
                        GetText()->spellbadword()
@@ -9564,8 +9563,7 @@ spellsuggest({word} [, {max} [, {capital}]])
                although it may appear capitalized.
 
                The spelling information for the current window is used.  The
-               'spell' option must be set and the values of 'spelllang' and
-               'spellsuggest' are used.
+               values of 'spelllang' and 'spellsuggest' are used.
 
                Can also be used as a |method|: >
                        GetWord()->spellsuggest()
index e67aa584867d6667bf973fd479d382d9ccf742e0..1f53095101754452369e0cbbf1047c96d6e01b80 100644 (file)
@@ -7596,9 +7596,30 @@ f_spellbadword(typval_T *argvars UNUSED, typval_T *rettv)
     char_u     *word = (char_u *)"";
     hlf_T      attr = HLF_COUNT;
     int                len = 0;
+#ifdef FEAT_SPELL
+    int                wo_spell_save = curwin->w_p_spell;
+
+    if (!curwin->w_p_spell)
+    {
+       did_set_spelllang(curwin);
+       curwin->w_p_spell = TRUE;
+    }
+
+    if (*curwin->w_s->b_p_spl == NUL)
+    {
+       emsg(_(e_no_spell));
+       curwin->w_p_spell = wo_spell_save;
+       return;
+    }
+#endif
 
     if (rettv_list_alloc(rettv) == FAIL)
+    {
+#ifdef FEAT_SPELL
+       curwin->w_p_spell = wo_spell_save;
+#endif
        return;
+    }
 
 #ifdef FEAT_SPELL
     if (argvars[0].v_type == VAR_UNKNOWN)
@@ -7611,7 +7632,7 @@ f_spellbadword(typval_T *argvars UNUSED, typval_T *rettv)
            curwin->w_set_curswant = TRUE;
        }
     }
-    else if (curwin->w_p_spell && *curbuf->b_s.b_p_spl != NUL)
+    else if (*curbuf->b_s.b_p_spl != NUL)
     {
        char_u  *str = tv_get_string_chk(&argvars[0]);
        int     capcol = -1;
@@ -7633,6 +7654,7 @@ f_spellbadword(typval_T *argvars UNUSED, typval_T *rettv)
            }
        }
     }
+    curwin->w_p_spell = wo_spell_save;
 #endif
 
     list_append_string(rettv->vval.v_list, word, len);
@@ -7658,13 +7680,32 @@ f_spellsuggest(typval_T *argvars UNUSED, typval_T *rettv)
     int                i;
     listitem_T *li;
     int                need_capital = FALSE;
+    int                wo_spell_save = curwin->w_p_spell;
+
+    if (!curwin->w_p_spell)
+    {
+       did_set_spelllang(curwin);
+       curwin->w_p_spell = TRUE;
+    }
+
+    if (*curwin->w_s->b_p_spl == NUL)
+    {
+       emsg(_(e_no_spell));
+       curwin->w_p_spell = wo_spell_save;
+       return;
+    }
 #endif
 
     if (rettv_list_alloc(rettv) == FAIL)
+    {
+#ifdef FEAT_SPELL
+       curwin->w_p_spell = wo_spell_save;
+#endif
        return;
+    }
 
 #ifdef FEAT_SPELL
-    if (curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL)
+    if (*curwin->w_s->b_p_spl != NUL)
     {
        str = tv_get_string(&argvars[0]);
        if (argvars[1].v_type != VAR_UNKNOWN)
@@ -7701,6 +7742,7 @@ f_spellsuggest(typval_T *argvars UNUSED, typval_T *rettv)
        }
        ga_clear(&ga);
     }
+    curwin->w_p_spell = wo_spell_save;
 #endif
 }
 
index 66b204b41ec9ce312d3218aeae72a0b6a9f4a72f..27a8d681461f1f62b4b8191a771cdc2ebd03a8d0 100644 (file)
@@ -1581,6 +1581,9 @@ EXTERN char e_invcmd[]            INIT(= N_("E476: Invalid command"));
 #if defined(UNIX) || defined(FEAT_SYN_HL) || defined(FEAT_SPELL)
 EXTERN char e_isadir2[]                INIT(= N_("E17: \"%s\" is a directory"));
 #endif
+#ifdef FEAT_SPELL
+EXTERN char e_no_spell[]       INIT(= N_("E756: Spell checking is not possible"));
+#endif
 #ifdef FEAT_LIBCALL
 EXTERN char e_libcall[]        INIT(= N_("E364: Library call failed for \"%s()\""));
 #endif
index cdb8e2ff0a53977ef6fe41fa5a7bff1a467e234a..102355f7caf3071f6a420eaa683e4ce6d8afc735 100644 (file)
@@ -1225,7 +1225,7 @@ no_spell_checking(win_T *wp)
     if (!wp->w_p_spell || *wp->w_s->b_p_spl == NUL
                                         || wp->w_s->b_langp.ga_len == 0)
     {
-       emsg(_("E756: Spell checking is not enabled"));
+       emsg(_(e_no_spell));
        return TRUE;
     }
     return FALSE;
index c1ead7cce1165cfd920a5c3e5b6f172bac9f9834..c03233f52ef997f1d2a18c2f75fe36df92610382 100644 (file)
@@ -471,9 +471,19 @@ spell_suggest(int count)
     int                selected = count;
     int                badlen = 0;
     int                msg_scroll_save = msg_scroll;
+    int                wo_spell_save = curwin->w_p_spell;
 
-    if (no_spell_checking(curwin))
+    if (!curwin->w_p_spell)
+    {
+       did_set_spelllang(curwin);
+       curwin->w_p_spell = TRUE;
+    }
+
+    if (*curwin->w_s->b_p_spl == NUL)
+    {
+       emsg(_(e_no_spell));
        return;
+    }
 
     if (VIsual_active)
     {
@@ -686,6 +696,7 @@ spell_suggest(int count)
     spell_find_cleanup(&sug);
 skip:
     vim_free(line);
+    curwin->w_p_spell = wo_spell_save;
 }
 
 /*
index 4e376b8102348dd60e9a9aedf2a03d64206ff922..7cc209bc8e96887b0a0e90236f1b273100f0d50e 100644 (file)
@@ -99,11 +99,14 @@ foobar/?
    set spelllang=Xwords.spl
    call assert_equal(['foobar', 'rare'], spellbadword('foo foobar'))
 
-  " Typo should not be detected without the 'spell' option.
+  " Typo should be detected even without the 'spell' option.
   set spelllang=en_gb nospell
   call assert_equal(['', ''], spellbadword('centre'))
-  call assert_equal(['', ''], spellbadword('My bycycle.'))
-  call assert_equal(['', ''], spellbadword('A sentence. another sentence'))
+  call assert_equal(['bycycle', 'bad'], spellbadword('My bycycle.'))
+  call assert_equal(['another', 'caps'], spellbadword('A sentence. another sentence'))
+
+  set spelllang=
+  call assert_fails("call spellbadword('maxch')", 'E756:')
 
   call delete('Xwords.spl')
   call delete('Xwords')
@@ -130,9 +133,9 @@ endfunc
 
 " Test spellsuggest({word} [, {max} [, {capital}]])
 func Test_spellsuggest()
-  " No suggestions when spell checking is not enabled.
+  " Verify suggestions are given even when spell checking is not enabled.
   set nospell
-  call assert_equal([], spellsuggest('marrch'))
+  call assert_equal(['march', 'March'], spellsuggest('marrch', 2))
 
   set spell
 
@@ -163,6 +166,10 @@ func Test_spellsuggest()
   call assert_fails("call spellsuggest('maxch', [])", 'E745:')
   call assert_fails("call spellsuggest('maxch', 2, [])", 'E745:')
 
+  set spelllang=
+  call assert_fails("call spellsuggest('maxch')", 'E756:')
+  set spelllang&
+
   set spell&
 endfunc
 
@@ -617,6 +624,34 @@ func Test_zeq_crash()
   bwipe!
 endfunc
 
+" Check that z= works even when 'nospell' is set.  This test uses one of the
+" tests in Test_spellsuggest_option_number() just to verify that z= basically
+" works and that "E756: Spell checking is not enabled" is not generated.
+func Test_zeq_nospell()
+  new
+  set nospell spellsuggest=1,best
+  call setline(1, 'A baord')
+  try
+    norm $1z=
+    call assert_equal('A board', getline(1))
+  catch
+    call assert_report("Caught exception: " . v:exception)
+  endtry
+  set spell& spellsuggest&
+  bwipe!
+endfunc
+
+" Check that "E756: Spell checking is not possible" is reported when z= is
+" executed and 'spelllang' is empty.
+func Test_zeq_no_spelllang()
+  new
+  set spelllang= spellsuggest=1,best
+  call setline(1, 'A baord')
+  call assert_fails('normal $1z=', 'E756:')
+  set spelllang& spellsuggest&
+  bwipe!
+endfunc
+
 " Check handling a word longer than MAXWLEN.
 func Test_spell_long_word()
   set enc=utf-8
index e0848174f55d704dbfcfb823445d92c3403f3961..30106ff003d2a18d8a772d86dfdd8f868e909a4e 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    945,
 /**/
     944,
 /**/