Skip to content

Commit

Permalink
feat: pass arguments to quarto preview (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChangqingW authored Sep 8, 2023
1 parent 93b0959 commit bad6f70
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions lua/quarto/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,24 @@ 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)
local cmd
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

Expand Down
2 changes: 1 addition & 1 deletion plugin/quarto.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit bad6f70

Please sign in to comment.