Skip to content

Commit eba078f

Browse files
luukvbaalchrisbra
authored andcommitted
patch 9.2.0081: Failed "z=" does not reset 'nospell' setting
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 <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 75c291f commit eba078f

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

src/spellsuggest.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ spell_check_sps(void)
463463
void
464464
spell_suggest(int count)
465465
{
466-
char_u *line;
466+
char_u *line = NULL;
467467
pos_T prev_cursor = curwin->w_cursor;
468468
char_u wcopy[MAXWLEN + 2];
469469
char_u *p;
@@ -488,7 +488,7 @@ spell_suggest(int count)
488488
if (*curwin->w_s->b_p_spl == NUL)
489489
{
490490
emsg(_(e_spell_checking_is_not_possible));
491-
return;
491+
goto skip;
492492
}
493493

494494
if (VIsual_active)
@@ -498,7 +498,7 @@ spell_suggest(int count)
498498
if (curwin->w_cursor.lnum != VIsual.lnum)
499499
{
500500
vim_beep(BO_SPELL);
501-
return;
501+
goto skip;
502502
}
503503
badlen = (int)curwin->w_cursor.col - (int)VIsual.col;
504504
if (badlen < 0)
@@ -518,21 +518,21 @@ spell_suggest(int count)
518518
// No bad word or it starts after the cursor: use the word under the
519519
// cursor.
520520
curwin->w_cursor = prev_cursor;
521-
line = ml_get_curline();
522-
p = line + curwin->w_cursor.col;
521+
char_u *curline = ml_get_curline();
522+
p = curline + curwin->w_cursor.col;
523523
// Backup to before start of word.
524-
while (p > line && spell_iswordp_nmw(p, curwin))
525-
MB_PTR_BACK(line, p);
524+
while (p > curline && spell_iswordp_nmw(p, curwin))
525+
MB_PTR_BACK(curline, p);
526526
// Forward to start of word.
527527
while (*p != NUL && !spell_iswordp_nmw(p, curwin))
528528
MB_PTR_ADV(p);
529529

530530
if (!spell_iswordp_nmw(p, curwin)) // No word found.
531531
{
532532
beep_flush();
533-
return;
533+
goto skip;
534534
}
535-
curwin->w_cursor.col = (colnr_T)(p - line);
535+
curwin->w_cursor.col = (colnr_T)(p - curline);
536536
}
537537

538538
// Get the word and its length.

src/testdir/test_spell.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,4 +1567,18 @@ let g:test_data_aff_sal = [
15671567
\"SAL Z S",
15681568
\ ]
15691569

1570+
func Test_suggest_spell_restore()
1571+
norm! z=
1572+
call assert_equal(0, &spell)
1573+
set spelllang=
1574+
sil! norm! z=
1575+
call assert_equal(0, &spell)
1576+
set spelllang=en
1577+
call setline(1, ['1','2'])
1578+
norm! vjz=
1579+
call assert_equal(0, &spell)
1580+
set spelllang&
1581+
bwipe!
1582+
endfunc
1583+
15701584
" vim: shiftwidth=2 sts=2 expandtab

src/testdir/test_spell_utf8.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,13 +808,14 @@ endfunc
808808

809809
func Test_check_empty_line()
810810
" This was using freed memory
811+
set spell
811812
enew
812813
spellgood!
813814
norm z=
814815
norm yy
815816
sil! norm P]svc
816817
norm P]s
817-
818+
set spell&
818819
bwipe!
819820
endfunc
820821

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
81,
737739
/**/
738740
80,
739741
/**/

0 commit comments

Comments
 (0)