Compare commits
2 commits
build/nix-
...
feat/detac
| Author | SHA1 | Date | |
|---|---|---|---|
| 64cf238c7f | |||
| b95493ddee |
4 changed files with 55 additions and 30 deletions
26
README.md
26
README.md
|
|
@ -21,8 +21,18 @@ Typst, Markdown, etc.)—diagnostics included.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Install with your package manager of choice or via
|
With lazy.nvim:
|
||||||
[luarocks](https://luarocks.org/modules/barrettruth/preview.nvim):
|
|
||||||
|
```lua
|
||||||
|
{
|
||||||
|
'barrettruth/preview.nvim',
|
||||||
|
init = function()
|
||||||
|
vim.g.preview = { typst = true, latex = true }
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Or via [luarocks](https://luarocks.org/modules/barrettruth/preview.nvim):
|
||||||
|
|
||||||
```
|
```
|
||||||
luarocks install preview.nvim
|
luarocks install preview.nvim
|
||||||
|
|
@ -39,7 +49,7 @@ luarocks install preview.nvim
|
||||||
**Q: How do I define a custom provider?**
|
**Q: How do I define a custom provider?**
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
require('preview').setup({
|
vim.g.preview = {
|
||||||
rst = {
|
rst = {
|
||||||
cmd = { 'rst2html' },
|
cmd = { 'rst2html' },
|
||||||
args = function(ctx)
|
args = function(ctx)
|
||||||
|
|
@ -49,15 +59,15 @@ require('preview').setup({
|
||||||
return ctx.file:gsub('%.rst$', '.html')
|
return ctx.file:gsub('%.rst$', '.html')
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Q: How do I override a preset?**
|
**Q: How do I override a preset?**
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
require('preview').setup({
|
vim.g.preview = {
|
||||||
typst = { env = { TYPST_FONT_PATHS = '/usr/share/fonts' } },
|
typst = { env = { TYPST_FONT_PATHS = '/usr/share/fonts' } },
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Q: How do I automatically open the output file?**
|
**Q: How do I automatically open the output file?**
|
||||||
|
|
@ -67,7 +77,7 @@ open the output with `vim.ui.open()` after the first successful compilation in
|
||||||
toggle/watch mode. For a specific application, pass a command table:
|
toggle/watch mode. For a specific application, pass a command table:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
require('preview').setup({
|
vim.g.preview = {
|
||||||
typst = { open = { 'sioyek', '--new-instance' } },
|
typst = { open = { 'sioyek', '--new-instance' } },
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -23,23 +23,20 @@ REQUIREMENTS *preview.nvim-requirements
|
||||||
==============================================================================
|
==============================================================================
|
||||||
SETUP *preview.nvim-setup*
|
SETUP *preview.nvim-setup*
|
||||||
|
|
||||||
Load preview.nvim with your package manager. For example, with lazy.nvim: >lua
|
Set |vim.g.preview| before the plugin loads: >lua
|
||||||
{
|
{
|
||||||
'barrettruth/preview.nvim',
|
'barrettruth/preview.nvim',
|
||||||
|
init = function()
|
||||||
|
vim.g.preview = { typst = true, latex = true }
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
<
|
<
|
||||||
Call |preview.setup()| to configure providers before use.
|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
CONFIGURATION *preview.nvim-configuration*
|
CONFIGURATION *preview.nvim-configuration*
|
||||||
|
|
||||||
Configure via `require('preview').setup()`.
|
Configure by setting |vim.g.preview| to a table where keys are preset names
|
||||||
|
or filetypes. For each key `k` with value `v` (excluding `debug`):
|
||||||
*preview.setup()*
|
|
||||||
setup({opts?})
|
|
||||||
|
|
||||||
`opts` is a table where keys are preset names or filetypes. For each
|
|
||||||
key `k` with value `v` (excluding `debug`):
|
|
||||||
|
|
||||||
- If `k` is a preset name and `v` is `true`, the preset is registered
|
- If `k` is a preset name and `v` is `true`, the preset is registered
|
||||||
as-is under its filetype.
|
as-is under its filetype.
|
||||||
|
|
@ -108,6 +105,12 @@ Provider fields:~
|
||||||
|preview.Context| and returns a
|
|preview.Context| and returns a
|
||||||
string[].
|
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*
|
*preview.Context*
|
||||||
Context fields:~
|
Context fields:~
|
||||||
|
|
||||||
|
|
@ -120,30 +123,30 @@ Context fields:~
|
||||||
|
|
||||||
Example enabling presets:~
|
Example enabling presets:~
|
||||||
>lua
|
>lua
|
||||||
require('preview').setup({ typst = true, latex = true, github = true })
|
vim.g.preview = { typst = true, latex = true, github = true }
|
||||||
<
|
<
|
||||||
|
|
||||||
Example overriding a preset field:~
|
Example overriding a preset field:~
|
||||||
>lua
|
>lua
|
||||||
require('preview').setup({
|
vim.g.preview = {
|
||||||
typst = { open = { 'sioyek', '--new-instance' } },
|
typst = { open = { 'sioyek', '--new-instance' } },
|
||||||
})
|
}
|
||||||
<
|
<
|
||||||
|
|
||||||
Example overriding the output path (e.g. latexmk `$out_dir`):~
|
Example overriding the output path (e.g. latexmk `$out_dir`):~
|
||||||
>lua
|
>lua
|
||||||
require('preview').setup({
|
vim.g.preview = {
|
||||||
latex = {
|
latex = {
|
||||||
output = function(ctx)
|
output = function(ctx)
|
||||||
return 'build/' .. vim.fn.fnamemodify(ctx.file, ':t:r') .. '.pdf'
|
return 'build/' .. vim.fn.fnamemodify(ctx.file, ':t:r') .. '.pdf'
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
<
|
<
|
||||||
|
|
||||||
Example with a fully custom provider (key is not a preset name):~
|
Example with a fully custom provider (key is not a preset name):~
|
||||||
>lua
|
>lua
|
||||||
require('preview').setup({
|
vim.g.preview = {
|
||||||
rst = {
|
rst = {
|
||||||
cmd = { 'rst2html' },
|
cmd = { 'rst2html' },
|
||||||
args = function(ctx)
|
args = function(ctx)
|
||||||
|
|
@ -153,7 +156,7 @@ Example with a fully custom provider (key is not a preset name):~
|
||||||
return ctx.file:gsub('%.rst$', '.html')
|
return ctx.file:gsub('%.rst$', '.html')
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
<
|
<
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
@ -173,14 +176,14 @@ Import them from `preview.presets`:
|
||||||
|
|
||||||
Enable presets with `preset_name = true`:
|
Enable presets with `preset_name = true`:
|
||||||
>lua
|
>lua
|
||||||
require('preview').setup({ typst = true, latex = true, github = true })
|
vim.g.preview = { typst = true, latex = true, github = true }
|
||||||
<
|
<
|
||||||
|
|
||||||
Override individual fields by passing a table instead of `true`:
|
Override individual fields by passing a table instead of `true`:
|
||||||
>lua
|
>lua
|
||||||
require('preview').setup({
|
vim.g.preview = {
|
||||||
typst = { env = { TYPST_FONT_PATHS = '/usr/share/fonts' } },
|
typst = { env = { TYPST_FONT_PATHS = '/usr/share/fonts' } },
|
||||||
})
|
}
|
||||||
<
|
<
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
|
||||||
|
|
@ -291,7 +291,9 @@ function M.compile(bufnr, name, provider, ctx, opts)
|
||||||
callback = function()
|
callback = function()
|
||||||
M.stop(bufnr)
|
M.stop(bufnr)
|
||||||
stop_open_watcher(bufnr)
|
stop_open_watcher(bufnr)
|
||||||
close_viewer(bufnr)
|
if not provider.detach then
|
||||||
|
close_viewer(bufnr)
|
||||||
|
end
|
||||||
last_output[bufnr] = nil
|
last_output[bufnr] = nil
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
@ -404,7 +406,9 @@ function M.compile(bufnr, name, provider, ctx, opts)
|
||||||
once = true,
|
once = true,
|
||||||
callback = function()
|
callback = function()
|
||||||
M.stop(bufnr)
|
M.stop(bufnr)
|
||||||
close_viewer(bufnr)
|
if not provider.detach then
|
||||||
|
close_viewer(bufnr)
|
||||||
|
end
|
||||||
last_output[bufnr] = nil
|
last_output[bufnr] = nil
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
@ -507,7 +511,9 @@ function M.toggle(bufnr, name, provider, ctx_builder)
|
||||||
callback = function()
|
callback = function()
|
||||||
M.unwatch(bufnr)
|
M.unwatch(bufnr)
|
||||||
stop_open_watcher(bufnr)
|
stop_open_watcher(bufnr)
|
||||||
close_viewer(bufnr)
|
if not provider.detach then
|
||||||
|
close_viewer(bufnr)
|
||||||
|
end
|
||||||
opened[bufnr] = nil
|
opened[bufnr] = nil
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
---@field clean? string[]|fun(ctx: preview.Context): string[]
|
---@field clean? string[]|fun(ctx: preview.Context): string[]
|
||||||
---@field open? boolean|string[]
|
---@field open? boolean|string[]
|
||||||
---@field reload? boolean|string[]|fun(ctx: preview.Context): string[]
|
---@field reload? boolean|string[]|fun(ctx: preview.Context): string[]
|
||||||
|
---@field detach? boolean
|
||||||
|
|
||||||
---@class preview.Config
|
---@class preview.Config
|
||||||
---@field debug boolean|string
|
---@field debug boolean|string
|
||||||
|
|
@ -101,6 +102,7 @@ function M.setup(opts)
|
||||||
end, 'false, "diagnostic", or "quickfix"')
|
end, 'false, "diagnostic", or "quickfix"')
|
||||||
vim.validate(prefix .. '.open', provider.open, { 'boolean', 'table' }, true)
|
vim.validate(prefix .. '.open', provider.open, { 'boolean', 'table' }, true)
|
||||||
vim.validate(prefix .. '.reload', provider.reload, { 'boolean', 'table', 'function' }, true)
|
vim.validate(prefix .. '.reload', provider.reload, { 'boolean', 'table', 'function' }, true)
|
||||||
|
vim.validate(prefix .. '.detach', provider.detach, 'boolean', true)
|
||||||
end
|
end
|
||||||
|
|
||||||
config = vim.tbl_deep_extend('force', default_config, {
|
config = vim.tbl_deep_extend('force', default_config, {
|
||||||
|
|
@ -246,4 +248,8 @@ M._test = {
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if vim.g.preview then
|
||||||
|
M.setup(vim.g.preview)
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue