No description
Find a file
Barrett Ruth e661ea78e8
fix(reload): bind SSE server to port 0 for OS-assigned port (#21)
Problem: the SSE reload server hardcoded port 5554, causing silent
failure when that port was already in use. bind() would fail but its
return value was never checked; listen() would also error and silently
drop via the if err then return end guard. inject() still wrote the
dead EventSource URL into the HTML, so the browser would connect to
whatever was on 5554 — or nothing — and live reload would silently
stop working.

Solution: bind to port or 0 so the OS assigns a free port, then call
getsockname() after bind to capture the actual port into actual_port.
inject() reads actual_port in preference to the hardcoded constant,
and stop() resets it. PORT = 5554 is kept only as a last-resort
fallback in inject() if actual_port is unset.
2026-03-03 17:46:04 -05:00
.github/workflows ci: format 2026-03-01 17:22:59 -05:00
doc docs: update help file for recent additions (#18) 2026-03-03 15:12:28 -05:00
lua/preview fix(reload): bind SSE server to port 0 for OS-assigned port (#21) 2026-03-03 17:46:04 -05:00
plugin feat: rename 2026-03-02 21:23:40 -05:00
spec feat: unified reload field for live-preview (SSE + long-running watch) (#19) 2026-03-03 16:41:47 -05:00
.busted ci: format 2026-03-01 17:22:59 -05:00
.editorconfig ci: format 2026-03-01 17:22:59 -05:00
.gitignore ci: format 2026-03-01 17:22:59 -05:00
.luarc.json ci: format 2026-03-01 17:22:59 -05:00
.prettierrc ci: format 2026-03-01 17:22:59 -05:00
flake.lock ci: format 2026-03-01 17:22:59 -05:00
flake.nix feat: rename 2026-03-02 21:23:40 -05:00
LICENSE ci: format 2026-03-01 17:22:59 -05:00
preview.nvim-scm-1.rockspec feat: rename 2026-03-02 21:23:40 -05:00
README.md doc: cleanup readme 2026-03-03 13:44:43 -05:00
selene.toml ci: format 2026-03-01 17:25:34 -05:00
stylua.toml ci: format 2026-03-01 17:22:59 -05:00
vim.yaml ci: format 2026-03-01 17:22:59 -05:00

preview.nvim

Async document compilation for Neovim

An extensible framework for compiling documents (LaTeX, Typst, Markdown, etc.) asynchronously with error diagnostics.

Features

  • Async compilation via vim.system()
  • Built-in presets for Typst, LaTeX, Markdown, and GitHub-flavored Markdown
  • Compiler errors as native vim.diagnostic
  • User events for extensibility (PreviewCompileStarted, PreviewCompileSuccess, PreviewCompileFailed)

Requirements

  • Neovim 0.11+

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({
  typst = {
    cmd = { 'typst', 'compile' },
    args = function(ctx)
      return { ctx.file }
    end,
    output = function(ctx)
      return ctx.file:gsub('%.typ$', '.pdf')
    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. For a specific application, pass a command table:

require('preview').setup({
  typst = { open = { 'sioyek', '--new-instance' } },
})