Karsten Hopp 4dd856
To: vim_dev@googlegroups.com
Karsten Hopp 4dd856
Subject: Patch 7.3.1112
Karsten Hopp 4dd856
Fcc: outbox
Karsten Hopp 4dd856
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 4dd856
Mime-Version: 1.0
Karsten Hopp 4dd856
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 4dd856
Content-Transfer-Encoding: 8bit
Karsten Hopp 4dd856
------------
Karsten Hopp 4dd856
Karsten Hopp 4dd856
Patch 7.3.1112
Karsten Hopp 4dd856
Problem:    New regexp engine: \%V not supported.
Karsten Hopp 4dd856
Solution:   Implement \%V.  Add tests.
Karsten Hopp 4dd856
Files:	    src/regexp.c, src/regexp_nfa.c, src/testdir/test64.in,
Karsten Hopp 4dd856
	    src/testdir/test64.ok
Karsten Hopp 4dd856
Karsten Hopp 4dd856
Karsten Hopp 4dd856
*** ../vim-7.3.1111/src/regexp.c	2013-06-03 19:41:01.000000000 +0200
Karsten Hopp 4dd856
--- src/regexp.c	2013-06-04 18:28:12.000000000 +0200
Karsten Hopp 4dd856
***************
Karsten Hopp 4dd856
*** 4165,4170 ****
Karsten Hopp 4dd856
--- 4165,4249 ----
Karsten Hopp 4dd856
  }
Karsten Hopp 4dd856
  
Karsten Hopp 4dd856
  #endif
Karsten Hopp 4dd856
+ #ifdef FEAT_VISUAL
Karsten Hopp 4dd856
+ static int reg_match_visual __ARGS((void));
Karsten Hopp 4dd856
+ 
Karsten Hopp 4dd856
+ /*
Karsten Hopp 4dd856
+  * Return TRUE if the current reginput position matches the Visual area.
Karsten Hopp 4dd856
+  */
Karsten Hopp 4dd856
+     static int
Karsten Hopp 4dd856
+ reg_match_visual()
Karsten Hopp 4dd856
+ {
Karsten Hopp 4dd856
+     pos_T	top, bot;
Karsten Hopp 4dd856
+     linenr_T    lnum;
Karsten Hopp 4dd856
+     colnr_T	col;
Karsten Hopp 4dd856
+     win_T	*wp = reg_win == NULL ? curwin : reg_win;
Karsten Hopp 4dd856
+     int		mode;
Karsten Hopp 4dd856
+     colnr_T	start, end;
Karsten Hopp 4dd856
+     colnr_T	start2, end2;
Karsten Hopp 4dd856
+     colnr_T	cols;
Karsten Hopp 4dd856
+ 
Karsten Hopp 4dd856
+     /* Check if the buffer is the current buffer. */
Karsten Hopp 4dd856
+     if (reg_buf != curbuf || VIsual.lnum == 0)
Karsten Hopp 4dd856
+ 	return FALSE;
Karsten Hopp 4dd856
+ 
Karsten Hopp 4dd856
+     if (VIsual_active)
Karsten Hopp 4dd856
+     {
Karsten Hopp 4dd856
+ 	if (lt(VIsual, wp->w_cursor))
Karsten Hopp 4dd856
+ 	{
Karsten Hopp 4dd856
+ 	    top = VIsual;
Karsten Hopp 4dd856
+ 	    bot = wp->w_cursor;
Karsten Hopp 4dd856
+ 	}
Karsten Hopp 4dd856
+ 	else
Karsten Hopp 4dd856
+ 	{
Karsten Hopp 4dd856
+ 	    top = wp->w_cursor;
Karsten Hopp 4dd856
+ 	    bot = VIsual;
Karsten Hopp 4dd856
+ 	}
Karsten Hopp 4dd856
+ 	mode = VIsual_mode;
Karsten Hopp 4dd856
+     }
Karsten Hopp 4dd856
+     else
Karsten Hopp 4dd856
+     {
Karsten Hopp 4dd856
+ 	if (lt(curbuf->b_visual.vi_start, curbuf->b_visual.vi_end))
Karsten Hopp 4dd856
+ 	{
Karsten Hopp 4dd856
+ 	    top = curbuf->b_visual.vi_start;
Karsten Hopp 4dd856
+ 	    bot = curbuf->b_visual.vi_end;
Karsten Hopp 4dd856
+ 	}
Karsten Hopp 4dd856
+ 	else
Karsten Hopp 4dd856
+ 	{
Karsten Hopp 4dd856
+ 	    top = curbuf->b_visual.vi_end;
Karsten Hopp 4dd856
+ 	    bot = curbuf->b_visual.vi_start;
Karsten Hopp 4dd856
+ 	}
Karsten Hopp 4dd856
+ 	mode = curbuf->b_visual.vi_mode;
Karsten Hopp 4dd856
+     }
Karsten Hopp 4dd856
+     lnum = reglnum + reg_firstlnum;
Karsten Hopp 4dd856
+     if (lnum < top.lnum || lnum > bot.lnum)
Karsten Hopp 4dd856
+ 	return FALSE;
Karsten Hopp 4dd856
+ 
Karsten Hopp 4dd856
+     if (mode == 'v')
Karsten Hopp 4dd856
+     {
Karsten Hopp 4dd856
+ 	col = (colnr_T)(reginput - regline);
Karsten Hopp 4dd856
+ 	if ((lnum == top.lnum && col < top.col)
Karsten Hopp 4dd856
+ 		|| (lnum == bot.lnum && col >= bot.col + (*p_sel != 'e')))
Karsten Hopp 4dd856
+ 	    return FALSE;
Karsten Hopp 4dd856
+     }
Karsten Hopp 4dd856
+     else if (mode == Ctrl_V)
Karsten Hopp 4dd856
+     {
Karsten Hopp 4dd856
+ 	getvvcol(wp, &top, &start, NULL, &end;;
Karsten Hopp 4dd856
+ 	getvvcol(wp, &bot, &start2, NULL, &end2);
Karsten Hopp 4dd856
+ 	if (start2 < start)
Karsten Hopp 4dd856
+ 	    start = start2;
Karsten Hopp 4dd856
+ 	if (end2 > end)
Karsten Hopp 4dd856
+ 	    end = end2;
Karsten Hopp 4dd856
+ 	if (top.col == MAXCOL || bot.col == MAXCOL)
Karsten Hopp 4dd856
+ 	    end = MAXCOL;
Karsten Hopp 4dd856
+ 	cols = win_linetabsize(wp, regline, (colnr_T)(reginput - regline));
Karsten Hopp 4dd856
+ 	if (cols < start || cols > end - (*p_sel == 'e'))
Karsten Hopp 4dd856
+ 	    return FALSE;
Karsten Hopp 4dd856
+     }
Karsten Hopp 4dd856
+     return TRUE;
Karsten Hopp 4dd856
+ }
Karsten Hopp 4dd856
+ #endif
Karsten Hopp 4dd856
+ 
Karsten Hopp 4dd856
  #define ADVANCE_REGINPUT() mb_ptr_adv(reginput)
Karsten Hopp 4dd856
  
Karsten Hopp 4dd856
  /*
Karsten Hopp 4dd856
***************
Karsten Hopp 4dd856
*** 4347,4426 ****
Karsten Hopp 4dd856
  
Karsten Hopp 4dd856
  	  case RE_VISUAL:
Karsten Hopp 4dd856
  #ifdef FEAT_VISUAL
Karsten Hopp 4dd856
! 	    /* Check if the buffer is the current buffer. and whether the
Karsten Hopp 4dd856
! 	     * position is inside the Visual area. */
Karsten Hopp 4dd856
! 	    if (reg_buf != curbuf || VIsual.lnum == 0)
Karsten Hopp 4dd856
! 		status = RA_NOMATCH;
Karsten Hopp 4dd856
! 	    else
Karsten Hopp 4dd856
! 	    {
Karsten Hopp 4dd856
! 		pos_T	    top, bot;
Karsten Hopp 4dd856
! 		linenr_T    lnum;
Karsten Hopp 4dd856
! 		colnr_T	    col;
Karsten Hopp 4dd856
! 		win_T	    *wp = reg_win == NULL ? curwin : reg_win;
Karsten Hopp 4dd856
! 		int	    mode;
Karsten Hopp 4dd856
! 
Karsten Hopp 4dd856
! 		if (VIsual_active)
Karsten Hopp 4dd856
! 		{
Karsten Hopp 4dd856
! 		    if (lt(VIsual, wp->w_cursor))
Karsten Hopp 4dd856
! 		    {
Karsten Hopp 4dd856
! 			top = VIsual;
Karsten Hopp 4dd856
! 			bot = wp->w_cursor;
Karsten Hopp 4dd856
! 		    }
Karsten Hopp 4dd856
! 		    else
Karsten Hopp 4dd856
! 		    {
Karsten Hopp 4dd856
! 			top = wp->w_cursor;
Karsten Hopp 4dd856
! 			bot = VIsual;
Karsten Hopp 4dd856
! 		    }
Karsten Hopp 4dd856
! 		    mode = VIsual_mode;
Karsten Hopp 4dd856
! 		}
Karsten Hopp 4dd856
! 		else
Karsten Hopp 4dd856
! 		{
Karsten Hopp 4dd856
! 		    if (lt(curbuf->b_visual.vi_start, curbuf->b_visual.vi_end))
Karsten Hopp 4dd856
! 		    {
Karsten Hopp 4dd856
! 			top = curbuf->b_visual.vi_start;
Karsten Hopp 4dd856
! 			bot = curbuf->b_visual.vi_end;
Karsten Hopp 4dd856
! 		    }
Karsten Hopp 4dd856
! 		    else
Karsten Hopp 4dd856
! 		    {
Karsten Hopp 4dd856
! 			top = curbuf->b_visual.vi_end;
Karsten Hopp 4dd856
! 			bot = curbuf->b_visual.vi_start;
Karsten Hopp 4dd856
! 		    }
Karsten Hopp 4dd856
! 		    mode = curbuf->b_visual.vi_mode;
Karsten Hopp 4dd856
! 		}
Karsten Hopp 4dd856
! 		lnum = reglnum + reg_firstlnum;
Karsten Hopp 4dd856
! 		col = (colnr_T)(reginput - regline);
Karsten Hopp 4dd856
! 		if (lnum < top.lnum || lnum > bot.lnum)
Karsten Hopp 4dd856
! 		    status = RA_NOMATCH;
Karsten Hopp 4dd856
! 		else if (mode == 'v')
Karsten Hopp 4dd856
! 		{
Karsten Hopp 4dd856
! 		    if ((lnum == top.lnum && col < top.col)
Karsten Hopp 4dd856
! 			    || (lnum == bot.lnum
Karsten Hopp 4dd856
! 					 && col >= bot.col + (*p_sel != 'e')))
Karsten Hopp 4dd856
! 			status = RA_NOMATCH;
Karsten Hopp 4dd856
! 		}
Karsten Hopp 4dd856
! 		else if (mode == Ctrl_V)
Karsten Hopp 4dd856
! 		{
Karsten Hopp 4dd856
! 		    colnr_T	    start, end;
Karsten Hopp 4dd856
! 		    colnr_T	    start2, end2;
Karsten Hopp 4dd856
! 		    colnr_T	    cols;
Karsten Hopp 4dd856
! 
Karsten Hopp 4dd856
! 		    getvvcol(wp, &top, &start, NULL, &end;;
Karsten Hopp 4dd856
! 		    getvvcol(wp, &bot, &start2, NULL, &end2);
Karsten Hopp 4dd856
! 		    if (start2 < start)
Karsten Hopp 4dd856
! 			start = start2;
Karsten Hopp 4dd856
! 		    if (end2 > end)
Karsten Hopp 4dd856
! 			end = end2;
Karsten Hopp 4dd856
! 		    if (top.col == MAXCOL || bot.col == MAXCOL)
Karsten Hopp 4dd856
! 			end = MAXCOL;
Karsten Hopp 4dd856
! 		    cols = win_linetabsize(wp,
Karsten Hopp 4dd856
! 				      regline, (colnr_T)(reginput - regline));
Karsten Hopp 4dd856
! 		    if (cols < start || cols > end - (*p_sel == 'e'))
Karsten Hopp 4dd856
! 			status = RA_NOMATCH;
Karsten Hopp 4dd856
! 		}
Karsten Hopp 4dd856
! 	    }
Karsten Hopp 4dd856
! #else
Karsten Hopp 4dd856
! 	    status = RA_NOMATCH;
Karsten Hopp 4dd856
  #endif
Karsten Hopp 4dd856
  	    break;
Karsten Hopp 4dd856
  
Karsten Hopp 4dd856
  	  case RE_LNUM:
Karsten Hopp 4dd856
--- 4426,4434 ----
Karsten Hopp 4dd856
  
Karsten Hopp 4dd856
  	  case RE_VISUAL:
Karsten Hopp 4dd856
  #ifdef FEAT_VISUAL
Karsten Hopp 4dd856
! 	    if (!reg_match_visual())
Karsten Hopp 4dd856
  #endif
Karsten Hopp 4dd856
+ 		status = RA_NOMATCH;
Karsten Hopp 4dd856
  	    break;
Karsten Hopp 4dd856
  
Karsten Hopp 4dd856
  	  case RE_LNUM:
Karsten Hopp 4dd856
*** ../vim-7.3.1111/src/regexp_nfa.c	2013-06-04 17:47:00.000000000 +0200
Karsten Hopp 4dd856
--- src/regexp_nfa.c	2013-06-04 18:22:04.000000000 +0200
Karsten Hopp 4dd856
***************
Karsten Hopp 4dd856
*** 178,183 ****
Karsten Hopp 4dd856
--- 178,184 ----
Karsten Hopp 4dd856
      NFA_VCOL,		/*	Match cursor virtual column */
Karsten Hopp 4dd856
      NFA_VCOL_GT,	/*	Match > cursor virtual column */
Karsten Hopp 4dd856
      NFA_VCOL_LT,	/*	Match < cursor virtual column */
Karsten Hopp 4dd856
+     NFA_VISUAL,		/*	Match Visual area */
Karsten Hopp 4dd856
  
Karsten Hopp 4dd856
      NFA_FIRST_NL = NFA_ANY + ADD_NL,
Karsten Hopp 4dd856
      NFA_LAST_NL = NFA_NUPPER + ADD_NL,
Karsten Hopp 4dd856
***************
Karsten Hopp 4dd856
*** 960,967 ****
Karsten Hopp 4dd856
  		    break;
Karsten Hopp 4dd856
  
Karsten Hopp 4dd856
  		case 'V':
Karsten Hopp 4dd856
! 		    /* TODO: not supported yet */
Karsten Hopp 4dd856
! 		    return FAIL;
Karsten Hopp 4dd856
  		    break;
Karsten Hopp 4dd856
  
Karsten Hopp 4dd856
  		case '[':
Karsten Hopp 4dd856
--- 961,967 ----
Karsten Hopp 4dd856
  		    break;
Karsten Hopp 4dd856
  
Karsten Hopp 4dd856
  		case 'V':
Karsten Hopp 4dd856
! 		    EMIT(NFA_VISUAL);
Karsten Hopp 4dd856
  		    break;
Karsten Hopp 4dd856
  
Karsten Hopp 4dd856
  		case '[':
Karsten Hopp 4dd856
***************
Karsten Hopp 4dd856
*** 4731,4736 ****
Karsten Hopp 4dd856
--- 4731,4743 ----
Karsten Hopp 4dd856
  		if (result)
Karsten Hopp 4dd856
  		    addstate_here(thislist, t->state->out, &t->subs,
Karsten Hopp 4dd856
  							    t->pim, &listidx);
Karsten Hopp 4dd856
+ 		break;
Karsten Hopp 4dd856
+ 
Karsten Hopp 4dd856
+ 	    case NFA_VISUAL:
Karsten Hopp 4dd856
+ 		result = reg_match_visual();
Karsten Hopp 4dd856
+ 		if (result)
Karsten Hopp 4dd856
+ 		    addstate_here(thislist, t->state->out, &t->subs,
Karsten Hopp 4dd856
+ 							    t->pim, &listidx);
Karsten Hopp 4dd856
  		break;
Karsten Hopp 4dd856
  
Karsten Hopp 4dd856
  	    default:	/* regular character */
Karsten Hopp 4dd856
*** ../vim-7.3.1111/src/testdir/test64.in	2013-06-02 16:07:05.000000000 +0200
Karsten Hopp 4dd856
--- src/testdir/test64.in	2013-06-04 18:07:59.000000000 +0200
Karsten Hopp 4dd856
***************
Karsten Hopp 4dd856
*** 458,463 ****
Karsten Hopp 4dd856
--- 458,471 ----
Karsten Hopp 4dd856
  :.yank
Karsten Hopp 4dd856
  Go?p:"
Karsten Hopp 4dd856
  :"
Karsten Hopp 4dd856
+ :" Check matching Visual area
Karsten Hopp 4dd856
+ /^Visual:
Karsten Hopp 4dd856
+ jfxvfx:s/\%Ve/E/g
Karsten Hopp 4dd856
+ jV:s/\%Va/A/g
Karsten Hopp 4dd856
+ jfx?fxj:s/\%Vo/O/g
Karsten Hopp 4dd856
+ :/^Visual/+1,/^Visual/+4yank
Karsten Hopp 4dd856
+ Go?p:"
Karsten Hopp 4dd856
+ :"
Karsten Hopp 4dd856
  :" Check patterns matching cursor position.
Karsten Hopp 4dd856
  :func! Postest()
Karsten Hopp 4dd856
   new
Karsten Hopp 4dd856
***************
Karsten Hopp 4dd856
*** 520,523 ****
Karsten Hopp 4dd856
--- 528,537 ----
Karsten Hopp 4dd856
  asdfasd
Karsten Hopp 4dd856
  xxstart3
Karsten Hopp 4dd856
  
Karsten Hopp 4dd856
+ Visual:
Karsten Hopp 4dd856
+ thexe the thexethe
Karsten Hopp 4dd856
+ andaxand andaxand
Karsten Hopp 4dd856
+ oooxofor foroxooo
Karsten Hopp 4dd856
+ oooxofor foroxooo
Karsten Hopp 4dd856
+ 
Karsten Hopp 4dd856
  Results of test64:
Karsten Hopp 4dd856
*** ../vim-7.3.1111/src/testdir/test64.ok	2013-06-02 16:07:05.000000000 +0200
Karsten Hopp 4dd856
--- src/testdir/test64.ok	2013-06-04 18:08:08.000000000 +0200
Karsten Hopp 4dd856
***************
Karsten Hopp 4dd856
*** 857,862 ****
Karsten Hopp 4dd856
--- 857,867 ----
Karsten Hopp 4dd856
  ghi
Karsten Hopp 4dd856
  
Karsten Hopp 4dd856
  xxstart3
Karsten Hopp 4dd856
+ 
Karsten Hopp 4dd856
+ thexE thE thExethe
Karsten Hopp 4dd856
+ AndAxAnd AndAxAnd
Karsten Hopp 4dd856
+ oooxOfOr fOrOxooo
Karsten Hopp 4dd856
+ oooxOfOr fOrOxooo
Karsten Hopp 4dd856
  -0-
Karsten Hopp 4dd856
  ffo
Karsten Hopp 4dd856
  bob
Karsten Hopp 4dd856
*** ../vim-7.3.1111/src/version.c	2013-06-04 17:47:00.000000000 +0200
Karsten Hopp 4dd856
--- src/version.c	2013-06-04 18:26:28.000000000 +0200
Karsten Hopp 4dd856
***************
Karsten Hopp 4dd856
*** 730,731 ****
Karsten Hopp 4dd856
--- 730,733 ----
Karsten Hopp 4dd856
  {   /* Add new patch number below this line */
Karsten Hopp 4dd856
+ /**/
Karsten Hopp 4dd856
+     1112,
Karsten Hopp 4dd856
  /**/
Karsten Hopp 4dd856
Karsten Hopp 4dd856
-- 
Karsten Hopp 4dd856
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 4dd856
87. Everyone you know asks why your phone line is always busy ...and
Karsten Hopp 4dd856
    you tell them to send an e-mail.
Karsten Hopp 4dd856
Karsten Hopp 4dd856
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 4dd856
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 4dd856
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 4dd856
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///