On 08:22 Sat 08 Feb     , Marcin Szamotulski wrote:
> On 22:27 Fri 07 Feb     , Bram Moolenaar wrote:
> > 
> > Marcin Szamotulski wrote:
> > 
> > > > > I wrote a small patch which adds argisglobal() function which returns
> > > > > 1 if the current buffer has global arglist otherwise, if there is
> > > > > a local arg list it return 0.  I haven't found any other way to test 
> > > > > if
> > > > > the arglist is gobal/local.
> > > > > 
> > > > > I've been using this patch for some time already (I have a plugin
> > > > > http://www.vim.org/scripts/script.php?script_id=4681 which is using 
> > > > > it)
> > > > > and it works fine.
> > > > 
> > > > I'm sure someone will ask for another thing: What local argument list is
> > > > being used.  They can be shared between windows.
> > > > 
> > > > A more generic solution would be to request the ID of the local argument
> > > > list.  When zero, then the window is using the global argument list.
> > > > 
> > > > And then we of course also want to optionally pass in the window number.
> > > > So it would be:
> > > > 
> > > >         arglistid([winnr])
> > > 
> > > Yes that's much better solution.  I have a question though.  The alist_T
> > > structure does not contain an ID of arglist (only list of files, and
> > > number of windows using it).  How should I generate the ID?
> > 
> > You could use the pointer and turn it into an int, but that's ugly (and
> > doesn't work if sizeof(int) is smaller than sizeof(char *).
> > 
> > So the best is to add an ID to alist_T and use a static global to store
> > the last used ID.  That's in alist_new().
> 
> Thanks.  I'll follow your advice.
> 
> Best regards,
> Marcin


Dear Bram,

I attach the patch for arglistid().


Best regards,
Marcin Szamotulski
diff -r 01f2b7e6b33c -r 0e4dacbbe8b4 .hgtags
--- a/.hgtags	Thu Apr 24 17:12:33 2014 +0200
+++ b/.hgtags	Sun Apr 27 08:05:29 2014 +0100
@@ -2987,4 +2987,3 @@
 0ea551fa607dc443b97c2fba97dc0c9cb0bcf303 v7-4-262
 af1bb39774f41c28eabd24d80cffc775695bc124 v7-4-263
 00acac0af680c2d8c82db5258474b121a5908926 v7-4-264
-8ec9d2196bee0c5108f2d2c196a660a7f4e5f29f v7-4-265
diff -r 01f2b7e6b33c -r 0e4dacbbe8b4 runtime/doc/eval.txt
--- a/runtime/doc/eval.txt	Thu Apr 24 17:12:33 2014 +0200
+++ b/runtime/doc/eval.txt	Sun Apr 27 08:05:29 2014 +0100
@@ -1716,6 +1716,8 @@
 append( {lnum}, {list})		Number	append lines {list} below line {lnum}
 argc()				Number	number of files in the argument list
 argidx()			Number	current index in the argument list
+arglistid( [{winnr}, [ {tabnr}]])
+				Number	argument list id
 argv( {nr})			String	{nr} entry of the argument list
 argv( )				List	the argument list
 asin( {expr})			Float	arc sine of {expr}
@@ -2103,6 +2105,12 @@
 argidx()	The result is the current index in the argument list.  0 is
 		the first file.  argc() - 1 is the last one.  See |arglist|.
 
+							*arglistid()*
+arglistid([{winnr}, [ {tabnr} ]])
+		Return argument list id for the current window or for the
+		winndow number {winnr} in tabpage {tabnr}. 0 if the window is
+		using global argument list, -1 is returned on error. 
+
 							*argv()*
 argv([{nr}])	The result is the {nr}th file in the argument list of the
 		current window.  See |arglist|.  "argv(0)" is the first one.
diff -r 01f2b7e6b33c -r 0e4dacbbe8b4 runtime/doc/usr_41.txt
--- a/runtime/doc/usr_41.txt	Thu Apr 24 17:12:33 2014 +0200
+++ b/runtime/doc/usr_41.txt	Sun Apr 27 08:05:29 2014 +0100
@@ -772,6 +772,7 @@
 Buffers, windows and the argument list:
 	argc()			number of entries in the argument list
 	argidx()		current position in the argument list
+	arglistid()		return id of the argument list
 	argv()			get one entry from the argument list
 	bufexists()		check if a buffer exists
 	buflisted()		check if a buffer exists and is listed
diff -r 01f2b7e6b33c -r 0e4dacbbe8b4 src/eval.c
--- a/src/eval.c	Thu Apr 24 17:12:33 2014 +0200
+++ b/src/eval.c	Sun Apr 27 08:05:29 2014 +0100
@@ -100,6 +100,7 @@
 static char *e_missbrac = N_("E111: Missing ']'");
 static char *e_listarg = N_("E686: Argument of %s must be a List");
 static char *e_listdictarg = N_("E712: Argument of %s must be a List or Dictionary");
+max_alist_id = 0;
 static char *e_emptykey = N_("E713: Cannot use empty key for Dictionary");
 static char *e_listreq = N_("E714: List required");
 static char *e_dictreq = N_("E715: Dictionary required");
@@ -463,6 +464,7 @@
 static void f_append __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_argc __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_argidx __ARGS((typval_T *argvars, typval_T *rettv));
+static void f_arglistid __ARGS((typval_T *argvars, typval_T *rettv));
 static void f_argv __ARGS((typval_T *argvars, typval_T *rettv));
 #ifdef FEAT_FLOAT
 static void f_asin __ARGS((typval_T *argvars, typval_T *rettv));
@@ -7872,6 +7874,7 @@
     {"append",		2, 2, f_append},
     {"argc",		0, 0, f_argc},
     {"argidx",		0, 0, f_argidx},
+    {"arglistid",	0, 2, f_arglistid},
     {"argv",		0, 1, f_argv},
 #ifdef FEAT_FLOAT
     {"asin",		1, 1, f_asin},	/* WJMc */
@@ -8856,6 +8859,50 @@
 }
 
 /*
+ * "arglistid()" function
+ */
+    static void
+f_arglistid(argvars, rettv)
+    typval_T	*argvars UNUSED;
+    typval_T	*rettv;
+{
+    win_T   *wp;
+    tabpage_T	*tp;
+    long    n;
+
+    if (argvars[0].v_type == VAR_NUMBER) {
+	if (argvars[1].v_type == VAR_NUMBER) {
+	    n = get_tv_number(&argvars[1]);
+	    if (n != -1)
+		tp = find_tabpage(n);
+	    if (n == -1 || tp == NULL) {
+		rettv->vval.v_number = -1;
+		return;
+	    }
+	    wp = find_win_by_nr(&argvars[0], tp);
+	    if (wp == NULL) {
+		rettv->vval.v_number = -1;
+		return;
+	    }
+	    rettv->vval.v_number = wp->w_alist->id;
+	    return;
+	} else {
+	    wp = find_win_by_nr(&argvars[0], curtab);
+	    if (wp == NULL) {
+		rettv->vval.v_number = -1;
+		return;
+	    }
+	    rettv->vval.v_number = wp->w_alist->id;
+	    return;
+	}
+    } else if (argvars[0].v_type == VAR_UNKNOWN) {
+	rettv->vval.v_number = curwin->w_alist->id;
+    } else {
+	rettv->vval.v_number = -1;
+    }
+}
+
+/*
  * "argv(nr)" function
  */
     static void
diff -r 01f2b7e6b33c -r 0e4dacbbe8b4 src/ex_docmd.c
--- a/src/ex_docmd.c	Thu Apr 24 17:12:33 2014 +0200
+++ b/src/ex_docmd.c	Sun Apr 27 08:05:29 2014 +0100
@@ -7207,10 +7207,13 @@
     {
 	curwin->w_alist = &global_alist;
 	++global_alist.al_refcount;
+	global_alist.id = 0;
     }
     else
     {
 	curwin->w_alist->al_refcount = 1;
+	max_alist_id += 1;
+	curwin->w_alist->id = max_alist_id;
 	alist_init(curwin->w_alist);
     }
 }
diff -r 01f2b7e6b33c -r 0e4dacbbe8b4 src/globals.h
--- a/src/globals.h	Thu Apr 24 17:12:33 2014 +0200
+++ b/src/globals.h	Sun Apr 27 08:05:29 2014 +0100
@@ -601,6 +601,7 @@
  * to this when the window is using the global argument list.
  */
 EXTERN alist_T	global_alist;	/* global argument list */
+EXTERN int	max_alist_id;	/* the greatest value of argument list id */
 EXTERN int	arg_had_last INIT(= FALSE); /* accessed last file in
 					       global_alist */
 
diff -r 01f2b7e6b33c -r 0e4dacbbe8b4 src/structs.h
--- a/src/structs.h	Thu Apr 24 17:12:33 2014 +0200
+++ b/src/structs.h	Sun Apr 27 08:05:29 2014 +0100
@@ -675,6 +675,7 @@
 {
     garray_T	al_ga;		/* growarray with the array of file names */
     int		al_refcount;	/* number of windows using this arglist */
+    int		id;		/* id of this arglist */
 } alist_T;
 
 /*

Attachment: signature.asc
Description: Digital signature

Raspunde prin e-mail lui