To: vim_dev@googlegroups.com Subject: Patch 8.2.4702 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4702 Problem: C++ scope labels are hard-coded. Solution: Add 'cinscopedecls' to define the labels. (Rom Praschan, closes #10109) Files: runtime/doc/indent.txt, runtime/doc/options.txt, runtime/doc/quickref.txt, runtime/optwin.vim, src/buffer.c, src/cindent.c, src/option.c, src/option.h, src/optiondefs.h, src/optionstr.c, src/structs.h, src/testdir/test_cindent.vim *** ../vim-8.2.4701/runtime/doc/indent.txt 2021-01-31 16:02:06.254490174 +0000 --- runtime/doc/indent.txt 2022-04-07 12:09:19.688544000 +0100 *************** *** 42,52 **** that toplevel functions have a '{' in the first column. Otherwise they are easily confused with declarations. ! These four 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. If 'lisp' is not on and 'equalprg' is empty, the "=" operator indents using Vim's built-in algorithm rather than calling an external program. --- 42,53 ---- that toplevel functions have a '{' in the first column. Otherwise they are easily confused with declarations. ! 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. *************** *** 293,300 **** < *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:". cino= cino=g0 > { { --- 294,302 ---- < *cino-g* gN Place C++ scope declarations N characters from the indent of the ! 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 > { { *** ../vim-8.2.4701/runtime/doc/options.txt 2022-04-03 15:46:57.385502610 +0100 --- runtime/doc/options.txt 2022-04-07 12:11:06.868209954 +0100 *************** *** 1648,1660 **** matter, include the keyword both the uppercase and lowercase: "if,If,IF". ! *'clipboard'* *'cb'* 'clipboard' 'cb' string (default "autoselect,exclude:cons\|linux" for X-windows, "" otherwise) global {only in GUI versions or when the |+xterm_clipboard| feature is included} ! This option is a list of comma separated names. 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 prepend, e.g.: > --- 1661,1683 ---- matter, include the keyword both the uppercase and lowercase: "if,If,IF". ! *'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" for X-windows, "" otherwise) global {only in GUI versions or when the |+xterm_clipboard| feature is included} ! This option is a list of comma-separated names. 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 prepend, e.g.: > *** ../vim-8.2.4701/runtime/doc/quickref.txt 2021-12-11 12:26:55.920402418 +0000 --- runtime/doc/quickref.txt 2022-04-07 12:03:27.757923388 +0100 *************** *** 643,648 **** --- 643,649 ---- '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 *** ../vim-8.2.4701/runtime/optwin.vim 2021-12-21 09:11:45.629393263 +0000 --- runtime/optwin.vim 2022-04-07 12:17:51.847155108 +0100 *************** *** 624,629 **** --- 624,631 ---- if has("gui") call AddOption("mousehide", gettext("hide the mouse pointer while typing")) call BinOptionG("mh", &mh) + call AddOption("mousemoveevent", gettext("report mouse movement events")) + call BinOptionG("mousemev", &mousemev) endif call AddOption("mousemodel", gettext("\"extend\", \"popup\" or \"popup_setpos\"; what the right\nmouse button is used for")) call OptionG("mousem", &mousem) *************** *** 927,932 **** --- 929,937 ---- call AddOption("cinwords", gettext("list of words that cause more C-indent")) call append("$", "\t" .. s:local_to_buffer) call OptionL("cinw") + call AddOption("cinscopedecls", gettext("list of scope declaration names used by cino-g")) + call append("$", "\t" .. s:local_to_buffer) + call OptionL("cinsd") call AddOption("indentexpr", gettext("expression used to obtain the indent of a line")) call append("$", "\t" .. s:local_to_buffer) call OptionL("inde") *** ../vim-8.2.4701/src/buffer.c 2022-04-04 16:56:50.772629666 +0100 --- src/buffer.c 2022-04-07 12:03:27.757923388 +0100 *************** *** 2353,2358 **** --- 2353,2359 ---- #ifdef FEAT_CINDENT clear_string_option(&buf->b_p_cink); clear_string_option(&buf->b_p_cino); + clear_string_option(&buf->b_p_cinsd); #endif #if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT) clear_string_option(&buf->b_p_cinw); *** ../vim-8.2.4701/src/cindent.c 2022-01-31 14:59:33.510943820 +0000 --- src/cindent.c 2022-04-07 12:20:49.618758535 +0100 *************** *** 423,442 **** * Recognize a "public/private/protected" scope declaration label. */ static int ! cin_isscopedecl(char_u *s) { ! int i; ! 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; ! return (*(s = cin_skipcomment(s + i)) == ':' && s[1] != ':'); } /* --- 423,456 ---- * Recognize a "public/private/protected" scope declaration label. */ static int ! cin_isscopedecl(char_u *p) { ! size_t cinsd_len; ! char_u *cinsd_buf; ! char_u *cinsd; ! size_t len; ! char_u *skip; ! char_u *s = cin_skipcomment(p); ! cinsd_len = STRLEN(curbuf->b_p_cinsd) + 1; ! cinsd_buf = alloc(cinsd_len); ! if (cinsd_buf != NULL) ! { ! for (cinsd = curbuf->b_p_cinsd; *cinsd; ) ! { ! len = copy_option_part(&cinsd, cinsd_buf, cinsd_len, ","); ! if (STRNCMP(s, cinsd_buf, len) == 0) ! { ! skip = cin_skipcomment(s + len); ! if (*skip == ':' && skip[1] != ':') ! return TRUE; ! } ! } ! ! vim_free(cinsd_buf); ! } ! ! return FALSE; } /* *** ../vim-8.2.4701/src/option.c 2022-04-05 14:17:40.360983091 +0100 --- src/option.c 2022-04-07 12:03:27.757923388 +0100 *************** *** 5449,5454 **** --- 5449,5455 ---- case PV_CIN: return (char_u *)&(curbuf->b_p_cin); case PV_CINK: 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); #endif #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) case PV_CINW: return (char_u *)&(curbuf->b_p_cinw); *************** *** 6020,6025 **** --- 6021,6028 ---- 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); #endif // Don't copy 'filetype', it must be detected buf->b_p_ft = empty_option; *** ../vim-8.2.4701/src/option.h 2022-04-03 15:46:57.389502603 +0100 --- src/option.h 2022-04-07 12:03:27.757923388 +0100 *************** *** 400,405 **** --- 400,406 ---- #ifdef FEAT_CINDENT EXTERN int p_cin; // 'cindent' EXTERN char_u *p_cink; // 'cinkeys' + EXTERN char_u *p_cinsd; // 'cinscopedecls' #endif #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) EXTERN char_u *p_cinw; // 'cinwords' *************** *** 1126,1131 **** --- 1127,1133 ---- , BV_CIN , BV_CINK , BV_CINO + , BV_CINSD #endif #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) , BV_CINW *** ../vim-8.2.4701/src/optiondefs.h 2022-04-05 14:17:40.360983091 +0100 --- src/optiondefs.h 2022-04-07 12:32:50.381335384 +0100 *************** *** 44,49 **** --- 44,50 ---- # define PV_CIN OPT_BUF(BV_CIN) # define PV_CINK OPT_BUF(BV_CINK) # define PV_CINO OPT_BUF(BV_CINO) + # define PV_CINSD OPT_BUF(BV_CINSD) #endif #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) # define PV_CINW OPT_BUF(BV_CINW) *************** *** 603,608 **** --- 604,618 ---- (char_u *)NULL, PV_NONE, #endif {(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, #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) (char_u *)&p_cinw, PV_CINW, *** ../vim-8.2.4701/src/optionstr.c 2022-04-05 14:17:40.360983091 +0100 --- src/optionstr.c 2022-04-07 12:22:15.118576951 +0100 *************** *** 260,265 **** --- 260,266 ---- #ifdef FEAT_CINDENT check_string_option(&buf->b_p_cink); check_string_option(&buf->b_p_cino); + check_string_option(&buf->b_p_cinsd); parse_cino(buf); #endif check_string_option(&buf->b_p_ft); *** ../vim-8.2.4701/src/structs.h 2022-04-05 21:40:32.107458262 +0100 --- src/structs.h 2022-04-07 12:03:27.761923367 +0100 *************** *** 2881,2886 **** --- 2881,2887 ---- int b_p_cin; // 'cindent' char_u *b_p_cino; // 'cinoptions' char_u *b_p_cink; // 'cinkeys' + char_u *b_p_cinsd; // 'cinscopedecls' #endif #if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT) char_u *b_p_cinw; // 'cinwords' *** ../vim-8.2.4701/src/testdir/test_cindent.vim 2021-12-22 20:55:26.309070326 +0000 --- src/testdir/test_cindent.vim 2022-04-07 12:03:27.761923367 +0100 *************** *** 5319,5324 **** --- 5319,5367 ---- close! 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 *** ../vim-8.2.4701/src/version.c 2022-04-06 18:57:34.119958768 +0100 --- src/version.c 2022-04-07 12:17:03.839267597 +0100 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 4702, /**/ -- Another bucket of what can only be described as human ordure hits ARTHUR. ARTHUR: ... Right! (to the KNIGHTS) That settles it! "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///