Thanks for the review. I updated the patch. On Tue, Oct 4, 2011 at 4:19 AM, Yasuhiro MATSUMOTO <mattn...@gmail.com> wrote: > It prefer to return zero for invalid cases. > > let sid getsid() > if sid > " using sid > endif > > On Sun, Oct 2, 2011 at 1:52 PM, tyru <tyru....@gmail.com> wrote: >> 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 >> > > > > -- > - Yasuhiro Matsumoto > > -- > 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 >
-- 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..75e005a 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, 0 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..5d5d916 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 : 0; +} + +/* * "getmatches()" function */ static void