fix: open correct pdf file when previewing from nvim
This commit is contained in:
parent
dc84e6baf0
commit
d7a183d95b
@ -3,14 +3,20 @@ local M = {}
|
||||
local pdf_viewer_pid = 0
|
||||
|
||||
local compile = function(file)
|
||||
vim.fn.jobstart({ "compiledoc", file }, {
|
||||
return vim.fn.jobstart({ "compiledoc", file }, {
|
||||
on_exit = function() print("Finished compiling.") end
|
||||
})
|
||||
end
|
||||
|
||||
local file_exists = function(name)
|
||||
local f=io.open(name,"r")
|
||||
if f~=nil then io.close(f) return true else return false end
|
||||
end
|
||||
|
||||
|
||||
M.open_document_preview = function()
|
||||
local filename = vim.api.nvim_buf_get_name(0)
|
||||
compile(filename)
|
||||
local compile_job = compile(filename)
|
||||
|
||||
vim.api.nvim_create_augroup("compileDoc", {})
|
||||
|
||||
@ -21,6 +27,17 @@ M.open_document_preview = function()
|
||||
})
|
||||
|
||||
local pdf_filename = string.gsub(filename, "%..+$", ".pdf")
|
||||
|
||||
vim.fn.jobwait({compile_job})
|
||||
|
||||
if not file_exists(pdf_filename) then
|
||||
local scan = require'plenary.scandir'
|
||||
local build_dir = scan.scan_dir({ '.', '..' }, { depth = 1, add_dirs = true, search_pattern = 'build' })
|
||||
local result = scan.scan_dir(build_dir[1], { depth = 3, search_pattern = ".*%.pdf" })
|
||||
|
||||
pdf_filename = result[1]
|
||||
end
|
||||
|
||||
pdf_viewer_pid = vim.fn.jobstart({ "zathura", pdf_filename })
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user