diff src/evalfunc.c @ 20786:90b96fa35e4b v8.2.0945

patch 8.2.0945: cannot use "z=" when 'spell' is off Commit: https://github.com/vim/vim/commit/152e79e94bb935e75b866bd55479648cde11066a Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jun 10 15:32:08 2020 +0200 patch 8.2.0945: cannot use "z=" when 'spell' is off Problem: Cannot use "z=" when 'spell' is off. Solution: Make "z=" work even when 'spell' is off. (Christian Brabandt, Gary Johnson, closes #6227)
author Bram Moolenaar <Bram@vim.org>
date Wed, 10 Jun 2020 15:45:04 +0200
parents 821925509d8c
children 2616c5a337e0
line wrap: on
line diff
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -7596,9 +7596,30 @@ f_spellbadword(typval_T *argvars UNUSED,
     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,
 	    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,
 	    }
 	}
     }
+    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,
     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,
 	}
 	ga_clear(&ga);
     }
+    curwin->w_p_spell = wo_spell_save;
 #endif
 }