fix: fall back to /tmp for buffers without a backing file (#60)

* fix: fall back to /tmp for buffers without a backing file

Problem: markdown and gfm presets fail when the buffer has no file on
disk (e.g. unnamed buffer with `ft=markdown`, or a named buffer whose
path doesn't exist yet) because `build_context` passes a nonexistent
path to pandoc and `compile` guards reject empty buffer names.

Solution: `build_context` now detects missing files and redirects
`ctx.file` to `/tmp/{bufnr}-{name}`. `compile` writes buffer contents
to that temp path via `vim.fn.writefile` instead of `:silent! update`.

* test: update unnamed buffer tests for tmpfile fallback

Problem: the unnamed buffer guard tests expected a "no file name"
warning that no longer exists after the tmpfile fallback change.

Solution: update assertions to expect the downstream messages that
unnamed buffers now reach ("no provider configured", "no output file").
This commit is contained in:
Barrett Ruth 2026-03-13 08:22:45 -04:00 committed by GitHub
parent 272153a158
commit f185ae78f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 48 additions and 32 deletions

View file

@ -215,8 +215,14 @@ function M.compile(bufnr, name, provider, ctx, opts)
return
end
if vim.bo[bufnr].modified then
vim.cmd('silent! update')
local buf_file = vim.api.nvim_buf_get_name(bufnr)
if buf_file ~= '' and buf_file == ctx.file then
if vim.bo[bufnr].modified then
vim.cmd('silent! update')
end
else
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
vim.fn.writefile(lines, ctx.file)
end
local s = get_state(bufnr)