diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-08-16 06:04:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-16 06:04:09 +0800 |
commit | 63e4436d8e9d25548cdc7c5b7e334ef164c150fc (patch) | |
tree | 63219cc75b3495147873595053a62b8ee4792052 /src/nvim/runtime.c | |
parent | e954d62527a6dc081d8942ccac740f17442446be (diff) | |
parent | d1464d16d6897144b29c22f8113aad9b7210e14c (diff) | |
download | rneovim-63e4436d8e9d25548cdc7c5b7e334ef164c150fc.tar.gz rneovim-63e4436d8e9d25548cdc7c5b7e334ef164c150fc.tar.bz2 rneovim-63e4436d8e9d25548cdc7c5b7e334ef164c150fc.zip |
Merge pull request #19781 from zeertzjq/source-lua-estack
fix(source): fix expand('<sfile>') no longer works for Lua
Diffstat (limited to 'src/nvim/runtime.c')
-rw-r--r-- | src/nvim/runtime.c | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index 4eb38c2c9e..edcaa27e2b 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -1941,9 +1941,6 @@ int do_source(char *fname, int check_other, int is_vimrc) cookie.level = ex_nesting_level; - // Keep the sourcing name/lnum, for recursive calls. - estack_push(ETYPE_SCRIPT, fname_exp, 0); - // start measuring script load time if --startuptime was passed and // time_fd was successfully opened afterwards. proftime_T rel_time; @@ -1966,6 +1963,9 @@ int do_source(char *fname, int check_other, int is_vimrc) const sctx_T save_current_sctx = current_sctx; si = get_current_script_id(&fname_exp, ¤t_sctx); + // Keep the sourcing name/lnum, for recursive calls. + estack_push(ETYPE_SCRIPT, (char *)si->sn_name, 0); + if (l_do_profiling == PROF_YES) { bool forceit = false; @@ -1983,30 +1983,27 @@ int do_source(char *fname, int check_other, int is_vimrc) cookie.conv.vc_type = CONV_NONE; // no conversion - // Read the first line so we can check for a UTF-8 BOM. - firstline = (uint8_t *)getsourceline(0, (void *)&cookie, 0, true); - if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef - && firstline[1] == 0xbb && firstline[2] == 0xbf) { - // Found BOM; setup conversion, skip over BOM and recode the line. - convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc); - p = (char *)string_convert(&cookie.conv, (char_u *)firstline + 3, NULL); - if (p == NULL) { - p = xstrdup((char *)firstline + 3); - } - xfree(firstline); - firstline = (uint8_t *)p; - } - if (path_with_extension((const char *)fname_exp, "lua")) { const sctx_T current_sctx_backup = current_sctx; current_sctx.sc_sid = SID_LUA; current_sctx.sc_lnum = 0; - estack_push(ETYPE_SCRIPT, NULL, 0); // Source the file as lua nlua_exec_file((const char *)fname_exp); current_sctx = current_sctx_backup; - estack_pop(); } else { + // Read the first line so we can check for a UTF-8 BOM. + firstline = (uint8_t *)getsourceline(0, (void *)&cookie, 0, true); + if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef + && firstline[1] == 0xbb && firstline[2] == 0xbf) { + // Found BOM; setup conversion, skip over BOM and recode the line. + convert_setup(&cookie.conv, (char_u *)"utf-8", p_enc); + p = (char *)string_convert(&cookie.conv, (char_u *)firstline + 3, NULL); + if (p == NULL) { + p = xstrdup((char *)firstline + 3); + } + xfree(firstline); + firstline = (uint8_t *)p; + } // Call do_cmdline, which will call getsourceline() to get the lines. do_cmdline((char *)firstline, getsourceline, (void *)&cookie, DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT); |