mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
startup: respect earlier :filetype and :syntax.
If user invokes :filetype or :syntax before startup defaults are applied, don't clobber their choices.
This commit is contained in:
parent
da6299445a
commit
6c9c08c370
@ -437,7 +437,9 @@ accordingly. Vim proceeds in this order:
|
||||
5. Enable syntax highlighting.
|
||||
This does the same as the command: >
|
||||
:runtime! syntax/syntax.vim
|
||||
< This can be skipped with the "-u NONE" command line argument.
|
||||
< Note: This enables filetype detection even if ":filetype off" was
|
||||
called before now.
|
||||
This step is skipped if the "-u NONE" command line argument was given.
|
||||
|
||||
6. Load the plugin scripts. *load-plugins*
|
||||
This does the same as the command: >
|
||||
|
@ -24,6 +24,9 @@ augroup END
|
||||
|
||||
if exists("syntax_on")
|
||||
unlet syntax_on
|
||||
else
|
||||
" only used when starting, to disable the default syntax enable
|
||||
let syntax_off = 1
|
||||
endif
|
||||
if exists("syntax_manual")
|
||||
unlet syntax_manual
|
||||
|
@ -9222,9 +9222,15 @@ char_u *get_behave_arg(expand_T *xp, int idx)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int filetype_detect = FALSE;
|
||||
static int filetype_plugin = FALSE;
|
||||
static int filetype_indent = FALSE;
|
||||
typedef enum {
|
||||
ft_UNSET,
|
||||
ft_DISABLED,
|
||||
ft_ENABLED
|
||||
} ft_flag_state;
|
||||
|
||||
static ft_flag_state filetype_detect = ft_UNSET;
|
||||
static ft_flag_state filetype_plugin = ft_UNSET;
|
||||
static ft_flag_state filetype_indent = ft_UNSET;
|
||||
|
||||
/*
|
||||
* ":filetype [plugin] [indent] {on,off,detect}"
|
||||
@ -9244,21 +9250,21 @@ static void ex_filetype(exarg_T *eap)
|
||||
if (*eap->arg == NUL) {
|
||||
/* Print current status. */
|
||||
smsg("filetype detection:%s plugin:%s indent:%s",
|
||||
filetype_detect ? "ON" : "OFF",
|
||||
filetype_plugin ? (filetype_detect ? "ON" : "(on)") : "OFF",
|
||||
filetype_indent ? (filetype_detect ? "ON" : "(on)") : "OFF");
|
||||
filetype_detect == ft_ENABLED ? "ON" : "OFF",
|
||||
filetype_plugin == ft_ENABLED ? (filetype_detect == ft_ENABLED ? "ON" : "(on)") : "OFF", // NOLINT
|
||||
filetype_indent == ft_ENABLED ? (filetype_detect == ft_ENABLED ? "ON" : "(on)") : "OFF"); // NOLINT
|
||||
return;
|
||||
}
|
||||
|
||||
/* Accept "plugin" and "indent" in any order. */
|
||||
for (;; ) {
|
||||
if (STRNCMP(arg, "plugin", 6) == 0) {
|
||||
plugin = TRUE;
|
||||
plugin = true;
|
||||
arg = skipwhite(arg + 6);
|
||||
continue;
|
||||
}
|
||||
if (STRNCMP(arg, "indent", 6) == 0) {
|
||||
indent = TRUE;
|
||||
indent = true;
|
||||
arg = skipwhite(arg + 6);
|
||||
continue;
|
||||
}
|
||||
@ -9266,15 +9272,15 @@ static void ex_filetype(exarg_T *eap)
|
||||
}
|
||||
if (STRCMP(arg, "on") == 0 || STRCMP(arg, "detect") == 0) {
|
||||
if (*arg == 'o' || !filetype_detect) {
|
||||
source_runtime((char_u *)FILETYPE_FILE, TRUE);
|
||||
filetype_detect = TRUE;
|
||||
source_runtime((char_u *)FILETYPE_FILE, true);
|
||||
filetype_detect = ft_ENABLED;
|
||||
if (plugin) {
|
||||
source_runtime((char_u *)FTPLUGIN_FILE, TRUE);
|
||||
filetype_plugin = TRUE;
|
||||
source_runtime((char_u *)FTPLUGIN_FILE, true);
|
||||
filetype_plugin = ft_ENABLED;
|
||||
}
|
||||
if (indent) {
|
||||
source_runtime((char_u *)INDENT_FILE, TRUE);
|
||||
filetype_indent = TRUE;
|
||||
source_runtime((char_u *)INDENT_FILE, true);
|
||||
filetype_indent = ft_ENABLED;
|
||||
}
|
||||
}
|
||||
if (*arg == 'd') {
|
||||
@ -9284,16 +9290,16 @@ static void ex_filetype(exarg_T *eap)
|
||||
} else if (STRCMP(arg, "off") == 0) {
|
||||
if (plugin || indent) {
|
||||
if (plugin) {
|
||||
source_runtime((char_u *)FTPLUGOF_FILE, TRUE);
|
||||
filetype_plugin = FALSE;
|
||||
source_runtime((char_u *)FTPLUGOF_FILE, true);
|
||||
filetype_plugin = ft_DISABLED;
|
||||
}
|
||||
if (indent) {
|
||||
source_runtime((char_u *)INDOFF_FILE, TRUE);
|
||||
filetype_indent = FALSE;
|
||||
source_runtime((char_u *)INDOFF_FILE, true);
|
||||
filetype_indent = ft_DISABLED;
|
||||
}
|
||||
} else {
|
||||
source_runtime((char_u *)FTOFF_FILE, TRUE);
|
||||
filetype_detect = FALSE;
|
||||
source_runtime((char_u *)FTOFF_FILE, true);
|
||||
filetype_detect = ft_DISABLED;
|
||||
}
|
||||
} else
|
||||
EMSG2(_(e_invarg2), arg);
|
||||
@ -9303,13 +9309,15 @@ static void ex_filetype(exarg_T *eap)
|
||||
/// permutation thereof.
|
||||
void maybe_enable_filetype(void)
|
||||
{
|
||||
if (!filetype_detect && !filetype_plugin && !filetype_indent) {
|
||||
if (filetype_detect == ft_UNSET
|
||||
&& filetype_plugin == ft_UNSET
|
||||
&& filetype_indent == ft_UNSET) {
|
||||
source_runtime((char_u *)FILETYPE_FILE, true);
|
||||
filetype_detect = true;
|
||||
filetype_detect = ft_ENABLED;
|
||||
source_runtime((char_u *)FTPLUGIN_FILE, true);
|
||||
filetype_plugin = true;
|
||||
filetype_plugin = ft_ENABLED;
|
||||
source_runtime((char_u *)INDENT_FILE, true);
|
||||
filetype_indent = true;
|
||||
filetype_indent = ft_ENABLED;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -337,7 +337,8 @@ int main(int argc, char **argv)
|
||||
// Do ":filetype plugin indent on".
|
||||
maybe_enable_filetype();
|
||||
// Enable syntax (sources syntax/syntax.vim, which calls `:filetype on`).
|
||||
syn_cmd("syntax");
|
||||
do_cmdline_cmd("if !exists('syntax_off') | syntax on |"
|
||||
"else | unlet syntax_off | endif");
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user