From bad6f70269bcaf063513782c085aa2295ed3af25 Mon Sep 17 00:00:00 2001 From: ChangqingW <87298334+ChangqingW@users.noreply.github.com> Date: Fri, 8 Sep 2023 17:50:56 +1000 Subject: [PATCH] feat: pass arguments to quarto preview (#88) --- lua/quarto/init.lua | 11 +++++++---- plugin/quarto.lua | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lua/quarto/init.lua b/lua/quarto/init.lua index 39251b9..96ff1a9 100644 --- a/lua/quarto/init.lua +++ b/lua/quarto/init.lua @@ -34,7 +34,10 @@ M.defaultConfig = { -- use defaultConfig if not setup M.config = M.defaultConfig -function M.quartoPreview() +function M.quartoPreview(opts) + opts = opts or {} + local args = opts.args or '' + -- find root directory / check if it is a project local buffer_path = api.nvim_buf_get_name(0) local root_dir = util.root_pattern("_quarto.yml")(buffer_path) @@ -42,13 +45,13 @@ function M.quartoPreview() local mode if root_dir then mode = "project" - cmd = 'quarto preview' + cmd = 'quarto preview' .. ' ' .. args else mode = "file" if vim.loop.os_uname().sysname == "Windows_NT" then - cmd = 'quarto preview \\"' .. buffer_path .. '\\"' + cmd = 'quarto preview \\"' .. buffer_path .. '\\"' .. ' ' .. args else - cmd = 'quarto preview \'' .. buffer_path .. '\'' + cmd = 'quarto preview \'' .. buffer_path .. '\'' .. ' ' .. args end end diff --git a/plugin/quarto.lua b/plugin/quarto.lua index a3494c3..e1aa8d6 100644 --- a/plugin/quarto.lua +++ b/plugin/quarto.lua @@ -16,7 +16,7 @@ end local quarto = require 'quarto' local api = vim.api -api.nvim_create_user_command('QuartoPreview', quarto.quartoPreview, {}) +api.nvim_create_user_command('QuartoPreview', quarto.quartoPreview, {nargs = '*'}) api.nvim_create_user_command('QuartoClosePreview', quarto.quartoClosePreview, {}) api.nvim_create_user_command('QuartoActivate', quarto.activate, {}) api.nvim_create_user_command('QuartoHelp', quarto.searchHelp, { nargs = 1 })