Hi list.
Vimscript does not have the easy way to get current script ID.
so :help <SID> recommends that add s:SID() and use it.
but it is a little bit hacky thing.
so I want to add new vimscript function getsid().
Attached patch added the function and its help.
Could you include this patch?
--
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 624b47d..4c717db 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1792,6 +1792,7 @@ getpos( {expr}) List position of cursor, mark, etc.
getqflist() List list of quickfix items
getreg( [{regname} [, 1]]) String contents of register
getregtype( [{regname}]) String type of register
+getsid() Number the current script local ID
gettabvar( {nr}, {varname}) any variable {varname} in tab {nr}
gettabwinvar( {tabnr}, {winnr}, {name})
any {name} in {winnr} in tab page {tabnr}
@@ -3396,6 +3397,10 @@ getregtype([{regname}]) *getregtype()*
<CTRL-V> is one character with value 0x16.
If {regname} is not specified, |v:register| is used.
+getsid() *getsid()*
+ Return the current script local ID. (<SID>)
+ If an error occurred, -1 is returned.
+
gettabvar({tabnr}, {varname}) *gettabvar()*
Get the value of a tab-local variable {varname} in tab page
{tabnr}. |t:var|
diff --git a/src/eval.c b/src/eval.c
index 6e8c26f..dc52bf8 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -574,6 +574,7 @@ static void f_getpos __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getqflist __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getreg __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getregtype __ARGS((typval_T *argvars, typval_T *rettv));
+static void f_getsid __ARGS((typval_T *argvars, typval_T *rettv));
static void f_gettabvar __ARGS((typval_T *argvars, typval_T *rettv));
static void f_gettabwinvar __ARGS((typval_T *argvars, typval_T *rettv));
static void f_getwinposx __ARGS((typval_T *argvars, typval_T *rettv));
@@ -7817,6 +7818,7 @@ static struct fst
{"getqflist", 0, 0, f_getqflist},
{"getreg", 0, 2, f_getreg},
{"getregtype", 0, 1, f_getregtype},
+ {"getsid", 0, 0, f_getsid},
{"gettabvar", 2, 2, f_gettabvar},
{"gettabwinvar", 3, 3, f_gettabwinvar},
{"getwinposx", 0, 0, f_getwinposx},
@@ -11363,6 +11365,17 @@ f_getline(argvars, rettv)
}
/*
+ * "getsid()" function
+ */
+ static void
+f_getsid(argvars, rettv)
+ typval_T *argvars;
+ typval_T *rettv;
+{
+ rettv->vval.v_number = current_SID > 0 ? current_SID : -1;
+}
+
+/*
* "getmatches()" function
*/
static void