diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-05-07 14:54:11 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-05-07 14:54:11 +0100 |
commit | 2bf875f881f7c6f6900bc0eb2a93a552db894109 (patch) | |
tree | 43f3b1e70f88d05eeae1020899af539b23775846 /src | |
parent | aa04e1b0be343ff606e25a48d59bc057edcc6e87 (diff) |
patch 8.2.4907: some users do not want a line comment always insertedv8.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".
Diffstat (limited to 'src')
-rw-r--r-- | src/change.c | 3 | ||||
-rw-r--r-- | src/option.h | 5 | ||||
-rw-r--r-- | src/testdir/test_textformat.vim | 12 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 19 insertions, 3 deletions
diff --git a/src/change.c b/src/change.c index 259f07664a..bebfaabff8 100644 --- a/src/change.c +++ b/src/change.c @@ -1659,7 +1659,8 @@ open_line( 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) + 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); diff --git a/src/option.h b/src/option.h index 936f260e83..fdbe926a00 100644 --- a/src/option.h +++ b/src/option.h @@ -141,6 +141,7 @@ typedef enum { #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,7 +160,7 @@ typedef enum { #define DFLT_FO_VI "vt" #define DFLT_FO_VIM "tcq" -#define FO_ALL "tcroq2vlb1mMBn,aw]jp" // for do_set() +#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,7 +197,7 @@ typedef enum { #define CPO_REMMARK 'R' // remove marks when filtering #define CPO_BUFOPT 's' #define CPO_BUFOPTGLOB 'S' -#define CPO_TAGPAT 't' +#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 diff --git a/src/testdir/test_textformat.vim b/src/testdir/test_textformat.vim index 1d4ade9b7a..79e282eff0 100644 --- a/src/testdir/test_textformat.vim +++ b/src/testdir/test_textformat.vim @@ -278,6 +278,18 @@ func Test_format_c_comment() // 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 diff --git a/src/version.c b/src/version.c index d5963d46d5..f53be12400 100644 --- a/src/version.c +++ b/src/version.c @@ -747,6 +747,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4907, +/**/ 4906, /**/ 4905, |