Skip to content

Commit 362b44b

Browse files
committed
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 #1235)
1 parent be5ee86 commit 362b44b

10 files changed

Lines changed: 45 additions & 0 deletions

File tree

runtime/doc/options.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7105,6 +7105,16 @@ A jump table for the options with a short description can be found at |Q_op|.
71057105
up to the first character that is not an ASCII letter or number and
71067106
not a dash. Also see |set-spc-auto|.
71077107

7108+
*'spelloptions'* *'spo'*
7109+
'spelloptions' 'spo' string (default "")
7110+
local to buffer
7111+
{not available when compiled without the |+syntax|
7112+
feature}
7113+
A comma separated list of options for spell checking:
7114+
camel When a word is CamelCased, assume "Cased" is a
7115+
separate word: every upper-case character in a word
7116+
that comes after a lower case character indicates the
7117+
start of a new word.
71087118

71097119
*'spellsuggest'* *'sps'*
71107120
'spellsuggest' 'sps' string (default "best")

runtime/doc/spell.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ When there is a line break right after a sentence the highlighting of the next
215215
line may be postponed. Use |CTRL-L| when needed. Also see |set-spc-auto| for
216216
how it can be set automatically when 'spelllang' is set.
217217

218+
The 'spelloptions' option has a few more flags that influence the way spell
219+
checking works.
220+
218221
Vim counts the number of times a good word is encountered. This is used to
219222
sort the suggestions: words that have been seen before get a small bonus,
220223
words that have been seen often get a bigger bonus. The COMMON item in the

src/buffer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,6 +2287,7 @@ free_buf_options(
22872287
vim_regfree(buf->b_s.b_cap_prog);
22882288
buf->b_s.b_cap_prog = NULL;
22892289
clear_string_option(&buf->b_s.b_p_spl);
2290+
clear_string_option(&buf->b_s.b_p_spo);
22902291
#endif
22912292
#ifdef FEAT_SEARCHPATH
22922293
clear_string_option(&buf->b_p_sua);

src/option.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5329,6 +5329,7 @@ get_varp(struct vimoption *p)
53295329
case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
53305330
case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
53315331
case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
5332+
case PV_SPO: return (char_u *)&(curwin->w_s->b_p_spo);
53325333
#endif
53335334
case PV_SW: return (char_u *)&(curbuf->b_p_sw);
53345335
case PV_TS: return (char_u *)&(curbuf->b_p_ts);
@@ -5838,6 +5839,8 @@ buf_copy_options(buf_T *buf, int flags)
58385839
COPY_OPT_SCTX(buf, BV_SPF);
58395840
buf->b_s.b_p_spl = vim_strsave(p_spl);
58405841
COPY_OPT_SCTX(buf, BV_SPL);
5842+
buf->b_s.b_p_spo = vim_strsave(p_spo);
5843+
COPY_OPT_SCTX(buf, BV_SPO);
58415844
#endif
58425845
#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
58435846
buf->b_p_inde = vim_strsave(p_inde);

src/option.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,7 @@ EXTERN char_u *p_tfu; // 'tagfunc'
913913
EXTERN char_u *p_spc; // 'spellcapcheck'
914914
EXTERN char_u *p_spf; // 'spellfile'
915915
EXTERN char_u *p_spl; // 'spelllang'
916+
EXTERN char_u *p_spo; // 'spelloptions'
916917
EXTERN char_u *p_sps; // 'spellsuggest'
917918
#endif
918919
EXTERN int p_spr; // 'splitright'
@@ -1185,6 +1186,7 @@ enum
11851186
, BV_SPC
11861187
, BV_SPF
11871188
, BV_SPL
1189+
, BV_SPO
11881190
#endif
11891191
, BV_STS
11901192
#ifdef FEAT_SEARCHPATH

src/optiondefs.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
# define PV_SPC OPT_BUF(BV_SPC)
130130
# define PV_SPF OPT_BUF(BV_SPF)
131131
# define PV_SPL OPT_BUF(BV_SPL)
132+
# define PV_SPO OPT_BUF(BV_SPO)
132133
#endif
133134
#define PV_STS OPT_BUF(BV_STS)
134135
#ifdef FEAT_SEARCHPATH
@@ -2396,6 +2397,16 @@ static struct vimoption options[] =
23962397
#else
23972398
(char_u *)NULL, PV_NONE,
23982399
{(char_u *)0L, (char_u *)0L}
2400+
#endif
2401+
SCTX_INIT},
2402+
{"spelloptions", "spo", P_STRING|P_ALLOCED|P_VI_DEF
2403+
|P_ONECOMMA|P_NODUP|P_RBUF,
2404+
#ifdef FEAT_SPELL
2405+
(char_u *)&p_spo, PV_SPO,
2406+
{(char_u *)"", (char_u *)0L}
2407+
#else
2408+
(char_u *)NULL, PV_NONE,
2409+
{(char_u *)0L, (char_u *)0L}
23992410
#endif
24002411
SCTX_INIT},
24012412
{"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,

src/optionstr.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ check_buf_options(buf_T *buf)
248248
check_string_option(&buf->b_s.b_p_spc);
249249
check_string_option(&buf->b_s.b_p_spf);
250250
check_string_option(&buf->b_s.b_p_spl);
251+
check_string_option(&buf->b_s.b_p_spo);
251252
#endif
252253
#ifdef FEAT_SEARCHPATH
253254
check_string_option(&buf->b_p_sua);
@@ -1714,6 +1715,12 @@ did_set_string_option(
17141715
{
17151716
errmsg = compile_cap_prog(curwin->w_s);
17161717
}
1718+
// 'spelloptions'
1719+
else if (varp == &(curwin->w_s->b_p_spo))
1720+
{
1721+
if (**varp != NUL && STRCMP("camel", *varp) != 0)
1722+
errmsg = e_invarg;
1723+
}
17171724
// 'spellsuggest'
17181725
else if (varp == &p_sps)
17191726
{

src/testdir/gen_opt_test.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ let test_values = {
132132
\ 'signcolumn': [['', 'auto', 'no'], ['xxx', 'no,yes']],
133133
\ 'spellfile': [['', 'file.en.add'], ['xxx', '/tmp/file']],
134134
\ 'spelllang': [['', 'xxx', 'sr@latin'], ['not&lang', "that\\\rthere"]],
135+
\ 'spelloptions': [['', 'camel'], ['xxx']],
135136
\ 'spellsuggest': [['', 'best', 'double,33'], ['xxx']],
136137
\ 'switchbuf': [['', 'useopen', 'split,newtab'], ['xxx']],
137138
\ 'tagcase': [['smart', 'match'], ['', 'xxx', 'smart,match']],

src/testdir/test_spell.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ func Test_spellbadword()
7777
call assert_equal(['bycycle', 'bad'], spellbadword('My bycycle.'))
7878
call assert_equal(['another', 'caps'], 'A sentence. another sentence'->spellbadword())
7979

80+
call assert_equal(['TheCamelWord', 'bad'], 'TheCamelWord asdf'->spellbadword())
81+
set spelloptions=camel
82+
call assert_equal(['asdf', 'bad'], 'TheCamelWord asdf'->spellbadword())
83+
set spelloptions=
84+
8085
set spelllang=en
8186
call assert_equal(['', ''], spellbadword('centre'))
8287
call assert_equal(['', ''], spellbadword('center'))

src/version.c

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

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
953,
757759
/**/
758760
952,
759761
/**/

0 commit comments

Comments
 (0)