On 18:21 Tue 02 Dec     , Marcin Szamotulski wrote:
> On 07:13 Tue 02 Dec     , Matteo Cavalleri wrote:
> > I think I've tracked down the remaining problem.
> > 
> > CoffeeCompile is defined as:
> > 
> > command! -buffer -range=% -bar -nargs=*
> >   \  -complete=customlist,s:CoffeeComplete
> >   \  CoffeeCompile call s:CoffeeCompile(<line1>, <line2>, <q-args>)
> > 
> > and it still gives me the "invalid range" error. If i remove the "-buffer" 
> > argument it works again. If I take the example I posted and add the 
> > "-buffer" argument, I can reproduce the problem again when running vim with 
> > "--noplugin -u NONE -N"
> 
> Do you still get this with vim-7.4.539?
> 
> Marcin

This patch should fix this.

Best regards,
Marcin

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 607dbd9..26630f6 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -27,6 +27,7 @@ typedef struct ucmd
     char_u	*uc_rep;	/* The command's replacement string */
     long	uc_def;		/* The default value for a range/count */
     int		uc_compl;	/* completion type */
+    int		uc_addr_type;	/* The command's address type */
 # ifdef FEAT_EVAL
     scid_T	uc_scriptID;	/* SID where the command was defined */
 #  ifdef FEAT_CMDL_COMPL
@@ -2135,8 +2136,9 @@ do_one_cmd(cmdlinep, sourcing,
 #endif
        )
 	ea.addr_type = cmdnames[(int)ea.cmdidx].cmd_addr_type;
-    else
+    else if (ea.cmdidx != CMD_USER)
 	ea.addr_type = ADDR_LINES;
+    /* ea.addr_type for user commands is set by find_ucmd */
     ea.cmd = cmd;
 
     /* repeat for all ',' or ';' separated addresses */
@@ -2196,9 +2198,32 @@ do_one_cmd(cmdlinep, sourcing,
 			ea.line2 = lastbuf->b_fnum;
 			break;
 		    case ADDR_WINDOWS:
+			if (IS_USER_CMDIDX(ea.cmdidx))
+			{
+			    ea.line1 = 1;
+			    ea.line2 = LAST_WIN_NR;
+			}
+			else
+			{
+			    /* there is no vim command which uses '%' and
+			     * ADDR_WINDOWS */
+			    errormsg = (char_u *)_(e_invrange);
+			    goto doend;
+			}
+			break;
 		    case ADDR_TABS:
-			errormsg = (char_u *)_(e_invrange);
-			goto doend;
+			if (IS_USER_CMDIDX(ea.cmdidx))
+			{
+			    ea.line1 = 1;
+			    ea.line2 = LAST_TAB_NR;
+			}
+			else
+			{
+			    /* there is no vim command which uses '%' and
+			     * ADDR_TABS */
+			    errormsg = (char_u *)_(e_invrange);
+			    goto doend;
+			}
 			break;
 		    case ADDR_ARGUMENTS:
 			ea.line1 = 1;
@@ -2629,8 +2654,40 @@ do_one_cmd(cmdlinep, sourcing,
 
     if ((ea.argt & DFLALL) && ea.addr_count == 0)
     {
-	ea.line1 = 1;
-	ea.line2 = curbuf->b_ml.ml_line_count;
+	buf_T	    *buf;
+	switch (ea.addr_type)
+	{
+	    case ADDR_LINES:
+		ea.line1 = 1;
+		ea.line2 = curbuf->b_ml.ml_line_count;
+		break;
+	    case ADDR_LOADED_BUFFERS:
+		buf = firstbuf;
+		while (buf->b_next != NULL && buf->b_ml.ml_mfp == NULL)
+		    buf = buf->b_next;
+		ea.line1 = buf->b_fnum;
+		buf = lastbuf;
+		while (buf->b_prev != NULL && buf->b_ml.ml_mfp == NULL)
+		    buf = buf->b_prev;
+		ea.line2 = buf->b_fnum;
+		break;
+	    case ADDR_UNLOADED_BUFFERS:
+		ea.line1 = firstbuf->b_fnum;
+		ea.line2 = lastbuf->b_fnum;
+		break;
+	    case ADDR_WINDOWS:
+		ea.line1 = 1;
+		ea.line2 = LAST_WIN_NR;
+		break;
+	    case ADDR_TABS:
+		ea.line1 = 1;
+		ea.line2 = LAST_TAB_NR;
+		break;
+	    case ADDR_ARGUMENTS:
+		ea.line1 = 1;
+		ea.line2 = ARGCOUNT;
+		break;
+	}
     }
 
     /* accept numbered register only when no count allowed (:put) */
@@ -3211,6 +3268,7 @@ find_ucmd(eap, p, full, xp, compl)
 			eap->cmdidx = CMD_USER_BUF;
 		    eap->argt = (long)uc->uc_argt;
 		    eap->useridx = j;
+		    eap->addr_type = uc->uc_addr_type;
 
 # ifdef FEAT_CMDL_COMPL
 		    if (compl != NULL)
@@ -5585,14 +5643,14 @@ get_command_name(xp, idx)
 #endif
 
 #if defined(FEAT_USR_CMDS) || defined(PROTO)
-static int	uc_add_command __ARGS((char_u *name, size_t name_len, char_u *rep, long argt, long def, int flags, int compl, char_u *compl_arg, int force));
+static int	uc_add_command __ARGS((char_u *name, size_t name_len, char_u *rep, long argt, long def, int flags, int compl, char_u *compl_arg, int addr_type, int force));
 static void	uc_list __ARGS((char_u *name, size_t name_len));
-static int	uc_scan_attr __ARGS((char_u *attr, size_t len, long *argt, long *def, int *flags, int *compl, char_u **compl_arg));
+static int	uc_scan_attr __ARGS((char_u *attr, size_t len, long *argt, long *def, int *flags, int *compl, char_u **compl_arg, int* attr_type_arg));
 static char_u	*uc_split_args __ARGS((char_u *arg, size_t *lenp));
 static size_t	uc_check_code __ARGS((char_u *code, size_t len, char_u *buf, ucmd_T *cmd, exarg_T *eap, char_u **split_buf, size_t *split_len));
 
     static int
-uc_add_command(name, name_len, rep, argt, def, flags, compl, compl_arg, force)
+uc_add_command(name, name_len, rep, argt, def, flags, compl, compl_arg, addr_type, force)
     char_u	*name;
     size_t	name_len;
     char_u	*rep;
@@ -5601,6 +5659,7 @@ uc_add_command(name, name_len, rep, argt, def, flags, compl, compl_arg, force)
     int		flags;
     int		compl;
     char_u	*compl_arg;
+    int		addr_type;
     int		force;
 {
     ucmd_T	*cmd = NULL;
@@ -5695,6 +5754,7 @@ uc_add_command(name, name_len, rep, argt, def, flags, compl, compl_arg, force)
     cmd->uc_compl_arg = compl_arg;
 # endif
 #endif
+    cmd->uc_addr_type = addr_type;
 
     return OK;
 
@@ -5707,6 +5767,23 @@ fail:
 }
 #endif
 
+#if defined(FEAT_USR_CMDS)
+static struct
+{
+    int	    expand;
+    char    *name;
+} addr_type_complete[] =
+{
+    {ADDR_ARGUMENTS, "arguments"},
+    {ADDR_LINES, "lines"},
+    {ADDR_LOADED_BUFFERS, "buffers"},
+    {ADDR_TABS, "tabs"},
+    {ADDR_UNLOADED_BUFFERS, "unloaded_buffers"},
+    {ADDR_WINDOWS, "windows"},
+    {-1, NULL}
+};
+#endif
+
 #if defined(FEAT_USR_CMDS) || defined(FEAT_EVAL) || defined(PROTO)
 /*
  * List of names for completion for ":command" with the EXPAND_ flag.
@@ -5906,7 +5983,7 @@ uc_fun_cmd()
 }
 
     static int
-uc_scan_attr(attr, len, argt, def, flags, compl, compl_arg)
+uc_scan_attr(attr, len, argt, def, flags, compl, compl_arg, addr_type_arg)
     char_u	*attr;
     size_t	len;
     long	*argt;
@@ -5914,6 +5991,7 @@ uc_scan_attr(attr, len, argt, def, flags, compl, compl_arg)
     int		*flags;
     int		*compl;
     char_u	**compl_arg;
+    int		*addr_type_arg;
 {
     char_u	*p;
 
@@ -6032,6 +6110,16 @@ invalid_count:
 								      == FAIL)
 		return FAIL;
 	}
+	else if (STRNICMP(attr, "addr", attrlen) == 0)
+	{
+	    if (val == NULL)
+	    {
+		EMSG(_("E179: argument required for -addr"));
+		return FAIL;
+	    }
+	    if (parse_addr_type_arg(val, (int)vallen, argt, addr_type_arg) == FAIL)
+		return FAIL;
+	}
 	else
 	{
 	    char_u ch = attr[len];
@@ -6060,6 +6148,7 @@ ex_command(eap)
     int	    flags = 0;
     int	    compl = EXPAND_NOTHING;
     char_u  *compl_arg = NULL;
+    int	    addr_type_arg = ADDR_LINES;
     int	    has_attr = (eap->arg[0] == '-');
     int	    name_len;
 
@@ -6070,7 +6159,7 @@ ex_command(eap)
     {
 	++p;
 	end = skiptowhite(p);
-	if (uc_scan_attr(p, end - p, &argt, &def, &flags, &compl, &compl_arg)
+	if (uc_scan_attr(p, end - p, &argt, &def, &flags, &compl, &compl_arg, &addr_type_arg)
 		== FAIL)
 	    return;
 	p = skipwhite(end);
@@ -6111,7 +6200,7 @@ ex_command(eap)
     }
     else
 	uc_add_command(name, end - name, p, argt, def, flags, compl, compl_arg,
-								eap->forceit);
+								addr_type_arg, eap->forceit);
 }
 
 /*
@@ -6696,6 +6785,40 @@ get_user_cmd_complete(xp, idx)
 }
 # endif /* FEAT_CMDL_COMPL */
 
+/*
+ * Parse address type argument
+ */
+    int
+parse_addr_type_arg(value, vallen, argt, addr_type_arg)
+    char_u	*value;
+    int		vallen;
+    long	*argt;
+    int		*addr_type_arg;
+{
+    int	    i, a, b;
+    for (i = 0; addr_type_complete[i].expand != -1; ++i)
+    {
+	a = (int)STRLEN(addr_type_complete[i].name) == vallen;
+	b = STRNCMP(value, addr_type_complete[i].name, vallen) == 0;
+	if (a && b)
+	{
+	    *addr_type_arg = addr_type_complete[i].expand;
+	    break;
+	}
+    }
+
+    if (addr_type_complete[i].expand == -1)
+    {
+	EMSG2(_("E180: Invalid address type value: %s"), value);
+	return FAIL;
+    }
+
+    if (*addr_type_arg != ADDR_LINES)
+	*argt |= NOTADR;
+
+    return OK;
+}
+
 #endif	/* FEAT_USR_CMDS */
 
 #if defined(FEAT_USR_CMDS) || defined(FEAT_EVAL) || defined(PROTO)

Attachment: signature.asc
Description: Digital signature

Raspunde prin e-mail lui