comparison 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
comparison
equal deleted inserted replaced
20785:919ff930619d 20786:90b96fa35e4b
7594 f_spellbadword(typval_T *argvars UNUSED, typval_T *rettv) 7594 f_spellbadword(typval_T *argvars UNUSED, typval_T *rettv)
7595 { 7595 {
7596 char_u *word = (char_u *)""; 7596 char_u *word = (char_u *)"";
7597 hlf_T attr = HLF_COUNT; 7597 hlf_T attr = HLF_COUNT;
7598 int len = 0; 7598 int len = 0;
7599 #ifdef FEAT_SPELL
7600 int wo_spell_save = curwin->w_p_spell;
7601
7602 if (!curwin->w_p_spell)
7603 {
7604 did_set_spelllang(curwin);
7605 curwin->w_p_spell = TRUE;
7606 }
7607
7608 if (*curwin->w_s->b_p_spl == NUL)
7609 {
7610 emsg(_(e_no_spell));
7611 curwin->w_p_spell = wo_spell_save;
7612 return;
7613 }
7614 #endif
7599 7615
7600 if (rettv_list_alloc(rettv) == FAIL) 7616 if (rettv_list_alloc(rettv) == FAIL)
7617 {
7618 #ifdef FEAT_SPELL
7619 curwin->w_p_spell = wo_spell_save;
7620 #endif
7601 return; 7621 return;
7622 }
7602 7623
7603 #ifdef FEAT_SPELL 7624 #ifdef FEAT_SPELL
7604 if (argvars[0].v_type == VAR_UNKNOWN) 7625 if (argvars[0].v_type == VAR_UNKNOWN)
7605 { 7626 {
7606 // Find the start and length of the badly spelled word. 7627 // Find the start and length of the badly spelled word.
7609 { 7630 {
7610 word = ml_get_cursor(); 7631 word = ml_get_cursor();
7611 curwin->w_set_curswant = TRUE; 7632 curwin->w_set_curswant = TRUE;
7612 } 7633 }
7613 } 7634 }
7614 else if (curwin->w_p_spell && *curbuf->b_s.b_p_spl != NUL) 7635 else if (*curbuf->b_s.b_p_spl != NUL)
7615 { 7636 {
7616 char_u *str = tv_get_string_chk(&argvars[0]); 7637 char_u *str = tv_get_string_chk(&argvars[0]);
7617 int capcol = -1; 7638 int capcol = -1;
7618 7639
7619 if (str != NULL) 7640 if (str != NULL)
7631 capcol -= len; 7652 capcol -= len;
7632 len = 0; 7653 len = 0;
7633 } 7654 }
7634 } 7655 }
7635 } 7656 }
7657 curwin->w_p_spell = wo_spell_save;
7636 #endif 7658 #endif
7637 7659
7638 list_append_string(rettv->vval.v_list, word, len); 7660 list_append_string(rettv->vval.v_list, word, len);
7639 list_append_string(rettv->vval.v_list, (char_u *)( 7661 list_append_string(rettv->vval.v_list, (char_u *)(
7640 attr == HLF_SPB ? "bad" : 7662 attr == HLF_SPB ? "bad" :
7656 int maxcount; 7678 int maxcount;
7657 garray_T ga; 7679 garray_T ga;
7658 int i; 7680 int i;
7659 listitem_T *li; 7681 listitem_T *li;
7660 int need_capital = FALSE; 7682 int need_capital = FALSE;
7683 int wo_spell_save = curwin->w_p_spell;
7684
7685 if (!curwin->w_p_spell)
7686 {
7687 did_set_spelllang(curwin);
7688 curwin->w_p_spell = TRUE;
7689 }
7690
7691 if (*curwin->w_s->b_p_spl == NUL)
7692 {
7693 emsg(_(e_no_spell));
7694 curwin->w_p_spell = wo_spell_save;
7695 return;
7696 }
7661 #endif 7697 #endif
7662 7698
7663 if (rettv_list_alloc(rettv) == FAIL) 7699 if (rettv_list_alloc(rettv) == FAIL)
7700 {
7701 #ifdef FEAT_SPELL
7702 curwin->w_p_spell = wo_spell_save;
7703 #endif
7664 return; 7704 return;
7705 }
7665 7706
7666 #ifdef FEAT_SPELL 7707 #ifdef FEAT_SPELL
7667 if (curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) 7708 if (*curwin->w_s->b_p_spl != NUL)
7668 { 7709 {
7669 str = tv_get_string(&argvars[0]); 7710 str = tv_get_string(&argvars[0]);
7670 if (argvars[1].v_type != VAR_UNKNOWN) 7711 if (argvars[1].v_type != VAR_UNKNOWN)
7671 { 7712 {
7672 maxcount = (int)tv_get_number_chk(&argvars[1], &typeerr); 7713 maxcount = (int)tv_get_number_chk(&argvars[1], &typeerr);
7699 list_append(rettv->vval.v_list, li); 7740 list_append(rettv->vval.v_list, li);
7700 } 7741 }
7701 } 7742 }
7702 ga_clear(&ga); 7743 ga_clear(&ga);
7703 } 7744 }
7745 curwin->w_p_spell = wo_spell_save;
7704 #endif 7746 #endif
7705 } 7747 }
7706 7748
7707 static void 7749 static void
7708 f_split(typval_T *argvars, typval_T *rettv) 7750 f_split(typval_T *argvars, typval_T *rettv)