From 68be8b99cfb1ab6105c48707986ce409ca38dd35 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Wed, 2 Jun 2021 13:48:13 +0600 Subject: feat(runtime): Allow lua to be used in compiler --- src/nvim/ex_cmds2.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds2.c') diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 56a14887df..3f35c41e7a 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2421,6 +2421,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 +2446,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); -- cgit From e1edc079dd0d0cb4a53e5998086568cf9d10a26a Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Thu, 3 Jun 2021 07:07:51 +0600 Subject: refactor(source): Move lua file detection to do_source So now :source can run lua files too :) * feat: Add support for :[ranged]source for lua files --- src/nvim/ex_cmds2.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/nvim/ex_cmds2.c') diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 3f35c41e7a..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. @@ -2661,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. @@ -2774,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! /// @@ -2801,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; -- cgit