aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorshadmansaleh <shadmansaleh3@gmail.com>2021-05-31 17:35:13 +0600
committershadmansaleh <shadmansaleh3@gmail.com>2021-06-11 00:58:38 +0600
commit687eb0b39f3bcad9566198b4c60bbd2755032991 (patch)
treed118e6d1adc4e9fdff845912e1606ab40ae8b454 /src
parent1df8a34a7b91028413d6ac751b9dbf9fdcd6cda2 (diff)
downloadrneovim-687eb0b39f3bcad9566198b4c60bbd2755032991.tar.gz
rneovim-687eb0b39f3bcad9566198b4c60bbd2755032991.tar.bz2
rneovim-687eb0b39f3bcad9566198b4c60bbd2755032991.zip
feat(startup): Source runtime/plugin/**/*.lua at startup
For opt plugins these files are sourced on `:packadd` * `:runtime` Now can exexute lua files
Diffstat (limited to 'src')
-rw-r--r--src/nvim/main.c11
-rw-r--r--src/nvim/runtime.c33
2 files changed, 27 insertions, 17 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 56cd97f133..e626ad03db 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -1367,7 +1367,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 +1381,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 +1396,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");
}
}
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index 1fb7e3b434..dadff42456 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -15,6 +15,7 @@
#include "nvim/misc1.h"
#include "nvim/os/os.h"
#include "nvim/runtime.h"
+#include "nvim/lua/executor.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "runtime.c.generated.h"
@@ -49,7 +50,11 @@ void ex_runtime(exarg_T *eap)
static void source_callback(char_u *fname, void *cookie)
{
- (void)do_source(fname, false, DOSO_NONE);
+ if (path_with_extension((const char *)fname, "lua")) {
+ nlua_exec_file((const char *)fname);
+ } else {
+ (void)do_source(fname, false, DOSO_NONE);
+ }
}
/// Find the file "name" in all directories in "path" and invoke
@@ -245,7 +250,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;
@@ -253,7 +259,11 @@ static void source_all_matches(char_u *pat)
if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) == OK) {
for (int i = 0; i < num_files; i++) {
- (void)do_source(files[i], false, DOSO_NONE);
+ if (path_with_extension((const char *)files[i], "lua")) {
+ nlua_exec_file((const char *)files[i]);
+ } else {
+ (void)do_source(files[i], false, DOSO_NONE);
+ }
}
FreeWild(num_files, files);
}
@@ -405,17 +415,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);
+ source_all_matches(pat);
+ vim_snprintf((char *)pat, len, "%s/plugin/**/*.lua", ffname);
source_all_matches(pat);
char_u *cmd = vim_strsave((char_u *)"g:did_load_filetypes");
@@ -430,12 +438,9 @@ static int load_pack_plugin(char_u *fname)
}
xfree(cmd);
xfree(pat);
- retval = OK;
-
-theend:
xfree(ffname);
- return retval;
+ return OK;
}
// used for "cookie" of add_pack_plugin()