feat: live preview for plantuml documents
This commit is contained in:
parent
045de7a918
commit
af0739e297
@ -94,8 +94,8 @@ autocmd({ 'BufNewFile', 'BufRead' }, {
|
||||
})
|
||||
|
||||
autocmd({ 'BufNewFile', 'BufRead' }, {
|
||||
desc = 'When editing .md and .tex files, register commands for live preview',
|
||||
pattern = { '*.md', '*.tex' },
|
||||
desc = 'When editing compileable documents, register commands for live preview',
|
||||
pattern = { '*.md', '*.tex', '*.puml' },
|
||||
callback = function()
|
||||
buf_map(0, 'n', '<leader>p', '<cmd>lua require("compileDoc").open_document_preview()<CR>', { noremap = true })
|
||||
buf_map(0, 'n', '<leader>P', '<cmd>lua require("compileDoc").close_document_preview()<CR>', { noremap = true })
|
||||
|
@ -1,6 +1,6 @@
|
||||
local M = {}
|
||||
|
||||
local pdf_viewer_pid = 0
|
||||
local output_viewer_pid = 0
|
||||
|
||||
local compile = function(file)
|
||||
return vim.fn.jobstart({ "compiledoc", file }, {
|
||||
@ -24,29 +24,40 @@ M.open_document_preview = function()
|
||||
|
||||
vim.api.nvim_create_autocmd("BufWritePost", {
|
||||
group = "compileDoc",
|
||||
pattern = { "*.tex", "*.md" },
|
||||
pattern = { "*.tex", "*.md", "*.puml" },
|
||||
callback = function() compile(filename) end
|
||||
})
|
||||
|
||||
local pdf_filename = string.gsub(filename, "%..+$", ".pdf")
|
||||
local output_file_extension
|
||||
local output_file_viewer
|
||||
|
||||
if string.match(filename, "%.tex$") or string.match(filename, "%.md") then
|
||||
output_file_extension = ".pdf"
|
||||
output_file_viewer = "zathura"
|
||||
elseif string.match(filename, "%.puml$") then
|
||||
output_file_extension = ".png"
|
||||
output_file_viewer = "feh"
|
||||
end
|
||||
|
||||
local output_filename = string.gsub(filename, "%..+$", output_file_extension)
|
||||
|
||||
vim.fn.jobwait({compile_job})
|
||||
|
||||
if not file_exists(pdf_filename) then
|
||||
if not file_exists(output_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]
|
||||
output_filename = result[1]
|
||||
end
|
||||
|
||||
pdf_viewer_pid = vim.fn.jobstart({ "zathura", pdf_filename })
|
||||
output_viewer_pid = vim.fn.jobstart({ output_file_viewer, output_filename })
|
||||
end
|
||||
|
||||
M.close_document_preview = function()
|
||||
vim.api.nvim_del_augroup_by_name("compileDoc")
|
||||
if (pdf_viewer_pid ~= 0) then
|
||||
vim.fn.jobstop(pdf_viewer_pid)
|
||||
if (output_viewer_pid ~= 0) then
|
||||
vim.fn.jobstop(output_viewer_pid)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -33,4 +33,5 @@ case "$ext" in
|
||||
--include-in-header ~/.local/bin/inline_code.tex \
|
||||
-o "$base".pdf "$file" ;;
|
||||
tex) compile_tex ;;
|
||||
puml) plantuml "$file" ;;
|
||||
esac
|
||||
|
@ -7,6 +7,8 @@
|
||||
- ttf-liberation
|
||||
- maim
|
||||
- xdotool
|
||||
- plantuml
|
||||
- graphviz
|
||||
state: present
|
||||
become: true
|
||||
tags: [pc, setup]
|
||||
|
Loading…
Reference in New Issue
Block a user