patch 9.1.0547: No way to get the arity of a Vim function
Problem: No way to get the arity of a Vim function
(Austin Ziegler)
Solution: Enhance get() Vim script function to return the function
argument info using get(func, "arity") (LemonBoy)
fixes: #15097
closes: #15109
Signed-off-by: LemonBoy <thatlemon@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index 238b7e4..635b7b2 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -1,4 +1,4 @@
-*builtin.txt* For Vim version 9.1. Last change: 2024 Jun 23
+*builtin.txt* For Vim version 9.1. Last change: 2024 Jul 09
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -3574,7 +3574,7 @@
Return type: |String|
-get({list}, {idx} [, {default}]) *get()*
+get({list}, {idx} [, {default}]) *get()* *get()-list*
Get item {idx} from |List| {list}. When this item is not
available return {default}. Return zero when {default} is
omitted.
@@ -3583,7 +3583,7 @@
<
Return type: any, depending on {list}
-get({blob}, {idx} [, {default}])
+get({blob}, {idx} [, {default}]) *get()-blob*
Get byte {idx} from |Blob| {blob}. When this byte is not
available return {default}. Return -1 when {default} is
omitted.
@@ -3592,7 +3592,7 @@
<
Return type: |Number|
-get({dict}, {key} [, {default}])
+get({dict}, {key} [, {default}]) *get()-dict*
Get item with key {key} from |Dictionary| {dict}. When this
item is not available return {default}. Return zero when
{default} is omitted. Useful example: >
@@ -3604,18 +3604,32 @@
<
Return type: any, depending on {dict}
-get({func}, {what})
- Get item {what} from Funcref {func}. Possible values for
+get({func}, {what}) *get()-func*
+ Get item {what} from |Funcref| {func}. Possible values for
{what} are:
- "name" The function name
- "func" The function
- "dict" The dictionary
- "args" The list with arguments
+ "name" The function name
+ "func" The function
+ "dict" The dictionary
+ "args" The list with arguments
+ "arity" A dictionary with information about the number of
+ arguments accepted by the function (minus the
+ {arglist}) with the following fields:
+ required the number of positional arguments
+ optional the number of optional arguments,
+ in addition to the required ones
+ varargs |TRUE| if the function accepts a
+ variable number of arguments |...|
+
+ Note: There is no error, if the {arglist} of
+ the Funcref contains more arguments than the
+ Funcref expects, it's not validated.
+
Returns zero on error.
+
Preferably used as a |method|: >
myfunc->get(what)
<
- Return type: any, depending on {func}
+ Return type: any, depending on {func} and {what}
*getbufinfo()*
getbufinfo([{buf}])
diff --git a/runtime/doc/tags b/runtime/doc/tags
index e72f739..be71710 100644
--- a/runtime/doc/tags
+++ b/runtime/doc/tags
@@ -7783,6 +7783,10 @@
ge motion.txt /*ge*
gender-neutral helphelp.txt /*gender-neutral*
get() builtin.txt /*get()*
+get()-blob builtin.txt /*get()-blob*
+get()-dict builtin.txt /*get()-dict*
+get()-func builtin.txt /*get()-func*
+get()-list builtin.txt /*get()-list*
get-ms-debuggers debug.txt /*get-ms-debuggers*
getbufinfo() builtin.txt /*getbufinfo()*
getbufline() builtin.txt /*getbufline()*
diff --git a/runtime/doc/version9.txt b/runtime/doc/version9.txt
index 92792b9..43de269 100644
--- a/runtime/doc/version9.txt
+++ b/runtime/doc/version9.txt
@@ -1,4 +1,4 @@
-*version9.txt* For Vim version 9.1. Last change: 2024 Jul 06
+*version9.txt* For Vim version 9.1. Last change: 2024 Jul 08
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -41577,6 +41577,8 @@
- 'nrformat' accepts the new "blank" suboption, to determine a signed or
unsigned number based on whitespace in front of a minus sign.
- allow to specify a priority when defining a new sign |:sign-define|
+- provide information about function arguments using the get(func, "arity")
+ function |get()-func|
*added-9.2*
Added ~