aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/ex_cmds2.c25
-rw-r--r--src/nvim/ex_getln.c32
-rw-r--r--src/nvim/lua/executor.c18
-rw-r--r--src/nvim/main.c25
-rw-r--r--src/nvim/runtime.c22
-rw-r--r--src/nvim/syntax.c4
-rw-r--r--src/nvim/vim.h1
7 files changed, 93 insertions, 34 deletions
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index 56a14887df..4798e93b91 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -27,6 +27,7 @@
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
#include "nvim/getchar.h"
+#include "nvim/globals.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
@@ -53,6 +54,7 @@
#include "nvim/os/fs_defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/private/defs.h"
+#include "nvim/lua/executor.h"
/// Growarray to store info about already sourced scripts.
@@ -2421,6 +2423,7 @@ void ex_compiler(exarg_T *eap)
if (*eap->arg == NUL) {
// List all compiler scripts.
do_cmdline_cmd("echo globpath(&rtp, 'compiler/*.vim')"); // NOLINT
+ do_cmdline_cmd("echo globpath(&rtp, 'compiler/*.lua')"); // NOLINT
} else {
size_t bufsize = STRLEN(eap->arg) + 14;
buf = xmalloc(bufsize);
@@ -2445,7 +2448,11 @@ void ex_compiler(exarg_T *eap)
snprintf((char *)buf, bufsize, "compiler/%s.vim", eap->arg);
if (source_in_path(p_rtp, buf, DIP_ALL) == FAIL) {
- EMSG2(_("E666: compiler not supported: %s"), eap->arg);
+ // Try lua compiler
+ snprintf((char *)buf, bufsize, "compiler/%s.lua", eap->arg);
+ if (source_in_path(p_rtp, buf, DIP_ALL) == FAIL) {
+ EMSG2(_("E666: compiler not supported: %s"), eap->arg);
+ }
}
xfree(buf);
@@ -2656,8 +2663,13 @@ static void cmd_source_buffer(const exarg_T *eap)
.curr_lnum = eap->line1,
.final_lnum = eap->line2,
};
- source_using_linegetter((void *)&cookie, get_buffer_line,
- ":source (no file)");
+ if (curbuf != NULL && curbuf->b_fname
+ && path_with_extension((const char *)curbuf->b_fname, "lua")) {
+ nlua_source_using_linegetter(get_buffer_line, (void *)&cookie, ":source");
+ } else {
+ source_using_linegetter((void *)&cookie, get_buffer_line,
+ ":source (no file)");
+ }
}
/// ":source" and associated commands.
@@ -2769,7 +2781,8 @@ int do_source_str(const char *cmd, const char *traceback_name)
return source_using_linegetter((void *)&cookie, get_str_line, traceback_name);
}
-/// Reads the file `fname` and executes its lines as Ex commands.
+/// When fname is a 'lua' file nlua_exec_file() is invoked to source it.
+/// Otherwise reads the file `fname` and executes its lines as Ex commands.
///
/// This function may be called recursively!
///
@@ -2796,6 +2809,10 @@ int do_source(char_u *fname, int check_other, int is_vimrc)
proftime_T wait_start;
bool trigger_source_post = false;
+ if (path_with_extension((const char *)fname, "lua")) {
+ return (int)nlua_exec_file((const char *)fname);
+ }
+
p = expand_env_save(fname);
if (p == NULL) {
return retval;
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 75ed5dc0e5..f63987136f 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -5115,11 +5115,12 @@ ExpandFromContext (
}
if (xp->xp_context == EXPAND_COLORS) {
char *directories[] = { "colors", NULL };
- return ExpandRTDir(pat, DIP_START + DIP_OPT, num_file, file, directories);
+ return ExpandRTDir(pat, DIP_START + DIP_OPT + DIP_LUA, num_file, file,
+ directories);
}
if (xp->xp_context == EXPAND_COMPILER) {
char *directories[] = { "compiler", NULL };
- return ExpandRTDir(pat, 0, num_file, file, directories);
+ return ExpandRTDir(pat, DIP_LUA, num_file, file, directories);
}
if (xp->xp_context == EXPAND_OWNSYNTAX) {
char *directories[] = { "syntax", NULL };
@@ -5127,7 +5128,7 @@ ExpandFromContext (
}
if (xp->xp_context == EXPAND_FILETYPE) {
char *directories[] = { "syntax", "indent", "ftplugin", NULL };
- return ExpandRTDir(pat, 0, num_file, file, directories);
+ return ExpandRTDir(pat, DIP_LUA, num_file, file, directories);
}
if (xp->xp_context == EXPAND_CHECKHEALTH) {
char *directories[] = { "autoload/health", NULL };
@@ -5567,6 +5568,7 @@ static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file)
/// 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim
/// When "flags" has DIP_OPT: search also from 'opt' of 'packpath':
/// 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim
+/// When "flags" has DIP_LUA: search also performed for .lua files
/// "dirnames" is an array with one or more directory names.
static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file,
char *dirnames[])
@@ -5584,6 +5586,10 @@ static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file,
char_u *s = xmalloc(size);
snprintf((char *)s, size, "%s/%s*.vim", dirnames[i], pat);
globpath(p_rtp, s, &ga, 0);
+ if (flags & DIP_LUA) {
+ snprintf((char *)s, size, "%s/%s*.lua", dirnames[i], pat);
+ globpath(p_rtp, s, &ga, 0);
+ }
xfree(s);
}
@@ -5593,6 +5599,10 @@ static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file,
char_u *s = xmalloc(size);
snprintf((char *)s, size, "pack/*/start/*/%s/%s*.vim", dirnames[i], pat); // NOLINT
globpath(p_pp, s, &ga, 0);
+ if (flags & DIP_LUA) {
+ snprintf((char *)s, size, "pack/*/start/*/%s/%s*.lua", dirnames[i], pat); // NOLINT
+ globpath(p_pp, s, &ga, 0);
+ }
xfree(s);
}
@@ -5601,6 +5611,10 @@ static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file,
char_u *s = xmalloc(size);
snprintf((char *)s, size, "start/*/%s/%s*.vim", dirnames[i], pat); // NOLINT
globpath(p_pp, s, &ga, 0);
+ if (flags & DIP_LUA) {
+ snprintf((char *)s, size, "start/*/%s/%s*.lua", dirnames[i], pat); // NOLINT
+ globpath(p_pp, s, &ga, 0);
+ }
xfree(s);
}
}
@@ -5611,6 +5625,10 @@ static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file,
char_u *s = xmalloc(size);
snprintf((char *)s, size, "pack/*/opt/*/%s/%s*.vim", dirnames[i], pat); // NOLINT
globpath(p_pp, s, &ga, 0);
+ if (flags & DIP_LUA) {
+ snprintf((char *)s, size, "pack/*/opt/*/%s/%s*.lua", dirnames[i], pat); // NOLINT
+ globpath(p_pp, s, &ga, 0);
+ }
xfree(s);
}
@@ -5619,6 +5637,10 @@ static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file,
char_u *s = xmalloc(size);
snprintf((char *)s, size, "opt/*/%s/%s*.vim", dirnames[i], pat); // NOLINT
globpath(p_pp, s, &ga, 0);
+ if (flags & DIP_LUA) {
+ snprintf((char *)s, size, "opt/*/%s/%s*.lua", dirnames[i], pat); // NOLINT
+ globpath(p_pp, s, &ga, 0);
+ }
xfree(s);
}
}
@@ -5627,7 +5649,9 @@ static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file,
char_u *match = ((char_u **)ga.ga_data)[i];
char_u *s = match;
char_u *e = s + STRLEN(s);
- if (e - s > 4 && STRNICMP(e - 4, ".vim", 4) == 0) {
+ if (e - s > 4 && (STRNICMP(e - 4, ".vim", 4) == 0
+ || ((flags & DIP_LUA)
+ && STRNICMP(e - 4, ".lua", 4) == 0))) {
e -= 4;
for (s = e; s > match; MB_PTR_BACK(match, s)) {
if (vim_ispathsep(*s)) {
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 0a52cc16cb..afc387ef38 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -1161,6 +1161,24 @@ static void nlua_typval_exec(const char *lcmd, size_t lcmd_len,
}
}
+int nlua_source_using_linegetter(LineGetter fgetline,
+ void *cookie, char *name)
+{
+ garray_T ga;
+ char_u *line = NULL;
+
+ ga_init(&ga, (int)sizeof(char_u *), 10);
+ while ((line = fgetline(0, cookie, 0, false)) != NULL) {
+ GA_APPEND(char_u *, &ga, line);
+ }
+ char *code = (char *)ga_concat_strings_sep(&ga, "\n");
+ size_t len = strlen(code);
+ nlua_typval_exec(code, len, name, NULL, 0, false, NULL);
+ ga_clear_strings(&ga);
+ xfree(code);
+ return OK;
+}
+
/// Call a LuaCallable given some typvals
///
/// Used to call any lua callable passed from Lua into VimL
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 56cd97f133..53043d293e 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -1101,11 +1101,7 @@ static void command_line_scan(mparm_T *parmp)
size_t s_size = STRLEN(a) + 9;
char *s = xmalloc(s_size);
- if (path_with_extension(a, "lua")) {
- snprintf(s, s_size, "luafile %s", a);
- } else {
- snprintf(s, s_size, "so %s", a);
- }
+ snprintf(s, s_size, "so %s", a);
parmp->cmds_tofree[parmp->n_commands] = true;
parmp->commands[parmp->n_commands++] = s;
} else {
@@ -1367,7 +1363,8 @@ static void load_plugins(void)
{
if (p_lpl) {
char_u *rtp_copy = NULL;
- char_u *const plugin_pattern = (char_u *)"plugin/**/*.vim"; // NOLINT
+ char_u *const plugin_pattern_vim = (char_u *)"plugin/**/*.vim"; // NOLINT
+ char_u *const plugin_pattern_lua = (char_u *)"plugin/**/*.lua"; // NOLINT
// First add all package directories to 'runtimepath', so that their
// autoload directories can be found. Only if not done already with a
@@ -1380,7 +1377,10 @@ static void load_plugins(void)
}
source_in_path(rtp_copy == NULL ? p_rtp : rtp_copy,
- plugin_pattern,
+ plugin_pattern_vim,
+ DIP_ALL | DIP_NOAFTER);
+ source_in_path(rtp_copy == NULL ? p_rtp : rtp_copy,
+ plugin_pattern_lua,
DIP_ALL | DIP_NOAFTER);
TIME_MSG("loading plugins");
xfree(rtp_copy);
@@ -1392,7 +1392,8 @@ static void load_plugins(void)
}
TIME_MSG("loading packages");
- source_runtime(plugin_pattern, DIP_ALL | DIP_AFTER);
+ source_runtime(plugin_pattern_vim, DIP_ALL | DIP_AFTER);
+ source_runtime(plugin_pattern_lua, DIP_ALL | DIP_AFTER);
TIME_MSG("loading after plugins");
}
}
@@ -1883,12 +1884,8 @@ static void source_startup_scripts(const mparm_T *const parmp)
|| strequal(parmp->use_vimrc, "NORC")) {
// Do nothing.
} else {
- if (path_with_extension(parmp->use_vimrc, "lua")) {
- nlua_exec_file(parmp->use_vimrc);
- } else {
- if (do_source((char_u *)parmp->use_vimrc, false, DOSO_NONE) != OK) {
- EMSG2(_("E282: Cannot read from \"%s\""), parmp->use_vimrc);
- }
+ if (do_source((char_u *)parmp->use_vimrc, false, DOSO_NONE) != OK) {
+ EMSG2(_("E282: Cannot read from \"%s\""), parmp->use_vimrc);
}
}
} else if (!silent_mode) {
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index 1fb7e3b434..c3cd210538 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -245,7 +245,8 @@ int source_in_path(char_u *path, char_u *name, int flags)
return do_in_path_and_pp(path, name, flags, source_callback, NULL);
}
-// Expand wildcards in "pat" and invoke do_source() for each match.
+// Expand wildcards in "pat" and invoke do_source()/nlua_exec_file()
+// for each match.
static void source_all_matches(char_u *pat)
{
int num_files;
@@ -405,17 +406,15 @@ theend:
/// Load scripts in "plugin" and "ftdetect" directories of the package.
static int load_pack_plugin(char_u *fname)
{
- static const char *plugpat = "%s/plugin/**/*.vim"; // NOLINT
static const char *ftpat = "%s/ftdetect/*.vim"; // NOLINT
- int retval = FAIL;
char *const ffname = fix_fname((char *)fname);
size_t len = strlen(ffname) + STRLEN(ftpat);
- char_u *pat = try_malloc(len + 1);
- if (pat == NULL) {
- goto theend;
- }
- vim_snprintf((char *)pat, len, plugpat, ffname);
+ char_u *pat = xmallocz(len);
+
+ vim_snprintf((char *)pat, len, "%s/plugin/**/*.vim", ffname); // NOLINT
+ source_all_matches(pat);
+ vim_snprintf((char *)pat, len, "%s/plugin/**/*.lua", ffname); // NOLINT
source_all_matches(pat);
char_u *cmd = vim_strsave((char_u *)"g:did_load_filetypes");
@@ -426,16 +425,15 @@ static int load_pack_plugin(char_u *fname)
do_cmdline_cmd("augroup filetypedetect");
vim_snprintf((char *)pat, len, ftpat, ffname);
source_all_matches(pat);
+ vim_snprintf((char *)pat, len, "%s/ftdetect/*.lua", ffname); // NOLINT
+ source_all_matches(pat);
do_cmdline_cmd("augroup END");
}
xfree(cmd);
xfree(pat);
- retval = OK;
-
-theend:
xfree(ffname);
- return retval;
+ return OK;
}
// used for "cookie" of add_pack_plugin()
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index ed886ab7f9..ce81f26d38 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -6438,6 +6438,10 @@ int load_colors(char_u *name)
apply_autocmds(EVENT_COLORSCHEMEPRE, name, curbuf->b_fname, false, curbuf);
snprintf((char *)buf, buflen, "colors/%s.vim", name);
retval = source_runtime(buf, DIP_START + DIP_OPT);
+ if (retval == FAIL) {
+ snprintf((char *)buf, buflen, "colors/%s.lua", name);
+ retval = source_runtime(buf, DIP_START + DIP_OPT);
+ }
xfree(buf);
apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname, FALSE, curbuf);
diff --git a/src/nvim/vim.h b/src/nvim/vim.h
index 0245c472ef..df4ab04eb6 100644
--- a/src/nvim/vim.h
+++ b/src/nvim/vim.h
@@ -313,6 +313,7 @@ enum { FOLD_TEXT_LEN = 51 }; //!< buffer size for get_foldtext()
#define DIP_NORTP 0x20 // do not use 'runtimepath'
#define DIP_NOAFTER 0x40 // skip "after" directories
#define DIP_AFTER 0x80 // only use "after" directories
+#define DIP_LUA 0x100 // also use ".lua" files
// Lowest number used for window ID. Cannot have this many windows per tab.
#define LOWEST_WIN_ID 1000