diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-12-02 20:47:52 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-12-02 21:28:07 +0800 |
commit | 7d1019442642d51f1af49bafa3b0450841129c2d (patch) | |
tree | 483704c6954e7d9694d0e06e7ec94a348293c421 /src/nvim/option.c | |
parent | 1aad5af637b0fc042e1155cc0955931e9ca75295 (diff) | |
download | rneovim-7d1019442642d51f1af49bafa3b0450841129c2d.tar.gz rneovim-7d1019442642d51f1af49bafa3b0450841129c2d.tar.bz2 rneovim-7d1019442642d51f1af49bafa3b0450841129c2d.zip |
vim-patch:8.2.3838: cannot use script-local function for setting *func options
Problem: Cannot use script-local function for setting *func options.
Solution: Use the script context. (Yegappan Lakshmanan, closes vim/vim#9362)
https://github.com/vim/vim/commit/db1a410b610b2c1941311acc57dcc4afec20720e
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/nvim/option.c')
-rw-r--r-- | src/nvim/option.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index 72090fdbcc..6d461d9b9d 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5157,10 +5157,6 @@ int option_set_callback_func(char *optval, Callback *optcb) return OK; } - if (strncmp(optval, "s:", 2) == 0 && !SCRIPT_ID_VALID(current_sctx.sc_sid)) { - return FAIL; - } - typval_T *tv; if (*optval == '{' || (strncmp(optval, "function(", 9) == 0) @@ -5174,7 +5170,26 @@ int option_set_callback_func(char *optval, Callback *optcb) // treat everything else as a function name string tv = xcalloc(1, sizeof(*tv)); tv->v_type = VAR_STRING; - tv->vval.v_string = xstrdup(optval); + + // Function name starting with "s:" are supported only in a vimscript + // context. + if (strncmp(optval, "s:", 2) == 0) { + char sid_buf[25]; + + if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) { + emsg(_(e_usingsid)); + return FAIL; + } + // Expand s: prefix into <SNR>nr_<name> + snprintf(sid_buf, sizeof(sid_buf), "<SNR>%" PRId64 "_", + (int64_t)current_sctx.sc_sid); + char *funcname = xmalloc(strlen(sid_buf) + strlen(optval + 2) + 1); + STRCPY(funcname, sid_buf); + STRCAT(funcname, optval + 2); + tv->vval.v_string = funcname; + } else { + tv->vval.v_string = xstrdup(optval); + } } Callback cb; |