diff options
-rw-r--r-- | runtime/doc/starting.txt | 4 | ||||
-rw-r--r-- | runtime/syntax/nosyntax.vim | 3 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 56 | ||||
-rw-r--r-- | src/nvim/main.c | 3 |
4 files changed, 40 insertions, 26 deletions
diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt index ed3f379275..be108d4633 100644 --- a/runtime/doc/starting.txt +++ b/runtime/doc/starting.txt @@ -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: > diff --git a/runtime/syntax/nosyntax.vim b/runtime/syntax/nosyntax.vim index 0ab3412373..3583cd0bc3 100644 --- a/runtime/syntax/nosyntax.vim +++ b/runtime/syntax/nosyntax.vim @@ -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 diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index f4e2667c1f..4664ca7785 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -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; } } diff --git a/src/nvim/main.c b/src/nvim/main.c index a5515a30f1..2070125b2e 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -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"); } /* |