diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-03-09 15:28:55 +0000 |
---|---|---|
committer | Lewis Russell <lewis6991@gmail.com> | 2023-03-10 11:51:33 +0000 |
commit | 46b73bf22cb951151de9bf0712d42e194000b677 (patch) | |
tree | 670fd0241b94031b26ba2c7a9fb5e48033dbff45 /src/nvim/lua/stdlib.c | |
parent | c5b9643bf1b0f6d5166b4abf6a7c3f29532aefeb (diff) | |
download | rneovim-46b73bf22cb951151de9bf0712d42e194000b677.tar.gz rneovim-46b73bf22cb951151de9bf0712d42e194000b677.tar.bz2 rneovim-46b73bf22cb951151de9bf0712d42e194000b677.zip |
perf(treesitter): more efficient foldexpr
Diffstat (limited to 'src/nvim/lua/stdlib.c')
-rw-r--r-- | src/nvim/lua/stdlib.c | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index d9682ff63d..b6e56c35d6 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -26,6 +26,7 @@ #include "nvim/eval/typval.h" #include "nvim/eval/typval_defs.h" #include "nvim/ex_eval.h" +#include "nvim/fold.h" #include "nvim/globals.h" #include "nvim/lua/converter.h" #include "nvim/lua/spell.h" @@ -528,6 +529,31 @@ static int nlua_iconv(lua_State *lstate) return 1; } +// Like 'zx' but don't call newFoldLevel() +static int nlua_foldupdate(lua_State *lstate) +{ + curwin->w_foldinvalid = true; // recompute folds + foldOpenCursor(); + + return 0; +} + +// Access to internal functions. For use in runtime/ +static void nlua_state_add_internal(lua_State *const lstate) +{ + // _getvar + lua_pushcfunction(lstate, &nlua_getvar); + lua_setfield(lstate, -2, "_getvar"); + + // _setvar + lua_pushcfunction(lstate, &nlua_setvar); + lua_setfield(lstate, -2, "_setvar"); + + // _updatefolds + lua_pushcfunction(lstate, &nlua_foldupdate); + lua_setfield(lstate, -2, "_foldupdate"); +} + void nlua_state_add_stdlib(lua_State *const lstate, bool is_thread) { if (!is_thread) { @@ -562,14 +588,6 @@ void nlua_state_add_stdlib(lua_State *const lstate, bool is_thread) lua_setfield(lstate, -2, "__index"); // [meta] lua_pop(lstate, 1); // don't use metatable now - // _getvar - lua_pushcfunction(lstate, &nlua_getvar); - lua_setfield(lstate, -2, "_getvar"); - - // _setvar - lua_pushcfunction(lstate, &nlua_setvar); - lua_setfield(lstate, -2, "_setvar"); - // vim.spell luaopen_spell(lstate); lua_setfield(lstate, -2, "spell"); @@ -578,6 +596,8 @@ void nlua_state_add_stdlib(lua_State *const lstate, bool is_thread) // depends on p_ambw, p_emoji lua_pushcfunction(lstate, &nlua_iconv); lua_setfield(lstate, -2, "iconv"); + + nlua_state_add_internal(lstate); } // vim.mpack |