aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregory Anders <greg@gpanders.com>2021-09-02 05:17:04 -0600
committerGitHub <noreply@github.com>2021-09-02 04:17:04 -0700
commit622a36b1f1c652a8de433028bc4a03a1216db23f (patch)
tree2895b1fc5eefbf02e4b316ecb404a5b00f194dd6 /src
parent6751d6254b35d216a86817cd414d5d06e3ff641d (diff)
downloadrneovim-622a36b1f1c652a8de433028bc4a03a1216db23f.tar.gz
rneovim-622a36b1f1c652a8de433028bc4a03a1216db23f.tar.bz2
rneovim-622a36b1f1c652a8de433028bc4a03a1216db23f.zip
feat(defaults): limit syntax cost on CmdwinEnter #15401
Add a new default autocommand to limit syntax highlighting synchronization in the command window. This refactors the nvim_terminal autocommand out of main() and into a new init_default_autocmds() function, which is now part of the startup process and can be further extended with more default autocommands down the road. ref #6289 #6399
Diffstat (limited to 'src')
-rw-r--r--src/nvim/aucmd.c25
-rw-r--r--src/nvim/main.c23
2 files changed, 30 insertions, 18 deletions
diff --git a/src/nvim/aucmd.c b/src/nvim/aucmd.c
index 32c77fa288..8544a3d2e0 100644
--- a/src/nvim/aucmd.c
+++ b/src/nvim/aucmd.c
@@ -8,6 +8,7 @@
#include "nvim/ui.h"
#include "nvim/aucmd.h"
#include "nvim/eval.h"
+#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/buffer.h"
@@ -35,6 +36,30 @@ void do_autocmd_uienter(uint64_t chanid, bool attached)
recursive = false;
}
+void init_default_autocmds(void)
+{
+ // open terminals when opening files that start with term://
+#define PROTO "term://"
+ do_cmdline_cmd("augroup nvim_terminal");
+ do_cmdline_cmd("autocmd!");
+ do_cmdline_cmd("autocmd BufReadCmd " PROTO "* ++nested "
+ "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");
+ do_cmdline_cmd("augroup END");
+#undef PROTO
+
+ // limit syntax synchronization in the command window
+ do_cmdline_cmd("augroup nvim_cmdwin");
+ do_cmdline_cmd("autocmd! CmdWinEnter [:>] exe 'syntax sync minlines=1 maxlines='..&cmdwinheight");
+ do_cmdline_cmd("augroup END");
+}
+
static void focusgained_event(void **argv)
{
bool *gainedp = argv[0];
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 9fc82a75af..b73f5aad76 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -309,9 +309,6 @@ int main(int argc, char **argv)
init_highlight(true, false); // Default highlight groups.
TIME_MSG("init highlight");
- init_default_mappings(); // Default mappings.
- TIME_MSG("init default mappings");
-
// Set the break level after the terminal is initialized.
debug_break_level = params.use_debug_break_level;
@@ -340,21 +337,11 @@ int main(int argc, char **argv)
TIME_MSG("initialized screen early for UI");
}
- // open terminals when opening files that start with term://
-#define PROTO "term://"
- do_cmdline_cmd("augroup nvim_terminal");
- do_cmdline_cmd("autocmd!");
- do_cmdline_cmd("autocmd BufReadCmd " PROTO "* nested "
- ":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");
- do_cmdline_cmd("augroup END");
-#undef PROTO
+ init_default_mappings(); // Default mappings.
+ TIME_MSG("init default mappings");
+
+ init_default_autocmds();
+ TIME_MSG("init default autocommands");
// Reset 'loadplugins' for "-u NONE" before "--cmd" arguments.
// Allows for setting 'loadplugins' there.