Public Access
pdfs
This commit is contained in:
1 parent
b9a4bb8dda
commit
f707596a5a
2 files changed
+32
No files matched your search
+31
@@ -0,0 +1,31 @@
|
||||
-- PDF reader: Snacks.image already renders a PDF buffer (page 1) via
|
||||
-- magick/gs in Ghostty. This adds page turning on top of it.
|
||||
-- Open from Oil with <CR> like any file. In a PDF buffer:
|
||||
-- n / N next / previous page {n}gp go to page n (gp = last page)
|
||||
local function page_count(file)
|
||||
local out = vim.fn.system({ "pdfinfo", file })
|
||||
return tonumber(out:match("Pages:%s*(%d+)")) or 1
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd("BufReadCmd", {
|
||||
pattern = "*.pdf",
|
||||
callback = function(ev)
|
||||
local buf, file = ev.buf, vim.api.nvim_buf_get_name(ev.buf)
|
||||
local pages, page = page_count(file), 1
|
||||
|
||||
local function show(n)
|
||||
page = math.max(1, math.min(pages, n))
|
||||
require("snacks.image.buf").attach(buf, { src = file .. "#page=" .. page })
|
||||
vim.wo.statusline = ("%%f [%d/%d]"):format(page, pages)
|
||||
end
|
||||
|
||||
vim.wo.statusline = ("%%f [1/%d]"):format(pages)
|
||||
|
||||
local function map(lhs, fn, desc)
|
||||
vim.keymap.set("n", lhs, fn, { buffer = buf, desc = "PDF: " .. desc })
|
||||
end
|
||||
map("n", function() show(page + vim.v.count1) end, "next page")
|
||||
map("N", function() show(page - vim.v.count1) end, "previous page")
|
||||
map("gp", function() show(vim.v.count > 0 and vim.v.count or pages) end, "go to page (last if no count)")
|
||||
end,
|
||||
})
|
||||
Reference in new issue
Block a user