mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 22:18:33 +00:00
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
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user