From 3e6ba580e4e3c8dc544c0994659757ed12066c3f Mon Sep 17 00:00:00 2001
From: Barrett Ruth <62671086+barrettruth@users.noreply.github.com>
Date: Wed, 4 Mar 2026 17:23:06 -0500
Subject: [PATCH] fix: quickfix support for long-running providers (#41)
* fix(compiler): open quickfix in background, retain focus on source buffer
* fix(compiler): use cwindow and win_gotoid for quickfix focus management
* fix: unused var warning and update typst reload test for short format
* fix: remove testing files
---
README.html | 963 ---------------------------------------
README.md | 4 +-
lua/preview/compiler.lua | 16 +-
spec/presets_spec.lua | 4 +-
4 files changed, 17 insertions(+), 970 deletions(-)
delete mode 100644 README.html
diff --git a/README.html b/README.html
deleted file mode 100644
index b6600fc..0000000
--- a/README.html
+++ /dev/null
@@ -1,963 +0,0 @@
-
-
-
-
-
-
- README
-
-
-
-
-preview.nvim
-Universal document previewer for Neovim
-An extensible framework for compiling and previewing any
-documents (LaTeX, Typst, Markdown, etc.)—diagnostics included.
-Features
-
-- Async compilation via
vim.system()
-- Built-in presets for Typst, LaTeX (latexmk, pdflatex, tectonic),
-Markdown, GitHub-flavored Markdown, AsciiDoc, and Quarto
-- Compiler errors as native
vim.diagnostic
-- User events for extensibility (
PreviewCompileStarted,
-PreviewCompileSuccess,
-PreviewCompileFailed)
-
-Requirements
-
-Installation
-Install with your package manager of choice or via luarocks:
-luarocks install preview.nvim
-Documentation
-:help preview.nvim
-FAQ
-Q: How do I define a custom provider?
-require('preview').setup({
- rst = {
- cmd = { 'rst2html' },
- args = function(ctx)
- return { ctx.file, ctx.output }
- end,
- output = function(ctx)
- return ctx.file:gsub('%.rst$', '.html')
- end,
- },
-})
-Q: How do I override a preset?
-require('preview').setup({
- typst = { env = { TYPST_FONT_PATHS = '/usr/share/fonts' } },
-})
-Q: How do I automatically open the output file?
-Set open = true on your provider (all built-in presets
-have this enabled) to open the output with vim.ui.open()
-after the first successful compilation in toggle/watch mode. For a
-specific application, pass a command table:
-require('preview').setup({
- typst = { open = { 'sioyek', '--new-instance' } },
-})
-
-
-
diff --git a/README.md b/README.md
index 286e1ac..18bc192 100644
--- a/README.md
+++ b/README.md
@@ -2,8 +2,8 @@
**Universal document previewer for Neovim**
-An extensible framework for compiling and previewing *any* documents (LaTeX, Typst,
-Markdown, etc.)—diagnostics included.
+An extensible framework for compiling and previewing _any_ documents (LaTeX,
+Typst, Markdown, etc.)—diagnostics included.
## Features
diff --git a/lua/preview/compiler.lua b/lua/preview/compiler.lua
index 3f897ad..a3b9c47 100644
--- a/lua/preview/compiler.lua
+++ b/lua/preview/compiler.lua
@@ -150,7 +150,7 @@ function M.compile(bufnr, name, provider, ctx, opts)
{
cwd = cwd,
env = provider.env,
- stderr = vim.schedule_wrap(function(err, data)
+ stderr = vim.schedule_wrap(function(_err, data)
if not data or not vim.api.nvim_buf_is_valid(bufnr) then
return
end
@@ -177,7 +177,9 @@ function M.compile(bufnr, name, provider, ctx, opts)
})
end
vim.fn.setqflist(items, 'r')
- vim.cmd('copen')
+ local win = vim.fn.win_getid()
+ vim.cmd.cwindow()
+ vim.fn.win_gotoid(win)
end
end
end
@@ -215,7 +217,9 @@ function M.compile(bufnr, name, provider, ctx, opts)
})
end
vim.fn.setqflist(items, 'r')
- vim.cmd('copen')
+ local win = vim.fn.win_getid()
+ vim.cmd.cwindow()
+ vim.fn.win_gotoid(win)
end
end
end
@@ -270,6 +274,7 @@ function M.compile(bufnr, name, provider, ctx, opts)
diagnostic.clear(bufnr)
elseif errors_mode == 'quickfix' then
vim.fn.setqflist({}, 'r')
+ vim.cmd.cwindow()
end
do_open(bufnr, output_file, provider.open)
opened[bufnr] = true
@@ -331,6 +336,7 @@ function M.compile(bufnr, name, provider, ctx, opts)
diagnostic.clear(bufnr)
elseif errors_mode == 'quickfix' then
vim.fn.setqflist({}, 'r')
+ vim.cmd.cwindow()
end
vim.api.nvim_exec_autocmds('User', {
pattern = 'PreviewCompileSuccess',
@@ -372,7 +378,9 @@ function M.compile(bufnr, name, provider, ctx, opts)
})
end
vim.fn.setqflist(items, 'r')
- vim.cmd('copen')
+ local win = vim.fn.win_getid()
+ vim.cmd.cwindow()
+ vim.fn.win_gotoid(win)
end
end
end
diff --git a/spec/presets_spec.lua b/spec/presets_spec.lua
index 2a63d18..2160dfa 100644
--- a/spec/presets_spec.lua
+++ b/spec/presets_spec.lua
@@ -50,7 +50,9 @@ describe('presets', function()
assert.is_table(result)
assert.are.equal('typst', result[1])
assert.are.equal('watch', result[2])
- assert.are.equal(ctx.file, result[3])
+ assert.are.equal('--diagnostic-format', result[3])
+ assert.are.equal('short', result[4])
+ assert.are.equal(ctx.file, result[5])
end)
it('parses errors from stderr', function()