feat: rename watch → toggle, auto-compile on start, built-in opener
Problem: :Preview watch only registered a BufWritePost autocmd without
compiling immediately, required boilerplate to open output files after
first compilation, and was misleadingly named.
Solution: Rename watch → toggle throughout. M.toggle now compiles
immediately on activation. Add an open field to ProviderConfig: true
calls vim.ui.open(), a string[] runs the command with the output path
appended, tracked per-buffer so the file opens only once. All presets
default to { 'xdg-open' }. Health check validates opener binaries.
Guard the async compile callback against invalid buffer ids.
This commit is contained in:
parent
c62c930454
commit
673573044f
12 changed files with 346 additions and 176 deletions
|
|
@ -13,6 +13,10 @@ describe('presets', function()
|
|||
}
|
||||
|
||||
describe('typst', function()
|
||||
it('has ft', function()
|
||||
assert.are.equal('typst', presets.typst.ft)
|
||||
end)
|
||||
|
||||
it('has cmd', function()
|
||||
assert.are.same({ 'typst', 'compile' }, presets.typst.cmd)
|
||||
end)
|
||||
|
|
@ -28,6 +32,10 @@ describe('presets', function()
|
|||
assert.is_string(output)
|
||||
assert.are.equal('/tmp/document.pdf', output)
|
||||
end)
|
||||
|
||||
it('has open enabled', function()
|
||||
assert.are.same({ 'xdg-open' }, presets.typst.open)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('latex', function()
|
||||
|
|
@ -38,6 +46,10 @@ describe('presets', function()
|
|||
ft = 'tex',
|
||||
}
|
||||
|
||||
it('has ft', function()
|
||||
assert.are.equal('tex', presets.latex.ft)
|
||||
end)
|
||||
|
||||
it('has cmd', function()
|
||||
assert.are.same({ 'latexmk' }, presets.latex.cmd)
|
||||
end)
|
||||
|
|
@ -59,6 +71,10 @@ describe('presets', function()
|
|||
assert.is_table(clean)
|
||||
assert.are.same({ 'latexmk', '-c', '/tmp/document.tex' }, clean)
|
||||
end)
|
||||
|
||||
it('has open enabled', function()
|
||||
assert.are.same({ 'xdg-open' }, presets.latex.open)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('markdown', function()
|
||||
|
|
@ -69,20 +85,84 @@ describe('presets', function()
|
|||
ft = 'markdown',
|
||||
}
|
||||
|
||||
it('has ft', function()
|
||||
assert.are.equal('markdown', presets.markdown.ft)
|
||||
end)
|
||||
|
||||
it('has cmd', function()
|
||||
assert.are.same({ 'pandoc' }, presets.markdown.cmd)
|
||||
end)
|
||||
|
||||
it('returns args with file and output flag', function()
|
||||
it('returns args with standalone and embed-resources flags', function()
|
||||
local args = presets.markdown.args(md_ctx)
|
||||
assert.is_table(args)
|
||||
assert.are.same({ '/tmp/document.md', '-o', '/tmp/document.pdf' }, args)
|
||||
assert.are.same(
|
||||
{ '/tmp/document.md', '-s', '--embed-resources', '-o', '/tmp/document.html' },
|
||||
args
|
||||
)
|
||||
end)
|
||||
|
||||
it('returns pdf output path', function()
|
||||
it('returns html output path', function()
|
||||
local output = presets.markdown.output(md_ctx)
|
||||
assert.is_string(output)
|
||||
assert.are.equal('/tmp/document.pdf', output)
|
||||
assert.are.equal('/tmp/document.html', output)
|
||||
end)
|
||||
|
||||
it('returns clean command', function()
|
||||
local clean = presets.markdown.clean(md_ctx)
|
||||
assert.is_table(clean)
|
||||
assert.are.same({ 'rm', '-f', '/tmp/document.html' }, clean)
|
||||
end)
|
||||
|
||||
it('has open enabled', function()
|
||||
assert.are.same({ 'xdg-open' }, presets.markdown.open)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('github', function()
|
||||
local md_ctx = {
|
||||
bufnr = 1,
|
||||
file = '/tmp/document.md',
|
||||
root = '/tmp',
|
||||
ft = 'markdown',
|
||||
}
|
||||
|
||||
it('has ft', function()
|
||||
assert.are.equal('markdown', presets.github.ft)
|
||||
end)
|
||||
|
||||
it('has cmd', function()
|
||||
assert.are.same({ 'pandoc' }, presets.github.cmd)
|
||||
end)
|
||||
|
||||
it('returns args with standalone, embed-resources, and css flags', function()
|
||||
local args = presets.github.args(md_ctx)
|
||||
assert.is_table(args)
|
||||
assert.are.same({
|
||||
'/tmp/document.md',
|
||||
'-s',
|
||||
'--embed-resources',
|
||||
'--css',
|
||||
'https://cdn.jsdelivr.net/gh/pixelbrackets/gfm-stylesheet@master/github.css',
|
||||
'-o',
|
||||
'/tmp/document.html',
|
||||
}, args)
|
||||
end)
|
||||
|
||||
it('returns html output path', function()
|
||||
local output = presets.github.output(md_ctx)
|
||||
assert.is_string(output)
|
||||
assert.are.equal('/tmp/document.html', output)
|
||||
end)
|
||||
|
||||
it('returns clean command', function()
|
||||
local clean = presets.github.clean(md_ctx)
|
||||
assert.is_table(clean)
|
||||
assert.are.same({ 'rm', '-f', '/tmp/document.html' }, clean)
|
||||
end)
|
||||
|
||||
it('has open enabled', function()
|
||||
assert.are.same({ 'xdg-open' }, presets.github.open)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue