]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4907: some users do not want a line comment always inserted v8.2.4907
authorBram Moolenaar <Bram@vim.org>
Sat, 7 May 2022 13:54:11 +0000 (14:54 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 7 May 2022 13:54:11 +0000 (14:54 +0100)
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".

runtime/doc/change.txt
src/change.c
src/option.h
src/testdir/test_textformat.vim
src/version.c

index 6278b7dca85989dd7980c98e41d2d4a8e4f78613..ff6995d00002bc2890be0922a6f5f826df5456ab 100644 (file)
@@ -1673,9 +1673,9 @@ readability.
 
 letter  meaning when present in 'formatoptions'    ~
                                                        *fo-t*
-t      Auto-wrap text using textwidth
+t      Auto-wrap text using 'textwidth'
                                                        *fo-c*
-c      Auto-wrap comments using textwidth, inserting the current comment
+c      Auto-wrap comments using 'textwidth', inserting the current comment
        leader automatically.
                                                        *fo-r*
 r      Automatically insert the current comment leader after hitting
@@ -1684,6 +1684,9 @@ r Automatically insert the current comment leader after hitting
 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
@@ -1746,8 +1749,8 @@ B When joining lines, don't insert a space between two multibyte
 1      Don't break a line after a one-letter word.  It's broken before it
        instead (if possible).
                                                        *fo-]*
-]      Respect textwidth rigorously. With this flag set, no line can be
-       longer than textwidth, unless line-break-prohibition rules make this
+]      Respect 'textwidth' rigorously. With this flag set, no line can be
+       longer than 'textwidth', unless line-break-prohibition rules make this
        impossible.  Mainly for CJK scripts and works only if 'encoding' is
        "utf-8".
                                                        *fo-j*
index 259f07664a905646d989766d4b7d32dec439ef01..bebfaabff8aae7d04fb8866604097474d8f29f32 100644 (file)
@@ -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);
index 936f260e833b0efdb80be186494369f87bdad4a5..fdbe926a00fd1f2750d4feea040cef9c0412b138 100644 (file)
@@ -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
index 1d4ade9b7ad4fa52ca1f2b7d842f50714e7a78f9..79e282eff06cf58f50b721b821dd8b24b24fc0df 100644 (file)
@@ -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
index d5963d46d5c452497cce2f43ed4f21806923993c..f53be1240039139733374530e4b01aa1c30378d8 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4907,
 /**/
     4906,
 /**/