Compare commits
No commits in common. "64cf238c7f0e8ef606217c1f7fbc56105f20d580" and "bb9ca987e10883ecb89a84feac5f1e32ba5a7bd8" have entirely different histories.
64cf238c7f
...
bb9ca987e1
4 changed files with 30 additions and 55 deletions
26
README.md
26
README.md
|
|
@ -21,18 +21,8 @@ Typst, Markdown, etc.)—diagnostics included.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
With lazy.nvim:
|
Install with your package manager of choice or via
|
||||||
|
[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
|
||||||
|
|
@ -49,7 +39,7 @@ luarocks install preview.nvim
|
||||||
**Q: How do I define a custom provider?**
|
**Q: How do I define a custom provider?**
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
vim.g.preview = {
|
require('preview').setup({
|
||||||
rst = {
|
rst = {
|
||||||
cmd = { 'rst2html' },
|
cmd = { 'rst2html' },
|
||||||
args = function(ctx)
|
args = function(ctx)
|
||||||
|
|
@ -59,15 +49,15 @@ vim.g.preview = {
|
||||||
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
|
||||||
vim.g.preview = {
|
require('preview').setup({
|
||||||
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?**
|
||||||
|
|
@ -77,7 +67,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
|
||||||
vim.g.preview = {
|
require('preview').setup({
|
||||||
typst = { open = { 'sioyek', '--new-instance' } },
|
typst = { open = { 'sioyek', '--new-instance' } },
|
||||||
}
|
})
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -23,20 +23,23 @@ REQUIREMENTS *preview.nvim-requirements
|
||||||
==============================================================================
|
==============================================================================
|
||||||
SETUP *preview.nvim-setup*
|
SETUP *preview.nvim-setup*
|
||||||
|
|
||||||
Set |vim.g.preview| before the plugin loads: >lua
|
Load preview.nvim with your package manager. For example, with lazy.nvim: >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 by setting |vim.g.preview| to a table where keys are preset names
|
Configure via `require('preview').setup()`.
|
||||||
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.
|
||||||
|
|
@ -105,12 +108,6 @@ 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:~
|
||||||
|
|
||||||
|
|
@ -123,30 +120,30 @@ Context fields:~
|
||||||
|
|
||||||
Example enabling presets:~
|
Example enabling presets:~
|
||||||
>lua
|
>lua
|
||||||
vim.g.preview = { typst = true, latex = true, github = true }
|
require('preview').setup({ typst = true, latex = true, github = true })
|
||||||
<
|
<
|
||||||
|
|
||||||
Example overriding a preset field:~
|
Example overriding a preset field:~
|
||||||
>lua
|
>lua
|
||||||
vim.g.preview = {
|
require('preview').setup({
|
||||||
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
|
||||||
vim.g.preview = {
|
require('preview').setup({
|
||||||
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
|
||||||
vim.g.preview = {
|
require('preview').setup({
|
||||||
rst = {
|
rst = {
|
||||||
cmd = { 'rst2html' },
|
cmd = { 'rst2html' },
|
||||||
args = function(ctx)
|
args = function(ctx)
|
||||||
|
|
@ -156,7 +153,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,
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
<
|
<
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
@ -176,14 +173,14 @@ Import them from `preview.presets`:
|
||||||
|
|
||||||
Enable presets with `preset_name = true`:
|
Enable presets with `preset_name = true`:
|
||||||
>lua
|
>lua
|
||||||
vim.g.preview = { typst = true, latex = true, github = true }
|
require('preview').setup({ 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
|
||||||
vim.g.preview = {
|
require('preview').setup({
|
||||||
typst = { env = { TYPST_FONT_PATHS = '/usr/share/fonts' } },
|
typst = { env = { TYPST_FONT_PATHS = '/usr/share/fonts' } },
|
||||||
}
|
})
|
||||||
<
|
<
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
|
||||||
|
|
@ -291,9 +291,7 @@ 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)
|
||||||
if not provider.detach then
|
|
||||||
close_viewer(bufnr)
|
close_viewer(bufnr)
|
||||||
end
|
|
||||||
last_output[bufnr] = nil
|
last_output[bufnr] = nil
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
@ -406,9 +404,7 @@ function M.compile(bufnr, name, provider, ctx, opts)
|
||||||
once = true,
|
once = true,
|
||||||
callback = function()
|
callback = function()
|
||||||
M.stop(bufnr)
|
M.stop(bufnr)
|
||||||
if not provider.detach then
|
|
||||||
close_viewer(bufnr)
|
close_viewer(bufnr)
|
||||||
end
|
|
||||||
last_output[bufnr] = nil
|
last_output[bufnr] = nil
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
@ -511,9 +507,7 @@ 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)
|
||||||
if not provider.detach then
|
|
||||||
close_viewer(bufnr)
|
close_viewer(bufnr)
|
||||||
end
|
|
||||||
opened[bufnr] = nil
|
opened[bufnr] = nil
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@
|
||||||
---@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
|
||||||
|
|
@ -102,7 +101,6 @@ 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, {
|
||||||
|
|
@ -248,8 +246,4 @@ 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