diff options
author | glacambre <code@lacamb.re> | 2023-02-11 09:45:11 +0100 |
---|---|---|
committer | glacambre <code@lacamb.re> | 2023-02-11 14:02:17 +0100 |
commit | c5b34fa55483d84d1de32937ffff0b7cf1aeba78 (patch) | |
tree | 998baa459cda97c369ba4323f8f527696270816c /src | |
parent | 5ca6cf55f9c772f5c691b08dc49581f27f88e8f9 (diff) | |
download | rneovim-c5b34fa55483d84d1de32937ffff0b7cf1aeba78.tar.gz rneovim-c5b34fa55483d84d1de32937ffff0b7cf1aeba78.tar.bz2 rneovim-c5b34fa55483d84d1de32937ffff0b7cf1aeba78.zip |
refactor: move init_default_autocmds to lua
The original motivation for this change came from developping
https://github.com/neovim/neovim/pull/22159, which will require adding
more autocommand creation to Neovim's startup sequence.
This change requires lightly editing a test that expected no autocommand
to have been created from lua.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/autocmd.c | 29 | ||||
-rw-r--r-- | src/nvim/main.c | 9 |
2 files changed, 3 insertions, 35 deletions
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index 0485fbcdb0..4cc75fa9a6 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 2bbe70784d..1f155aa343 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -404,19 +404,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"); |