diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-04-09 22:13:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-09 22:13:34 +0800 |
commit | f3183a4d7c051e8062d28cfc9905b21e13bb7775 (patch) | |
tree | c1b15674392d50ce4b2f3d2f9c9ffe765373a69a /src | |
parent | 8055f9857b8e384634d457533dfdb08618fc36f0 (diff) | |
parent | bf39c5fe4fcd54f32610849b5bacd129e449729d (diff) | |
download | rneovim-f3183a4d7c051e8062d28cfc9905b21e13bb7775.tar.gz rneovim-f3183a4d7c051e8062d28cfc9905b21e13bb7775.tar.bz2 rneovim-f3183a4d7c051e8062d28cfc9905b21e13bb7775.zip |
Merge pull request #18023 from tom-anders/vim-8.2.4702
vim-patch:8.2.{4702,4703}: C++ scope labels are hard-coded
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/buffer.c | 1 | ||||
-rw-r--r-- | src/nvim/buffer_defs.h | 1 | ||||
-rw-r--r-- | src/nvim/indent_c.c | 36 | ||||
-rw-r--r-- | src/nvim/option.c | 6 | ||||
-rw-r--r-- | src/nvim/option_defs.h | 1 | ||||
-rw-r--r-- | src/nvim/options.lua | 9 | ||||
-rw-r--r-- | src/nvim/testdir/test_cindent.vim | 43 |
7 files changed, 82 insertions, 15 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 4ec23244cd..4948e2bb69 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1945,6 +1945,7 @@ void free_buf_options(buf_T *buf, int free_p_ff) clear_string_option(&buf->b_p_cink); clear_string_option(&buf->b_p_cino); clear_string_option(&buf->b_p_cinw); + clear_string_option(&buf->b_p_cinsd); clear_string_option(&buf->b_p_cpt); clear_string_option(&buf->b_p_cfu); clear_string_option(&buf->b_p_ofu); diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 422741cc2f..2bb45e9fa0 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -696,6 +696,7 @@ struct file_buffer { char_u *b_p_cino; ///< 'cinoptions' char_u *b_p_cink; ///< 'cinkeys' char_u *b_p_cinw; ///< 'cinwords' + char_u *b_p_cinsd; ///< 'cinscopedecls' char_u *b_p_com; ///< 'comments' char_u *b_p_cms; ///< 'commentstring' char_u *b_p_cpt; ///< 'complete' diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 7f483d02ab..f2ae8079d8 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -512,24 +512,30 @@ static int cin_isdefault(const char_u *s) && s[1] != ':'; } -/* - * Recognize a "public/private/protected" scope declaration label. - */ -bool cin_isscopedecl(const char_u *s) +/// Recognize a scope declaration label set in 'cinscopedecls'. +bool cin_isscopedecl(const char_u *p) { - int i; + const char_u *s = cin_skipcomment(p); - s = cin_skipcomment(s); - if (STRNCMP(s, "public", 6) == 0) { - i = 6; - } else if (STRNCMP(s, "protected", 9) == 0) { - i = 9; - } else if (STRNCMP(s, "private", 7) == 0) { - i = 7; - } else { - return false; + const size_t cinsd_len = STRLEN(curbuf->b_p_cinsd) + 1; + char_u *cinsd_buf = xmalloc(cinsd_len); + + bool found = false; + + for (char_u *cinsd = curbuf->b_p_cinsd; *cinsd; ) { + const size_t len = copy_option_part(&cinsd, cinsd_buf, cinsd_len, ","); + if (STRNCMP(s, cinsd_buf, len) == 0) { + const char_u *skip = cin_skipcomment(s + len); + if (*skip == ':' && skip[1] != ':') { + found = true; + break; + } + } } - return *(s = cin_skipcomment(s + i)) == ':' && s[1] != ':'; + + xfree(cinsd_buf); + + return found; } // Maximum number of lines to search back for a "namespace" line. diff --git a/src/nvim/option.c b/src/nvim/option.c index 551bc1fbdf..f6037fc20a 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -133,6 +133,7 @@ static int p_cin; static char_u *p_cink; static char_u *p_cino; static char_u *p_cinw; +static char_u *p_cinsd; static char_u *p_com; static char_u *p_cms; static char_u *p_cpt; @@ -2060,6 +2061,7 @@ void check_buf_options(buf_T *buf) parse_cino(buf); check_string_option(&buf->b_p_ft); check_string_option(&buf->b_p_cinw); + check_string_option(&buf->b_p_cinsd); check_string_option(&buf->b_p_cpt); check_string_option(&buf->b_p_cfu); check_string_option(&buf->b_p_ofu); @@ -6058,6 +6060,8 @@ static char_u *get_varp(vimoption_T *p) return (char_u *)&(curbuf->b_p_cink); case PV_CINO: return (char_u *)&(curbuf->b_p_cino); + case PV_CINSD: + return (char_u *)&(curbuf->b_p_cinsd); case PV_CINW: return (char_u *)&(curbuf->b_p_cinw); case PV_COM: @@ -6505,6 +6509,8 @@ void buf_copy_options(buf_T *buf, int flags) COPY_OPT_SCTX(buf, BV_CINK); buf->b_p_cino = vim_strsave(p_cino); COPY_OPT_SCTX(buf, BV_CINO); + buf->b_p_cinsd = vim_strsave(p_cinsd); + COPY_OPT_SCTX(buf, BV_CINSD); // Don't copy 'filetype', it must be detected buf->b_p_ft = empty_option; buf->b_p_pi = p_pi; diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 6ce95ea690..bf71b63cc8 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -773,6 +773,7 @@ enum { BV_CINK, BV_CINO, BV_CINW, + BV_CINSD, BV_CM, BV_CMS, BV_COM, diff --git a/src/nvim/options.lua b/src/nvim/options.lua index e665ffd346..313cace4b2 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -351,6 +351,15 @@ return { defaults={if_true="if,else,while,do,for,switch"} }, { + full_name='cinscopedecls', abbreviation='cinsd', + short_desc=N_("words that are recognized by 'cino-g'"), + type='string', list='onecomma', scope={'buffer'}, + deny_duplicates=true, + alloced=true, + varname='p_cinsd', + defaults={if_true="public,protected,private"} + }, + { full_name='clipboard', abbreviation='cb', short_desc=N_("use the clipboard as the unnamed register"), type='string', list='onecomma', scope={'global'}, diff --git a/src/nvim/testdir/test_cindent.vim b/src/nvim/testdir/test_cindent.vim index 4b702bf2b8..4d69aed96c 100644 --- a/src/nvim/testdir/test_cindent.vim +++ b/src/nvim/testdir/test_cindent.vim @@ -5311,6 +5311,49 @@ func Test_cindent_case() bwipe! endfunc +func Test_cindent_scopedecls() + new + setl cindent ts=4 sw=4 + setl cino=g0 + setl cinsd+=public\ slots,signals + + let code =<< trim [CODE] + class Foo + { + public: + virtual void foo() = 0; + public slots: + void onBar(); + signals: + void baz(); + private: + int x; + }; + [CODE] + + call append(0, code) + normal gg + normal ]]=][ + + let expected =<< trim [CODE] + class Foo + { + public: + virtual void foo() = 0; + public slots: + void onBar(); + signals: + void baz(); + private: + int x; + }; + + [CODE] + + call assert_equal(expected, getline(1, '$')) + enew! | close +endfunc + func Test_cindent_pragma() new setl cindent ts=4 sw=4 |