Compare commits

..

No commits in common. "86a3523f2d4735a6d1aeaa5f5be5389aa014f61e" and "4732696a623683be8ebb605125e2c008280f0c2c" have entirely different histories.

8 changed files with 39 additions and 67 deletions

View file

@ -2,13 +2,7 @@
"runtime.version": "LuaJIT",
"runtime.path": ["lua/?.lua", "lua/?/init.lua"],
"diagnostics.globals": ["vim", "jit"],
"workspace.library": [
"$VIMRUNTIME/lua",
"${3rd}/luv/library",
"${3rd}/busted/library",
"${3rd}/luassert/library"
],
"workspace.library": ["$VIMRUNTIME/lua", "${3rd}/luv/library"],
"workspace.checkThirdParty": false,
"workspace.ignoreDir": [".direnv"],
"completion.callSnippet": "Replace"
}

View file

@ -1 +0,0 @@
.direnv/

View file

@ -10,8 +10,8 @@ preview.nvim is an extensible framework for compiling documents asynchronously
in Neovim. It provides a unified interface for any compilation workflow —
LaTeX, Typst, Markdown, or anything else with a CLI compiler.
The plugin ships with opt-in presets for common tools (Typst, LaTeX, Pandoc)
and supports fully custom providers. See |preview.nvim-presets|.
The plugin ships with zero provider defaults. Users must explicitly configure
their compiler commands. preview.nvim is purely an orchestration framework.
==============================================================================
REQUIREMENTS *preview.nvim-requirements*
@ -93,14 +93,6 @@ Provider fields:~
|vim.ui.open()|. A string[] is run as
a command with the output path appended.
`reload` boolean|string[]|function
Reload the output after recompilation.
`true` uses a built-in SSE server for
HTML files. A string[] is run as a
command. If a function, receives a
|preview.Context| and returns a
string[].
*preview.Context*
Context fields:~
@ -123,17 +115,6 @@ Example overriding a preset field:~
})
<
Example overriding the output path (e.g. latexmk `$out_dir`):~
>lua
require('preview').setup({
latex = {
output = function(ctx)
return 'build/' .. vim.fn.fnamemodify(ctx.file, ':t:r') .. '.pdf'
end,
},
})
<
Example with a fully custom provider (key is not a preset name):~
>lua
require('preview').setup({
@ -179,30 +160,30 @@ COMMANDS *preview.nvim-commands*
Subcommands:~
`toggle` Toggle auto-compile on save (default if omitted).
`compile` One-shot compile of the current buffer.
`compile` Compile the current buffer (default if omitted).
`stop` Kill active compilation for the current buffer.
`clean` Run the provider's clean command.
`toggle` Toggle auto-compile on save for the current buffer.
`open` Open the last compiled output without recompiling.
`status` Echo compilation status (idle, compiling, watching).
==============================================================================
API *preview.nvim-api*
preview.compile({bufnr?}) *preview.compile()*
Compile the document in the given buffer (default: current).
preview.stop({bufnr?}) *preview.stop()*
Kill the active compilation process for the buffer.
preview.clean({bufnr?}) *preview.clean()*
Run the provider's clean command for the buffer.
preview.toggle({bufnr?}) *preview.toggle()*
Toggle auto-compile for the buffer. When enabled, the buffer is
immediately compiled and automatically recompiled on each save
(`BufWritePost`). Call again to stop.
preview.compile({bufnr?}) *preview.compile()*
One-shot compile the document in the given buffer (default: current).
preview.stop({bufnr?}) *preview.stop()*
Kill the active compilation process for the buffer. Programmatic
escape hatch — not exposed as a subcommand.
preview.clean({bufnr?}) *preview.clean()*
Run the provider's clean command for the buffer.
preview.open({bufnr?}) *preview.open()*
Open the last compiled output for the buffer without recompiling.

View file

@ -16,8 +16,6 @@
forEachSystem = f: nixpkgs.lib.genAttrs (import systems) (system: f nixpkgs.legacyPackages.${system});
in
{
formatter = forEachSystem (pkgs: pkgs.nixfmt-tree);
devShells = forEachSystem (pkgs: {
default = pkgs.mkShell {
packages = [

View file

@ -1,14 +1,17 @@
local M = {}
local handlers = {
compile = function()
require('preview').compile()
build = function()
require('preview').build()
end,
stop = function()
require('preview').stop()
end,
clean = function()
require('preview').clean()
end,
toggle = function()
require('preview').toggle()
watch = function()
require('preview').watch()
end,
open = function()
require('preview').open()
@ -30,7 +33,7 @@ local handlers = {
---@param args string
local function dispatch(args)
local subcmd = args ~= '' and args or 'toggle'
local subcmd = args ~= '' and args or 'build'
local handler = handlers[subcmd]
if handler then
handler()
@ -55,7 +58,7 @@ function M.setup()
complete = function(lead)
return complete(lead)
end,
desc = 'Toggle, compile, clean, open, or check status of document preview',
desc = 'Build, stop, clean, watch, open, or check status of document preview',
})
end

View file

@ -39,10 +39,10 @@
---@class preview
---@field setup fun(opts?: table)
---@field compile fun(bufnr?: integer)
---@field build fun(bufnr?: integer)
---@field stop fun(bufnr?: integer)
---@field clean fun(bufnr?: integer)
---@field toggle fun(bufnr?: integer)
---@field watch fun(bufnr?: integer)
---@field open fun(bufnr?: integer)
---@field status fun(bufnr?: integer): preview.Status
---@field statusline fun(bufnr?: integer): string
@ -144,7 +144,7 @@ function M.build_context(bufnr)
end
---@param bufnr? integer
function M.compile(bufnr)
function M.build(bufnr)
bufnr = bufnr or vim.api.nvim_get_current_buf()
local name = M.resolve_provider(bufnr)
if not name then
@ -176,7 +176,7 @@ function M.clean(bufnr)
end
---@param bufnr? integer
function M.toggle(bufnr)
function M.watch(bufnr)
bufnr = bufnr or vim.api.nvim_get_current_buf()
local name = M.resolve_provider(bufnr)
if not name then

View file

@ -1,10 +0,0 @@
#!/bin/sh
set -eu
nix develop --command stylua --check .
git ls-files '*.lua' | xargs nix develop --command selene --display-style quiet
nix develop --command prettier --check .
nix fmt
git diff --exit-code -- '*.nix'
nix develop --command lua-language-server --check . --checklevel=Warning
nix develop --command busted

View file

@ -14,10 +14,17 @@ describe('commands', function()
end)
describe('dispatch', function()
it('does not error on :Preview compile with no provider', function()
it('does not error on :Preview with no provider', function()
require('preview.commands').setup()
assert.has_no.errors(function()
vim.cmd('Preview compile')
vim.cmd('Preview build')
end)
end)
it('does not error on :Preview stop', function()
require('preview.commands').setup()
assert.has_no.errors(function()
vim.cmd('Preview stop')
end)
end)
@ -35,10 +42,10 @@ describe('commands', function()
end)
end)
it('does not error on :Preview toggle with no provider', function()
it('does not error on :Preview watch with no provider', function()
require('preview.commands').setup()
assert.has_no.errors(function()
vim.cmd('Preview toggle')
vim.cmd('Preview watch')
end)
end)
end)