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.
|
5. Enable syntax highlighting.
|
||||||
This does the same as the command: >
|
This does the same as the command: >
|
||||||
:runtime! syntax/syntax.vim
|
: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*
|
6. Load the plugin scripts. *load-plugins*
|
||||||
This does the same as the command: >
|
This does the same as the command: >
|
||||||
|
@ -24,6 +24,9 @@ augroup END
|
|||||||
|
|
||||||
if exists("syntax_on")
|
if exists("syntax_on")
|
||||||
unlet syntax_on
|
unlet syntax_on
|
||||||
|
else
|
||||||
|
" only used when starting, to disable the default syntax enable
|
||||||
|
let syntax_off = 1
|
||||||
endif
|
endif
|
||||||
if exists("syntax_manual")
|
if exists("syntax_manual")
|
||||||
unlet syntax_manual
|
unlet syntax_manual
|
||||||
|
@ -9222,9 +9222,15 @@ char_u *get_behave_arg(expand_T *xp, int idx)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int filetype_detect = FALSE;
|
typedef enum {
|
||||||
static int filetype_plugin = FALSE;
|
ft_UNSET,
|
||||||
static int filetype_indent = FALSE;
|
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}"
|
* ":filetype [plugin] [indent] {on,off,detect}"
|
||||||
@ -9244,21 +9250,21 @@ static void ex_filetype(exarg_T *eap)
|
|||||||
if (*eap->arg == NUL) {
|
if (*eap->arg == NUL) {
|
||||||
/* Print current status. */
|
/* Print current status. */
|
||||||
smsg("filetype detection:%s plugin:%s indent:%s",
|
smsg("filetype detection:%s plugin:%s indent:%s",
|
||||||
filetype_detect ? "ON" : "OFF",
|
filetype_detect == ft_ENABLED ? "ON" : "OFF",
|
||||||
filetype_plugin ? (filetype_detect ? "ON" : "(on)") : "OFF",
|
filetype_plugin == ft_ENABLED ? (filetype_detect == ft_ENABLED ? "ON" : "(on)") : "OFF", // NOLINT
|
||||||
filetype_indent ? (filetype_detect ? "ON" : "(on)") : "OFF");
|
filetype_indent == ft_ENABLED ? (filetype_detect == ft_ENABLED ? "ON" : "(on)") : "OFF"); // NOLINT
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Accept "plugin" and "indent" in any order. */
|
/* Accept "plugin" and "indent" in any order. */
|
||||||
for (;; ) {
|
for (;; ) {
|
||||||
if (STRNCMP(arg, "plugin", 6) == 0) {
|
if (STRNCMP(arg, "plugin", 6) == 0) {
|
||||||
plugin = TRUE;
|
plugin = true;
|
||||||
arg = skipwhite(arg + 6);
|
arg = skipwhite(arg + 6);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (STRNCMP(arg, "indent", 6) == 0) {
|
if (STRNCMP(arg, "indent", 6) == 0) {
|
||||||
indent = TRUE;
|
indent = true;
|
||||||
arg = skipwhite(arg + 6);
|
arg = skipwhite(arg + 6);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -9266,15 +9272,15 @@ static void ex_filetype(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
if (STRCMP(arg, "on") == 0 || STRCMP(arg, "detect") == 0) {
|
if (STRCMP(arg, "on") == 0 || STRCMP(arg, "detect") == 0) {
|
||||||
if (*arg == 'o' || !filetype_detect) {
|
if (*arg == 'o' || !filetype_detect) {
|
||||||
source_runtime((char_u *)FILETYPE_FILE, TRUE);
|
source_runtime((char_u *)FILETYPE_FILE, true);
|
||||||
filetype_detect = TRUE;
|
filetype_detect = ft_ENABLED;
|
||||||
if (plugin) {
|
if (plugin) {
|
||||||
source_runtime((char_u *)FTPLUGIN_FILE, TRUE);
|
source_runtime((char_u *)FTPLUGIN_FILE, true);
|
||||||
filetype_plugin = TRUE;
|
filetype_plugin = ft_ENABLED;
|
||||||
}
|
}
|
||||||
if (indent) {
|
if (indent) {
|
||||||
source_runtime((char_u *)INDENT_FILE, TRUE);
|
source_runtime((char_u *)INDENT_FILE, true);
|
||||||
filetype_indent = TRUE;
|
filetype_indent = ft_ENABLED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*arg == 'd') {
|
if (*arg == 'd') {
|
||||||
@ -9284,16 +9290,16 @@ static void ex_filetype(exarg_T *eap)
|
|||||||
} else if (STRCMP(arg, "off") == 0) {
|
} else if (STRCMP(arg, "off") == 0) {
|
||||||
if (plugin || indent) {
|
if (plugin || indent) {
|
||||||
if (plugin) {
|
if (plugin) {
|
||||||
source_runtime((char_u *)FTPLUGOF_FILE, TRUE);
|
source_runtime((char_u *)FTPLUGOF_FILE, true);
|
||||||
filetype_plugin = FALSE;
|
filetype_plugin = ft_DISABLED;
|
||||||
}
|
}
|
||||||
if (indent) {
|
if (indent) {
|
||||||
source_runtime((char_u *)INDOFF_FILE, TRUE);
|
source_runtime((char_u *)INDOFF_FILE, true);
|
||||||
filetype_indent = FALSE;
|
filetype_indent = ft_DISABLED;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
source_runtime((char_u *)FTOFF_FILE, TRUE);
|
source_runtime((char_u *)FTOFF_FILE, true);
|
||||||
filetype_detect = FALSE;
|
filetype_detect = ft_DISABLED;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
EMSG2(_(e_invarg2), arg);
|
EMSG2(_(e_invarg2), arg);
|
||||||
@ -9303,13 +9309,15 @@ static void ex_filetype(exarg_T *eap)
|
|||||||
/// permutation thereof.
|
/// permutation thereof.
|
||||||
void maybe_enable_filetype(void)
|
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);
|
source_runtime((char_u *)FILETYPE_FILE, true);
|
||||||
filetype_detect = true;
|
filetype_detect = ft_ENABLED;
|
||||||
source_runtime((char_u *)FTPLUGIN_FILE, true);
|
source_runtime((char_u *)FTPLUGIN_FILE, true);
|
||||||
filetype_plugin = true;
|
filetype_plugin = ft_ENABLED;
|
||||||
source_runtime((char_u *)INDENT_FILE, true);
|
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".
|
// Do ":filetype plugin indent on".
|
||||||
maybe_enable_filetype();
|
maybe_enable_filetype();
|
||||||
// Enable syntax (sources syntax/syntax.vim, which calls `:filetype on`).
|
// 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