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:
Barrett Ruth 2026-03-03 00:44:46 -05:00
parent 6e48c6716b
commit 50580ecde5
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
3 changed files with 8 additions and 80 deletions

View file

@ -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', {

View file

@ -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

View file

@ -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')