aboutsummaryrefslogtreecommitdiff
path: root/test/functional/fixtures
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2021-09-20 19:00:50 -0700
committerJustin M. Keyes <justinkz@gmail.com>2023-01-05 17:10:02 +0100
commit7c94bcd2d77e2e54b8836ab8325460a367b79eae (patch)
tree454e637f46ed74202e97bcc8f5eb6d8118cddcf9 /test/functional/fixtures
parent39d70fcafd6efa9d01b88bb90cab81c393040453 (diff)
downloadrneovim-7c94bcd2d77e2e54b8836ab8325460a367b79eae.tar.gz
rneovim-7c94bcd2d77e2e54b8836ab8325460a367b79eae.tar.bz2
rneovim-7c94bcd2d77e2e54b8836ab8325460a367b79eae.zip
feat(lua)!: execute Lua with "nvim -l"
Problem: Nvim has Lua but the "nvim" CLI can't easily be used to execute Lua scripts, especially scripts that take arguments or produce output. Solution: - support "nvim -l [args...]" for running scripts. closes #15749 - exit without +q - remove lua2dox_filter - remove Doxyfile. This wasn't used anyway, because the doxygen config is inlined in gen_vimdoc.py (`Doxyfile` variable). - use "nvim -l" in docs-gen CI job Examples: $ nvim -l scripts/lua2dox.lua --help Lua2DoX (0.2 20130128) ... $ echo "print(vim.inspect(_G.arg))" | nvim -l - --arg1 --arg2 $ echo 'print(vim.inspect(vim.api.nvim_buf_get_text(1,0,0,-1,-1,{})))' | nvim +"put ='text'" -l - TODO? -e executes Lua code -l loads a module -i enters REPL _after running the other arguments_.
Diffstat (limited to 'test/functional/fixtures')
-rw-r--r--test/functional/fixtures/startup.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/functional/fixtures/startup.lua b/test/functional/fixtures/startup.lua
new file mode 100644
index 0000000000..37e738c75e
--- /dev/null
+++ b/test/functional/fixtures/startup.lua
@@ -0,0 +1,34 @@
+-- Test "nvim -l foo.lua …"
+
+local function printbufs()
+ local bufs = ''
+ for _, v in ipairs(vim.api.nvim_list_bufs()) do
+ local b = vim.fn.bufname(v)
+ if b:len() > 0 then
+ bufs = ('%s %s'):format(bufs, b)
+ end
+ end
+ print(('bufs:%s'):format(bufs))
+end
+
+local function parseargs(args)
+ local exitcode = nil
+ for i = 1, #args do
+ if args[i] == '--exitcode' then
+ exitcode = tonumber(args[i + 1])
+ end
+ end
+ return exitcode
+end
+
+local function main()
+ printbufs()
+ print('args:', vim.inspect(_G.arg))
+
+ local exitcode = parseargs(_G.arg)
+ if type(exitcode) == 'number' then
+ os.exit(exitcode)
+ end
+end
+
+main()