mirror of
https://github.com/neovim/neovim.git
synced 2025-12-10 16:42:42 +00:00
Merge pull request #4252 from justinmk/filetype
defaults: Enable filetypes, syntax
This commit is contained in:
@@ -315,9 +315,10 @@ argument.
|
|||||||
When {vimrc} is equal to "NONE" (all uppercase), all
|
When {vimrc} is equal to "NONE" (all uppercase), all
|
||||||
initializations from files and environment variables are
|
initializations from files and environment variables are
|
||||||
skipped, including reading the |ginit.vim| file when the GUI
|
skipped, including reading the |ginit.vim| file when the GUI
|
||||||
starts. Loading plugins is also skipped.
|
starts. Plugins and syntax highlighting are also skipped.
|
||||||
When {vimrc} is equal to "NORC" (all uppercase), this has the
|
When {vimrc} is equal to "NORC" (all uppercase), this has the
|
||||||
same effect as "NONE", but loading plugins is not skipped.
|
same effect as "NONE", but plugins and syntax highlighting are
|
||||||
|
not skipped.
|
||||||
|
|
||||||
*-i*
|
*-i*
|
||||||
-i {shada} The file {shada} is used instead of the default ShaDa
|
-i {shada} The file {shada} is used instead of the default ShaDa
|
||||||
@@ -391,7 +392,8 @@ accordingly. Vim proceeds in this order:
|
|||||||
All following initializations until 4. are skipped. $MYVIMRC is not
|
All following initializations until 4. are skipped. $MYVIMRC is not
|
||||||
set.
|
set.
|
||||||
"vim -u NORC" can be used to skip these initializations without
|
"vim -u NORC" can be used to skip these initializations without
|
||||||
reading a file. "vim -u NONE" also skips loading plugins. |-u|
|
reading a file. "vim -u NONE" also skips plugins and syntax
|
||||||
|
highlighting. |-u|
|
||||||
|
|
||||||
If Vim was started in Ex mode with the "-s" argument, all following
|
If Vim was started in Ex mode with the "-s" argument, all following
|
||||||
initializations until 4. are skipped. Only the "-u" option is
|
initializations until 4. are skipped. Only the "-u" option is
|
||||||
@@ -424,7 +426,22 @@ accordingly. Vim proceeds in this order:
|
|||||||
- The file ".exrc" (for Unix)
|
- The file ".exrc" (for Unix)
|
||||||
"_exrc" (for Win32)
|
"_exrc" (for Win32)
|
||||||
|
|
||||||
4. Load the plugin scripts. *load-plugins*
|
4. Enable filetype and indent plugins.
|
||||||
|
This does the same as the commands: >
|
||||||
|
:runtime! filetype.vim
|
||||||
|
:runtime! ftplugin.vim
|
||||||
|
:runtime! indent.vim
|
||||||
|
< This step is skipped if ":filetype ..." was called before now or if
|
||||||
|
the "-u NONE" command line argument was given.
|
||||||
|
|
||||||
|
5. Enable syntax highlighting.
|
||||||
|
This does the same as the command: >
|
||||||
|
:runtime! syntax/syntax.vim
|
||||||
|
< 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: >
|
This does the same as the command: >
|
||||||
:runtime! plugin/**/*.vim
|
:runtime! plugin/**/*.vim
|
||||||
< The result is that all directories in the 'runtimepath' option will be
|
< The result is that all directories in the 'runtimepath' option will be
|
||||||
@@ -440,31 +457,30 @@ accordingly. Vim proceeds in this order:
|
|||||||
commands from the command line have not been executed yet. You can
|
commands from the command line have not been executed yet. You can
|
||||||
use "--cmd 'set noloadplugins'" |--cmd|.
|
use "--cmd 'set noloadplugins'" |--cmd|.
|
||||||
|
|
||||||
5. Set 'shellpipe' and 'shellredir'
|
7. Set 'shellpipe' and 'shellredir'
|
||||||
The 'shellpipe' and 'shellredir' options are set according to the
|
The 'shellpipe' and 'shellredir' options are set according to the
|
||||||
value of the 'shell' option, unless they have been set before.
|
value of the 'shell' option, unless they have been set before.
|
||||||
This means that Vim will figure out the values of 'shellpipe' and
|
This means that Vim will figure out the values of 'shellpipe' and
|
||||||
'shellredir' for you, unless you have set them yourself.
|
'shellredir' for you, unless you have set them yourself.
|
||||||
|
|
||||||
6. Set 'updatecount' to zero, if "-n" command argument used
|
8. Set 'updatecount' to zero, if "-n" command argument used
|
||||||
|
|
||||||
7. Set binary options
|
9. Set binary options
|
||||||
If the "-b" flag was given to Vim, the options for binary editing will
|
If the "-b" flag was given to Vim, the options for binary editing will
|
||||||
be set now. See |-b|.
|
be set now. See |-b|.
|
||||||
|
|
||||||
8. Perform GUI initializations
|
10. Perform GUI initializations
|
||||||
Only when starting "gvim", the GUI initializations will be done. See
|
Only when starting "gvim", the GUI initializations will be done. See
|
||||||
|gui-init|.
|
|gui-init|.
|
||||||
|
|
||||||
9. Read the ShaDa file
|
11. Read the ShaDa file
|
||||||
If the 'shada' option is not empty, the ShaDa file is read. See
|
See |shada-file|.
|
||||||
|shada-file|.
|
|
||||||
|
|
||||||
10. Read the quickfix file
|
12. Read the quickfix file
|
||||||
If the "-q" flag was given to Vim, the quickfix file is read. If this
|
If the "-q" flag was given to Vim, the quickfix file is read. If this
|
||||||
fails, Vim exits.
|
fails, Vim exits.
|
||||||
|
|
||||||
11. Open all windows
|
13. Open all windows
|
||||||
When the |-o| flag was given, windows will be opened (but not
|
When the |-o| flag was given, windows will be opened (but not
|
||||||
displayed yet).
|
displayed yet).
|
||||||
When the |-p| flag was given, tab pages will be created (but not
|
When the |-p| flag was given, tab pages will be created (but not
|
||||||
@@ -473,7 +489,7 @@ accordingly. Vim proceeds in this order:
|
|||||||
If the "-q" flag was given to Vim, the first error is jumped to.
|
If the "-q" flag was given to Vim, the first error is jumped to.
|
||||||
Buffers for all windows will be loaded.
|
Buffers for all windows will be loaded.
|
||||||
|
|
||||||
12. Execute startup commands
|
14. Execute startup commands
|
||||||
If a "-t" flag was given to Vim, the tag is jumped to.
|
If a "-t" flag was given to Vim, the tag is jumped to.
|
||||||
The commands given with the |-c| and |+cmd| arguments are executed.
|
The commands given with the |-c| and |+cmd| arguments are executed.
|
||||||
The starting flag is reset, has("vim_starting") will now return zero.
|
The starting flag is reset, has("vim_starting") will now return zero.
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ the "{Nvim}" tag. This document is a complete and centralized list of all
|
|||||||
these differences.
|
these differences.
|
||||||
|
|
||||||
1. Configuration |nvim-configuration|
|
1. Configuration |nvim-configuration|
|
||||||
2. Option defaults |nvim-option-defaults|
|
2. Defaults |nvim-defaults|
|
||||||
3. Changed features |nvim-features-changed|
|
3. Changed features |nvim-features-changed|
|
||||||
4. New features |nvim-features-new|
|
4. New features |nvim-features-new|
|
||||||
5. Missing legacy features |nvim-features-missing|
|
5. Missing legacy features |nvim-features-missing|
|
||||||
@@ -28,7 +28,12 @@ these differences.
|
|||||||
session information.
|
session information.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
2. Option defaults *nvim-option-defaults*
|
2. Defaults *nvim-defaults*
|
||||||
|
|
||||||
|
- Syntax highlighting is enabled by default
|
||||||
|
- Filetype-related plugins and scripts are enabled by default
|
||||||
|
Note: these defaults can be disabled with the "-u NONE" command line
|
||||||
|
argument. |-u|
|
||||||
|
|
||||||
- 'autoindent' is set by default
|
- 'autoindent' is set by default
|
||||||
- 'autoread' is set by default
|
- 'autoread' is set by default
|
||||||
|
|||||||
@@ -9222,9 +9222,9 @@ char_u *get_behave_arg(expand_T *xp, int idx)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int filetype_detect = FALSE;
|
static TriState filetype_detect = kNone;
|
||||||
static int filetype_plugin = FALSE;
|
static TriState filetype_plugin = kNone;
|
||||||
static int filetype_indent = FALSE;
|
static TriState filetype_indent = kNone;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ":filetype [plugin] [indent] {on,off,detect}"
|
* ":filetype [plugin] [indent] {on,off,detect}"
|
||||||
@@ -9238,27 +9238,27 @@ static int filetype_indent = FALSE;
|
|||||||
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 ? "ON" : "OFF",
|
filetype_detect == kTrue ? "ON" : "OFF",
|
||||||
filetype_plugin ? (filetype_detect ? "ON" : "(on)") : "OFF",
|
filetype_plugin == kTrue ? (filetype_detect == kTrue ? "ON" : "(on)") : "OFF", // NOLINT(whitespace/line_length)
|
||||||
filetype_indent ? (filetype_detect ? "ON" : "(on)") : "OFF");
|
filetype_indent == kTrue ? (filetype_detect == kTrue ? "ON" : "(on)") : "OFF"); // NOLINT(whitespace/line_length)
|
||||||
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 +9266,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 = kTrue;
|
||||||
if (plugin) {
|
if (plugin) {
|
||||||
source_runtime((char_u *)FTPLUGIN_FILE, TRUE);
|
source_runtime((char_u *)FTPLUGIN_FILE, true);
|
||||||
filetype_plugin = TRUE;
|
filetype_plugin = kTrue;
|
||||||
}
|
}
|
||||||
if (indent) {
|
if (indent) {
|
||||||
source_runtime((char_u *)INDENT_FILE, TRUE);
|
source_runtime((char_u *)INDENT_FILE, true);
|
||||||
filetype_indent = TRUE;
|
filetype_indent = kTrue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*arg == 'd') {
|
if (*arg == 'd') {
|
||||||
@@ -9284,21 +9284,37 @@ 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 = kFalse;
|
||||||
}
|
}
|
||||||
if (indent) {
|
if (indent) {
|
||||||
source_runtime((char_u *)INDOFF_FILE, TRUE);
|
source_runtime((char_u *)INDOFF_FILE, true);
|
||||||
filetype_indent = FALSE;
|
filetype_indent = kFalse;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
source_runtime((char_u *)FTOFF_FILE, TRUE);
|
source_runtime((char_u *)FTOFF_FILE, true);
|
||||||
filetype_detect = FALSE;
|
filetype_detect = kFalse;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
EMSG2(_(e_invarg2), arg);
|
EMSG2(_(e_invarg2), arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Do ":filetype plugin indent on" if user did not already do some
|
||||||
|
/// permutation thereof.
|
||||||
|
void filetype_maybe_enable(void)
|
||||||
|
{
|
||||||
|
if (filetype_detect == kNone
|
||||||
|
&& filetype_plugin == kNone
|
||||||
|
&& filetype_indent == kNone) {
|
||||||
|
source_runtime((char_u *)FILETYPE_FILE, true);
|
||||||
|
filetype_detect = kTrue;
|
||||||
|
source_runtime((char_u *)FTPLUGIN_FILE, true);
|
||||||
|
filetype_plugin = kTrue;
|
||||||
|
source_runtime((char_u *)INDENT_FILE, true);
|
||||||
|
filetype_indent = kTrue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ":setfiletype {name}"
|
* ":setfiletype {name}"
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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 */
|
||||||
|
|||||||
@@ -332,6 +332,14 @@ int main(int argc, char **argv)
|
|||||||
/* Source startup scripts. */
|
/* Source startup scripts. */
|
||||||
source_startup_scripts(¶ms);
|
source_startup_scripts(¶ms);
|
||||||
|
|
||||||
|
// If using the runtime (-u is not NONE), enable syntax & filetype plugins.
|
||||||
|
if (params.use_vimrc != NULL && strcmp(params.use_vimrc, "NONE") != 0) {
|
||||||
|
// Does ":filetype plugin indent on".
|
||||||
|
filetype_maybe_enable();
|
||||||
|
// Sources syntax/syntax.vim, which calls `:filetype on`.
|
||||||
|
syn_maybe_on();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read all the plugin files.
|
* Read all the plugin files.
|
||||||
* Only when compiled with +eval, since most plugins need it.
|
* Only when compiled with +eval, since most plugins need it.
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -3286,17 +3288,28 @@ 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
|
||||||
{
|
{
|
||||||
char buf[100];
|
did_syntax_onoff = true;
|
||||||
|
|
||||||
eap->nextcmd = check_nextcmd(eap->arg);
|
eap->nextcmd = check_nextcmd(eap->arg);
|
||||||
if (!eap->skip) {
|
if (!eap->skip) {
|
||||||
strcpy(buf, "so ");
|
char buf[100];
|
||||||
|
strncpy(buf, "so ", 3);
|
||||||
vim_snprintf(buf + 3, sizeof(buf) - 3, SYNTAX_FNAME, name);
|
vim_snprintf(buf + 3, sizeof(buf) - 3, SYNTAX_FNAME, name);
|
||||||
do_cmdline_cmd(buf);
|
do_cmdline_cmd(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void syn_maybe_on(void)
|
||||||
|
{
|
||||||
|
if (!did_syntax_onoff) {
|
||||||
|
exarg_T ea;
|
||||||
|
ea.arg = (char_u *)"";
|
||||||
|
ea.skip = false;
|
||||||
|
syn_cmd_onoff(&ea, "syntax");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle ":syntax [list]" command: list current syntax words.
|
* Handle ":syntax [list]" command: list current syntax words.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user