>
> I don't like "stay", but can't think of something better right now.
>
> Perhaps "keepline"?
>
How do you feel about using 'range!' (with a bang) instead?
It would keep the :function argument space more concise, and would only be
usable with 'range', both of which are nice. However, there's no precedent
(that I can find) for command arguments having bangs.
--
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..e1f2208 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] [keepline] [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 [keepline] argument is added, the cursor will
+ not jump to "a:firstline" before entering the
+ function. This only has 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..9b2c99e 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 "\[keepline]"
syn match helpSpecial "\[line]"
syn match helpSpecial "\[count]"
syn match helpSpecial "\[offset]"
diff --git a/src/eval.c b/src/eval.c
index aab9b0b..81df89d 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_KEEPLINE 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_KEEPLINE))
+ {
+ 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_KEEPLINE | 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, "keepline", 8) == 0)
+ {
+ flags |= FC_KEEPLINE;
+ p += 8;
+ }
else if (STRNCMP(p, "dict", 4) == 0)
{
flags |= FC_DICT;