vim-patch:8.2.0953: spell checking doesn't work for CamelCased words

Problem:    Spell checking doesn't work for CamelCased words.
Solution:   Add the "camel" value in the new option 'spelloptions'.
            (closes vim/vim#1235)
362b44bd4a
This commit is contained in:
Thomas Vigouroux
2020-09-21 15:38:57 +02:00
parent 4f8d98e583
commit a08959bc7a
7 changed files with 36 additions and 0 deletions

View File

@@ -5672,6 +5672,14 @@ A jump table for the options with a short description can be found at |Q_op|.
up to the first character that is not an ASCII letter or number and up to the first character that is not an ASCII letter or number and
not a dash. Also see |set-spc-auto|. not a dash. Also see |set-spc-auto|.
*'spelloptions'* *'spo'*
'spelloptions' 'spo' string (default "")
local to buffer
A comma separated list of options for spell checking:
camel When a word is CamelCased, assume "Cased" is a
separate word: every upper-case character in a word
that comes after a lower case character indicates the
start of a new word.
*'spellsuggest'* *'sps'* *'spellsuggest'* *'sps'*
'spellsuggest' 'sps' string (default "best") 'spellsuggest' 'sps' string (default "best")

View File

@@ -187,6 +187,9 @@ When there is a line break right after a sentence the highlighting of the next
line may be postponed. Use |CTRL-L| when needed. Also see |set-spc-auto| for line may be postponed. Use |CTRL-L| when needed. Also see |set-spc-auto| for
how it can be set automatically when 'spelllang' is set. how it can be set automatically when 'spelllang' is set.
The 'spelloptions' option has a few more flags that influence the way spell
checking works.
Vim counts the number of times a good word is encountered. This is used to Vim counts the number of times a good word is encountered. This is used to
sort the suggestions: words that have been seen before get a small bonus, sort the suggestions: words that have been seen before get a small bonus,
words that have been seen often get a bigger bonus. The COMMON item in the words that have been seen often get a bigger bonus. The COMMON item in the

View File

@@ -1941,6 +1941,7 @@ void free_buf_options(buf_T *buf, int free_p_ff)
vim_regfree(buf->b_s.b_cap_prog); vim_regfree(buf->b_s.b_cap_prog);
buf->b_s.b_cap_prog = NULL; buf->b_s.b_cap_prog = NULL;
clear_string_option(&buf->b_s.b_p_spl); clear_string_option(&buf->b_s.b_p_spl);
clear_string_option(&buf->b_s.b_p_spo);
clear_string_option(&buf->b_p_sua); clear_string_option(&buf->b_p_sua);
clear_string_option(&buf->b_p_ft); clear_string_option(&buf->b_p_ft);
clear_string_option(&buf->b_p_cink); clear_string_option(&buf->b_p_cink);

View File

@@ -174,6 +174,7 @@ static char_u *p_syn;
static char_u *p_spc; static char_u *p_spc;
static char_u *p_spf; static char_u *p_spf;
static char_u *p_spl; static char_u *p_spl;
static char_u *p_spo;
static long p_ts; static long p_ts;
static long p_tw; static long p_tw;
static int p_udf; static int p_udf;
@@ -2285,6 +2286,7 @@ void check_buf_options(buf_T *buf)
check_string_option(&buf->b_s.b_p_spc); check_string_option(&buf->b_s.b_p_spc);
check_string_option(&buf->b_s.b_p_spf); check_string_option(&buf->b_s.b_p_spf);
check_string_option(&buf->b_s.b_p_spl); check_string_option(&buf->b_s.b_p_spl);
check_string_option(&buf->b_s.b_p_spo);
check_string_option(&buf->b_p_sua); check_string_option(&buf->b_p_sua);
check_string_option(&buf->b_p_cink); check_string_option(&buf->b_p_cink);
check_string_option(&buf->b_p_cino); check_string_option(&buf->b_p_cino);
@@ -3090,6 +3092,10 @@ ambw_end:
} else if (varp == &(curwin->w_s->b_p_spc)) { } else if (varp == &(curwin->w_s->b_p_spc)) {
// When 'spellcapcheck' is set compile the regexp program. // When 'spellcapcheck' is set compile the regexp program.
errmsg = compile_cap_prog(curwin->w_s); errmsg = compile_cap_prog(curwin->w_s);
} else if (varp == &(curwin->w_s->b_p_spo)) { // 'spelloptions'
if (**varp != NUL && STRCMP("camel", *varp) != 0) {
errmsg = e_invarg;
}
} else if (varp == &p_sps) { // 'spellsuggest' } else if (varp == &p_sps) { // 'spellsuggest'
if (spell_check_sps() != OK) { if (spell_check_sps() != OK) {
errmsg = e_invarg; errmsg = e_invarg;
@@ -5896,6 +5902,7 @@ static char_u *get_varp(vimoption_T *p)
case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc); case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf); case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl); case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
case PV_SPO: return (char_u *)&(curwin->w_s->b_p_spo);
case PV_SW: return (char_u *)&(curbuf->b_p_sw); case PV_SW: return (char_u *)&(curbuf->b_p_sw);
case PV_TFU: return (char_u *)&(curbuf->b_p_tfu); case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
case PV_TS: return (char_u *)&(curbuf->b_p_ts); case PV_TS: return (char_u *)&(curbuf->b_p_ts);
@@ -6175,6 +6182,7 @@ void buf_copy_options(buf_T *buf, int flags)
(void)compile_cap_prog(&buf->b_s); (void)compile_cap_prog(&buf->b_s);
buf->b_s.b_p_spf = vim_strsave(p_spf); buf->b_s.b_p_spf = vim_strsave(p_spf);
buf->b_s.b_p_spl = vim_strsave(p_spl); buf->b_s.b_p_spl = vim_strsave(p_spl);
buf->b_s.b_p_spo = vim_strsave(p_spo);
buf->b_p_inde = vim_strsave(p_inde); buf->b_p_inde = vim_strsave(p_inde);
buf->b_p_indk = vim_strsave(p_indk); buf->b_p_indk = vim_strsave(p_indk);
buf->b_p_fp = empty_option; buf->b_p_fp = empty_option;

View File

@@ -787,6 +787,7 @@ enum {
, BV_SPC , BV_SPC
, BV_SPF , BV_SPF
, BV_SPL , BV_SPL
, BV_SPO
, BV_STS , BV_STS
, BV_SUA , BV_SUA
, BV_SW , BV_SW

View File

@@ -2319,6 +2319,16 @@ return {
varname='p_sps', varname='p_sps',
defaults={if_true={vi="best"}} defaults={if_true={vi="best"}}
}, },
{
full_name='spelloptions', abbreviation='spo',
type='string', list='onecomma', scope={'buffer'},
deny_duplicates=true,
secure=true,
vi_def=true,
expand=true,
varname='p_spo',
defaults={if_true={vi="", vim=""}}
},
{ {
full_name='splitbelow', abbreviation='sb', full_name='splitbelow', abbreviation='sb',
type='bool', scope={'global'}, type='bool', scope={'global'},

View File

@@ -79,6 +79,11 @@ func Test_spellbadword()
call assert_equal(['bycycle', 'bad'], spellbadword('My bycycle.')) call assert_equal(['bycycle', 'bad'], spellbadword('My bycycle.'))
call assert_equal(['another', 'caps'], spellbadword('A sentence. another sentence')) call assert_equal(['another', 'caps'], spellbadword('A sentence. another sentence'))
call assert_equal(['TheCamelWord', 'bad'], spellbadword('TheCamelWord asdf'))
set spelloptions=camel
call assert_equal(['asdf', 'bad'], spellbadword('TheCamelWord asdf'))
set spelloptions=
set spelllang=en set spelllang=en
call assert_equal(['', ''], spellbadword('centre')) call assert_equal(['', ''], spellbadword('centre'))
call assert_equal(['', ''], spellbadword('center')) call assert_equal(['', ''], spellbadword('center'))