Mercurial > vim
diff src/term.c @ 28447:6f753a8125f0 v8.2.4748
patch 8.2.4748: cannot use an imported function in a mapping
Commit: https://github.com/vim/vim/commit/8944551534b311a2d25acf6e8db235c6d906256c
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Apr 14 12:58:23 2022 +0100
patch 8.2.4748: cannot use an imported function in a mapping
Problem: Cannot use an imported function in a mapping.
Solution: Recognize <SID>name.Func.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 14 Apr 2022 14:00:05 +0200 |
parents | dbf6d5ea7a1f |
children | 862068e9e2a7 |
line wrap: on
line diff
--- a/src/term.c +++ b/src/term.c @@ -6010,8 +6010,11 @@ replace_termcodes( { #ifdef FEAT_EVAL /* - * Replace <SID> by K_SNR <script-nr> _. + * Change <SID>Func to K_SNR <script-nr> _Func. This name is used + * for script-locla user functions. * (room: 5 * 6 = 30 bytes; needed: 3 + <nr> + 1 <= 14) + * Also change <SID>name.Func to K_SNR <import-script-nr> _Func. + * Only if "name" is recognized as an import. */ if (STRNICMP(src, "<SID>", 5) == 0) { @@ -6019,12 +6022,26 @@ replace_termcodes( emsg(_(e_using_sid_not_in_script_context)); else { + char_u *dot; + long sid = current_sctx.sc_sid; + src += 5; + if (in_vim9script() + && (dot = vim_strchr(src, '.')) != NULL) + { + imported_T *imp = find_imported(src, dot - src, FALSE); + + if (imp != NULL) + { + sid = imp->imp_sid; + src = dot + 1; + } + } + result[dlen++] = K_SPECIAL; result[dlen++] = (int)KS_EXTRA; result[dlen++] = (int)KE_SNR; - sprintf((char *)result + dlen, "%ld", - (long)current_sctx.sc_sid); + sprintf((char *)result + dlen, "%ld", sid); dlen += (int)STRLEN(result + dlen); result[dlen++] = '_'; continue;