forked from aniani/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. (Rom Praschan, closes #10109)
This commit is contained in:
committed by
Bram Moolenaar
parent
3ad2090316
commit
3506cf34c1
@@ -42,11 +42,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
|
that toplevel functions have a '{' in the first column. Otherwise they are
|
||||||
easily confused with declarations.
|
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.
|
'cindent' Enables Vim to perform C program indenting automatically.
|
||||||
'cinkeys' Specifies which keys trigger reindenting in insert mode.
|
'cinkeys' Specifies which keys trigger reindenting in insert mode.
|
||||||
'cinoptions' Sets your preferred indent style.
|
'cinoptions' Sets your preferred indent style.
|
||||||
'cinwords' Defines keywords that start an extra indent in the next line.
|
'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
|
If 'lisp' is not on and 'equalprg' is empty, the "=" operator indents using
|
||||||
Vim's built-in algorithm rather than calling an external program.
|
Vim's built-in algorithm rather than calling an external program.
|
||||||
@@ -293,8 +294,9 @@ The examples below assume a 'shiftwidth' of 4.
|
|||||||
<
|
<
|
||||||
*cino-g*
|
*cino-g*
|
||||||
gN Place C++ scope declarations N characters from the indent of the
|
gN Place C++ scope declarations N characters from the indent of the
|
||||||
block they are in. (default 'shiftwidth'). A scope declaration
|
block they are in. (default 'shiftwidth'). By default, a scope
|
||||||
can be "public:", "protected:" or "private:".
|
declaration is "public:", "protected:" or "private:". This can
|
||||||
|
be adjusted with the 'cinscopedecls' option.
|
||||||
|
|
||||||
cino= cino=g0 >
|
cino= cino=g0 >
|
||||||
{ {
|
{ {
|
||||||
|
@@ -1661,13 +1661,23 @@ 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:
|
matter, include the keyword both the uppercase and lowercase:
|
||||||
"if,If,IF".
|
"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 "autoselect,exclude:cons\|linux"
|
'clipboard' 'cb' string (default "autoselect,exclude:cons\|linux"
|
||||||
for X-windows, "" otherwise)
|
for X-windows, "" otherwise)
|
||||||
global
|
global
|
||||||
{only in GUI versions or when the |+xterm_clipboard|
|
{only in GUI versions or when the |+xterm_clipboard|
|
||||||
feature is included}
|
feature is included}
|
||||||
This option is a list of comma separated names.
|
This option is a list of comma-separated names.
|
||||||
Note: if one of the items is "exclude:", then you can't add an item
|
Note: if one of the items is "exclude:", then you can't add an item
|
||||||
after that. Therefore do append an item with += but use ^= to
|
after that. Therefore do append an item with += but use ^= to
|
||||||
prepend, e.g.: >
|
prepend, e.g.: >
|
||||||
|
@@ -643,6 +643,7 @@ Short explanation of each option: *option-list*
|
|||||||
'cinkeys' 'cink' keys that trigger indent when 'cindent' is set
|
'cinkeys' 'cink' keys that trigger indent when 'cindent' is set
|
||||||
'cinoptions' 'cino' how to do indenting when 'cindent' is set
|
'cinoptions' 'cino' how to do indenting when 'cindent' is set
|
||||||
'cinwords' 'cinw' words where 'si' and 'cin' add an indent
|
'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
|
'clipboard' 'cb' use the clipboard as the unnamed register
|
||||||
'cmdheight' 'ch' number of lines to use for the command-line
|
'cmdheight' 'ch' number of lines to use for the command-line
|
||||||
'cmdwinheight' 'cwh' height of the command-line window
|
'cmdwinheight' 'cwh' height of the command-line window
|
||||||
|
@@ -624,6 +624,8 @@ call <SID>BinOptionG("scf", &scf)
|
|||||||
if has("gui")
|
if has("gui")
|
||||||
call <SID>AddOption("mousehide", gettext("hide the mouse pointer while typing"))
|
call <SID>AddOption("mousehide", gettext("hide the mouse pointer while typing"))
|
||||||
call <SID>BinOptionG("mh", &mh)
|
call <SID>BinOptionG("mh", &mh)
|
||||||
|
call <SID>AddOption("mousemoveevent", gettext("report mouse movement events"))
|
||||||
|
call <SID>BinOptionG("mousemev", &mousemev)
|
||||||
endif
|
endif
|
||||||
call <SID>AddOption("mousemodel", gettext("\"extend\", \"popup\" or \"popup_setpos\"; what the right\nmouse button is used for"))
|
call <SID>AddOption("mousemodel", gettext("\"extend\", \"popup\" or \"popup_setpos\"; what the right\nmouse button is used for"))
|
||||||
call <SID>OptionG("mousem", &mousem)
|
call <SID>OptionG("mousem", &mousem)
|
||||||
@@ -927,6 +929,9 @@ if has("cindent")
|
|||||||
call <SID>AddOption("cinwords", gettext("list of words that cause more C-indent"))
|
call <SID>AddOption("cinwords", gettext("list of words that cause more C-indent"))
|
||||||
call append("$", "\t" .. s:local_to_buffer)
|
call append("$", "\t" .. s:local_to_buffer)
|
||||||
call <SID>OptionL("cinw")
|
call <SID>OptionL("cinw")
|
||||||
|
call <SID>AddOption("cinscopedecls", gettext("list of scope declaration names used by cino-g"))
|
||||||
|
call append("$", "\t" .. s:local_to_buffer)
|
||||||
|
call <SID>OptionL("cinsd")
|
||||||
call <SID>AddOption("indentexpr", gettext("expression used to obtain the indent of a line"))
|
call <SID>AddOption("indentexpr", gettext("expression used to obtain the indent of a line"))
|
||||||
call append("$", "\t" .. s:local_to_buffer)
|
call append("$", "\t" .. s:local_to_buffer)
|
||||||
call <SID>OptionL("inde")
|
call <SID>OptionL("inde")
|
||||||
|
@@ -2353,6 +2353,7 @@ free_buf_options(
|
|||||||
#ifdef FEAT_CINDENT
|
#ifdef FEAT_CINDENT
|
||||||
clear_string_option(&buf->b_p_cink);
|
clear_string_option(&buf->b_p_cink);
|
||||||
clear_string_option(&buf->b_p_cino);
|
clear_string_option(&buf->b_p_cino);
|
||||||
|
clear_string_option(&buf->b_p_cinsd);
|
||||||
#endif
|
#endif
|
||||||
#if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT)
|
#if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT)
|
||||||
clear_string_option(&buf->b_p_cinw);
|
clear_string_option(&buf->b_p_cinw);
|
||||||
|
@@ -423,20 +423,34 @@ cin_islabel_skip(char_u **s)
|
|||||||
* Recognize a "public/private/protected" scope declaration label.
|
* Recognize a "public/private/protected" scope declaration label.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
cin_isscopedecl(char_u *s)
|
cin_isscopedecl(char_u *p)
|
||||||
{
|
{
|
||||||
int i;
|
size_t cinsd_len;
|
||||||
|
char_u *cinsd_buf;
|
||||||
|
char_u *cinsd;
|
||||||
|
size_t len;
|
||||||
|
char_u *skip;
|
||||||
|
char_u *s = cin_skipcomment(p);
|
||||||
|
|
||||||
s = cin_skipcomment(s);
|
cinsd_len = STRLEN(curbuf->b_p_cinsd) + 1;
|
||||||
if (STRNCMP(s, "public", 6) == 0)
|
cinsd_buf = alloc(cinsd_len);
|
||||||
i = 6;
|
if (cinsd_buf != NULL)
|
||||||
else if (STRNCMP(s, "protected", 9) == 0)
|
{
|
||||||
i = 9;
|
for (cinsd = curbuf->b_p_cinsd; *cinsd; )
|
||||||
else if (STRNCMP(s, "private", 7) == 0)
|
{
|
||||||
i = 7;
|
len = copy_option_part(&cinsd, cinsd_buf, cinsd_len, ",");
|
||||||
else
|
if (STRNCMP(s, cinsd_buf, len) == 0)
|
||||||
return FALSE;
|
{
|
||||||
return (*(s = cin_skipcomment(s + i)) == ':' && s[1] != ':');
|
skip = cin_skipcomment(s + len);
|
||||||
|
if (*skip == ':' && skip[1] != ':')
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vim_free(cinsd_buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -5449,6 +5449,7 @@ get_varp(struct vimoption *p)
|
|||||||
case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
|
case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
|
||||||
case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
|
case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
|
||||||
case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
|
case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
|
||||||
|
case PV_CINSD: return (char_u *)&(curbuf->b_p_cinsd);
|
||||||
#endif
|
#endif
|
||||||
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
|
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
|
||||||
case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
|
case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
|
||||||
@@ -6020,6 +6021,8 @@ buf_copy_options(buf_T *buf, int flags)
|
|||||||
COPY_OPT_SCTX(buf, BV_CINK);
|
COPY_OPT_SCTX(buf, BV_CINK);
|
||||||
buf->b_p_cino = vim_strsave(p_cino);
|
buf->b_p_cino = vim_strsave(p_cino);
|
||||||
COPY_OPT_SCTX(buf, BV_CINO);
|
COPY_OPT_SCTX(buf, BV_CINO);
|
||||||
|
buf->b_p_cinsd = vim_strsave(p_cinsd);
|
||||||
|
COPY_OPT_SCTX(buf, BV_CINSD);
|
||||||
#endif
|
#endif
|
||||||
// Don't copy 'filetype', it must be detected
|
// Don't copy 'filetype', it must be detected
|
||||||
buf->b_p_ft = empty_option;
|
buf->b_p_ft = empty_option;
|
||||||
|
@@ -400,6 +400,7 @@ EXTERN int p_bl; // 'buflisted'
|
|||||||
#ifdef FEAT_CINDENT
|
#ifdef FEAT_CINDENT
|
||||||
EXTERN int p_cin; // 'cindent'
|
EXTERN int p_cin; // 'cindent'
|
||||||
EXTERN char_u *p_cink; // 'cinkeys'
|
EXTERN char_u *p_cink; // 'cinkeys'
|
||||||
|
EXTERN char_u *p_cinsd; // 'cinscopedecls'
|
||||||
#endif
|
#endif
|
||||||
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
|
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
|
||||||
EXTERN char_u *p_cinw; // 'cinwords'
|
EXTERN char_u *p_cinw; // 'cinwords'
|
||||||
@@ -1126,6 +1127,7 @@ enum
|
|||||||
, BV_CIN
|
, BV_CIN
|
||||||
, BV_CINK
|
, BV_CINK
|
||||||
, BV_CINO
|
, BV_CINO
|
||||||
|
, BV_CINSD
|
||||||
#endif
|
#endif
|
||||||
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
|
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
|
||||||
, BV_CINW
|
, BV_CINW
|
||||||
|
@@ -44,6 +44,7 @@
|
|||||||
# define PV_CIN OPT_BUF(BV_CIN)
|
# define PV_CIN OPT_BUF(BV_CIN)
|
||||||
# define PV_CINK OPT_BUF(BV_CINK)
|
# define PV_CINK OPT_BUF(BV_CINK)
|
||||||
# define PV_CINO OPT_BUF(BV_CINO)
|
# define PV_CINO OPT_BUF(BV_CINO)
|
||||||
|
# define PV_CINSD OPT_BUF(BV_CINSD)
|
||||||
#endif
|
#endif
|
||||||
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
|
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
|
||||||
# define PV_CINW OPT_BUF(BV_CINW)
|
# define PV_CINW OPT_BUF(BV_CINW)
|
||||||
@@ -603,6 +604,15 @@ static struct vimoption options[] =
|
|||||||
(char_u *)NULL, PV_NONE,
|
(char_u *)NULL, PV_NONE,
|
||||||
#endif
|
#endif
|
||||||
{(char_u *)"", (char_u *)0L} SCTX_INIT},
|
{(char_u *)"", (char_u *)0L} SCTX_INIT},
|
||||||
|
{"cinscopedecls", "cinsd", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
|
||||||
|
#ifdef FEAT_CINDENT
|
||||||
|
(char_u *)&p_cinsd, PV_CINSD,
|
||||||
|
{(char_u *)"public,protected,private", (char_u *)0L}
|
||||||
|
#else
|
||||||
|
(char_u *)NULL, PV_NONE,
|
||||||
|
{(char_u *)0L, (char_u *)0L}
|
||||||
|
#endif
|
||||||
|
SCTX_INIT},
|
||||||
{"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
|
{"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
|
||||||
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
|
#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
|
||||||
(char_u *)&p_cinw, PV_CINW,
|
(char_u *)&p_cinw, PV_CINW,
|
||||||
|
@@ -260,6 +260,7 @@ check_buf_options(buf_T *buf)
|
|||||||
#ifdef FEAT_CINDENT
|
#ifdef FEAT_CINDENT
|
||||||
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);
|
||||||
|
check_string_option(&buf->b_p_cinsd);
|
||||||
parse_cino(buf);
|
parse_cino(buf);
|
||||||
#endif
|
#endif
|
||||||
check_string_option(&buf->b_p_ft);
|
check_string_option(&buf->b_p_ft);
|
||||||
|
@@ -2881,6 +2881,7 @@ struct file_buffer
|
|||||||
int b_p_cin; // 'cindent'
|
int b_p_cin; // 'cindent'
|
||||||
char_u *b_p_cino; // 'cinoptions'
|
char_u *b_p_cino; // 'cinoptions'
|
||||||
char_u *b_p_cink; // 'cinkeys'
|
char_u *b_p_cink; // 'cinkeys'
|
||||||
|
char_u *b_p_cinsd; // 'cinscopedecls'
|
||||||
#endif
|
#endif
|
||||||
#if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT)
|
#if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT)
|
||||||
char_u *b_p_cinw; // 'cinwords'
|
char_u *b_p_cinw; // 'cinwords'
|
||||||
|
@@ -5319,6 +5319,49 @@ func Test_cindent_change_multline()
|
|||||||
close!
|
close!
|
||||||
endfunc
|
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()
|
func Test_cindent_pragma()
|
||||||
new
|
new
|
||||||
setl cindent ts=4 sw=4
|
setl cindent ts=4 sw=4
|
||||||
|
@@ -746,6 +746,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
4702,
|
||||||
/**/
|
/**/
|
||||||
4701,
|
4701,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user