83eea17
To: vim-dev@vim.org
83eea17
Subject: patch 7.1.031
83eea17
Fcc: outbox
83eea17
From: Bram Moolenaar <Bram@moolenaar.net>
83eea17
Mime-Version: 1.0
83eea17
Content-Type: text/plain; charset=ISO-8859-1
83eea17
Content-Transfer-Encoding: 8bit
83eea17
------------
83eea17
83eea17
Patch 7.1.031
83eea17
Problem:    virtcol([123, '$']) doesn't work. (Michael Schaap)
83eea17
Solution:   When '$' is used for the column number get the last column.
83eea17
Files:	    runtime/doc/eval.txt, src/eval.c
83eea17
83eea17
83eea17
*** ../vim-7.1.030/runtime/doc/eval.txt	Tue Jun 19 17:23:46 2007
83eea17
--- runtime/doc/eval.txt	Wed Jul 11 21:21:28 2007
83eea17
***************
83eea17
*** 1,4 ****
83eea17
! *eval.txt*      For Vim version 7.1.  Last change: 2007 Jun 09
83eea17
  
83eea17
  
83eea17
  		  VIM REFERENCE MANUAL    by Bram Moolenaar
83eea17
--- 1,4 ----
83eea17
! *eval.txt*      For Vim version 7.1.  Last change: 2007 Jul 11
83eea17
  
83eea17
  
83eea17
  		  VIM REFERENCE MANUAL    by Bram Moolenaar
83eea17
***************
83eea17
*** 2020,2025 ****
83eea17
--- 2020,2029 ----
83eea17
  			    number of characters in the cursor line plus one)
83eea17
  		    'x	    position of mark x (if the mark is not set, 0 is
83eea17
  			    returned)
83eea17
+ 		Additionally {expr} can be [lnum, col]: a |List| with the line
83eea17
+ 		and column number. Most useful when the column is "$", to get
83eea17
+ 		the las column of a specific line.  When "lnum" or "col" is
83eea17
+ 		out of range then col() returns zero.
83eea17
  		To get the line number use |line()|.  To get both use
83eea17
  		|getpos()|.
83eea17
  		For the screen column position use |virtcol()|.
83eea17
***************
83eea17
*** 5024,5037 ****
83eea17
  		position, the returned Number will be the column at the end of
83eea17
  		the <Tab>.  For example, for a <Tab> in column 1, with 'ts'
83eea17
  		set to 8, it returns 8.
83eea17
! 		For the use of {expr} see |col()|.  Additionally you can use
83eea17
! 		[lnum, col]: a |List| with the line and column number.  When
83eea17
! 		"lnum" or "col" is out of range then virtcol() returns zero.
83eea17
! 		When 'virtualedit' is used it can be [lnum, col, off], where
83eea17
  		"off" is the offset in screen columns from the start of the
83eea17
  		character.  E.g., a position within a <Tab> or after the last
83eea17
  		character.
83eea17
- 		For the byte position use |col()|.
83eea17
  		When Virtual editing is active in the current mode, a position
83eea17
  		beyond the end of the line can be returned. |'virtualedit'|
83eea17
  		The accepted positions are:
83eea17
--- 5029,5040 ----
83eea17
  		position, the returned Number will be the column at the end of
83eea17
  		the <Tab>.  For example, for a <Tab> in column 1, with 'ts'
83eea17
  		set to 8, it returns 8.
83eea17
! 		For the byte position use |col()|.
83eea17
! 		For the use of {expr} see |col()|.
83eea17
! 		When 'virtualedit' is used {expr} can be [lnum, col, off], where
83eea17
  		"off" is the offset in screen columns from the start of the
83eea17
  		character.  E.g., a position within a <Tab> or after the last
83eea17
  		character.
83eea17
  		When Virtual editing is active in the current mode, a position
83eea17
  		beyond the end of the line can be returned. |'virtualedit'|
83eea17
  		The accepted positions are:
83eea17
*** ../vim-7.1.030/src/eval.c	Tue Jul 10 13:27:46 2007
83eea17
--- src/eval.c	Wed Jul 11 19:50:27 2007
83eea17
***************
83eea17
*** 672,678 ****
83eea17
  static void f_writefile __ARGS((typval_T *argvars, typval_T *rettv));
83eea17
  
83eea17
  static int list2fpos __ARGS((typval_T *arg, pos_T *posp, int *fnump));
83eea17
! static pos_T *var2fpos __ARGS((typval_T *varp, int lnum, int *fnum));
83eea17
  static int get_env_len __ARGS((char_u **arg));
83eea17
  static int get_id_len __ARGS((char_u **arg));
83eea17
  static int get_name_len __ARGS((char_u **arg, char_u **alias, int evaluate, int verbose));
83eea17
--- 672,678 ----
83eea17
  static void f_writefile __ARGS((typval_T *argvars, typval_T *rettv));
83eea17
  
83eea17
  static int list2fpos __ARGS((typval_T *arg, pos_T *posp, int *fnump));
83eea17
! static pos_T *var2fpos __ARGS((typval_T *varp, int dollar_lnum, int *fnum));
83eea17
  static int get_env_len __ARGS((char_u **arg));
83eea17
  static int get_id_len __ARGS((char_u **arg));
83eea17
  static int get_name_len __ARGS((char_u **arg, char_u **alias, int evaluate, int verbose));
83eea17
***************
83eea17
*** 16505,16513 ****
83eea17
   * Returns NULL when there is an error.
83eea17
   */
83eea17
      static pos_T *
83eea17
! var2fpos(varp, lnum, fnum)
83eea17
      typval_T	*varp;
83eea17
!     int		lnum;		/* TRUE when $ is last line */
83eea17
      int		*fnum;		/* set to fnum for '0, 'A, etc. */
83eea17
  {
83eea17
      char_u		*name;
83eea17
--- 16508,16516 ----
83eea17
   * Returns NULL when there is an error.
83eea17
   */
83eea17
      static pos_T *
83eea17
! var2fpos(varp, dollar_lnum, fnum)
83eea17
      typval_T	*varp;
83eea17
!     int		dollar_lnum;	/* TRUE when $ is last line */
83eea17
      int		*fnum;		/* set to fnum for '0, 'A, etc. */
83eea17
  {
83eea17
      char_u		*name;
83eea17
***************
83eea17
*** 16520,16525 ****
83eea17
--- 16523,16529 ----
83eea17
  	list_T		*l;
83eea17
  	int		len;
83eea17
  	int		error = FALSE;
83eea17
+ 	listitem_T	*li;
83eea17
  
83eea17
  	l = varp->vval.v_list;
83eea17
  	if (l == NULL)
83eea17
***************
83eea17
*** 16535,16540 ****
83eea17
--- 16539,16552 ----
83eea17
  	if (error)
83eea17
  	    return NULL;
83eea17
  	len = (long)STRLEN(ml_get(pos.lnum));
83eea17
+ 
83eea17
+ 	/* We accept "$" for the column number: last column. */
83eea17
+ 	li = list_find(l, 1L);
83eea17
+ 	if (li != NULL && li->li_tv.v_type == VAR_STRING
83eea17
+ 		&& li->li_tv.vval.v_string != NULL
83eea17
+ 		&& STRCMP(li->li_tv.vval.v_string, "$") == 0)
83eea17
+ 	    pos.col = len + 1;
83eea17
+ 
83eea17
  	/* Accept a position up to the NUL after the line. */
83eea17
  	if (pos.col == 0 || (int)pos.col > len + 1)
83eea17
  	    return NULL;	/* invalid column number */
83eea17
***************
83eea17
*** 16567,16573 ****
83eea17
      pos.coladd = 0;
83eea17
  #endif
83eea17
  
83eea17
!     if (name[0] == 'w' && lnum)
83eea17
      {
83eea17
  	pos.col = 0;
83eea17
  	if (name[1] == '0')		/* "w0": first visible line */
83eea17
--- 16579,16585 ----
83eea17
      pos.coladd = 0;
83eea17
  #endif
83eea17
  
83eea17
!     if (name[0] == 'w' && dollar_lnum)
83eea17
      {
83eea17
  	pos.col = 0;
83eea17
  	if (name[1] == '0')		/* "w0": first visible line */
83eea17
***************
83eea17
*** 16585,16591 ****
83eea17
      }
83eea17
      else if (name[0] == '$')		/* last column or line */
83eea17
      {
83eea17
! 	if (lnum)
83eea17
  	{
83eea17
  	    pos.lnum = curbuf->b_ml.ml_line_count;
83eea17
  	    pos.col = 0;
83eea17
--- 16597,16603 ----
83eea17
      }
83eea17
      else if (name[0] == '$')		/* last column or line */
83eea17
      {
83eea17
! 	if (dollar_lnum)
83eea17
  	{
83eea17
  	    pos.lnum = curbuf->b_ml.ml_line_count;
83eea17
  	    pos.col = 0;
83eea17
*** ../vim-7.1.030/src/version.c	Tue Jul 17 14:32:07 2007
83eea17
--- src/version.c	Tue Jul 17 16:24:54 2007
83eea17
***************
83eea17
*** 668,669 ****
83eea17
--- 668,671 ----
83eea17
  {   /* Add new patch number below this line */
83eea17
+ /**/
83eea17
+     31,
83eea17
  /**/
83eea17
83eea17
-- 
83eea17
CRONE:  Who sent you?
83eea17
ARTHUR: The Knights Who Say GNU!
83eea17
CRONE:  Aaaagh!  (she looks around in rear) No!  We have no licenses here.
83eea17
           "Monty Python and the Holy editor wars" PYTHON (MONTY) SOFTWARE LTD
83eea17
83eea17
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
83eea17
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
83eea17
\\\        download, build and distribute -- http://www.A-A-P.org        ///
83eea17
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///