NOTE: some mail and patch programs may have a problem with the non-ASCII
characters in this patch.  You can fetch the patch from
ftp://ftp.vim.org/pub/vim/patches/7.2/7.2.301  and/or fetch the updated
files from CVS.  http://www.vim.org/cvs.php


Patch 7.2.301
Problem:    Formatting is wrong when 'tw' is set to a small value.
Solution:   Fix it and add tests.  Also fix behavior of "1" in 'fo'. (Yukihiro
            Nakadaira)
Files:      src/edit.c, src/testdir/Makefile, src/testdir/test68.in,
            src/testdir/test68.ok, src/testdir/test69.in,
            src/testdir/test69.ok


*** ../vim-7.2.300/src/edit.c   2009-11-11 13:22:32.000000000 +0100
--- src/edit.c  2009-11-17 15:34:47.000000000 +0100
***************
*** 181,187 ****
  static void ins_ctrl_v __ARGS((void));
  static void undisplay_dollar __ARGS((void));
  static void insert_special __ARGS((int, int, int));
! static void internal_format __ARGS((int textwidth, int second_indent, int 
flags, int format_only));
  static void check_auto_format __ARGS((int));
  static void redo_literal __ARGS((int c));
  static void start_arrow __ARGS((pos_T *end_insert_pos));
--- 181,187 ----
  static void ins_ctrl_v __ARGS((void));
  static void undisplay_dollar __ARGS((void));
  static void insert_special __ARGS((int, int, int));
! static void internal_format __ARGS((int textwidth, int second_indent, int 
flags, int format_only, int c));
  static void check_auto_format __ARGS((int));
  static void redo_literal __ARGS((int c));
  static void start_arrow __ARGS((pos_T *end_insert_pos));
***************
*** 2164,2170 ****
      int               i, c;
      int               actual_len;             /* Take multi-byte characters */
      int               actual_compl_length;    /* into account. */
!     int               *wca;                   /* Wide character array. */
      int               has_lower = FALSE;
      int               was_letter = FALSE;
  
--- 2164,2170 ----
      int               i, c;
      int               actual_len;             /* Take multi-byte characters */
      int               actual_compl_length;    /* into account. */
!     int               *wca;                   /* Wide character array. */
      int               has_lower = FALSE;
      int               was_letter = FALSE;
  
***************
*** 5558,5564 ****
        }
        if (do_internal)
  #endif
!           internal_format(textwidth, second_indent, flags, c == NUL);
      }
  
      if (c == NUL)         /* only formatting was wanted */
--- 5558,5564 ----
        }
        if (do_internal)
  #endif
!           internal_format(textwidth, second_indent, flags, c == NUL, c);
      }
  
      if (c == NUL)         /* only formatting was wanted */
***************
*** 5738,5748 ****
   * Format text at the current insert position.
   */
      static void
! internal_format(textwidth, second_indent, flags, format_only)
      int               textwidth;
      int               second_indent;
      int               flags;
      int               format_only;
  {
      int               cc;
      int               save_char = NUL;
--- 5738,5749 ----
   * Format text at the current insert position.
   */
      static void
! internal_format(textwidth, second_indent, flags, format_only, c)
      int               textwidth;
      int               second_indent;
      int               flags;
      int               format_only;
+     int               c; /* character to be inserted (can be NUL) */
  {
      int               cc;
      int               save_char = NUL;
***************
*** 5763,5769 ****
       * When 'ai' is off we don't want a space under the cursor to be
       * deleted.  Replace it with an 'x' temporarily.
       */
!     if (!curbuf->b_p_ai)
      {
        cc = gchar_cursor();
        if (vim_iswhite(cc))
--- 5764,5774 ----
       * When 'ai' is off we don't want a space under the cursor to be
       * deleted.  Replace it with an 'x' temporarily.
       */
!     if (!curbuf->b_p_ai
! #ifdef FEAT_VREPLACE
!           && !(State & VREPLACE_FLAG)
! #endif
!           )
      {
        cc = gchar_cursor();
        if (vim_iswhite(cc))
***************
*** 5789,5797 ****
        char_u  *saved_text = NULL;
  #endif
        colnr_T col;
  
!       virtcol = get_nolist_virtcol();
!       if (virtcol < (colnr_T)textwidth)
            break;
  
  #ifdef FEAT_COMMENTS
--- 5794,5804 ----
        char_u  *saved_text = NULL;
  #endif
        colnr_T col;
+       colnr_T end_col;
  
!       virtcol = get_nolist_virtcol()
!               + char2cells(c != NUL ? c : gchar_cursor());
!       if (virtcol <= (colnr_T)textwidth)
            break;
  
  #ifdef FEAT_COMMENTS
***************
*** 5831,5842 ****
        coladvance((colnr_T)textwidth);
        wantcol = curwin->w_cursor.col;
  
!       curwin->w_cursor.col = startcol - 1;
! #ifdef FEAT_MBYTE
!       /* Correct cursor for multi-byte character. */
!       if (has_mbyte)
!           mb_adjust_cursor();
! #endif
        foundcol = 0;
  
        /*
--- 5838,5844 ----
        coladvance((colnr_T)textwidth);
        wantcol = curwin->w_cursor.col;
  
!       curwin->w_cursor.col = startcol;
        foundcol = 0;
  
        /*
***************
*** 5847,5857 ****
                    || curwin->w_cursor.lnum != Insstart.lnum
                    || curwin->w_cursor.col >= Insstart.col)
        {
!           cc = gchar_cursor();
            if (WHITECHAR(cc))
            {
                /* remember position of blank just before text */
!               end_foundcol = curwin->w_cursor.col;
  
                /* find start of sequence of blanks */
                while (curwin->w_cursor.col > 0 && WHITECHAR(cc))
--- 5849,5862 ----
                    || curwin->w_cursor.lnum != Insstart.lnum
                    || curwin->w_cursor.col >= Insstart.col)
        {
!           if (curwin->w_cursor.col == startcol && c != NUL)
!               cc = c;
!           else
!               cc = gchar_cursor();
            if (WHITECHAR(cc))
            {
                /* remember position of blank just before text */
!               end_col = curwin->w_cursor.col;
  
                /* find start of sequence of blanks */
                while (curwin->w_cursor.col > 0 && WHITECHAR(cc))
***************
*** 5871,5877 ****
                    /* do not break after one-letter words */
                    if (curwin->w_cursor.col == 0)
                        break;  /* one-letter word at begin */
! 
                    col = curwin->w_cursor.col;
                    dec_cursor();
                    cc = gchar_cursor();
--- 5876,5886 ----
                    /* do not break after one-letter words */
                    if (curwin->w_cursor.col == 0)
                        break;  /* one-letter word at begin */
! #ifdef FEAT_COMMENTS
!                   /* do not break "#a b" when 'tw' is 2 */
!                   if (curwin->w_cursor.col <= leader_len)
!                       break;
! #endif
                    col = curwin->w_cursor.col;
                    dec_cursor();
                    cc = gchar_cursor();
***************
*** 5880,5905 ****
                        continue;       /* one-letter, continue */
                    curwin->w_cursor.col = col;
                }
! #ifdef FEAT_MBYTE
!               if (has_mbyte)
!                   foundcol = curwin->w_cursor.col
!                                        + (*mb_ptr2len)(ml_get_cursor());
!               else
! #endif
!                   foundcol = curwin->w_cursor.col + 1;
!               if (curwin->w_cursor.col < (colnr_T)wantcol)
                    break;
            }
  #ifdef FEAT_MBYTE
!           else if (cc >= 0x100 && fo_multibyte
!                             && curwin->w_cursor.col <= (colnr_T)wantcol)
            {
                /* Break after or before a multi-byte character. */
                foundcol = curwin->w_cursor.col;
-               if (curwin->w_cursor.col < (colnr_T)wantcol)
-                   foundcol += (*mb_char2len)(cc);
                end_foundcol = foundcol;
!               break;
            }
  #endif
            if (curwin->w_cursor.col == 0)
--- 5889,5948 ----
                        continue;       /* one-letter, continue */
                    curwin->w_cursor.col = col;
                }
! 
!               inc_cursor();
! 
!               end_foundcol = end_col + 1;
!               foundcol = curwin->w_cursor.col;
!               if (curwin->w_cursor.col <= (colnr_T)wantcol)
                    break;
            }
  #ifdef FEAT_MBYTE
!           else if (cc >= 0x100 && fo_multibyte)
            {
                /* Break after or before a multi-byte character. */
+               if (curwin->w_cursor.col != startcol)
+               {
+ #ifdef FEAT_COMMENTS
+                   /* Don't break until after the comment leader */
+                   if (curwin->w_cursor.col < leader_len)
+                       break;
+ #endif
+                   col = curwin->w_cursor.col;
+                   inc_cursor();
+                   /* Don't change end_foundcol if already set. */
+                   if (foundcol != curwin->w_cursor.col)
+                   {
+                       foundcol = curwin->w_cursor.col;
+                       end_foundcol = foundcol;
+                       if (curwin->w_cursor.col <= (colnr_T)wantcol)
+                           break;
+                   }
+                   curwin->w_cursor.col = col;
+               }
+ 
+               if (curwin->w_cursor.col == 0)
+                   break;
+ 
+               col = curwin->w_cursor.col;
+ 
+               dec_cursor();
+               cc = gchar_cursor();
+ 
+               if (WHITECHAR(cc))
+                   continue;           /* break with space */
+ #ifdef FEAT_COMMENTS
+               /* Don't break until after the comment leader */
+               if (curwin->w_cursor.col < leader_len)
+                   break;
+ #endif
+ 
+               curwin->w_cursor.col = col;
+ 
                foundcol = curwin->w_cursor.col;
                end_foundcol = foundcol;
!               if (curwin->w_cursor.col <= (colnr_T)wantcol)
!                   break;
            }
  #endif
            if (curwin->w_cursor.col == 0)
***************
*** 5926,5939 ****
            orig_col = startcol;        /* Will start backspacing from here */
        else
  #endif
!           replace_offset = startcol - end_foundcol - 1;
  
        /*
         * adjust startcol for spaces that will be deleted and
         * characters that will remain on top line
         */
        curwin->w_cursor.col = foundcol;
!       while (cc = gchar_cursor(), WHITECHAR(cc))
            inc_cursor();
        startcol -= curwin->w_cursor.col;
        if (startcol < 0)
--- 5969,5983 ----
            orig_col = startcol;        /* Will start backspacing from here */
        else
  #endif
!           replace_offset = startcol - end_foundcol;
  
        /*
         * adjust startcol for spaces that will be deleted and
         * characters that will remain on top line
         */
        curwin->w_cursor.col = foundcol;
!       while ((cc = gchar_cursor(), WHITECHAR(cc))
!                   && (!fo_white_par || curwin->w_cursor.col < startcol))
            inc_cursor();
        startcol -= curwin->w_cursor.col;
        if (startcol < 0)
***************
*** 8509,8515 ****
        if (mode == BACKSPACE_LINE
                && (curbuf->b_p_ai
  #ifdef FEAT_CINDENT
!                     || cindent_on()
  #endif
                   )
  #ifdef FEAT_RIGHTLEFT
--- 8553,8559 ----
        if (mode == BACKSPACE_LINE
                && (curbuf->b_p_ai
  #ifdef FEAT_CINDENT
!                   || cindent_on()
  #endif
                   )
  #ifdef FEAT_RIGHTLEFT
*** ../vim-7.2.300/src/testdir/Makefile 2009-11-17 17:36:13.000000000 +0100
--- src/testdir/Makefile        2009-11-17 15:11:26.000000000 +0100
***************
*** 22,28 ****
                test48.out test49.out test51.out test52.out test53.out \
                test54.out test55.out test56.out test57.out test58.out \
                test59.out test60.out test61.out test62.out test63.out \
!               test64.out test65.out test66.out test67.out
  
  SCRIPTS_GUI = test16.out
  
--- 22,29 ----
                test48.out test49.out test51.out test52.out test53.out \
                test54.out test55.out test56.out test57.out test58.out \
                test59.out test60.out test61.out test62.out test63.out \
!               test64.out test65.out test66.out test67.out test68.out \
!               test69.out
  
  SCRIPTS_GUI = test16.out
  
*** ../vim-7.2.300/src/testdir/test68.in        2009-11-17 17:39:36.000000000 
+0100
--- src/testdir/test68.in       2009-11-17 15:39:09.000000000 +0100
***************
*** 0 ****
--- 1,56 ----
+ Test for text formatting.
+ 
+ Results of test68:
+ 
+ STARTTEST
+ :so small.vim
+ /^{/+1
+ :set noai tw=2 fo=t
+ gRa b 
+ ENDTEST
+ 
+ {
+     
+ 
+ }
+ 
+ STARTTEST
+ /^{/+1
+ :set ai tw=2 fo=tw
+ gqgqjjllab 
+ ENDTEST
+ 
+ {
+ a  b  
+ 
+ a    
+ }
+ 
+ STARTTEST
+ /^{/+1
+ :set tw=3 fo=t
+ gqgqo
+ a    
+ ENDTEST
+ 
+ {
+ a  
+ }
+ 
+ STARTTEST
+ /^{/+1
+ :set tw=2 fo=tcq1 comments=:#
+ gqgqjgqgqo
+ a b
+ #a b 
+ ENDTEST
+ 
+ {
+ a b
+ #a b
+ }
+ 
+ STARTTEST
+ :g/^STARTTEST/.,/^ENDTEST/d
+ :1;/^Results/,$wq! test.out
+ ENDTEST
*** ../vim-7.2.300/src/testdir/test68.ok        2009-11-17 17:39:36.000000000 
+0100
--- src/testdir/test68.ok       2009-11-17 15:11:26.000000000 +0100
***************
*** 0 ****
--- 1,35 ----
+ Results of test68:
+ 
+ 
+ {
+ a
+ b
+ }
+ 
+ 
+ {
+ a  
+ b  
+ 
+ a  
+ b
+ }
+ 
+ 
+ {
+ a
+  
+ 
+ a
+  
+ }
+ 
+ 
+ {
+ a b
+ #a b
+ 
+ a b
+ #a b
+ }
+ 
*** ../vim-7.2.300/src/testdir/test69.in        2009-11-17 17:39:36.000000000 
+0100
--- src/testdir/test69.in       2009-11-17 15:11:26.000000000 +0100
***************
*** 0 ****
--- 1,139 ----
+ Test for multi-byte text formatting.
+ 
+ STARTTEST
+ :so mbyte.vim
+ :set encoding=utf-8
+ ENDTEST
+ 
+ Results of test69:
+ 
+ STARTTEST
+ /^{/+1
+ :set tw=2 fo=t
+ gqgqjgqgqo
+ XYZ
+ abc XYZ 
+ ENDTEST
+ 
+ {
+ XYZ
+ abc XYZ
+ }
+ 
+ STARTTEST
+ /^{/+1
+ :set tw=1 fo=tm
+ gqgqjgqgqjgqgqjgqgqjgqgqo
+ X
+ Xa
+ X a
+ XY
+ X Y 
+ ENDTEST
+ 
+ {
+ X
+ Xa
+ X a
+ XY
+ X Y
+ }
+ 
+ STARTTEST
+ /^{/+1
+ :set tw=2 fo=tm
+ gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo
+ X
+ Xa
+ X a
+ XY
+ X Y
+ aX
+ abX
+ abcX
+ abX c
+ abXY 
+ ENDTEST
+ 
+ {
+ X
+ Xa
+ X a
+ XY
+ X Y
+ aX
+ abX
+ abcX
+ abX c
+ abXY
+ }
+ 
+ STARTTEST
+ /^{/+1
+ :set ai tw=2 fo=tm
+ gqgqjgqgqo
+ X
+ Xa 
+ ENDTEST
+ 
+ {
+   X
+   Xa
+ }
+ 
+ STARTTEST
+ /^{/+1
+ :set noai tw=2 fo=tm
+ gqgqjgqgqo
+   X
+   Xa 
+ ENDTEST
+ 
+ {
+   X
+   Xa
+ }
+ 
+ STARTTEST
+ /^{/+1
+ :set tw=2 fo=cqm comments=n:X
+ gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo
+ X
+ Xa
+ XaY
+ XY
+ XYZ
+ X Y
+ X YZ
+ XX
+ XXa
+ XXY 
+ ENDTEST
+ 
+ {
+ X
+ Xa
+ XaY
+ XY
+ XYZ
+ X Y
+ X YZ
+ XX
+ XXa
+ XXY
+ }
+ 
+ STARTTEST
+ /^{/+1
+ :set tw=2 fo=tm
+ RXa 
+ ENDTEST
+ 
+ {
+ 
+ }
+ 
+ STARTTEST
+ :g/^STARTTEST/.,/^ENDTEST/d
+ :1;/^Results/,$wq! test.out
+ ENDTEST
*** ../vim-7.2.300/src/testdir/test69.ok        2009-11-17 17:39:36.000000000 
+0100
--- src/testdir/test69.ok       2009-11-17 15:11:26.000000000 +0100
***************
*** 0 ****
--- 1,142 ----
+ Results of test69:
+ 
+ 
+ {
+ XYZ
+ abc
+ XYZ
+ 
+ XYZ
+ abc
+ XYZ
+ }
+ 
+ 
+ {
+ X
+ X
+ a
+ X
+ a
+ X
+ Y
+ X
+ Y
+ 
+ X
+ X
+ a
+ X
+ a
+ X
+ Y
+ X
+ Y
+ }
+ 
+ 
+ {
+ X
+ X
+ a
+ X
+ a
+ X
+ Y
+ X
+ Y
+ a
+ X
+ ab
+ X
+ abc
+ X
+ ab
+ X
+ c
+ ab
+ X
+ Y
+ 
+ X
+ X
+ a
+ X
+ a
+ X
+ Y
+ X
+ Y
+ a
+ X
+ ab
+ X
+ abc
+ X
+ ab
+ X
+ c
+ ab
+ X
+ Y
+ }
+ 
+ 
+ {
+   X
+   X
+   a
+ 
+   X
+   X
+   a
+ }
+ 
+ 
+ {
+   X
+   X
+ a
+ 
+   X
+   X
+ a
+ }
+ 
+ 
+ {
+ X
+ Xa
+ Xa
+ XY
+ XY
+ XY
+ XZ
+ X Y
+ X Y
+ X Z
+ XX
+ XXa
+ XXY
+ 
+ X
+ Xa
+ Xa
+ XY
+ XY
+ XY
+ XZ
+ X Y
+ X Y
+ X Z
+ XX
+ XXa
+ XXY
+ }
+ 
+ 
+ {
+ X
+ a
+ }
+ 
*** ../vim-7.2.300/src/version.c        2009-11-17 17:37:34.000000000 +0100
--- src/version.c       2009-11-17 17:26:35.000000000 +0100
***************
*** 683,684 ****
--- 683,686 ----
  {   /* Add new patch number below this line */
+ /**/
+     301,
  /**/

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui