Karsten Hopp e6148a
To: vim-dev@vim.org
Karsten Hopp e6148a
Subject: Patch 7.1.215
Karsten Hopp e6148a
Fcc: outbox
Karsten Hopp e6148a
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp e6148a
Mime-Version: 1.0
Karsten Hopp e6148a
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp e6148a
Content-Transfer-Encoding: 8bit
Karsten Hopp e6148a
------------
Karsten Hopp e6148a
Karsten Hopp e6148a
Patch 7.1.215
Karsten Hopp e6148a
Problem:    It is difficult to figure out what syntax items are nested at a
Karsten Hopp e6148a
	    certain position.
Karsten Hopp e6148a
Solution:   Add the synstack() function.
Karsten Hopp e6148a
Files:	    runtime/doc/eval.txt, src/eval.c, src/proto/syntax.pro,
Karsten Hopp e6148a
	    src/syntax.c
Karsten Hopp e6148a
Karsten Hopp e6148a
Karsten Hopp e6148a
*** ../vim-7.1.214/runtime/doc/eval.txt	Sun Jan  6 20:05:36 2008
Karsten Hopp e6148a
--- runtime/doc/eval.txt	Thu Jan 10 22:20:31 2008
Karsten Hopp e6148a
***************
Karsten Hopp e6148a
*** 1,4 ****
Karsten Hopp e6148a
! *eval.txt*      For Vim version 7.1.  Last change: 2008 Jan 06
Karsten Hopp e6148a
  
Karsten Hopp e6148a
  
Karsten Hopp e6148a
  		  VIM REFERENCE MANUAL    by Bram Moolenaar
Karsten Hopp e6148a
--- 1,4 ----
Karsten Hopp e6148a
! *eval.txt*      For Vim version 7.1.  Last change: 2008 Jan 10
Karsten Hopp e6148a
  
Karsten Hopp e6148a
  
Karsten Hopp e6148a
  		  VIM REFERENCE MANUAL    by Bram Moolenaar
Karsten Hopp e6148a
***************
Karsten Hopp e6148a
*** 1786,1791 ****
Karsten Hopp e6148a
--- 1786,1792 ----
Karsten Hopp e6148a
  synIDattr( {synID}, {what} [, {mode}])
Karsten Hopp e6148a
  				String	attribute {what} of syntax ID {synID}
Karsten Hopp e6148a
  synIDtrans( {synID})		Number	translated syntax ID of {synID}
Karsten Hopp e6148a
+ synstack({lnum}, {col})		List    stack of syntax IDs at {lnum} and {col}
Karsten Hopp e6148a
  system( {expr} [, {input}])	String	output of shell command/filter {expr}
Karsten Hopp e6148a
  tabpagebuflist( [{arg}])	List	list of buffer numbers in tab page
Karsten Hopp e6148a
  tabpagenr( [{arg}])		Number	number of current or last tab page
Karsten Hopp e6148a
***************
Karsten Hopp e6148a
*** 4962,4967 ****
Karsten Hopp e6148a
--- 4966,4989 ----
Karsten Hopp e6148a
  		highlight the character.  Highlight links given with
Karsten Hopp e6148a
  		":highlight link" are followed.
Karsten Hopp e6148a
  
Karsten Hopp e6148a
+ synstack({lnum}, {col})					*synstack()*
Karsten Hopp e6148a
+ 		Return a |List|, which is the stack of syntax items at the
Karsten Hopp e6148a
+ 		position {lnum} and {col} in the current window.  Each item in
Karsten Hopp e6148a
+ 		the List is an ID like what |synID()| returns.
Karsten Hopp e6148a
+ 		The stack is the situation in between the character at "col"
Karsten Hopp e6148a
+ 		and the next character.  Note that a region of only one
Karsten Hopp e6148a
+ 		character will not show up, it only exists inside that
Karsten Hopp e6148a
+ 		character, not in between characters.
Karsten Hopp e6148a
+ 		The first item in the List is the outer region, following are
Karsten Hopp e6148a
+ 		items contained in that one.  The last one is what |synID()|
Karsten Hopp e6148a
+ 		returns, unless not the whole item is highlighted or it is a
Karsten Hopp e6148a
+ 		transparent item.
Karsten Hopp e6148a
+ 		This function is useful for debugging a syntax file.
Karsten Hopp e6148a
+ 		Example that shows the syntax stack under the cursor: >
Karsten Hopp e6148a
+ 			for id in synstack(line("."), col("."))
Karsten Hopp e6148a
+ 			   echo synIDattr(id, "name")
Karsten Hopp e6148a
+ 			endfor
Karsten Hopp e6148a
+ 
Karsten Hopp e6148a
  system({expr} [, {input}])				*system()* *E677*
Karsten Hopp e6148a
  		Get the output of the shell command {expr}.
Karsten Hopp e6148a
  		When {input} is given, this string is written to a file and
Karsten Hopp e6148a
*** ../vim-7.1.214/src/eval.c	Sun Jan  6 20:05:36 2008
Karsten Hopp e6148a
--- src/eval.c	Wed Jan  9 13:42:56 2008
Karsten Hopp e6148a
***************
Karsten Hopp e6148a
*** 651,656 ****
Karsten Hopp e6148a
--- 651,657 ----
Karsten Hopp e6148a
  static void f_synID __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp e6148a
  static void f_synIDattr __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp e6148a
  static void f_synIDtrans __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp e6148a
+ static void f_synstack __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp e6148a
  static void f_system __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp e6148a
  static void f_tabpagebuflist __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp e6148a
  static void f_tabpagenr __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp e6148a
***************
Karsten Hopp e6148a
*** 7252,7257 ****
Karsten Hopp e6148a
--- 7253,7259 ----
Karsten Hopp e6148a
      {"synID",		3, 3, f_synID},
Karsten Hopp e6148a
      {"synIDattr",	2, 3, f_synIDattr},
Karsten Hopp e6148a
      {"synIDtrans",	1, 1, f_synIDtrans},
Karsten Hopp e6148a
+     {"synstack",	2, 2, f_synstack},
Karsten Hopp e6148a
      {"system",		1, 2, f_system},
Karsten Hopp e6148a
      {"tabpagebuflist",	0, 1, f_tabpagebuflist},
Karsten Hopp e6148a
      {"tabpagenr",	0, 1, f_tabpagenr},
Karsten Hopp e6148a
***************
Karsten Hopp e6148a
*** 15843,15848 ****
Karsten Hopp e6148a
--- 15845,15890 ----
Karsten Hopp e6148a
  	id = 0;
Karsten Hopp e6148a
  
Karsten Hopp e6148a
      rettv->vval.v_number = id;
Karsten Hopp e6148a
+ }
Karsten Hopp e6148a
+ 
Karsten Hopp e6148a
+ /*
Karsten Hopp e6148a
+  * "synstack(lnum, col)" function
Karsten Hopp e6148a
+  */
Karsten Hopp e6148a
+ /*ARGSUSED*/
Karsten Hopp e6148a
+     static void
Karsten Hopp e6148a
+ f_synstack(argvars, rettv)
Karsten Hopp e6148a
+     typval_T	*argvars;
Karsten Hopp e6148a
+     typval_T	*rettv;
Karsten Hopp e6148a
+ {
Karsten Hopp e6148a
+ #ifdef FEAT_SYN_HL
Karsten Hopp e6148a
+     long	lnum;
Karsten Hopp e6148a
+     long	col;
Karsten Hopp e6148a
+     int		i;
Karsten Hopp e6148a
+     int		id;
Karsten Hopp e6148a
+ #endif
Karsten Hopp e6148a
+ 
Karsten Hopp e6148a
+     rettv->v_type = VAR_LIST;
Karsten Hopp e6148a
+     rettv->vval.v_list = NULL;
Karsten Hopp e6148a
+ 
Karsten Hopp e6148a
+ #ifdef FEAT_SYN_HL
Karsten Hopp e6148a
+     lnum = get_tv_lnum(argvars);		/* -1 on type error */
Karsten Hopp e6148a
+     col = get_tv_number(&argvars[1]) - 1;	/* -1 on type error */
Karsten Hopp e6148a
+ 
Karsten Hopp e6148a
+     if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count
Karsten Hopp e6148a
+ 	    && col >= 0 && col < (long)STRLEN(ml_get(lnum))
Karsten Hopp e6148a
+ 	    && rettv_list_alloc(rettv) != FAIL)
Karsten Hopp e6148a
+     {
Karsten Hopp e6148a
+ 	(void)syn_get_id(curwin, lnum, (colnr_T)col, FALSE, NULL);
Karsten Hopp e6148a
+ 	for (i = 0; ; ++i)
Karsten Hopp e6148a
+ 	{
Karsten Hopp e6148a
+ 	    id = syn_get_stack_item(i);
Karsten Hopp e6148a
+ 	    if (id < 0)
Karsten Hopp e6148a
+ 		break;
Karsten Hopp e6148a
+ 	    if (list_append_number(rettv->vval.v_list, id) == FAIL)
Karsten Hopp e6148a
+ 		break;
Karsten Hopp e6148a
+ 	}
Karsten Hopp e6148a
+     }
Karsten Hopp e6148a
+ #endif
Karsten Hopp e6148a
  }
Karsten Hopp e6148a
  
Karsten Hopp e6148a
  /*
Karsten Hopp e6148a
*** ../vim-7.1.214/src/proto/syntax.pro	Tue Jul 24 14:32:44 2007
Karsten Hopp e6148a
--- src/proto/syntax.pro	Wed Jan  9 13:38:20 2008
Karsten Hopp e6148a
***************
Karsten Hopp e6148a
*** 13,18 ****
Karsten Hopp e6148a
--- 13,19 ----
Karsten Hopp e6148a
  void set_context_in_syntax_cmd __ARGS((expand_T *xp, char_u *arg));
Karsten Hopp e6148a
  char_u *get_syntax_name __ARGS((expand_T *xp, int idx));
Karsten Hopp e6148a
  int syn_get_id __ARGS((win_T *wp, long lnum, colnr_T col, int trans, int *spellp));
Karsten Hopp e6148a
+ int syn_get_stack_item __ARGS((int i));
Karsten Hopp e6148a
  int syn_get_foldlevel __ARGS((win_T *wp, long lnum));
Karsten Hopp e6148a
  void init_highlight __ARGS((int both, int reset));
Karsten Hopp e6148a
  int load_colors __ARGS((char_u *name));
Karsten Hopp e6148a
*** ../vim-7.1.214/src/syntax.c	Sun Oct  7 15:21:31 2007
Karsten Hopp e6148a
--- src/syntax.c	Wed Jan  9 15:17:47 2008
Karsten Hopp e6148a
***************
Karsten Hopp e6148a
*** 6104,6109 ****
Karsten Hopp e6148a
--- 6102,6123 ----
Karsten Hopp e6148a
  
Karsten Hopp e6148a
      return (trans ? current_trans_id : current_id);
Karsten Hopp e6148a
  }
Karsten Hopp e6148a
+ 
Karsten Hopp e6148a
+ #if defined(FEAT_EVAL) || defined(PROTO)
Karsten Hopp e6148a
+ /*
Karsten Hopp e6148a
+  * Return the syntax ID at position "i" in the current stack.
Karsten Hopp e6148a
+  * The caller must have called syn_get_id() before to fill the stack.
Karsten Hopp e6148a
+  * Returns -1 when "i" is out of range.
Karsten Hopp e6148a
+  */
Karsten Hopp e6148a
+     int
Karsten Hopp e6148a
+ syn_get_stack_item(i)
Karsten Hopp e6148a
+     int i;
Karsten Hopp e6148a
+ {
Karsten Hopp e6148a
+     if (i >= current_state.ga_len )
Karsten Hopp e6148a
+ 	return -1;
Karsten Hopp e6148a
+     return CUR_STATE(i).si_id;
Karsten Hopp e6148a
+ }
Karsten Hopp e6148a
+ #endif
Karsten Hopp e6148a
  
Karsten Hopp e6148a
  #if defined(FEAT_FOLDING) || defined(PROTO)
Karsten Hopp e6148a
  /*
Karsten Hopp e6148a
*** ../vim-7.1.214/src/version.c	Wed Jan  9 22:39:55 2008
Karsten Hopp e6148a
--- src/version.c	Thu Jan 10 22:17:38 2008
Karsten Hopp e6148a
***************
Karsten Hopp e6148a
*** 668,669 ****
Karsten Hopp e6148a
--- 668,671 ----
Karsten Hopp e6148a
  {   /* Add new patch number below this line */
Karsten Hopp e6148a
+ /**/
Karsten Hopp e6148a
+     215,
Karsten Hopp e6148a
  /**/
Karsten Hopp e6148a
Karsten Hopp e6148a
-- 
Karsten Hopp e6148a
TALL KNIGHT: We are now no longer the Knights Who Say Ni!
Karsten Hopp e6148a
ONE KNIGHT:  Ni!
Karsten Hopp e6148a
OTHERS:      Sh!
Karsten Hopp e6148a
ONE KNIGHT:  (whispers) Sorry.
Karsten Hopp e6148a
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
Karsten Hopp e6148a
Karsten Hopp e6148a
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp e6148a
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp e6148a
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp e6148a
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///