diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2023-02-14 19:13:12 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-14 19:13:12 -0500 |
commit | 1539f713639eb1c661da9f9003fd58bf4cbbc615 (patch) | |
tree | 549a5a5ae5d23995ad058e677a8025e4aece2f66 /src | |
parent | 05faa8f30ad770d4e4ead41cec601ccced8fb97f (diff) | |
parent | c5b34fa55483d84d1de32937ffff0b7cf1aeba78 (diff) | |
download | rneovim-1539f713639eb1c661da9f9003fd58bf4cbbc615.tar.gz rneovim-1539f713639eb1c661da9f9003fd58bf4cbbc615.tar.bz2 rneovim-1539f713639eb1c661da9f9003fd58bf4cbbc615.zip |
Merge #22214 move init_default_autocmds to lua
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/private/helpers.h | 2 | ||||
-rw-r--r-- | src/nvim/autocmd.c | 29 | ||||
-rw-r--r-- | src/nvim/main.c | 9 |
3 files changed, 5 insertions, 35 deletions
diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index ec97ba9ec6..b70452d7cb 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -175,11 +175,13 @@ typedef struct { #define WITH_SCRIPT_CONTEXT(channel_id, code) \ do { \ const sctx_T save_current_sctx = current_sctx; \ + const uint64_t save_channel_id = current_channel_id; \ current_sctx.sc_sid = \ (channel_id) == LUA_INTERNAL_CALL ? SID_LUA : SID_API_CLIENT; \ current_sctx.sc_lnum = 0; \ current_channel_id = channel_id; \ code; \ + current_channel_id = save_channel_id; \ current_sctx = save_current_sctx; \ } while (0); diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index 239a07da1f..2f1317b05d 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -2759,32 +2759,3 @@ void do_autocmd_focusgained(bool gained) recursive = false; } - -static void define_autocmd(event_T event, char *pat, char *group, bool once, bool nested, char *cmd) -{ - AucmdExecutable exec = AUCMD_EXECUTABLE_INIT; - exec.type = CALLABLE_EX; - exec.callable.cmd = cmd; // autocmd_register() makes a copy - int group_id = augroup_add(group); - autocmd_register(0, event, pat, (int)strlen(pat), group_id, once, nested, NULL, exec); -} - -/// initialization of default autocmds -void init_default_autocmds(void) -{ - // open terminals when opening files that start with term:// -#define PROTO "term://" - define_autocmd(EVENT_BUFREADCMD, PROTO "*", "nvim_terminal", false, true, - "if !exists('b:term_title')|call termopen(" - // Capture the command string - "matchstr(expand(\"<amatch>\"), " - "'\\c\\m" PROTO "\\%(.\\{-}//\\%(\\d\\+:\\)\\?\\)\\?\\zs.*'), " - // capture the working directory - "{'cwd': expand(get(matchlist(expand(\"<amatch>\"), " - "'\\c\\m" PROTO "\\(.\\{-}\\)//'), 1, ''))})" - "|endif"); -#undef PROTO - // limit syntax synchronization in the command window - define_autocmd(EVENT_CMDWINENTER, "[:>]", "nvim_cmdwin", false, false, - "syntax sync minlines=1 maxlines=1"); -} diff --git a/src/nvim/main.c b/src/nvim/main.c index c12de07077..52069a6742 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -407,19 +407,16 @@ int main(int argc, char **argv) open_script_files(¶ms); - // Default mappings (incl. menus) + // Default mappings (incl. menus) & autocommands Error err = ERROR_INIT; - Object o = NLUA_EXEC_STATIC("return vim._init_default_mappings()", + Object o = NLUA_EXEC_STATIC("return vim._init_defaults()", (Array)ARRAY_DICT_INIT, &err); assert(!ERROR_SET(&err)); api_clear_error(&err); assert(o.type == kObjectTypeNil); api_free_object(o); - TIME_MSG("init default mappings"); - - init_default_autocmds(); - TIME_MSG("init default autocommands"); + TIME_MSG("init default mappings & autocommands"); bool vimrc_none = strequal(params.use_vimrc, "NONE"); |