feat: add detach provider field and vim.g.preview config support

Problem: viewer processes launched via a string[] `open` command were
always killed on buffer deletion with no way to opt out. Configuring
the plugin also required an explicit `setup()` call in a `config`
hook, preventing config from being declared before the plugin loads.

Solution: add a `detach` boolean to `ProviderConfig` that skips
SIGTERM on buffer unload. Auto-call `setup()` from `vim.g.preview`
at module load time, enabling config via lazy.nvim's `init` hook.
Update vimdoc and README accordingly.
This commit is contained in:
Barrett Ruth 2026-03-04 19:22:32 -05:00
parent bb9ca987e1
commit b95493ddee
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
4 changed files with 40 additions and 7 deletions

View file

@ -23,12 +23,17 @@ REQUIREMENTS *preview.nvim-requirements
==============================================================================
SETUP *preview.nvim-setup*
Load preview.nvim with your package manager. For example, with lazy.nvim: >lua
With lazy.nvim, set |vim.g.preview| in `init` so configuration is applied
before the plugin loads: >lua
{
'barrettruth/preview.nvim',
init = function()
vim.g.preview = { typst = true, latex = true }
end,
}
<
Call |preview.setup()| to configure providers before use.
Alternatively, call |preview.setup()| directly in a `config` function or
anywhere the plugin is already loaded.
==============================================================================
CONFIGURATION *preview.nvim-configuration*
@ -108,6 +113,12 @@ Provider fields:~
|preview.Context| and returns a
string[].
`detach` boolean When `true`, the viewer process opened
via a string[] `open` command is not
sent SIGTERM when the buffer is deleted.
Has no effect when `open` is `true`.
Default: `false`.
*preview.Context*
Context fields:~