mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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)
This commit is contained in:
parent
6c9c08c370
commit
cc2dce45d0
@ -24,9 +24,6 @@ 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,15 +9222,9 @@ char_u *get_behave_arg(expand_T *xp, int idx)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef enum {
|
static TriState filetype_detect = kNone;
|
||||||
ft_UNSET,
|
static TriState filetype_plugin = kNone;
|
||||||
ft_DISABLED,
|
static TriState filetype_indent = kNone;
|
||||||
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,15 +9238,15 @@ static ft_flag_state filetype_indent = ft_UNSET;
|
|||||||
static void ex_filetype(exarg_T *eap)
|
static void ex_filetype(exarg_T *eap)
|
||||||
{
|
{
|
||||||
char_u *arg = eap->arg;
|
char_u *arg = eap->arg;
|
||||||
int plugin = FALSE;
|
bool plugin = false;
|
||||||
int indent = FALSE;
|
bool indent = false;
|
||||||
|
|
||||||
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 == ft_ENABLED ? "ON" : "OFF",
|
filetype_detect == kTrue ? "ON" : "OFF",
|
||||||
filetype_plugin == ft_ENABLED ? (filetype_detect == ft_ENABLED ? "ON" : "(on)") : "OFF", // NOLINT
|
filetype_plugin == kTrue ? (filetype_detect == kTrue ? "ON" : "(on)") : "OFF", // NOLINT(whitespace/line_length)
|
||||||
filetype_indent == ft_ENABLED ? (filetype_detect == ft_ENABLED ? "ON" : "(on)") : "OFF"); // NOLINT
|
filetype_indent == kTrue ? (filetype_detect == kTrue ? "ON" : "(on)") : "OFF"); // NOLINT(whitespace/line_length)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9273,14 +9267,14 @@ 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 = ft_ENABLED;
|
filetype_detect = kTrue;
|
||||||
if (plugin) {
|
if (plugin) {
|
||||||
source_runtime((char_u *)FTPLUGIN_FILE, true);
|
source_runtime((char_u *)FTPLUGIN_FILE, true);
|
||||||
filetype_plugin = ft_ENABLED;
|
filetype_plugin = kTrue;
|
||||||
}
|
}
|
||||||
if (indent) {
|
if (indent) {
|
||||||
source_runtime((char_u *)INDENT_FILE, true);
|
source_runtime((char_u *)INDENT_FILE, true);
|
||||||
filetype_indent = ft_ENABLED;
|
filetype_indent = kTrue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*arg == 'd') {
|
if (*arg == 'd') {
|
||||||
@ -9291,15 +9285,15 @@ static void ex_filetype(exarg_T *eap)
|
|||||||
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 = ft_DISABLED;
|
filetype_plugin = kFalse;
|
||||||
}
|
}
|
||||||
if (indent) {
|
if (indent) {
|
||||||
source_runtime((char_u *)INDOFF_FILE, true);
|
source_runtime((char_u *)INDOFF_FILE, true);
|
||||||
filetype_indent = ft_DISABLED;
|
filetype_indent = kFalse;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
source_runtime((char_u *)FTOFF_FILE, true);
|
source_runtime((char_u *)FTOFF_FILE, true);
|
||||||
filetype_detect = ft_DISABLED;
|
filetype_detect = kFalse;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
EMSG2(_(e_invarg2), arg);
|
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
|
/// Do ":filetype plugin indent on" if user did not already do some
|
||||||
/// permutation thereof.
|
/// permutation thereof.
|
||||||
void maybe_enable_filetype(void)
|
void filetype_maybe_enable(void)
|
||||||
{
|
{
|
||||||
if (filetype_detect == ft_UNSET
|
if (filetype_detect == kNone
|
||||||
&& filetype_plugin == ft_UNSET
|
&& filetype_plugin == kNone
|
||||||
&& filetype_indent == ft_UNSET) {
|
&& filetype_indent == kNone) {
|
||||||
source_runtime((char_u *)FILETYPE_FILE, true);
|
source_runtime((char_u *)FILETYPE_FILE, true);
|
||||||
filetype_detect = ft_ENABLED;
|
filetype_detect = kTrue;
|
||||||
source_runtime((char_u *)FTPLUGIN_FILE, true);
|
source_runtime((char_u *)FTPLUGIN_FILE, true);
|
||||||
filetype_plugin = ft_ENABLED;
|
filetype_plugin = kTrue;
|
||||||
source_runtime((char_u *)INDENT_FILE, true);
|
source_runtime((char_u *)INDENT_FILE, true);
|
||||||
filetype_indent = ft_ENABLED;
|
filetype_indent = kTrue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +100,12 @@
|
|||||||
# define VIMRC_FILE ".nvimrc"
|
# define VIMRC_FILE ".nvimrc"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
kNone = -1,
|
||||||
|
kFalse = 0,
|
||||||
|
kTrue = 1,
|
||||||
|
} TriState;
|
||||||
|
|
||||||
/* Values for "starting" */
|
/* Values for "starting" */
|
||||||
#define NO_SCREEN 2 /* no screen updating yet */
|
#define NO_SCREEN 2 /* no screen updating yet */
|
||||||
#define NO_BUFFERS 1 /* not all buffers loaded yet */
|
#define NO_BUFFERS 1 /* not all buffers loaded yet */
|
||||||
|
@ -334,11 +334,10 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
// If using the runtime (-u is not NONE), enable syntax & 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) {
|
if (params.use_vimrc != NULL && strcmp(params.use_vimrc, "NONE") != 0) {
|
||||||
// Do ":filetype plugin indent on".
|
// Does ":filetype plugin indent on".
|
||||||
maybe_enable_filetype();
|
filetype_maybe_enable();
|
||||||
// Enable syntax (sources syntax/syntax.vim, which calls `:filetype on`).
|
// Sources syntax/syntax.vim, which calls `:filetype on`.
|
||||||
do_cmdline_cmd("if !exists('syntax_off') | syntax on |"
|
syn_maybe_on();
|
||||||
"else | unlet syntax_off | endif");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -41,6 +41,8 @@
|
|||||||
#include "nvim/os/os.h"
|
#include "nvim/os/os.h"
|
||||||
#include "nvim/os/time.h"
|
#include "nvim/os/time.h"
|
||||||
|
|
||||||
|
static bool did_syntax_onoff = false;
|
||||||
|
|
||||||
// Structure that stores information about a highlight group.
|
// 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 ID of a highlight group is also called group ID. It is the index in
|
||||||
// the highlight_ga array PLUS ONE.
|
// 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)
|
static void syn_cmd_onoff(exarg_T *eap, char *name)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
|
did_syntax_onoff = true;
|
||||||
eap->nextcmd = check_nextcmd(eap->arg);
|
eap->nextcmd = check_nextcmd(eap->arg);
|
||||||
if (!eap->skip) {
|
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)
|
void syn_maybe_on(void)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
|
||||||
{
|
{
|
||||||
char buf[100];
|
if (!did_syntax_onoff) {
|
||||||
strncpy(buf, "so ", 3);
|
exarg_T ea;
|
||||||
vim_snprintf(buf + 3, sizeof(buf) - 3, SYNTAX_FNAME, name);
|
ea.arg = (char_u *)"";
|
||||||
do_cmdline_cmd(buf);
|
ea.skip = false;
|
||||||
|
syn_cmd_onoff(&ea, "syntax");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user