mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 22:48:34 +00:00
refactor(aucmd): call define_autocmd() directly for default autocmds
This commit is contained in:
@@ -2707,14 +2707,21 @@ static void do_autocmd_focusgained(bool gained)
|
|||||||
recursive = false;
|
recursive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialization
|
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)
|
void init_default_autocmds(void)
|
||||||
{
|
{
|
||||||
// open terminals when opening files that start with term://
|
// open terminals when opening files that start with term://
|
||||||
#define PROTO "term://"
|
#define PROTO "term://"
|
||||||
do_cmdline_cmd("augroup nvim_terminal");
|
define_autocmd(EVENT_BUFREADCMD, PROTO "*", "nvim_terminal", false, true,
|
||||||
do_cmdline_cmd("autocmd BufReadCmd " PROTO "* ++nested "
|
|
||||||
"if !exists('b:term_title')|call termopen("
|
"if !exists('b:term_title')|call termopen("
|
||||||
// Capture the command string
|
// Capture the command string
|
||||||
"matchstr(expand(\"<amatch>\"), "
|
"matchstr(expand(\"<amatch>\"), "
|
||||||
@@ -2723,11 +2730,8 @@ void init_default_autocmds(void)
|
|||||||
"{'cwd': expand(get(matchlist(expand(\"<amatch>\"), "
|
"{'cwd': expand(get(matchlist(expand(\"<amatch>\"), "
|
||||||
"'\\c\\m" PROTO "\\(.\\{-}\\)//'), 1, ''))})"
|
"'\\c\\m" PROTO "\\(.\\{-}\\)//'), 1, ''))})"
|
||||||
"|endif");
|
"|endif");
|
||||||
do_cmdline_cmd("augroup END");
|
|
||||||
#undef PROTO
|
#undef PROTO
|
||||||
|
|
||||||
// limit syntax synchronization in the command window
|
// limit syntax synchronization in the command window
|
||||||
do_cmdline_cmd("augroup nvim_cmdwin");
|
define_autocmd(EVENT_CMDWINENTER, "[:>]", "nvim_cmdwin", false, false,
|
||||||
do_cmdline_cmd("autocmd! CmdwinEnter [:>] syntax sync minlines=1 maxlines=1");
|
"syntax sync minlines=1 maxlines=1");
|
||||||
do_cmdline_cmd("augroup END");
|
|
||||||
}
|
}
|
||||||
|
@@ -499,11 +499,11 @@ describe('sysinit', function()
|
|||||||
[[" -u NONE -i NONE --cmd "set noruler" -D')]])
|
[[" -u NONE -i NONE --cmd "set noruler" -D')]])
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
^ |
|
^ |
|
||||||
|
|
|
||||||
Entering Debug mode. Type "cont" to continue. |
|
Entering Debug mode. Type "cont" to continue. |
|
||||||
cmd: augroup nvim_terminal |
|
pre-vimrc command line |
|
||||||
|
cmd: set noruler |
|
||||||
> |
|
> |
|
||||||
<" -u NONE -i NONE --cmd "set noruler" -D 1,0-1 All|
|
<" -u NONE -i NONE --cmd "set noruler" -D 1,1 All|
|
||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
command([[call chansend(g:id, "cont\n")]])
|
command([[call chansend(g:id, "cont\n")]])
|
||||||
|
Reference in New Issue
Block a user