On Wed, Jun 20, 2012 at 11:37:20PM +0200, Christian Brabandt wrote:
> On Mi, 20 Jun 2012, [email protected] wrote:
> > Status: New
> > Owner: ----
> > Labels: Type-Defect Priority-Medium
> > 
> > New issue 65 by [email protected]: Auto-wrap inside comments with
> > numbered list is broken (regression)
> > http://code.google.com/p/vim/issues/detail?id=65
> > 
> > What steps will reproduce the problem?
> > 
> > vim -N -u NONE
> > :setl tw=80 fo+=nc comments=:#
> > :call setline(1, '# 1 ' . repeat('x', 70))
> > :normal! A foobar
> > 
> > 
> > What is the expected output?
> > 
> > # 1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> > # foobar
> > 
> > What do you see instead?
> > 
> > # 1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> >     # foorba
> > 
> > 
> > What version of the product are you using? On what operating system?
> > 
> > This is the latest Vim on Ubuntu/x86. The problem does not occur
> > with Vim 7.3.0 on Windows/x86 or Vim 7.1.138 on Ubuntu/x86.
> > 
> > :version
> > VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Jun 20 2012 16:55:09)
> > Included patches: 1-562
> > Big version with GTK2 GUI.  Features included (+) or not (-):
> > 
> > 
> > Please provide any additional information below.
> > 
> > I encountered this when editing a shell script header (ft=sh), and
> > whittled it down to the steps above. There must be both a comment
> > leader (#) and a number following it for the bug to occur, together
> > with "n" and "c" in 'formatoptions'.
> 
> The bug was introduced with patch 7.3.552. The attached patch fixes it 
> (test included).
> 
> regards,
> Christian


Hello Christian,

Thanks for this patch and it does fix the test case mentioned in this
bug report.

I think, however, that it introduces a new bug for the case where
there are no comments in the text.  My variation to the test case
you've made looks like this:

  vi:tw=12:formatoptions=tqnc:autoindent

    1 xxxxx

  # 1 xxxxx

Appending ' foobar' to both, with your patch applied, results in:

    1 xxxxx 
    foobar

  # 1 xxxxx 
  # foobar

This behavior is a fix for the comments case because line wrapping
in insert mode was not impacted by formatoptions+=n prior to 7.3.552.

The non-comment case above it, however, shows a newly introduced
problem, as that did work prior to (and after) 7.3.552.  It should
look like this:

    1 xxxxx
      foobar

I've attached a patch that I think works a bit better.  It's a bit of
a band-aid, because ideally, I'd like to see the comment case act like
the non-comment case, e.g. both like so (my "ideal" scenario):

    1 xxxxx
      foobar

  # 1 xxxxx
  #   foobar

But for now, the attached diff brings it back to where it was before
7.3.552, e.g.:

    1 xxxxx
      foobar

  # 1 xxxxx
  # foobar

Which is what the person who filed this bug report is expecting...

Unless someone tells me (Bram for example :^) that it's a bad idea,
I'm going to look at making a new patch that strives for the "ideal"
mentioned above.

- Tor


-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
--- ./src/misc1.c.org	2012-06-11 23:15:49.000000000 -0700
+++ ./src/misc1.c	2012-06-11 23:42:35.000000000 -0700
@@ -429,11 +429,17 @@
     pos.lnum = 0;
 
 #ifdef FEAT_COMMENTS
-    if (has_format_option(FO_Q_COMS) && has_format_option(FO_Q_NUMBER))
+    if (!(State & INSERT) &&
+        has_format_option(FO_Q_COMS) && has_format_option(FO_Q_NUMBER))
     {
 	regmatch_T  regmatch;
 	int	    lead_len;	      /* length of comment leader */
 
+        /*
+         * This is the new "comment aware" code that is used when doing
+         * format_lines().  When doing insert_special() (i.e. (State & INSERT))
+         * then use the orig code (below) that is not "comment aware"...
+         */
 	lead_len = get_leader_len(ml_get(lnum), NULL, FALSE, TRUE);
 	regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
 	if (regmatch.regprog != NULL)

Raspunde prin e-mail lui