Patch 8.2.4907

5 views
Skip to first unread message

Bram Moolenaar

unread,
May 7, 2022, 9:54:59 AM5/7/22
to vim...@googlegroups.com

Patch 8.2.4907
Problem: Some users do not want a line comment always inserted.
Solution: Add the '/' flag to 'formatoptions' to not repeat the comment
leader after a statement when using "o".
Files: runtime/doc/change.txt, src/option.h, src/change.c,
src/testdir/test_textformat.vim


*** ../vim-8.2.4906/runtime/doc/change.txt 2022-05-06 11:44:03.811966282 +0100
--- runtime/doc/change.txt 2022-05-07 14:15:56.248733590 +0100
***************
*** 1652,1667 ****

letter meaning when present in 'formatoptions' ~
*fo-t*
! t Auto-wrap text using textwidth
*fo-c*
! c Auto-wrap comments using textwidth, inserting the current comment
leader automatically.
*fo-r*
r Automatically insert the current comment leader after hitting
<Enter> in Insert mode.
*fo-o*
o Automatically insert the current comment leader after hitting 'o' or
! 'O' in Normal mode.
*fo-q*
q Allow formatting of comments with "gq".
Note that formatting will not change blank lines or lines containing
--- 1673,1692 ----

letter meaning when present in 'formatoptions' ~
*fo-t*
! t Auto-wrap text using 'textwidth'
*fo-c*
! c Auto-wrap comments using 'textwidth', inserting the current comment
leader automatically.
*fo-r*
r Automatically insert the current comment leader after hitting
<Enter> in Insert mode.
*fo-o*
o Automatically insert the current comment leader after hitting 'o' or
! 'O' in Normal mode. In case comment is unwanted in a specific place
! use CTRL-U to quickly delete it. |i_CTRL-U|
! *fo-/*
! / When 'o' is included: do not insert the comment leader for a //
! comment after a statement, only when // is at the start of the line.
*fo-q*
q Allow formatting of comments with "gq".
Note that formatting will not change blank lines or lines containing
*** ../vim-8.2.4906/src/option.h 2022-04-13 11:47:21.711886557 +0100
--- src/option.h 2022-05-07 14:18:21.668687177 +0100
***************
*** 141,146 ****
--- 141,147 ----
#define FO_WRAP_COMS 'c'
#define FO_RET_COMS 'r'
#define FO_OPEN_COMS 'o'
+ #define FO_NO_OPEN_COMS '/'
#define FO_Q_COMS 'q'
#define FO_Q_NUMBER 'n'
#define FO_Q_SECOND '2'
***************
*** 159,165 ****

#define DFLT_FO_VI "vt"
#define DFLT_FO_VIM "tcq"
! #define FO_ALL "tcroq2vlb1mMBn,aw]jp" // for do_set()

// characters for the p_cpo option:
#define CPO_ALTREAD 'a' // ":read" sets alternate file name
--- 160,166 ----

#define DFLT_FO_VI "vt"
#define DFLT_FO_VIM "tcq"
! #define FO_ALL "tcro/q2vlb1mMBn,aw]jp" // for do_set()

// characters for the p_cpo option:
#define CPO_ALTREAD 'a' // ":read" sets alternate file name
***************
*** 196,202 ****
#define CPO_REMMARK 'R' // remove marks when filtering
#define CPO_BUFOPT 's'
#define CPO_BUFOPTGLOB 'S'
! #define CPO_TAGPAT 't'
#define CPO_UNDO 'u' // "u" undoes itself
#define CPO_BACKSPACE 'v' // "v" keep deleted text
#define CPO_CW 'w' // "cw" only changes one blank
--- 197,203 ----
#define CPO_REMMARK 'R' // remove marks when filtering
#define CPO_BUFOPT 's'
#define CPO_BUFOPTGLOB 'S'
! #define CPO_TAGPAT 't' // tag pattern is used for "n"
#define CPO_UNDO 'u' // "u" undoes itself
#define CPO_BACKSPACE 'v' // "v" keep deleted text
#define CPO_CW 'w' // "cw" only changes one blank
*** ../vim-8.2.4906/src/change.c 2022-04-11 17:36:33.456351921 +0100
--- src/change.c 2022-05-07 14:19:53.716657258 +0100
***************
*** 1659,1665 ****
lead_len = get_leader_len(saved_line, &lead_flags,
dir == BACKWARD, TRUE);
#ifdef FEAT_CINDENT
! if (lead_len == 0 && curbuf->b_p_cin && do_cindent && dir == FORWARD)
{
// Check for a line comment after code.
comment_start = check_linecomment(saved_line);
--- 1659,1666 ----
lead_len = get_leader_len(saved_line, &lead_flags,
dir == BACKWARD, TRUE);
#ifdef FEAT_CINDENT
! if (lead_len == 0 && curbuf->b_p_cin && do_cindent && dir == FORWARD
! && !has_format_option(FO_NO_OPEN_COMS))
{
// Check for a line comment after code.
comment_start = check_linecomment(saved_line);
*** ../vim-8.2.4906/src/testdir/test_textformat.vim 2022-04-11 17:36:33.456351921 +0100
--- src/testdir/test_textformat.vim 2022-05-07 14:26:49.624518404 +0100
***************
*** 278,283 ****
--- 278,295 ----
//
END
call assert_equal(expected, getline(1, '$'))
+ 3delete
+
+ " No comment repeated with a slash in 'formatoptions'
+ set fo+=/
+ normal 2Gox
+ let expected =<< trim END
+ nop;
+ val = val; // This is a comment
+ x
+ END
+ call assert_equal(expected, getline(1, '$'))
+ set fo-=/

" using 'indentexpr' instead of 'cindent' does not repeat a comment
setl nocindent indentexpr=2
*** ../vim-8.2.4906/src/version.c 2022-05-07 14:09:14.708852889 +0100
--- src/version.c 2022-05-07 14:27:11.744510896 +0100
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 4907,
/**/

--
hundred-and-one symptoms of being an internet addict:
126. You brag to all of your friends about your date Saturday night...but
you don't tell them it was only in a chat room.

/// Bram Moolenaar -- Br...@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 ///
Reply all
Reply to author
Forward
0 new messages