Just tried to apply these clean and realized that the doc patch had caught some
changes to tags. My mistake, a cleaned one is below.
Bram, do you have any preference on the name of this argument?
--
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
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 94c8f31..0410d84 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -6506,7 +6506,7 @@ last defined. Example: >
See |:verbose-cmd| for more information.
*E124* *E125* *E853*
-:fu[nction][!] {name}([arguments]) [range] [abort] [dict]
+:fu[nction][!] {name}([arguments]) [range] [stay] [abort] [dict]
Define a new function by the name {name}. The name
must be made of alphanumeric characters and '_', and
must start with a capital or "s:" (see above).
@@ -6538,6 +6538,10 @@ See |:verbose-cmd| for more information.
The cursor is still moved to the first line of the
range, as is the case with all Ex commands.
+ When the [stay] argument is added, the cursor will not
+ jump to "a:firstline" before entering the function.
+ This only has an effect when used with [range].
+
When the [abort] argument is added, the function will
abort as soon as an error is detected.
diff --git a/runtime/syntax/help.vim b/runtime/syntax/help.vim
index af97543..ca3258f 100644
--- a/runtime/syntax/help.vim
+++ b/runtime/syntax/help.vim
@@ -63,6 +63,7 @@ syn match helpSpecial "<[-a-zA-Z0-9_]\+>"
syn match helpSpecial "<[SCM]-.>"
syn match helpNormal "<---*>"
syn match helpSpecial "\[range]"
+syn match helpSpecial "\[stay]"
syn match helpSpecial "\[line]"
syn match helpSpecial "\[count]"
syn match helpSpecial "\[offset]"
diff --git a/src/eval.c b/src/eval.c
index aab9b0b..8b8733b 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -200,6 +200,7 @@ struct ufunc
#define FC_ABORT 1 /* abort function on error */
#define FC_RANGE 2 /* function accepts range */
#define FC_DICT 4 /* Dict function, uses "self" */
+#define FC_STAY 8 /* save function, prevent moving cursor */
/*
* All user-defined functions are found in this hashtable.
@@ -3453,14 +3454,6 @@ ex_call(eap)
lnum = eap->line1;
for ( ; lnum <= eap->line2; ++lnum)
{
- if (!eap->skip && eap->addr_count > 0)
- {
- curwin->w_cursor.lnum = lnum;
- curwin->w_cursor.col = 0;
-#ifdef FEAT_VIRTUALEDIT
- curwin->w_cursor.coladd = 0;
-#endif
- }
arg = startarg;
if (get_func_tv(name, (int)STRLEN(name), &rettv, &arg,
eap->line1, eap->line2, &doesrange,
@@ -3469,6 +3462,14 @@ ex_call(eap)
failed = TRUE;
break;
}
+ if (!eap->skip && eap->addr_count > 0 && !(doesrange & FC_STAY))
+ {
+ curwin->w_cursor.lnum = lnum;
+ curwin->w_cursor.col = 0;
+#ifdef FEAT_VIRTUALEDIT
+ curwin->w_cursor.coladd = 0;
+#endif
+ }
/* Handle a function returning a Funcref, Dictionary or List. */
if (handle_subscript(&arg, &rettv, !eap->skip, TRUE) == FAIL)
@@ -8422,7 +8423,7 @@ call_func(funcname, len, rettv, argcount, argvars, firstline, lastline,
else
fname = name;
- *doesrange = FALSE;
+ *doesrange = 0;
/* execute the function if no errors detected and executing */
@@ -8460,7 +8461,7 @@ call_func(funcname, len, rettv, argcount, argvars, firstline, lastline,
if (fp != NULL)
{
if (fp->uf_flags & FC_RANGE)
- *doesrange = TRUE;
+ *doesrange = fp->uf_flags & (FC_STAY | FC_RANGE);
if (argcount < fp->uf_args.ga_len)
error = ERROR_TOOFEW;
else if (!fp->uf_varargs && argcount > fp->uf_args.ga_len)
@@ -21145,6 +21146,11 @@ ex_function(eap)
flags |= FC_RANGE;
p += 5;
}
+ else if (STRNCMP(p, "stay", 4) == 0)
+ {
+ flags |= FC_STAY;
+ p += 4;
+ }
else if (STRNCMP(p, "dict", 4) == 0)
{
flags |= FC_DICT;