On 15:15 Wed 30 Jul     , Marcin Szamotulski wrote:
> On 12:53 Wed 30 Jul     , Bram Moolenaar wrote:
> > 
> > Marcin Szamotulski wrote:
> > 
> > > I wrote a patch to reuse an argument list from different window.
> > > I think it is useful to have a way of setting an argument list from
> > > a different window [tab page].  One scenario where it is useful is when
> > > a window has global argument list and one makes a ':split|argl' and
> > > after a while one would like to reuse the new local argument list 
> > > somewhere
> > > else.  With the attached patch one can:
> > > 
> > > :call usearglist({winnr} [, {tabnr}])
> > > 
> > > to use the argument list from window number {winnr} (in tab page
> > > {tabnr}) in the current window.
> > > 
> > > The function returns 0 on success and -1 on error (window or tab page not
> > > found).
> > 
> > Hmm, it's a bit strange to have this as a function.  Otherwise setting
> > the argument list is done with commands.  E.g. :argglobal is similar,
> > but always switches to the global argument list.
> > 
> > We could use :{nr}arglocal instead.  The question is where the user gets
> > the {nr} from.  When using arglistid() this requires using :exe.  I
> > think we need a command to list all the arglists.
> 
> I agree.
> > 
> > For a user who actually uses multiple arglists it would indeed be useful
> > to list the ones that are in use.  With a summary of the file names, and
> > which window/tab they are used in.
> > 
> 
> Maybe it should show columns:
> file name, window id, tab id and arglist id
> 
> or even omit tab id by default and only include other tab pages when
> a bang is used.  I think it is better to organize the list by tab page id
> and window id rather by arglist id, since it will be easier to find the
> correct arglist id.
> 
> Something like:
> tabdo windo echo printf('%2d %4d %4d  %s', tabpagenr(), winnr(), arglistid(), 
> bufname('%'))
> 
> (but without the drawback of landing in a different window/tab page)
> 
> Best regards,
> Marcin Szamotulski

Dear Bram,

I attach patch for :{N}arglocal (for using arglist with ID {N} in the
current window) command which also adds :arglists[!] (for listing all
the arglists).

During compilation I get a warning:
ex_docmd.c:205:13: warning: ‘ex_arglists’ used but never defined [enabled by 
default]
which I don't know how to fix.

Best regards,
Marcin Szamotulski
diff -r 7090d7f160f7 -r d4ccab55a143 runtime/doc/editing.txt
--- a/runtime/doc/editing.txt	Sat Jul 26 13:40:44 2014 +0200
+++ b/runtime/doc/editing.txt	Mon Aug 04 00:15:39 2014 +0100
@@ -798,6 +798,14 @@
 			Define a new argument list, which is local to the
 			current window.  Works like |:args_f| otherwise.
 
+:{count}argl[ocal]
+			Use argument list with ID {count} in the current
+			window.  To find the argument list ID use |:arglists|
+			command.  If the {count} is 0 the command acts like
+			|:argglobal|.
+			{not in Vi} {not available when compiled without the
+			|+listcmds| feature}
+
 							*:argglobal*
 :argg[lobal]		Use the global argument list for the current window.
 			Doesn't start editing another file.
@@ -808,6 +816,17 @@
 			All windows using the global argument list will see
 			this new list.
 
+							*:arglists*
+:argli[sts][!]
+			List all windows in the current tab page together with
+			their arugment list ID.  If bang is used show all
+			windows in all tab pages.  The '>' indicates the
+			current window and '<' indicates the previous window
+			as for |CTRL-W_p| normal command.  See also
+			|arglistid()|.
+			{not in Vi} {not available when compiled without the
+			|+listcmds| feature}
+
 There can be several argument lists.  They can be shared between windows.
 When they are shared, changing the argument list in one window will also
 change it in the other window.
diff -r 7090d7f160f7 -r d4ccab55a143 runtime/doc/eval.txt
--- a/runtime/doc/eval.txt	Sat Jul 26 13:40:44 2014 +0200
+++ b/runtime/doc/eval.txt	Mon Aug 04 00:15:39 2014 +0100
@@ -2113,7 +2113,7 @@
 		Return the argument list ID.  This is a number which
 		identifies the argument list being used.  Zero is used for the
 		global argument list.
-		Return zero if the arguments are invalid.
+		Return -1 if the arguments are invalid.
 
 		Without arguments use the current window.
 		With {winnr} only use this window in the current tab page.
diff -r 7090d7f160f7 -r d4ccab55a143 src/ex_cmds.h
--- a/src/ex_cmds.h	Sat Jul 26 13:40:44 2014 +0200
+++ b/src/ex_cmds.h	Mon Aug 04 00:15:39 2014 +0100
@@ -120,7 +120,9 @@
 EX(CMD_argglobal,	"argglobal",	ex_args,
 			BANG|FILES|EDITCMD|ARGOPT|TRLBAR),
 EX(CMD_arglocal,	"arglocal",	ex_args,
-			BANG|FILES|EDITCMD|ARGOPT|TRLBAR),
+			BANG|RANGE|NOTADR|ZEROR|COUNT|FILES|EDITCMD|ARGOPT|TRLBAR),
+EX(CMD_arglists,	"arglists",	ex_arglists,
+			BANG|TRLBAR|ARGOPT|CMDWIN),
 EX(CMD_argument,	"argument",	ex_argument,
 			BANG|RANGE|NOTADR|COUNT|EXTRA|EDITCMD|ARGOPT|TRLBAR),
 EX(CMD_ascii,		"ascii",	do_ascii,
diff -r 7090d7f160f7 -r d4ccab55a143 src/ex_cmds2.c
--- a/src/ex_cmds2.c	Sat Jul 26 13:40:44 2014 +0200
+++ b/src/ex_cmds2.c	Mon Aug 04 00:15:39 2014 +0100
@@ -2160,6 +2160,36 @@
     else if (eap->cmdidx == CMD_arglocal)
     {
 	garray_T	*gap = &curwin->w_alist->al_ga;
+	int		b_flag = 0;
+	tabpage_T	*tp;
+	win_T		*wp;
+
+	/*
+	 * ":Nargslocal": use arglist with ID eap->line2 if it is given.
+	 */
+	if (eap->addr_count > 0) {
+	    if ((int)eap->line2 == 0) {
+		alist_unlink(ALIST(curwin));
+		ALIST(curwin) = &global_alist;
+		return;
+	    }
+	    else
+	    {
+		FOR_ALL_TAB_WINDOWS(tp, wp) {
+		    if (wp->w_alist->id == (int)eap->line2) {
+			b_flag = 1;
+			goto foundwalist;
+		    }
+		}
+foundwalist:
+		if (b_flag == 1) {
+		    alist_unlink(ALIST(curwin));
+		    curwin->w_alist = wp->w_alist;
+		    ++curwin->w_alist->al_refcount;
+		}
+		return;
+	    }
+	}
 
 	/*
 	 * ":argslocal": make a local copy of the global argument list.
@@ -2178,6 +2208,81 @@
 #endif
 }
 
+#if defined(FEAT_LISTCMDS)
+/*
+ * ":arglists"
+ */
+    void
+ex_arglists(eap)
+    exarg_T	*eap;
+{
+
+    tabpage_T	*tp;
+    win_T	*wp;
+    buf_T	*buf;
+    int		len;
+    int		tp_idx = 0;
+    int		w_idx = 0;
+
+    if (eap->forceit)
+    {
+	msg_outtrans_attr("  ID tab win  bufname", hl_attr(HLF_T));
+	out_flush();
+	for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
+	    tp_idx++;
+	    w_idx = 0;
+	    for (wp = (tp == curtab)
+		    ? firstwin : tp->tp_firstwin; wp; wp = wp->w_next) {
+		w_idx++;
+		msg_putchar('\n');
+
+		buf = wp->w_buffer;
+		if (buf_spname(buf) != NULL)
+		    vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1);
+		else
+		    home_replace(wp->w_buffer, buf->b_fname, NameBuff, MAXPATHL, TRUE);
+
+		len = vim_snprintf((char *)IObuff, IOSIZE, "%c%3d %3d %3d  \"%s\"\0",
+			curwin == wp ? '>' :
+			    (tp == curtab && wp == prevwin ? '<' : ' '),
+			wp->w_alist->id,
+			tp_idx,
+			w_idx,
+			NameBuff);
+		msg_outtrans(IObuff);
+		out_flush();
+		ui_breakcheck();
+	    }
+	}
+    }
+    else
+    {
+	msg_outtrans_attr("  ID win  bufname", hl_attr(HLF_T));
+	out_flush();
+	for (wp = firstwin; wp; wp = wp->w_next) {
+	    w_idx++;
+	    msg_putchar('\n');
+
+	    buf = wp->w_buffer;
+	    if (buf_spname(buf) != NULL)
+		vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1);
+	    else
+		home_replace(wp->w_buffer, buf->b_fname, NameBuff, MAXPATHL, TRUE);
+
+	    len = vim_snprintf((char *)IObuff, IOSIZE, "%c%3d %3d  \"%s\"\0",
+		    curwin == wp ? '>' :
+			(wp == prevwin ? '<' : ' '),
+		    wp->w_alist->id,
+		    w_idx,
+		    NameBuff);
+	    msg_outtrans(IObuff);
+	    out_flush();
+	    ui_breakcheck();
+	}
+    }
+}
+#endif /* FEAT_LISTCMDS */
+
 /*
  * ":previous", ":sprevious", ":Next" and ":sNext".
  */
diff -r 7090d7f160f7 -r d4ccab55a143 src/ex_docmd.c
--- a/src/ex_docmd.c	Sat Jul 26 13:40:44 2014 +0200
+++ b/src/ex_docmd.c	Mon Aug 04 00:15:39 2014 +0100
@@ -200,6 +200,9 @@
 # define ex_argadd		ex_ni
 # define ex_argdelete		ex_ni
 # define ex_listdo		ex_ni
+# define ex_arglists		ex_ni
+#else
+static void	ex_arglists __ARGS((exarg_T *eap));
 #endif
 static void	ex_mode __ARGS((exarg_T *eap));
 static void	ex_wrongmodifier __ARGS((exarg_T *eap));

Attachment: signature.asc
Description: Digital signature

Reply via email to