vim-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 vim/vim#6227)
152e79e94b
This commit is contained in:
Jan Edmund Lazo 2021-06-11 22:43:22 -04:00
parent 82d1c29bfd
commit 72b512bd53
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15
5 changed files with 86 additions and 14 deletions

View File

@ -8230,9 +8230,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.
*spellsuggest()*
spellsuggest({word} [, {max} [, {capital}]])
@ -8254,8 +8253,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.
split({expr} [, {pattern} [, {keepempty}]]) *split()*

View File

@ -9661,6 +9661,18 @@ static void f_spellbadword(typval_T *argvars, typval_T *rettv, FunPtr fptr)
const char *word = "";
hlf_T attr = HLF_COUNT;
size_t len = 0;
const 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;
}
if (argvars[0].v_type == VAR_UNKNOWN) {
// Find the start and length of the badly spelled word.
@ -9669,7 +9681,7 @@ static void f_spellbadword(typval_T *argvars, typval_T *rettv, FunPtr fptr)
word = (char *)get_cursor_pos_ptr();
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) {
const char *str = tv_get_string_chk(&argvars[0]);
int capcol = -1;
@ -9687,6 +9699,7 @@ static void f_spellbadword(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
}
}
curwin->w_p_spell = wo_spell_save;
assert(len <= INT_MAX);
tv_list_alloc_ret(rettv, 2);
@ -9708,8 +9721,20 @@ static void f_spellsuggest(typval_T *argvars, typval_T *rettv, FunPtr fptr)
int maxcount;
garray_T ga = GA_EMPTY_INIT_VALUE;
bool need_capital = false;
const int wo_spell_save = curwin->w_p_spell;
if (curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) {
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;
}
if (*curwin->w_s->b_p_spl != NUL) {
const char *const str = tv_get_string(&argvars[0]);
if (argvars[1].v_type != VAR_UNKNOWN) {
maxcount = tv_get_number_chk(&argvars[1], &typeerr);
@ -9736,6 +9761,7 @@ f_spellsuggest_return:
tv_list_append_allocated_string(rettv->vval.v_list, p);
}
ga_clear(&ga);
curwin->w_p_spell = wo_spell_save;
}
static void f_split(typval_T *argvars, typval_T *rettv, FunPtr fptr)

View File

@ -878,6 +878,7 @@ EXTERN char_u e_invexpr2[] INIT(= N_("E15: Invalid expression: %s"));
EXTERN char_u e_invrange[] INIT(= N_("E16: Invalid range"));
EXTERN char_u e_invcmd[] INIT(= N_("E476: Invalid command"));
EXTERN char_u e_isadir2[] INIT(= N_("E17: \"%s\" is a directory"));
EXTERN char_u e_no_spell[] INIT(= N_("E756: Spell checking is not possible"));
EXTERN char_u e_invchan[] INIT(= N_("E900: Invalid channel id"));
EXTERN char_u e_invchanjob[] INIT(= N_("E900: Invalid channel id: not a job"));
EXTERN char_u e_jobtblfull[] INIT(= N_("E901: Job table is full"));

View File

@ -1343,7 +1343,7 @@ static bool no_spell_checking(win_T *wp)
{
if (!wp->w_p_spell || *wp->w_s->b_p_spl == NUL
|| GA_EMPTY(&wp->w_s->b_langp)) {
EMSG(_("E756: Spell checking is not enabled"));
EMSG(_(e_no_spell));
return true;
}
return false;
@ -2771,9 +2771,17 @@ void spell_suggest(int count)
int selected = count;
int badlen = 0;
int msg_scroll_save = msg_scroll;
const 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) {
// Use the Visually selected text as the bad word. But reject
@ -2966,6 +2974,7 @@ void spell_suggest(int count)
spell_find_cleanup(&sug);
xfree(line);
curwin->w_p_spell = wo_spell_save;
}
// Check if the word at line "lnum" column "col" is required to start with a

View File

@ -106,11 +106,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')
@ -174,9 +177,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
@ -204,6 +207,13 @@ func Test_spellsuggest()
call assert_equal(['Third'], spellsuggest('THird', 1))
call assert_equal(['All'], spellsuggest('ALl', 1))
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
@ -631,6 +641,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