Karsten Hopp aa9e99
To: vim_dev@googlegroups.com
Karsten Hopp aa9e99
Subject: Patch 7.3.239
Karsten Hopp aa9e99
Fcc: outbox
Karsten Hopp aa9e99
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp aa9e99
Mime-Version: 1.0
Karsten Hopp aa9e99
Content-Type: text/plain; charset=UTF-8
Karsten Hopp aa9e99
Content-Transfer-Encoding: 8bit
Karsten Hopp aa9e99
------------
Karsten Hopp aa9e99
Karsten Hopp aa9e99
Patch 7.3.239
Karsten Hopp aa9e99
Problem:    Python corrects the cursor column without taking 'virtualedit'
Karsten Hopp aa9e99
	    into account. (lilydjwg)
Karsten Hopp aa9e99
Solution:   Call check_cursor_col_win().
Karsten Hopp aa9e99
Files:	    src/if_py_both.h, src/mbyte.c, src/misc2.c, src/normal.c,
Karsten Hopp aa9e99
	    src/proto/mbyte.pro, src/proto/misc2.pro
Karsten Hopp aa9e99
Karsten Hopp aa9e99
Karsten Hopp aa9e99
*** ../vim-7.3.238/src/if_py_both.h	2011-06-26 04:01:37.000000000 +0200
Karsten Hopp aa9e99
--- src/if_py_both.h	2011-07-07 14:28:19.000000000 +0200
Karsten Hopp aa9e99
***************
Karsten Hopp aa9e99
*** 534,540 ****
Karsten Hopp aa9e99
      {
Karsten Hopp aa9e99
  	long lnum;
Karsten Hopp aa9e99
  	long col;
Karsten Hopp aa9e99
- 	long len;
Karsten Hopp aa9e99
  
Karsten Hopp aa9e99
  	if (!PyArg_Parse(val, "(ll)", &lnum, &col))
Karsten Hopp aa9e99
  	    return -1;
Karsten Hopp aa9e99
--- 534,539 ----
Karsten Hopp aa9e99
***************
Karsten Hopp aa9e99
*** 549,566 ****
Karsten Hopp aa9e99
  	if (VimErrorCheck())
Karsten Hopp aa9e99
  	    return -1;
Karsten Hopp aa9e99
  
Karsten Hopp aa9e99
- 	/* When column is out of range silently correct it. */
Karsten Hopp aa9e99
- 	len = (long)STRLEN(ml_get_buf(this->win->w_buffer, lnum, FALSE));
Karsten Hopp aa9e99
- 	if (col > len)
Karsten Hopp aa9e99
- 	    col = len;
Karsten Hopp aa9e99
- 
Karsten Hopp aa9e99
  	this->win->w_cursor.lnum = lnum;
Karsten Hopp aa9e99
  	this->win->w_cursor.col = col;
Karsten Hopp aa9e99
  #ifdef FEAT_VIRTUALEDIT
Karsten Hopp aa9e99
  	this->win->w_cursor.coladd = 0;
Karsten Hopp aa9e99
  #endif
Karsten Hopp aa9e99
! 	update_screen(VALID);
Karsten Hopp aa9e99
  
Karsten Hopp aa9e99
  	return 0;
Karsten Hopp aa9e99
      }
Karsten Hopp aa9e99
      else if (strcmp(name, "height") == 0)
Karsten Hopp aa9e99
--- 548,562 ----
Karsten Hopp aa9e99
  	if (VimErrorCheck())
Karsten Hopp aa9e99
  	    return -1;
Karsten Hopp aa9e99
  
Karsten Hopp aa9e99
  	this->win->w_cursor.lnum = lnum;
Karsten Hopp aa9e99
  	this->win->w_cursor.col = col;
Karsten Hopp aa9e99
  #ifdef FEAT_VIRTUALEDIT
Karsten Hopp aa9e99
  	this->win->w_cursor.coladd = 0;
Karsten Hopp aa9e99
  #endif
Karsten Hopp aa9e99
! 	/* When column is out of range silently correct it. */
Karsten Hopp aa9e99
! 	check_cursor_col_win(this->win);
Karsten Hopp aa9e99
  
Karsten Hopp aa9e99
+ 	update_screen(VALID);
Karsten Hopp aa9e99
  	return 0;
Karsten Hopp aa9e99
      }
Karsten Hopp aa9e99
      else if (strcmp(name, "height") == 0)
Karsten Hopp aa9e99
*** ../vim-7.3.238/src/mbyte.c	2011-04-11 14:29:13.000000000 +0200
Karsten Hopp aa9e99
--- src/mbyte.c	2011-07-07 14:27:07.000000000 +0200
Karsten Hopp aa9e99
***************
Karsten Hopp aa9e99
*** 3563,3569 ****
Karsten Hopp aa9e99
      void
Karsten Hopp aa9e99
  mb_adjust_cursor()
Karsten Hopp aa9e99
  {
Karsten Hopp aa9e99
!     mb_adjustpos(&curwin->w_cursor);
Karsten Hopp aa9e99
  }
Karsten Hopp aa9e99
  
Karsten Hopp aa9e99
  /*
Karsten Hopp aa9e99
--- 3563,3569 ----
Karsten Hopp aa9e99
      void
Karsten Hopp aa9e99
  mb_adjust_cursor()
Karsten Hopp aa9e99
  {
Karsten Hopp aa9e99
!     mb_adjustpos(curbuf, &curwin->w_cursor);
Karsten Hopp aa9e99
  }
Karsten Hopp aa9e99
  
Karsten Hopp aa9e99
  /*
Karsten Hopp aa9e99
***************
Karsten Hopp aa9e99
*** 3571,3577 ****
Karsten Hopp aa9e99
   * If it points to a tail byte it's moved backwards to the head byte.
Karsten Hopp aa9e99
   */
Karsten Hopp aa9e99
      void
Karsten Hopp aa9e99
! mb_adjustpos(lp)
Karsten Hopp aa9e99
      pos_T	*lp;
Karsten Hopp aa9e99
  {
Karsten Hopp aa9e99
      char_u	*p;
Karsten Hopp aa9e99
--- 3571,3578 ----
Karsten Hopp aa9e99
   * If it points to a tail byte it's moved backwards to the head byte.
Karsten Hopp aa9e99
   */
Karsten Hopp aa9e99
      void
Karsten Hopp aa9e99
! mb_adjustpos(buf, lp)
Karsten Hopp aa9e99
!     buf_T	*buf;
Karsten Hopp aa9e99
      pos_T	*lp;
Karsten Hopp aa9e99
  {
Karsten Hopp aa9e99
      char_u	*p;
Karsten Hopp aa9e99
***************
Karsten Hopp aa9e99
*** 3582,3588 ****
Karsten Hopp aa9e99
  #endif
Karsten Hopp aa9e99
  	    )
Karsten Hopp aa9e99
      {
Karsten Hopp aa9e99
! 	p = ml_get(lp->lnum);
Karsten Hopp aa9e99
  	lp->col -= (*mb_head_off)(p, p + lp->col);
Karsten Hopp aa9e99
  #ifdef FEAT_VIRTUALEDIT
Karsten Hopp aa9e99
  	/* Reset "coladd" when the cursor would be on the right half of a
Karsten Hopp aa9e99
--- 3583,3589 ----
Karsten Hopp aa9e99
  #endif
Karsten Hopp aa9e99
  	    )
Karsten Hopp aa9e99
      {
Karsten Hopp aa9e99
! 	p = ml_get_buf(buf, lp->lnum, FALSE);
Karsten Hopp aa9e99
  	lp->col -= (*mb_head_off)(p, p + lp->col);
Karsten Hopp aa9e99
  #ifdef FEAT_VIRTUALEDIT
Karsten Hopp aa9e99
  	/* Reset "coladd" when the cursor would be on the right half of a
Karsten Hopp aa9e99
*** ../vim-7.3.238/src/misc2.c	2011-04-11 16:56:29.000000000 +0200
Karsten Hopp aa9e99
--- src/misc2.c	2011-07-07 14:27:50.000000000 +0200
Karsten Hopp aa9e99
***************
Karsten Hopp aa9e99
*** 333,339 ****
Karsten Hopp aa9e99
  #ifdef FEAT_MBYTE
Karsten Hopp aa9e99
      /* prevent from moving onto a trail byte */
Karsten Hopp aa9e99
      if (has_mbyte)
Karsten Hopp aa9e99
! 	mb_adjustpos(pos);
Karsten Hopp aa9e99
  #endif
Karsten Hopp aa9e99
  
Karsten Hopp aa9e99
      if (col < wcol)
Karsten Hopp aa9e99
--- 333,339 ----
Karsten Hopp aa9e99
  #ifdef FEAT_MBYTE
Karsten Hopp aa9e99
      /* prevent from moving onto a trail byte */
Karsten Hopp aa9e99
      if (has_mbyte)
Karsten Hopp aa9e99
! 	mb_adjustpos(curbuf, pos);
Karsten Hopp aa9e99
  #endif
Karsten Hopp aa9e99
  
Karsten Hopp aa9e99
      if (col < wcol)
Karsten Hopp aa9e99
***************
Karsten Hopp aa9e99
*** 544,559 ****
Karsten Hopp aa9e99
      void
Karsten Hopp aa9e99
  check_cursor_col()
Karsten Hopp aa9e99
  {
Karsten Hopp aa9e99
      colnr_T len;
Karsten Hopp aa9e99
  #ifdef FEAT_VIRTUALEDIT
Karsten Hopp aa9e99
!     colnr_T oldcol = curwin->w_cursor.col;
Karsten Hopp aa9e99
!     colnr_T oldcoladd = curwin->w_cursor.col + curwin->w_cursor.coladd;
Karsten Hopp aa9e99
  #endif
Karsten Hopp aa9e99
  
Karsten Hopp aa9e99
!     len = (colnr_T)STRLEN(ml_get_curline());
Karsten Hopp aa9e99
      if (len == 0)
Karsten Hopp aa9e99
! 	curwin->w_cursor.col = 0;
Karsten Hopp aa9e99
!     else if (curwin->w_cursor.col >= len)
Karsten Hopp aa9e99
      {
Karsten Hopp aa9e99
  	/* Allow cursor past end-of-line when:
Karsten Hopp aa9e99
  	 * - in Insert mode or restarting Insert mode
Karsten Hopp aa9e99
--- 544,569 ----
Karsten Hopp aa9e99
      void
Karsten Hopp aa9e99
  check_cursor_col()
Karsten Hopp aa9e99
  {
Karsten Hopp aa9e99
+     check_cursor_col_win(curwin);
Karsten Hopp aa9e99
+ }
Karsten Hopp aa9e99
+ 
Karsten Hopp aa9e99
+ /*
Karsten Hopp aa9e99
+  * Make sure win->w_cursor.col is valid.
Karsten Hopp aa9e99
+  */
Karsten Hopp aa9e99
+     void
Karsten Hopp aa9e99
+ check_cursor_col_win(win)
Karsten Hopp aa9e99
+     win_T *win;
Karsten Hopp aa9e99
+ {
Karsten Hopp aa9e99
      colnr_T len;
Karsten Hopp aa9e99
  #ifdef FEAT_VIRTUALEDIT
Karsten Hopp aa9e99
!     colnr_T oldcol = win->w_cursor.col;
Karsten Hopp aa9e99
!     colnr_T oldcoladd = win->w_cursor.col + win->w_cursor.coladd;
Karsten Hopp aa9e99
  #endif
Karsten Hopp aa9e99
  
Karsten Hopp aa9e99
!     len = (colnr_T)STRLEN(ml_get_buf(win->w_buffer, win->w_cursor.lnum, FALSE));
Karsten Hopp aa9e99
      if (len == 0)
Karsten Hopp aa9e99
! 	win->w_cursor.col = 0;
Karsten Hopp aa9e99
!     else if (win->w_cursor.col >= len)
Karsten Hopp aa9e99
      {
Karsten Hopp aa9e99
  	/* Allow cursor past end-of-line when:
Karsten Hopp aa9e99
  	 * - in Insert mode or restarting Insert mode
Karsten Hopp aa9e99
***************
Karsten Hopp aa9e99
*** 567,599 ****
Karsten Hopp aa9e99
  		|| (ve_flags & VE_ONEMORE)
Karsten Hopp aa9e99
  #endif
Karsten Hopp aa9e99
  		|| virtual_active())
Karsten Hopp aa9e99
! 	    curwin->w_cursor.col = len;
Karsten Hopp aa9e99
  	else
Karsten Hopp aa9e99
  	{
Karsten Hopp aa9e99
! 	    curwin->w_cursor.col = len - 1;
Karsten Hopp aa9e99
  #ifdef FEAT_MBYTE
Karsten Hopp aa9e99
! 	    /* prevent cursor from moving on the trail byte */
Karsten Hopp aa9e99
  	    if (has_mbyte)
Karsten Hopp aa9e99
! 		mb_adjust_cursor();
Karsten Hopp aa9e99
  #endif
Karsten Hopp aa9e99
  	}
Karsten Hopp aa9e99
      }
Karsten Hopp aa9e99
!     else if (curwin->w_cursor.col < 0)
Karsten Hopp aa9e99
! 	curwin->w_cursor.col = 0;
Karsten Hopp aa9e99
  
Karsten Hopp aa9e99
  #ifdef FEAT_VIRTUALEDIT
Karsten Hopp aa9e99
      /* If virtual editing is on, we can leave the cursor on the old position,
Karsten Hopp aa9e99
       * only we must set it to virtual.  But don't do it when at the end of the
Karsten Hopp aa9e99
       * line. */
Karsten Hopp aa9e99
      if (oldcol == MAXCOL)
Karsten Hopp aa9e99
! 	curwin->w_cursor.coladd = 0;
Karsten Hopp aa9e99
      else if (ve_flags == VE_ALL)
Karsten Hopp aa9e99
      {
Karsten Hopp aa9e99
! 	if (oldcoladd > curwin->w_cursor.col)
Karsten Hopp aa9e99
! 	    curwin->w_cursor.coladd = oldcoladd - curwin->w_cursor.col;
Karsten Hopp aa9e99
  	else
Karsten Hopp aa9e99
  	    /* avoid weird number when there is a miscalculation or overflow */
Karsten Hopp aa9e99
! 	    curwin->w_cursor.coladd = 0;
Karsten Hopp aa9e99
      }
Karsten Hopp aa9e99
  #endif
Karsten Hopp aa9e99
  }
Karsten Hopp aa9e99
--- 577,609 ----
Karsten Hopp aa9e99
  		|| (ve_flags & VE_ONEMORE)
Karsten Hopp aa9e99
  #endif
Karsten Hopp aa9e99
  		|| virtual_active())
Karsten Hopp aa9e99
! 	    win->w_cursor.col = len;
Karsten Hopp aa9e99
  	else
Karsten Hopp aa9e99
  	{
Karsten Hopp aa9e99
! 	    win->w_cursor.col = len - 1;
Karsten Hopp aa9e99
  #ifdef FEAT_MBYTE
Karsten Hopp aa9e99
! 	    /* Move the cursor to the head byte. */
Karsten Hopp aa9e99
  	    if (has_mbyte)
Karsten Hopp aa9e99
! 		mb_adjustpos(win->w_buffer, &win->w_cursor);
Karsten Hopp aa9e99
  #endif
Karsten Hopp aa9e99
  	}
Karsten Hopp aa9e99
      }
Karsten Hopp aa9e99
!     else if (win->w_cursor.col < 0)
Karsten Hopp aa9e99
! 	win->w_cursor.col = 0;
Karsten Hopp aa9e99
  
Karsten Hopp aa9e99
  #ifdef FEAT_VIRTUALEDIT
Karsten Hopp aa9e99
      /* If virtual editing is on, we can leave the cursor on the old position,
Karsten Hopp aa9e99
       * only we must set it to virtual.  But don't do it when at the end of the
Karsten Hopp aa9e99
       * line. */
Karsten Hopp aa9e99
      if (oldcol == MAXCOL)
Karsten Hopp aa9e99
! 	win->w_cursor.coladd = 0;
Karsten Hopp aa9e99
      else if (ve_flags == VE_ALL)
Karsten Hopp aa9e99
      {
Karsten Hopp aa9e99
! 	if (oldcoladd > win->w_cursor.col)
Karsten Hopp aa9e99
! 	    win->w_cursor.coladd = oldcoladd - win->w_cursor.col;
Karsten Hopp aa9e99
  	else
Karsten Hopp aa9e99
  	    /* avoid weird number when there is a miscalculation or overflow */
Karsten Hopp aa9e99
! 	    win->w_cursor.coladd = 0;
Karsten Hopp aa9e99
      }
Karsten Hopp aa9e99
  #endif
Karsten Hopp aa9e99
  }
Karsten Hopp aa9e99
*** ../vim-7.3.238/src/normal.c	2011-06-20 00:45:55.000000000 +0200
Karsten Hopp aa9e99
--- src/normal.c	2011-07-07 14:27:57.000000000 +0200
Karsten Hopp aa9e99
***************
Karsten Hopp aa9e99
*** 8774,8780 ****
Karsten Hopp aa9e99
  	{
Karsten Hopp aa9e99
  	    --pp->col;
Karsten Hopp aa9e99
  #ifdef FEAT_MBYTE
Karsten Hopp aa9e99
! 	    mb_adjustpos(pp);
Karsten Hopp aa9e99
  #endif
Karsten Hopp aa9e99
  	}
Karsten Hopp aa9e99
  	else if (pp->lnum > 1)
Karsten Hopp aa9e99
--- 8774,8780 ----
Karsten Hopp aa9e99
  	{
Karsten Hopp aa9e99
  	    --pp->col;
Karsten Hopp aa9e99
  #ifdef FEAT_MBYTE
Karsten Hopp aa9e99
! 	    mb_adjustpos(curbuf, pp);
Karsten Hopp aa9e99
  #endif
Karsten Hopp aa9e99
  	}
Karsten Hopp aa9e99
  	else if (pp->lnum > 1)
Karsten Hopp aa9e99
*** ../vim-7.3.238/src/proto/mbyte.pro	2010-08-15 21:57:28.000000000 +0200
Karsten Hopp aa9e99
--- src/proto/mbyte.pro	2011-07-07 14:27:09.000000000 +0200
Karsten Hopp aa9e99
***************
Karsten Hopp aa9e99
*** 56,62 ****
Karsten Hopp aa9e99
  int utf_valid_string __ARGS((char_u *s, char_u *end));
Karsten Hopp aa9e99
  int dbcs_screen_tail_off __ARGS((char_u *base, char_u *p));
Karsten Hopp aa9e99
  void mb_adjust_cursor __ARGS((void));
Karsten Hopp aa9e99
! void mb_adjustpos __ARGS((pos_T *lp));
Karsten Hopp aa9e99
  char_u *mb_prevptr __ARGS((char_u *line, char_u *p));
Karsten Hopp aa9e99
  int mb_charlen __ARGS((char_u *str));
Karsten Hopp aa9e99
  int mb_charlen_len __ARGS((char_u *str, int len));
Karsten Hopp aa9e99
--- 56,62 ----
Karsten Hopp aa9e99
  int utf_valid_string __ARGS((char_u *s, char_u *end));
Karsten Hopp aa9e99
  int dbcs_screen_tail_off __ARGS((char_u *base, char_u *p));
Karsten Hopp aa9e99
  void mb_adjust_cursor __ARGS((void));
Karsten Hopp aa9e99
! void mb_adjustpos __ARGS((buf_T *buf, pos_T *lp));
Karsten Hopp aa9e99
  char_u *mb_prevptr __ARGS((char_u *line, char_u *p));
Karsten Hopp aa9e99
  int mb_charlen __ARGS((char_u *str));
Karsten Hopp aa9e99
  int mb_charlen_len __ARGS((char_u *str, int len));
Karsten Hopp aa9e99
*** ../vim-7.3.238/src/proto/misc2.pro	2011-04-11 16:56:29.000000000 +0200
Karsten Hopp aa9e99
--- src/proto/misc2.pro	2011-07-07 14:26:57.000000000 +0200
Karsten Hopp aa9e99
***************
Karsten Hopp aa9e99
*** 14,19 ****
Karsten Hopp aa9e99
--- 14,20 ----
Karsten Hopp aa9e99
  linenr_T get_cursor_rel_lnum __ARGS((win_T *wp, linenr_T lnum));
Karsten Hopp aa9e99
  void check_cursor_lnum __ARGS((void));
Karsten Hopp aa9e99
  void check_cursor_col __ARGS((void));
Karsten Hopp aa9e99
+ void check_cursor_col_win __ARGS((win_T *win));
Karsten Hopp aa9e99
  void check_cursor __ARGS((void));
Karsten Hopp aa9e99
  void adjust_cursor_col __ARGS((void));
Karsten Hopp aa9e99
  int leftcol_changed __ARGS((void));
Karsten Hopp aa9e99
*** ../vim-7.3.238/src/version.c	2011-07-07 15:04:38.000000000 +0200
Karsten Hopp aa9e99
--- src/version.c	2011-07-07 15:05:49.000000000 +0200
Karsten Hopp aa9e99
***************
Karsten Hopp aa9e99
*** 711,712 ****
Karsten Hopp aa9e99
--- 711,714 ----
Karsten Hopp aa9e99
  {   /* Add new patch number below this line */
Karsten Hopp aa9e99
+ /**/
Karsten Hopp aa9e99
+     239,
Karsten Hopp aa9e99
  /**/
Karsten Hopp aa9e99
Karsten Hopp aa9e99
-- 
Karsten Hopp aa9e99
hundred-and-one symptoms of being an internet addict:
Karsten Hopp aa9e99
256. You are able to write down over 250 symptoms of being an internet
Karsten Hopp aa9e99
     addict, even though they only asked for 101.
Karsten Hopp aa9e99
Karsten Hopp aa9e99
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp aa9e99
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp aa9e99
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp aa9e99
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///