diff options
author | Tom Praschan <13141438+tom-anders@users.noreply.github.com> | 2022-04-07 16:14:02 +0200 |
---|---|---|
committer | Tom Praschan <13141438+tom-anders@users.noreply.github.com> | 2022-04-09 15:39:46 +0200 |
commit | 45f62464d3e1f39e74fca627e27eea106ffe46ef (patch) | |
tree | 3ff4fdbd476d29c6427de9b3b02a63c0eb43b13a | |
parent | 233014f92b5d4d5bf8a6f019241aafd1b05dd383 (diff) | |
download | rneovim-45f62464d3e1f39e74fca627e27eea106ffe46ef.tar.gz rneovim-45f62464d3e1f39e74fca627e27eea106ffe46ef.tar.bz2 rneovim-45f62464d3e1f39e74fca627e27eea106ffe46ef.zip |
vim-patch:8.2.4702: C++ scope labels are hard-coded
Problem: C++ scope labels are hard-coded.
Solution: Add 'cinscopedecls' to define the labels. (Tom Praschan,
closes vim/vim#10109)
https://github.com/vim/vim/commit/3506cf34c17c5eae6c2d1317db1fcd5a8493c288
-rw-r--r-- | runtime/doc/indent.txt | 8 | ||||
-rw-r--r-- | runtime/doc/options.txt | 14 | ||||
-rw-r--r-- | runtime/doc/quickref.txt | 1 | ||||
-rw-r--r-- | runtime/optwin.vim | 3 | ||||
-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 | 33 | ||||
-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 |
11 files changed, 100 insertions, 20 deletions
diff --git a/runtime/doc/indent.txt b/runtime/doc/indent.txt index d0d4ddad32..3992b2d3d7 100644 --- a/runtime/doc/indent.txt +++ b/runtime/doc/indent.txt @@ -38,11 +38,12 @@ is not a C compiler: it does not recognize all syntax. One requirement is that toplevel functions have a '{' in the first column. Otherwise they are easily confused with declarations. -These four options control C program indenting: +These five options control C program indenting: 'cindent' Enables Vim to perform C program indenting automatically. 'cinkeys' Specifies which keys trigger reindenting in insert mode. 'cinoptions' Sets your preferred indent style. 'cinwords' Defines keywords that start an extra indent in the next line. +'cinscopedecls' Defines strings that are recognized as a C++ scope declaration. If 'lisp' is not on and 'equalprg' is empty, the "=" operator indents using Vim's built-in algorithm rather than calling an external program. @@ -289,8 +290,9 @@ The examples below assume a 'shiftwidth' of 4. < *cino-g* gN Place C++ scope declarations N characters from the indent of the - block they are in. (default 'shiftwidth'). A scope declaration - can be "public:", "protected:" or "private:". + block they are in. (default 'shiftwidth'). By default, a scope + declaration is "public:", "protected:" or "private:". This can + be adjusted with the 'cinscopedecls' option. cino= cino=g0 > { { diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index b60b8f8849..123577778f 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -1288,10 +1288,20 @@ A jump table for the options with a short description can be found at |Q_op|. matter, include the keyword both the uppercase and lowercase: "if,If,IF". - *'clipboard'* *'cb'* + *'cinscopedecls'* *'cinsd'* +'cinscopedecls' 'cinsd' string (default "public,protected,private") + local to buffer + {not available when compiled without the |+cindent| + feature} + Keywords that are interpreted as a C++ scope declaration by |cino-g|. + Useful e.g. for working with the Qt framework that defines additional + scope declarations "signals", "public slots" and "private slots": > + set cinscopedecls+=signals,public\ slots,private\ slots + +< *'clipboard'* *'cb'* 'clipboard' 'cb' string (default "") global - This option is a list of comma separated names. + This option is a list of comma-separated names. These names are recognized: *clipboard-unnamed* diff --git a/runtime/doc/quickref.txt b/runtime/doc/quickref.txt index e36eb2359f..c3badd5401 100644 --- a/runtime/doc/quickref.txt +++ b/runtime/doc/quickref.txt @@ -638,6 +638,7 @@ Short explanation of each option: *option-list* 'cinkeys' 'cink' keys that trigger indent when 'cindent' is set 'cinoptions' 'cino' how to do indenting when 'cindent' is set 'cinwords' 'cinw' words where 'si' and 'cin' add an indent +'cinscopedecls' 'cinsd' words that are recognized by 'cino-g' 'clipboard' 'cb' use the clipboard as the unnamed register 'cmdheight' 'ch' number of lines to use for the command-line 'cmdwinheight' 'cwh' height of the command-line window diff --git a/runtime/optwin.vim b/runtime/optwin.vim index c873252909..0e3f2d935e 100644 --- a/runtime/optwin.vim +++ b/runtime/optwin.vim @@ -870,6 +870,9 @@ if has("cindent") call append("$", "cinwords\tlist of words that cause more C-indent") call append("$", "\t(local to buffer)") call <SID>OptionL("cinw") + call append("$", "cinscopedecls\tlist of scope declaration names used by cino-g") + call append("$", "\t(local to buffer)") + call <SID>OptionL("cinsd") call append("$", "indentexpr\texpression used to obtain the indent of a line") call append("$", "\t(local to buffer)") call <SID>OptionL("inde") diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index bf592a626d..b65fa77660 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1938,6 +1938,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..d26a27c1c2 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -512,24 +512,27 @@ 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); + + 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] != ':') { + return true; + } + } } - return *(s = cin_skipcomment(s + i)) == ':' && s[1] != ':'; + + xfree(cinsd_buf); + + return false; } // Maximum number of lines to search back for a "namespace" line. diff --git a/src/nvim/option.c b/src/nvim/option.c index 9fd0e0b222..6522454aa5 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 |