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:
Barrett Ruth 2026-03-02 23:37:44 -05:00
parent c62c930454
commit 673573044f
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
12 changed files with 346 additions and 176 deletions

View file

@ -1,6 +1,6 @@
local M = {}
local subcommands = { 'compile', 'stop', 'clean', 'watch', 'status' }
local subcommands = { 'compile', 'stop', 'clean', 'toggle', 'status' }
---@param args string
local function dispatch(args)
@ -12,8 +12,8 @@ local function dispatch(args)
require('preview').stop()
elseif subcmd == 'clean' then
require('preview').clean()
elseif subcmd == 'watch' then
require('preview').watch()
elseif subcmd == 'toggle' then
require('preview').toggle()
elseif subcmd == 'status' then
local s = require('preview').status()
local parts = {}
@ -47,7 +47,7 @@ function M.setup()
complete = function(lead)
return complete(lead)
end,
desc = 'Compile, stop, clean, watch, or check status of document preview',
desc = 'Compile, stop, clean, toggle, or check status of document preview',
})
end