Charles E Campbell Jr wrote: >So, a feature request: how about a <p-args> that breaks the input >arguments at whitespace (but otherwise leaves the arguments alone). The >"p" is to be vaguely reminescent of: pattern-arguments (as in regular >expression patterns)? > > Hello!
If anyone's interested, here's a patch that implements <p-args>. No documentation yet as I'd like to see if Bram likes it first. Also, I've included a small test source to demonstrate (you'll need Decho.vim with it, that's at http://vim.sourceforge.net/scripts/script.php?script_id=120 ). Regards, Chip Campbell --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
*** old_ex_docmd.c 2007-08-17 11:06:47.000000000 -0400 --- ex_docmd.c 2007-08-17 11:43:52.000000000 -0400 *************** *** 5658,5663 **** --- 5658,5729 ---- } /* + * split and quote args for <p-args> + */ + static char_u * + uc_split_pargs(arg, lenp) + char_u *arg; + size_t *lenp; + { + char_u *buf; + char_u *p; + char_u *q; + int len; + + /* Precalculate length */ + p = arg; + len = 2; /* Initial and final quotes */ + + while (*p) + { + if (vim_iswhite(*p)) + { + p = skipwhite(p); + if (*p == NUL) + break; + len += 3; /* "," */ + } + else + { + ++len; + ++p; + } + } + + buf = alloc(len + 1); + if (buf == NULL) + { + *lenp = 0; + return buf; + } + + p = arg; + q = buf; + *q++ = '\''; + while (*p) + { + if (vim_iswhite(*p)) + { + p = skipwhite(p); + if (*p == NUL) + break; + *q++ = '\''; + *q++ = ','; + *q++ = '\''; + } + else + { + *q++ = *p++; + } + } + *q++ = '\''; + *q = 0; + + *lenp = len; + return buf; + } + + /* * Check for a <> code in a user command. * "code" points to the '<'. "len" the length of the <> (inclusive). * "buf" is where the result is to be added. *************** *** 5683,5691 **** enum { ct_ARGS, ct_BANG, ct_COUNT, ct_LINE1, ct_LINE2, ct_REGISTER, ct_LT, ct_NONE } type = ct_NONE; ! if ((vim_strchr((char_u *)"qQfF", *p) != NULL) && p[1] == '-') { ! quote = (*p == 'q' || *p == 'Q') ? 1 : 2; p += 2; l -= 2; } --- 5749,5758 ---- enum { ct_ARGS, ct_BANG, ct_COUNT, ct_LINE1, ct_LINE2, ct_REGISTER, ct_LT, ct_NONE } type = ct_NONE; ! if ((vim_strchr((char_u *)"pPqQfF", *p) != NULL) && p[1] == '-') { ! quote = (*p == 'q' || *p == 'Q')? 1 : ! (*p == 'p' || *p == 'P')? 2 : 3; p += 2; l -= 2; } *************** *** 5727,5733 **** /* When specified there is a single argument don't split it. * Works for ":Cmd %" when % is "a b c". */ ! if ((eap->argt & NOSPC) && quote == 2) quote = 1; switch (quote) --- 5794,5800 ---- /* When specified there is a single argument don't split it. * Works for ":Cmd %" when % is "a b c". */ ! if ((eap->argt & NOSPC) && (quote == 2 || quote == 3)) quote = 1; switch (quote) *************** *** 5737,5742 **** --- 5804,5810 ---- if (buf != NULL) STRCPY(buf, eap->arg); break; + case 1: /* Quote, but don't split */ result = STRLEN(eap->arg) + 2; for (p = eap->arg; *p; ++p) *************** *** 5756,5764 **** } *buf = '"'; } break; ! case 2: /* Quote and split (<f-args>) */ /* This is hard, so only do it once, and cache the result */ if (*split_buf == NULL) *split_buf = uc_split_args(eap->arg, split_len); --- 5824,5842 ---- } *buf = '"'; } + break; + + case 2: /* Quote and split (<p-args>) */ + /* This is hard, so only do it once, and cache the result */ + if (*split_buf == NULL) + *split_buf = uc_split_pargs(eap->arg, split_len); + result = *split_len; + if (buf != NULL && result != 0) + STRCPY(buf, *split_buf); break; ! ! case 3: /* Quote and split (<f-args>) */ /* This is hard, so only do it once, and cache the result */ if (*split_buf == NULL) *split_buf = uc_split_args(eap->arg, split_len);
com! -nargs=* Testf call Testf(<f-args>) com! -nargs=* Testp call Testp(<p-args>) fun! Testf(...) let i= 1 while i <= a:0 call Decho("Testf a:".i."<".a:{i}.">") let i= i + 1 endwhile call Decho("---") endfun fun! Testp(...) let i= 1 while i <= a:0 call Decho("Testp a:".i."<".a:{i}.">") let i= i + 1 endwhile call Decho("---") endfun Testf \ \x Testf \\ \\x Testf \\\ \\\x Testf \\\\ \\\\x Testp \ \x Testp \\ \\x Testp \\\ \\\x Testp \\\\ \\\\x