From 50e129f5a70bf291e6ec3afb7927e68e1f98e790 Mon Sep 17 00:00:00 2001 From: Felipe Morales Date: Sat, 16 May 2015 04:10:38 -0300 Subject: defaults: Enable syntax and filetype plugins. --- src/nvim/ex_docmd.c | 18 ++++++++++++++++++ src/nvim/globals.h | 4 ++++ src/nvim/main.c | 8 ++++++++ 3 files changed, 30 insertions(+) (limited to 'src') diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index d6976bcb8f..0387bd1ad7 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -9299,6 +9299,24 @@ static void ex_filetype(exarg_T *eap) EMSG2(_(e_invarg2), arg); } +/// Same as :filetype plugin indent enable +/// Updates the state used for :filetype without args. +void force_enable_filetype(void) +{ + if (!filetype_detect) { + source_runtime((char_u *)FILETYPE_FILE, true); + filetype_detect = true; + } + if (!filetype_plugin) { + source_runtime((char_u *)FTPLUGIN_FILE, true); + filetype_plugin = true; + } + if (!filetype_indent) { + source_runtime((char_u *)INDENT_FILE, true); + filetype_indent = true; + } +} + /* * ":setfiletype {name}" */ diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 697a4a765a..76ed09cc3a 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -92,6 +92,10 @@ # define SYNTAX_FNAME "$VIMRUNTIME" _PATHSEPSTR "syntax" _PATHSEPSTR "%s.vim" #endif +#ifndef SYNTAX_FILE +# define SYNTAX_FILE "$VIMRUNTIME" _PATHSEPSTR "syntax" _PATHSEPSTR "syntax.vim" +#endif + #ifndef EXRC_FILE # define EXRC_FILE ".exrc" #endif diff --git a/src/nvim/main.c b/src/nvim/main.c index a8c2cebbbd..97cccb2e25 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -332,6 +332,14 @@ int main(int argc, char **argv) /* Source startup scripts. */ source_startup_scripts(¶ms); + // If using the runtime (-u is not NONE), enable syntax and filetype plugins + if (params.use_vimrc != NULL && strcmp(params.use_vimrc, "NONE") != 0) { + // Do this before syntax/syntax.vim (which calls `:filetype on`). + force_enable_filetype(); + // Enable syntax highlighting. + do_source((char_u *)SYNTAX_FILE, false, DOSO_NONE); + } + /* * Read all the plugin files. * Only when compiled with +eval, since most plugins need it. -- cgit From cae090416046bb64326eff06847d4c9bd5d3d5f2 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 30 Nov 2015 02:09:37 -0500 Subject: syntax: avoid extra global macro --- src/nvim/globals.h | 4 ---- src/nvim/main.c | 2 +- src/nvim/syntax.c | 16 +++++++++++----- 3 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 76ed09cc3a..697a4a765a 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -92,10 +92,6 @@ # define SYNTAX_FNAME "$VIMRUNTIME" _PATHSEPSTR "syntax" _PATHSEPSTR "%s.vim" #endif -#ifndef SYNTAX_FILE -# define SYNTAX_FILE "$VIMRUNTIME" _PATHSEPSTR "syntax" _PATHSEPSTR "syntax.vim" -#endif - #ifndef EXRC_FILE # define EXRC_FILE ".exrc" #endif diff --git a/src/nvim/main.c b/src/nvim/main.c index 97cccb2e25..b1f5a6ccad 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -337,7 +337,7 @@ int main(int argc, char **argv) // Do this before syntax/syntax.vim (which calls `:filetype on`). force_enable_filetype(); // Enable syntax highlighting. - do_source((char_u *)SYNTAX_FILE, false, DOSO_NONE); + syn_cmd("syntax"); // sources syntax/syntax.vim } /* diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index baf5d4784d..ce19320331 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -3286,17 +3286,23 @@ static void syn_cmd_off(exarg_T *eap, int syncing) } static void syn_cmd_onoff(exarg_T *eap, char *name) + FUNC_ATTR_NONNULL_ALL { - char buf[100]; - eap->nextcmd = check_nextcmd(eap->arg); if (!eap->skip) { - strcpy(buf, "so "); - vim_snprintf(buf + 3, sizeof(buf) - 3, SYNTAX_FNAME, name); - do_cmdline_cmd(buf); + syn_cmd(name); } } +void syn_cmd(char *name) + FUNC_ATTR_NONNULL_ALL +{ + char buf[100]; + strncpy(buf, "so ", 3); + vim_snprintf(buf + 3, sizeof(buf) - 3, SYNTAX_FNAME, name); + do_cmdline_cmd(buf); +} + /* * Handle ":syntax [list]" command: list current syntax words. */ -- cgit From 9c2c24ec484ececc1869dafa973566f685418757 Mon Sep 17 00:00:00 2001 From: Felipe Morales Date: Fri, 12 Feb 2016 18:02:42 +0100 Subject: syntax: don't override user settings --- src/nvim/ex_docmd.c | 10 +++------- src/nvim/main.c | 8 ++++---- 2 files changed, 7 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 0387bd1ad7..7655659107 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -9299,19 +9299,15 @@ static void ex_filetype(exarg_T *eap) EMSG2(_(e_invarg2), arg); } -/// Same as :filetype plugin indent enable -/// Updates the state used for :filetype without args. +/// Do ":filetype plugin indent on" if user did not already do some +/// permutation thereof. void force_enable_filetype(void) { - if (!filetype_detect) { + if (!filetype_detect && !filetype_plugin && !filetype_indent) { source_runtime((char_u *)FILETYPE_FILE, true); filetype_detect = true; - } - if (!filetype_plugin) { source_runtime((char_u *)FTPLUGIN_FILE, true); filetype_plugin = true; - } - if (!filetype_indent) { source_runtime((char_u *)INDENT_FILE, true); filetype_indent = true; } diff --git a/src/nvim/main.c b/src/nvim/main.c index b1f5a6ccad..6f5d40645a 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -332,12 +332,12 @@ int main(int argc, char **argv) /* Source startup scripts. */ source_startup_scripts(¶ms); - // If using the runtime (-u is not NONE), enable syntax and filetype plugins + // If using the runtime (-u is not NONE), enable syntax & filetype plugins. if (params.use_vimrc != NULL && strcmp(params.use_vimrc, "NONE") != 0) { - // Do this before syntax/syntax.vim (which calls `:filetype on`). + // Do ":filetype plugin indent on". force_enable_filetype(); - // Enable syntax highlighting. - syn_cmd("syntax"); // sources syntax/syntax.vim + // Enable syntax (sources syntax/syntax.vim, which calls `:filetype on`). + syn_cmd("syntax"); } /* -- cgit From da6299445a0fd52be5af2d7ea9ee539f12c20a73 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 13 Feb 2016 17:06:33 -0500 Subject: ex_docmd: rename force_enable_filetype(). It is no longer forcing anything. --- src/nvim/ex_docmd.c | 2 +- src/nvim/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 7655659107..f4e2667c1f 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -9301,7 +9301,7 @@ static void ex_filetype(exarg_T *eap) /// Do ":filetype plugin indent on" if user did not already do some /// permutation thereof. -void force_enable_filetype(void) +void maybe_enable_filetype(void) { if (!filetype_detect && !filetype_plugin && !filetype_indent) { source_runtime((char_u *)FILETYPE_FILE, true); diff --git a/src/nvim/main.c b/src/nvim/main.c index 6f5d40645a..a5515a30f1 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -335,7 +335,7 @@ int main(int argc, char **argv) // If using the runtime (-u is not NONE), enable syntax & filetype plugins. if (params.use_vimrc != NULL && strcmp(params.use_vimrc, "NONE") != 0) { // Do ":filetype plugin indent on". - force_enable_filetype(); + maybe_enable_filetype(); // Enable syntax (sources syntax/syntax.vim, which calls `:filetype on`). syn_cmd("syntax"); } -- cgit From 6c9c08c3703b2044bce2cdd5b20e66222cf46483 Mon Sep 17 00:00:00 2001 From: Felipe Morales Date: Sun, 14 Feb 2016 12:28:11 +0100 Subject: startup: respect earlier :filetype and :syntax. If user invokes :filetype or :syntax before startup defaults are applied, don't clobber their choices. --- src/nvim/ex_docmd.c | 56 ++++++++++++++++++++++++++++++----------------------- src/nvim/main.c | 3 ++- 2 files changed, 34 insertions(+), 25 deletions(-) (limited to 'src') 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"); } /* -- cgit From cc2dce45d09fab2ec2269924942fdca7d5643e63 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 14 Feb 2016 15:14:38 -0500 Subject: startup: Avoid VimL global. Introduce TriState enum. - `syntax_on` is documented. Rather than introduce a new undocumented VimL global `g:syntax_off`, use a module-local flag. - Rename "maybe" functions to follow style guidelines (use standard module prefix) --- src/nvim/ex_docmd.c | 48 +++++++++++++++++++++--------------------------- src/nvim/globals.h | 6 ++++++ src/nvim/main.c | 9 ++++----- src/nvim/syntax.c | 21 ++++++++++++++------- 4 files changed, 45 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 4664ca7785..c785b1c1b9 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -9222,15 +9222,9 @@ char_u *get_behave_arg(expand_T *xp, int idx) return NULL; } -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; +static TriState filetype_detect = kNone; +static TriState filetype_plugin = kNone; +static TriState filetype_indent = kNone; /* * ":filetype [plugin] [indent] {on,off,detect}" @@ -9244,15 +9238,15 @@ static ft_flag_state filetype_indent = ft_UNSET; static void ex_filetype(exarg_T *eap) { char_u *arg = eap->arg; - int plugin = FALSE; - int indent = FALSE; + bool plugin = false; + bool indent = false; if (*eap->arg == NUL) { /* Print current status. */ smsg("filetype detection:%s plugin:%s indent:%s", - 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 + filetype_detect == kTrue ? "ON" : "OFF", + filetype_plugin == kTrue ? (filetype_detect == kTrue ? "ON" : "(on)") : "OFF", // NOLINT(whitespace/line_length) + filetype_indent == kTrue ? (filetype_detect == kTrue ? "ON" : "(on)") : "OFF"); // NOLINT(whitespace/line_length) return; } @@ -9273,14 +9267,14 @@ 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 = ft_ENABLED; + filetype_detect = kTrue; if (plugin) { source_runtime((char_u *)FTPLUGIN_FILE, true); - filetype_plugin = ft_ENABLED; + filetype_plugin = kTrue; } if (indent) { source_runtime((char_u *)INDENT_FILE, true); - filetype_indent = ft_ENABLED; + filetype_indent = kTrue; } } if (*arg == 'd') { @@ -9291,15 +9285,15 @@ static void ex_filetype(exarg_T *eap) if (plugin || indent) { if (plugin) { source_runtime((char_u *)FTPLUGOF_FILE, true); - filetype_plugin = ft_DISABLED; + filetype_plugin = kFalse; } if (indent) { source_runtime((char_u *)INDOFF_FILE, true); - filetype_indent = ft_DISABLED; + filetype_indent = kFalse; } } else { source_runtime((char_u *)FTOFF_FILE, true); - filetype_detect = ft_DISABLED; + filetype_detect = kFalse; } } else EMSG2(_(e_invarg2), arg); @@ -9307,17 +9301,17 @@ static void ex_filetype(exarg_T *eap) /// Do ":filetype plugin indent on" if user did not already do some /// permutation thereof. -void maybe_enable_filetype(void) +void filetype_maybe_enable(void) { - if (filetype_detect == ft_UNSET - && filetype_plugin == ft_UNSET - && filetype_indent == ft_UNSET) { + if (filetype_detect == kNone + && filetype_plugin == kNone + && filetype_indent == kNone) { source_runtime((char_u *)FILETYPE_FILE, true); - filetype_detect = ft_ENABLED; + filetype_detect = kTrue; source_runtime((char_u *)FTPLUGIN_FILE, true); - filetype_plugin = ft_ENABLED; + filetype_plugin = kTrue; source_runtime((char_u *)INDENT_FILE, true); - filetype_indent = ft_ENABLED; + filetype_indent = kTrue; } } diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 697a4a765a..69e65c3208 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -100,6 +100,12 @@ # define VIMRC_FILE ".nvimrc" #endif +typedef enum { + kNone = -1, + kFalse = 0, + kTrue = 1, +} TriState; + /* Values for "starting" */ #define NO_SCREEN 2 /* no screen updating yet */ #define NO_BUFFERS 1 /* not all buffers loaded yet */ diff --git a/src/nvim/main.c b/src/nvim/main.c index 2070125b2e..d3cdfe3edf 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -334,11 +334,10 @@ int main(int argc, char **argv) // If using the runtime (-u is not NONE), enable syntax & filetype plugins. if (params.use_vimrc != NULL && strcmp(params.use_vimrc, "NONE") != 0) { - // Do ":filetype plugin indent on". - maybe_enable_filetype(); - // Enable syntax (sources syntax/syntax.vim, which calls `:filetype on`). - do_cmdline_cmd("if !exists('syntax_off') | syntax on |" - "else | unlet syntax_off | endif"); + // Does ":filetype plugin indent on". + filetype_maybe_enable(); + // Sources syntax/syntax.vim, which calls `:filetype on`. + syn_maybe_on(); } /* diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index ce19320331..b7d8a19de9 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -41,6 +41,8 @@ #include "nvim/os/os.h" #include "nvim/os/time.h" +static bool did_syntax_onoff = false; + // Structure that stores information about a highlight group. // The ID of a highlight group is also called group ID. It is the index in // the highlight_ga array PLUS ONE. @@ -3288,19 +3290,24 @@ static void syn_cmd_off(exarg_T *eap, int syncing) static void syn_cmd_onoff(exarg_T *eap, char *name) FUNC_ATTR_NONNULL_ALL { + did_syntax_onoff = true; eap->nextcmd = check_nextcmd(eap->arg); if (!eap->skip) { - syn_cmd(name); + char buf[100]; + strncpy(buf, "so ", 3); + vim_snprintf(buf + 3, sizeof(buf) - 3, SYNTAX_FNAME, name); + do_cmdline_cmd(buf); } } -void syn_cmd(char *name) - FUNC_ATTR_NONNULL_ALL +void syn_maybe_on(void) { - char buf[100]; - strncpy(buf, "so ", 3); - vim_snprintf(buf + 3, sizeof(buf) - 3, SYNTAX_FNAME, name); - do_cmdline_cmd(buf); + if (!did_syntax_onoff) { + exarg_T ea; + ea.arg = (char_u *)""; + ea.skip = false; + syn_cmd_onoff(&ea, "syntax"); + } } /* -- cgit