To: vim_dev@googlegroups.com
Subject: Patch 7.3.768
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.3.768
Problem:    settabvar() and setwinvar() may move the cursor.
Solution:   Save and restore the cursor position when appropriate. (idea by
	    Yasuhiro Matsumoto)
Files:	    src/edit.c


*** ../vim-7.3.767/src/edit.c	2012-10-21 00:10:29.000000000 +0200
--- src/edit.c	2013-01-17 15:32:10.000000000 +0100
***************
*** 372,377 ****
--- 372,379 ----
       */
      if (cmdchar != 'r' && cmdchar != 'v')
      {
+ 	pos_T   save_cursor = curwin->w_cursor;
+ 
  # ifdef FEAT_EVAL
  	if (cmdchar == 'R')
  	    ptr = (char_u *)"r";
***************
*** 382,387 ****
--- 384,402 ----
  	set_vim_var_string(VV_INSERTMODE, ptr, 1);
  # endif
  	apply_autocmds(EVENT_INSERTENTER, NULL, NULL, FALSE, curbuf);
+ 
+ 	/* Since Insert mode was not started yet a call to check_cursor_col()
+ 	 * may have moved the cursor, especially with the "A" command. */
+ 	if (curwin->w_cursor.col != save_cursor.col
+ 		&& curwin->w_cursor.lnum == save_cursor.lnum)
+ 	{
+ 	    int save_state = State;
+ 
+ 	    curwin->w_cursor = save_cursor;
+ 	    State = INSERT;
+ 	    check_cursor_col();
+ 	    State = save_state;
+ 	}
      }
  #endif
  
*** ../vim-7.3.767/src/version.c	2013-01-17 14:39:43.000000000 +0100
--- src/version.c	2013-01-17 15:10:48.000000000 +0100
***************
*** 727,728 ****
--- 727,730 ----
  {   /* Add new patch number below this line */
+ /**/
+     768,
  /**/

-- 
Life would be so much easier if we could just look at the source code.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
