Patch 8.2.0945

5 views
Skip to first unread message

Bram Moolenaar

unread,
Jun 10, 2020, 9:34:24 AM6/10/20
to vim...@googlegroups.com

Patch 8.2.0945
Problem: Cannot use "z=" when 'spell' is off.
Solution: Make "z=" work even when 'spell' is off. (Christian Brabandt,
Gary Johnson, closes #6227)
Files: runtime/doc/eval.txt, src/evalfunc.c, src/spell.c,
src/spellsuggest.c, src/testdir/test_spell.vim, src/globals.h


*** ../vim-8.2.0944/runtime/doc/eval.txt 2020-06-08 20:50:23.428250680 +0200
--- runtime/doc/eval.txt 2020-06-10 14:58:19.526818502 +0200
***************
*** 9528,9536 ****
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.

Can also be used as a |method|: >
GetText()->spellbadword()
--- 9537,9544 ----
echo spellbadword("the quik brown fox")
< ['quik', 'bad'] ~

! The spelling information for the current window and the value
! of 'spelllang' are used.

Can also be used as a |method|: >
GetText()->spellbadword()
***************
*** 9555,9562 ****
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.

Can also be used as a |method|: >
GetWord()->spellsuggest()
--- 9563,9569 ----
although it may appear capitalized.

The spelling information for the current window is used. The
! values of 'spelllang' and 'spellsuggest' are used.

Can also be used as a |method|: >
GetWord()->spellsuggest()
*** ../vim-8.2.0944/src/evalfunc.c 2020-06-08 20:50:23.432250668 +0200
--- src/evalfunc.c 2020-06-10 15:04:12.061661739 +0200
***************
*** 7596,7604 ****
--- 7596,7625 ----
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,7617 ****
curwin->w_set_curswant = TRUE;
}
}
! else if (curwin->w_p_spell && *curbuf->b_s.b_p_spl != NUL)
{
char_u *str = tv_get_string_chk(&argvars[0]);
int capcol = -1;
--- 7632,7638 ----
curwin->w_set_curswant = TRUE;
}
}
! else if (*curbuf->b_s.b_p_spl != NUL)
{
char_u *str = tv_get_string_chk(&argvars[0]);
int capcol = -1;
***************
*** 7633,7638 ****
--- 7654,7660 ----
}
}
}
+ curwin->w_p_spell = wo_spell_save;
#endif

list_append_string(rettv->vval.v_list, word, len);
***************
*** 7658,7670 ****
int i;
listitem_T *li;
int need_capital = FALSE;
#endif

if (rettv_list_alloc(rettv) == FAIL)
return;

#ifdef FEAT_SPELL
! if (curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL)
{
str = tv_get_string(&argvars[0]);
if (argvars[1].v_type != VAR_UNKNOWN)
--- 7680,7711 ----
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_s->b_p_spl != NUL)
{
str = tv_get_string(&argvars[0]);
if (argvars[1].v_type != VAR_UNKNOWN)
***************
*** 7701,7706 ****
--- 7742,7748 ----
}
ga_clear(&ga);
}
+ curwin->w_p_spell = wo_spell_save;
#endif
}

*** ../vim-8.2.0944/src/spell.c 2020-06-08 18:54:44.957796367 +0200
--- src/spell.c 2020-06-10 15:03:39.257768569 +0200
***************
*** 1225,1231 ****
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"));
return TRUE;
}
return FALSE;
--- 1225,1231 ----
if (!wp->w_p_spell || *wp->w_s->b_p_spl == NUL
|| wp->w_s->b_langp.ga_len == 0)
{
! emsg(_(e_no_spell));
return TRUE;
}
return FALSE;
*** ../vim-8.2.0944/src/spellsuggest.c 2020-04-12 19:37:13.526297236 +0200
--- src/spellsuggest.c 2020-06-10 15:04:31.313599126 +0200
***************
*** 471,479 ****
int selected = count;
int badlen = 0;
int msg_scroll_save = msg_scroll;

! if (no_spell_checking(curwin))
return;

if (VIsual_active)
{
--- 471,489 ----
int selected = count;
int badlen = 0;
int msg_scroll_save = msg_scroll;
+ 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));
return;
+ }

if (VIsual_active)
{
***************
*** 686,691 ****
--- 696,702 ----
spell_find_cleanup(&sug);
skip:
vim_free(line);
+ curwin->w_p_spell = wo_spell_save;
}

/*
*** ../vim-8.2.0944/src/testdir/test_spell.vim 2020-03-25 22:23:41.898363595 +0100
--- src/testdir/test_spell.vim 2020-06-10 14:58:25.346799210 +0200
***************
*** 99,109 ****
set spelllang=Xwords.spl
call assert_equal(['foobar', 'rare'], spellbadword('foo foobar'))

! " Typo should not be detected 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 delete('Xwords.spl')
call delete('Xwords')
--- 99,112 ----
set spelllang=Xwords.spl
call assert_equal(['foobar', 'rare'], spellbadword('foo foobar'))

! " Typo should be detected even without the 'spell' option.
set spelllang=en_gb nospell
call assert_equal(['', ''], spellbadword('centre'))
! 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,138 ****

" Test spellsuggest({word} [, {max} [, {capital}]])
func Test_spellsuggest()
! " No suggestions when spell checking is not enabled.
set nospell
! call assert_equal([], spellsuggest('marrch'))

set spell

--- 133,141 ----

" Test spellsuggest({word} [, {max} [, {capital}]])
func Test_spellsuggest()
! " Verify suggestions are given even when spell checking is not enabled.
set nospell
! call assert_equal(['march', 'March'], spellsuggest('marrch', 2))

set spell

***************
*** 163,168 ****
--- 166,175 ----
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,622 ****
--- 624,657 ----
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
*** ../vim-8.2.0944/src/globals.h 2020-06-01 18:39:14.040317510 +0200
--- src/globals.h 2020-06-10 15:02:59.661897743 +0200
***************
*** 1581,1586 ****
--- 1581,1589 ----
#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
*** ../vim-8.2.0944/src/version.c 2020-06-10 14:21:17.270208681 +0200
--- src/version.c 2020-06-10 15:00:22.958411061 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 945,
/**/

--
FATHER: Did you kill all those guards?
LAUNCELOT: Yes ... I'm very sorry ...
FATHER: They cost fifty pounds each!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages