]> granicus.if.org Git - vim/commitdiff
patch 8.2.0953: spell checking doesn't work for CamelCased words v8.2.0953
authorBram Moolenaar <Bram@vim.org>
Wed, 10 Jun 2020 19:47:00 +0000 (21:47 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 10 Jun 2020 19:47:00 +0000 (21:47 +0200)
Problem:    Spell checking doesn't work for CamelCased words.
Solution:   Add the "camel" value in the new option 'spelloptions'.
            (closes #1235)

runtime/doc/options.txt
runtime/doc/spell.txt
src/buffer.c
src/option.c
src/option.h
src/optiondefs.h
src/optionstr.c
src/testdir/gen_opt_test.vim
src/testdir/test_spell.vim
src/version.c

index 9f9ae94917219f77f2ee0736ac8b97f0bd89588c..d8e3192fdae85c6ec1936bc83c22fc6817c2fde0 100644 (file)
@@ -7105,6 +7105,16 @@ 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
        not a dash.  Also see |set-spc-auto|.
 
+                                               *'spelloptions'* *'spo'*
+'spelloptions' 'spo'   string  (default "")
+                       local to buffer
+                       {not available when compiled without the |+syntax|
+                       feature}
+       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'   string  (default "best")
index d4f542d3ec05329cc07738218b252c1dd57de6bf..3f8302b7cca2c923924acf1af05ae8e717bcf510 100644 (file)
@@ -215,6 +215,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
 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
 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
index df92ecdbd4de3e888059f18ccef52a40450bee22..66b0050a65f029039d5f6c7d676f071ab73e6660 100644 (file)
@@ -2287,6 +2287,7 @@ free_buf_options(
     vim_regfree(buf->b_s.b_cap_prog);
     buf->b_s.b_cap_prog = NULL;
     clear_string_option(&buf->b_s.b_p_spl);
+    clear_string_option(&buf->b_s.b_p_spo);
 #endif
 #ifdef FEAT_SEARCHPATH
     clear_string_option(&buf->b_p_sua);
index 45a62310a33dce586d0f74136587fa56ea752573..f66fad9473b33ae0706d978d9d67877a1f968612 100644 (file)
@@ -5329,6 +5329,7 @@ get_varp(struct vimoption *p)
        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_SPL:    return (char_u *)&(curwin->w_s->b_p_spl);
+       case PV_SPO:    return (char_u *)&(curwin->w_s->b_p_spo);
 #endif
        case PV_SW:     return (char_u *)&(curbuf->b_p_sw);
        case PV_TS:     return (char_u *)&(curbuf->b_p_ts);
@@ -5838,6 +5839,8 @@ buf_copy_options(buf_T *buf, int flags)
            COPY_OPT_SCTX(buf, BV_SPF);
            buf->b_s.b_p_spl = vim_strsave(p_spl);
            COPY_OPT_SCTX(buf, BV_SPL);
+           buf->b_s.b_p_spo = vim_strsave(p_spo);
+           COPY_OPT_SCTX(buf, BV_SPO);
 #endif
 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
            buf->b_p_inde = vim_strsave(p_inde);
index 4b6eadc460ee5fdc2fc82d4f27a81242c8b1a801..7777bd689c74f31f9914dc1672aaa46be99988e0 100644 (file)
@@ -913,6 +913,7 @@ EXTERN char_u       *p_tfu;         // 'tagfunc'
 EXTERN char_u  *p_spc;         // 'spellcapcheck'
 EXTERN char_u  *p_spf;         // 'spellfile'
 EXTERN char_u  *p_spl;         // 'spelllang'
+EXTERN char_u  *p_spo;         // 'spelloptions'
 EXTERN char_u  *p_sps;         // 'spellsuggest'
 #endif
 EXTERN int     p_spr;          // 'splitright'
@@ -1185,6 +1186,7 @@ enum
     , BV_SPC
     , BV_SPF
     , BV_SPL
+    , BV_SPO
 #endif
     , BV_STS
 #ifdef FEAT_SEARCHPATH
index 571a3af5e207fe6b1c1212f45142d9d4d3e782fd..f1f1af3090f822e075a17037ec130a7b43ce160c 100644 (file)
 # define PV_SPC                OPT_BUF(BV_SPC)
 # define PV_SPF                OPT_BUF(BV_SPF)
 # define PV_SPL                OPT_BUF(BV_SPL)
+# define PV_SPO                OPT_BUF(BV_SPO)
 #endif
 #define PV_STS         OPT_BUF(BV_STS)
 #ifdef FEAT_SEARCHPATH
@@ -2396,6 +2397,16 @@ static struct vimoption options[] =
 #else
                            (char_u *)NULL, PV_NONE,
                            {(char_u *)0L, (char_u *)0L}
+#endif
+                           SCTX_INIT},
+    {"spelloptions", "spo",  P_STRING|P_ALLOCED|P_VI_DEF
+                                                   |P_ONECOMMA|P_NODUP|P_RBUF,
+#ifdef FEAT_SPELL
+                           (char_u *)&p_spo, PV_SPO,
+                           {(char_u *)"", (char_u *)0L}
+#else
+                           (char_u *)NULL, PV_NONE,
+                           {(char_u *)0L, (char_u *)0L}
 #endif
                            SCTX_INIT},
     {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
index 6071f46ed5dc892b5b89ed3d8d64e0db18d25d97..a0409fa77110259197a83e274edf9d64af31b132 100644 (file)
@@ -248,6 +248,7 @@ check_buf_options(buf_T *buf)
     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_spl);
+    check_string_option(&buf->b_s.b_p_spo);
 #endif
 #ifdef FEAT_SEARCHPATH
     check_string_option(&buf->b_p_sua);
@@ -1714,6 +1715,12 @@ did_set_string_option(
     {
        errmsg = compile_cap_prog(curwin->w_s);
     }
+    // 'spelloptions'
+    else if (varp == &(curwin->w_s->b_p_spo))
+    {
+       if (**varp != NUL && STRCMP("camel", *varp) != 0)
+           errmsg = e_invarg;
+    }
     // 'spellsuggest'
     else if (varp == &p_sps)
     {
index 8914902916faa391fc8b17329dae5f8ab7423e78..faff33a863c4fd0adebe47c37e19d555654d6799 100644 (file)
@@ -132,6 +132,7 @@ let test_values = {
       \ 'signcolumn': [['', 'auto', 'no'], ['xxx', 'no,yes']],
       \ 'spellfile': [['', 'file.en.add'], ['xxx', '/tmp/file']],
       \ 'spelllang': [['', 'xxx', 'sr@latin'], ['not&lang', "that\\\rthere"]],
+      \ 'spelloptions': [['', 'camel'], ['xxx']],
       \ 'spellsuggest': [['', 'best', 'double,33'], ['xxx']],
       \ 'switchbuf': [['', 'useopen', 'split,newtab'], ['xxx']],
       \ 'tagcase': [['smart', 'match'], ['', 'xxx', 'smart,match']],
index aee51c7785d664b38b281581b2021e931fc469ad..fbd5c1a1da8992924d67941705b93d458ca1c2e8 100644 (file)
@@ -77,6 +77,11 @@ func Test_spellbadword()
   call assert_equal(['bycycle', 'bad'],  spellbadword('My bycycle.'))
   call assert_equal(['another', 'caps'], 'A sentence. another sentence'->spellbadword())
 
+  call assert_equal(['TheCamelWord', 'bad'], 'TheCamelWord asdf'->spellbadword())
+  set spelloptions=camel
+  call assert_equal(['asdf', 'bad'], 'TheCamelWord asdf'->spellbadword())
+  set spelloptions=
+
   set spelllang=en
   call assert_equal(['', ''],            spellbadword('centre'))
   call assert_equal(['', ''],            spellbadword('center'))
index 0ed018c84963f26e3605ab8395804783a738146d..b30e5570cbd6acdfe38be59ab3dedfa40aa18479 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    953,
 /**/
     952,
 /**/