c535e2a
To: vim-dev@vim.org
c535e2a
Subject: Patch 7.0.155
c535e2a
Fcc: outbox
c535e2a
From: Bram Moolenaar <Bram@moolenaar.net>
c535e2a
Mime-Version: 1.0
c535e2a
Content-Type: text/plain; charset=ISO-8859-1
c535e2a
Content-Transfer-Encoding: 8bit
c535e2a
------------
c535e2a
c535e2a
Patch 7.0.155
c535e2a
Problem:    When getchar() returns a mouse button click there is no way to get
c535e2a
            the mouse coordinates.
c535e2a
Solution:   Add v:mouse_win, v:mouse_lnum and v:mouse_col.
c535e2a
Files:      runtime/doc/eval.txt, src/eval.c, src/vim.h
c535e2a
c535e2a
c535e2a
*** ../vim-7.0.154/runtime/doc/eval.txt	Tue Oct  3 14:43:31 2006
c535e2a
--- runtime/doc/eval.txt	Wed Nov  1 15:20:42 2006
c535e2a
***************
c535e2a
*** 1,4 ****
c535e2a
! *eval.txt*      For Vim version 7.0.  Last change: 2006 Sep 22
c535e2a
  
c535e2a
  
c535e2a
  		  VIM REFERENCE MANUAL    by Bram Moolenaar
c535e2a
--- 1,4 ----
c535e2a
! *eval.txt*      For Vim version 7.0.  Last change: 2006 Nov 01
c535e2a
  
c535e2a
  
c535e2a
  		  VIM REFERENCE MANUAL    by Bram Moolenaar
c535e2a
***************
c535e2a
*** 1374,1379 ****
c535e2a
--- 1380,1400 ----
c535e2a
  		'guitabtooltip'.  Only valid while one of these expressions is
c535e2a
  		being evaluated.  Read-only when in the |sandbox|.
c535e2a
  
c535e2a
+ 					*v:mouse_win* *mouse_win-variable*
c535e2a
+ v:mouse_win	Window number for a mouse click obtained with |getchar()|.
c535e2a
+ 		First window has number 1, like with |winnr()|.  The value is
c535e2a
+ 		zero when there was no mouse button click.
c535e2a
+ 
c535e2a
+ 					*v:mouse_lnum* *mouse_lnum-variable*
c535e2a
+ v:mouse_lnum	Line number for a mouse click obtained with |getchar()|.
c535e2a
+ 		This is the text line number, not the screen line number.  The
c535e2a
+ 		value is zero when there was no mouse button click.
c535e2a
+ 
c535e2a
+ 					*v:mouse_col* *mouse_col-variable*
c535e2a
+ v:mouse_col	Column number for a mouse click obtained with |getchar()|.
c535e2a
+ 		This is the screen column number, like with |virtcol()|.  The
c535e2a
+ 		value is zero when there was no mouse button click.
c535e2a
+ 
c535e2a
  					*v:prevcount* *prevcount-variable*
c535e2a
  v:prevcount	The count given for the last but one Normal mode command.
c535e2a
  		This is the v:count value of the previous command.  Useful if
c535e2a
***************
c535e2a
*** 2702,2707 ****
c535e2a
--- 2728,2744 ----
c535e2a
  		one-byte character it is the character itself as a number.
c535e2a
  		Use nr2char() to convert it to a String.
c535e2a
  
c535e2a
+ 		When the user clicks a mouse button, the mouse event will be
c535e2a
+ 		returned.  The position can then be found in |v:mouse_col|,
c535e2a
+ 		|v:mouse_lnum| and |v:mouse_win|.  This example positions the
c535e2a
+ 		mouse as it would normally happen: >
c535e2a
+ 			let c = getchar()
c535e2a
+ 		  	if c == "\<LeftMouse>" && v:mouse_win > 0
c535e2a
+ 			  exe v:mouse_win . "wincmd w"
c535e2a
+ 			  exe v:mouse_lnum
c535e2a
+ 			  exe "normal " . v:mouse_col . "|"
c535e2a
+ 			endif
c535e2a
+ <
c535e2a
  		There is no prompt, you will somehow have to make clear to the
c535e2a
  		user that a character has to be typed.
c535e2a
  		There is no mapping for the character.
c535e2a
*** ../vim-7.0.154/src/eval.c	Tue Oct 24 13:51:47 2006
c535e2a
--- src/eval.c	Wed Nov  1 13:39:52 2006
c535e2a
***************
c535e2a
*** 343,348 ****
c535e2a
--- 342,350 ----
c535e2a
      {VV_NAME("swapchoice",	 VAR_STRING), 0},
c535e2a
      {VV_NAME("swapcommand",	 VAR_STRING), VV_RO},
c535e2a
      {VV_NAME("char",		 VAR_STRING), VV_RO},
c535e2a
+     {VV_NAME("mouse_win",	 VAR_NUMBER), 0},
c535e2a
+     {VV_NAME("mouse_lnum",	 VAR_NUMBER), 0},
c535e2a
+     {VV_NAME("mouse_col",	 VAR_NUMBER), 0},
c535e2a
  };
c535e2a
  
c535e2a
  /* shorthand */
c535e2a
***************
c535e2a
*** 9855,9860 ****
c535e2a
--- 9857,9866 ----
c535e2a
      --no_mapping;
c535e2a
      --allow_keys;
c535e2a
  
c535e2a
+     vimvars[VV_MOUSE_WIN].vv_nr = 0;
c535e2a
+     vimvars[VV_MOUSE_LNUM].vv_nr = 0;
c535e2a
+     vimvars[VV_MOUSE_COL].vv_nr = 0;
c535e2a
+ 
c535e2a
      rettv->vval.v_number = n;
c535e2a
      if (IS_SPECIAL(n) || mod_mask != 0)
c535e2a
      {
c535e2a
***************
c535e2a
*** 9883,9888 ****
c535e2a
--- 9889,9941 ----
c535e2a
  	temp[i++] = NUL;
c535e2a
  	rettv->v_type = VAR_STRING;
c535e2a
  	rettv->vval.v_string = vim_strsave(temp);
c535e2a
+ 
c535e2a
+ #ifdef FEAT_MOUSE
c535e2a
+ 	if (n == K_LEFTMOUSE
c535e2a
+ 		|| n == K_LEFTMOUSE_NM
c535e2a
+ 		|| n == K_LEFTDRAG
c535e2a
+ 		|| n == K_LEFTRELEASE
c535e2a
+ 		|| n == K_LEFTRELEASE_NM
c535e2a
+ 		|| n == K_MIDDLEMOUSE
c535e2a
+ 		|| n == K_MIDDLEDRAG
c535e2a
+ 		|| n == K_MIDDLERELEASE
c535e2a
+ 		|| n == K_RIGHTMOUSE
c535e2a
+ 		|| n == K_RIGHTDRAG
c535e2a
+ 		|| n == K_RIGHTRELEASE
c535e2a
+ 		|| n == K_X1MOUSE
c535e2a
+ 		|| n == K_X1DRAG
c535e2a
+ 		|| n == K_X1RELEASE
c535e2a
+ 		|| n == K_X2MOUSE
c535e2a
+ 		|| n == K_X2DRAG
c535e2a
+ 		|| n == K_X2RELEASE
c535e2a
+ 		|| n == K_MOUSEDOWN
c535e2a
+ 		|| n == K_MOUSEUP)
c535e2a
+ 	{
c535e2a
+ 	    int		row = mouse_row;
c535e2a
+ 	    int		col = mouse_col;
c535e2a
+ 	    win_T	*win;
c535e2a
+ 	    linenr_T	lnum;
c535e2a
+ # ifdef FEAT_WINDOWS
c535e2a
+ 	    win_T	*wp;
c535e2a
+ # endif
c535e2a
+ 	    int		n = 1;
c535e2a
+ 
c535e2a
+ 	    if (row >= 0 && col >= 0)
c535e2a
+ 	    {
c535e2a
+ 		/* Find the window at the mouse coordinates and compute the
c535e2a
+ 		 * text position. */
c535e2a
+ 		win = mouse_find_win(&row, &col);
c535e2a
+ 		(void)mouse_comp_pos(win, &row, &col, &lnum);
c535e2a
+ # ifdef FEAT_WINDOWS
c535e2a
+ 		for (wp = firstwin; wp != win; wp = wp->w_next)
c535e2a
+ 		    ++n;
c535e2a
+ # endif
c535e2a
+ 		vimvars[VV_MOUSE_WIN].vv_nr = n;
c535e2a
+ 		vimvars[VV_MOUSE_LNUM].vv_nr = lnum;
c535e2a
+ 		vimvars[VV_MOUSE_COL].vv_nr = col + 1;
c535e2a
+ 	    }
c535e2a
+ 	}
c535e2a
+ #endif
c535e2a
      }
c535e2a
  }
c535e2a
  
c535e2a
*** ../vim-7.0.154/src/vim.h	Tue Aug 29 18:16:37 2006
c535e2a
--- src/vim.h	Wed Nov  1 13:11:16 2006
c535e2a
***************
c535e2a
*** 1669,1675 ****
c535e2a
  #define VV_SWAPCHOICE	46
c535e2a
  #define VV_SWAPCOMMAND	47
c535e2a
  #define VV_CHAR		48
c535e2a
! #define VV_LEN		49	/* number of v: vars */
c535e2a
  
c535e2a
  #ifdef FEAT_CLIPBOARD
c535e2a
  
c535e2a
--- 1669,1678 ----
c535e2a
  #define VV_SWAPCHOICE	46
c535e2a
  #define VV_SWAPCOMMAND	47
c535e2a
  #define VV_CHAR		48
c535e2a
! #define VV_MOUSE_WIN	49
c535e2a
! #define VV_MOUSE_LNUM   50
c535e2a
! #define VV_MOUSE_COL	51
c535e2a
! #define VV_LEN		52	/* number of v: vars */
c535e2a
  
c535e2a
  #ifdef FEAT_CLIPBOARD
c535e2a
  
c535e2a
*** ../vim-7.0.154/src/version.c	Wed Nov  1 12:43:07 2006
c535e2a
--- src/version.c	Wed Nov  1 15:22:33 2006
c535e2a
***************
c535e2a
*** 668,669 ****
c535e2a
--- 668,671 ----
c535e2a
  {   /* Add new patch number below this line */
c535e2a
+ /**/
c535e2a
+     155,
c535e2a
  /**/
c535e2a
c535e2a
-- 
c535e2a
hundred-and-one symptoms of being an internet addict:
c535e2a
138. You develop a liking for cold coffee.
c535e2a
c535e2a
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
c535e2a
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
c535e2a
\\\        download, build and distribute -- http://www.A-A-P.org        ///
c535e2a
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///