Refactor/preset name true syntax (#4)
* refactor(config): replace array preset syntax with preset_name = true Problem: setup() mixed array entries (preset names) and hash entries (custom providers keyed by filetype), requiring verbose vim.tbl_deep_extend boilerplate to override presets. Solution: unify under a single key=value model. Keys are preset names or filetypes; true registers the preset as-is, a table deep-merges with the matching preset (or registers a custom provider if no preset matches), and false is a no-op. Array entries are dropped. Also adds -f gfm to presets.github args so pandoc parses input as GFM. * ci: format * fix(presets): parenthesize gsub output to suppress redundant-return-value * ci: remove superfluous things * refactor: remove PreviewWatch* events and clean up docs Problem: PreviewWatchStarted/PreviewWatchStopped were redundant with the status() API, and the doc had a wrong author, stale INSTALLATION format, and "watch mode" language left over from the watch → toggle rename. Solution: Remove the events and their tests. Fix the doc author, rename INSTALLATION → SETUP to match sibling plugins, replace "watch mode" with "auto-compile" throughout, and drop the events from EVENTS.
This commit is contained in:
parent
2d212aa220
commit
0b16ff7178
4 changed files with 8 additions and 82 deletions
|
|
@ -71,5 +71,3 @@ require('preview').setup({
|
||||||
typst = { open = { 'sioyek', '--new-instance' } },
|
typst = { open = { 'sioyek', '--new-instance' } },
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
See `:h preview.nvim` for more information.
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
*preview.nvim.txt* Async document compilation for Neovim
|
*preview.nvim.txt* Async document compilation for Neovim
|
||||||
|
|
||||||
Author: Raphael
|
Author: Barrett Ruth <br.barrettruth@gmail.com>
|
||||||
License: MIT
|
License: MIT
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
@ -20,19 +20,14 @@ REQUIREMENTS *preview.nvim-requirements
|
||||||
- A compiler binary for each configured provider (e.g. `typst`, `latexmk`)
|
- A compiler binary for each configured provider (e.g. `typst`, `latexmk`)
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
INSTALLATION *preview.nvim-installation*
|
SETUP *preview.nvim-setup*
|
||||||
|
|
||||||
With luarocks (recommended):
|
Load preview.nvim with your package manager. For example, with lazy.nvim: >lua
|
||||||
>
|
|
||||||
:Rocks install preview.nvim
|
|
||||||
<
|
|
||||||
|
|
||||||
With lazy.nvim:
|
|
||||||
>lua
|
|
||||||
{
|
{
|
||||||
'barrettruth/preview.nvim',
|
'barrettruth/preview.nvim',
|
||||||
}
|
}
|
||||||
<
|
<
|
||||||
|
Call |preview.setup()| to configure providers before use.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
CONFIGURATION *preview.nvim-configuration*
|
CONFIGURATION *preview.nvim-configuration*
|
||||||
|
|
@ -161,7 +156,7 @@ COMMANDS *preview.nvim-commands*
|
||||||
`stop` Kill active compilation for the current buffer.
|
`stop` Kill active compilation for the current buffer.
|
||||||
`clean` Run the provider's clean command.
|
`clean` Run the provider's clean command.
|
||||||
`toggle` Toggle auto-compile on save for the current buffer.
|
`toggle` Toggle auto-compile on save for the current buffer.
|
||||||
`status` Echo compilation status (idle, compiling, watching).
|
`status` Echo compilation status (idle, compiling, toggled).
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
API *preview.nvim-api*
|
API *preview.nvim-api*
|
||||||
|
|
@ -176,9 +171,9 @@ preview.clean({bufnr?}) *preview.clean()*
|
||||||
Run the provider's clean command for the buffer.
|
Run the provider's clean command for the buffer.
|
||||||
|
|
||||||
preview.toggle({bufnr?}) *preview.toggle()*
|
preview.toggle({bufnr?}) *preview.toggle()*
|
||||||
Toggle watch mode for the buffer. When enabled, the buffer is
|
Toggle auto-compile for the buffer. When enabled, the buffer is
|
||||||
immediately compiled and automatically recompiled on each save
|
immediately compiled and automatically recompiled on each save
|
||||||
(`BufWritePost`). Call again to stop watching.
|
(`BufWritePost`). Call again to stop.
|
||||||
|
|
||||||
preview.status({bufnr?}) *preview.status()*
|
preview.status({bufnr?}) *preview.status()*
|
||||||
Returns a |preview.Status| table.
|
Returns a |preview.Status| table.
|
||||||
|
|
@ -187,7 +182,7 @@ preview.status({bufnr?}) *preview.status()*
|
||||||
Status fields:~
|
Status fields:~
|
||||||
|
|
||||||
`compiling` boolean Whether compilation is active.
|
`compiling` boolean Whether compilation is active.
|
||||||
`watching` boolean Whether watch mode is active.
|
`watching` boolean Whether auto-compile is active.
|
||||||
`provider` string? Name of the active provider.
|
`provider` string? Name of the active provider.
|
||||||
`output_file` string? Path to the output file.
|
`output_file` string? Path to the output file.
|
||||||
|
|
||||||
|
|
@ -208,12 +203,6 @@ preview.nvim fires User autocmds with structured data:
|
||||||
`PreviewCompileFailed` Compilation failed (non-zero exit).
|
`PreviewCompileFailed` Compilation failed (non-zero exit).
|
||||||
data: `{ bufnr, provider, code, stderr }`
|
data: `{ bufnr, provider, code, stderr }`
|
||||||
|
|
||||||
`PreviewWatchStarted` Watch mode enabled for a buffer.
|
|
||||||
data: `{ bufnr, provider }`
|
|
||||||
|
|
||||||
`PreviewWatchStopped` Watch mode disabled for a buffer.
|
|
||||||
data: `{ bufnr }`
|
|
||||||
|
|
||||||
Example:~
|
Example:~
|
||||||
>lua
|
>lua
|
||||||
vim.api.nvim_create_autocmd('User', {
|
vim.api.nvim_create_autocmd('User', {
|
||||||
|
|
|
||||||
|
|
@ -188,11 +188,6 @@ function M.toggle(bufnr, name, provider, ctx_builder)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
vim.api.nvim_exec_autocmds('User', {
|
|
||||||
pattern = 'PreviewWatchStarted',
|
|
||||||
data = { bufnr = bufnr, provider = name },
|
|
||||||
})
|
|
||||||
|
|
||||||
M.compile(bufnr, name, provider, ctx_builder(bufnr))
|
M.compile(bufnr, name, provider, ctx_builder(bufnr))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -205,11 +200,6 @@ function M.unwatch(bufnr)
|
||||||
vim.api.nvim_del_autocmd(au_id)
|
vim.api.nvim_del_autocmd(au_id)
|
||||||
watching[bufnr] = nil
|
watching[bufnr] = nil
|
||||||
log.dbg('unwatched buffer %d', bufnr)
|
log.dbg('unwatched buffer %d', bufnr)
|
||||||
|
|
||||||
vim.api.nvim_exec_autocmds('User', {
|
|
||||||
pattern = 'PreviewWatchStopped',
|
|
||||||
data = { bufnr = bufnr },
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
|
|
|
||||||
|
|
@ -190,31 +190,6 @@ describe('compiler', function()
|
||||||
helpers.delete_buffer(bufnr)
|
helpers.delete_buffer(bufnr)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('fires PreviewWatchStarted event', function()
|
|
||||||
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
|
||||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_watch_event.txt')
|
|
||||||
|
|
||||||
local fired = false
|
|
||||||
vim.api.nvim_create_autocmd('User', {
|
|
||||||
pattern = 'PreviewWatchStarted',
|
|
||||||
once = true,
|
|
||||||
callback = function()
|
|
||||||
fired = true
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
local provider = { cmd = { 'echo', 'ok' } }
|
|
||||||
local ctx_builder = function(b)
|
|
||||||
return { bufnr = b, file = '/tmp/preview_test_watch_event.txt', root = '/tmp', ft = 'text' }
|
|
||||||
end
|
|
||||||
|
|
||||||
compiler.toggle(bufnr, 'echo', provider, ctx_builder)
|
|
||||||
assert.is_true(fired)
|
|
||||||
|
|
||||||
compiler.unwatch(bufnr)
|
|
||||||
helpers.delete_buffer(bufnr)
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('toggles off when called again', function()
|
it('toggles off when called again', function()
|
||||||
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
||||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_watch_toggle.txt')
|
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_watch_toggle.txt')
|
||||||
|
|
@ -233,32 +208,6 @@ describe('compiler', function()
|
||||||
helpers.delete_buffer(bufnr)
|
helpers.delete_buffer(bufnr)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('fires PreviewWatchStopped on unwatch', function()
|
|
||||||
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
|
||||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_watch_stop.txt')
|
|
||||||
|
|
||||||
local stopped = false
|
|
||||||
vim.api.nvim_create_autocmd('User', {
|
|
||||||
pattern = 'PreviewWatchStopped',
|
|
||||||
once = true,
|
|
||||||
callback = function()
|
|
||||||
stopped = true
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
local provider = { cmd = { 'echo', 'ok' } }
|
|
||||||
local ctx_builder = function(b)
|
|
||||||
return { bufnr = b, file = '/tmp/preview_test_watch_stop.txt', root = '/tmp', ft = 'text' }
|
|
||||||
end
|
|
||||||
|
|
||||||
compiler.toggle(bufnr, 'echo', provider, ctx_builder)
|
|
||||||
compiler.unwatch(bufnr)
|
|
||||||
assert.is_true(stopped)
|
|
||||||
assert.is_nil(compiler._test.watching[bufnr])
|
|
||||||
|
|
||||||
helpers.delete_buffer(bufnr)
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('stop_all clears watches', function()
|
it('stop_all clears watches', function()
|
||||||
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
local bufnr = helpers.create_buffer({ 'hello' }, 'text')
|
||||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_watch_stopall.txt')
|
vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_watch_stopall.txt')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue