mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-12-05 03:22:32 +01:00
mzte-nv: TypstWatch: use fs events instead of timer to open viewer
This commit is contained in:
parent
33e82ac1ac
commit
96a83236f4
1 changed files with 12 additions and 11 deletions
|
@ -6,8 +6,8 @@
|
|||
(let [Terminal (. (require :toggleterm.terminal) :Terminal)
|
||||
lspc-util (require :lspconfig.util)
|
||||
file (vim.api.nvim_buf_get_name 0)
|
||||
outfile (.. :/tmp/
|
||||
(string.gsub (vim.fs.basename file) "%.typ$" :.pdf))
|
||||
outfile-base (string.gsub (vim.fs.basename file) "%.typ$" :.pdf)
|
||||
outfile (.. :/tmp/ outfile-base)
|
||||
root ((lspc-util.root_pattern :.typstroot) file)
|
||||
term (Terminal:new {:direction :horizontal
|
||||
:cmd (if root
|
||||
|
@ -15,13 +15,14 @@
|
|||
" " file " " outfile)
|
||||
(.. "typst watch " file " "
|
||||
outfile))})
|
||||
viewer-timer (vim.uv.new_timer)]
|
||||
(term:open)
|
||||
(viewer-timer:start 2000 0
|
||||
(fn []
|
||||
(viewer-timer:stop)
|
||||
(viewer-timer:close)
|
||||
fsev (vim.uv.new_fs_event)
|
||||
on-file-appear (fn [err file events]
|
||||
(when (and (not err) (= file outfile-base))
|
||||
(print :open)
|
||||
(fsev:stop)
|
||||
(vim.uv.spawn :zathura {:args [outfile]}
|
||||
(fn [code signal]
|
||||
(vim.schedule #(term:shutdown))))))))]
|
||||
(vim.schedule #(term:shutdown))))))]
|
||||
(fsev:start :/tmp {} on-file-appear)
|
||||
(term:open)))]
|
||||
(vim.api.nvim_create_user_command :TypstWatch cb {:nargs 0}))
|
||||
|
|
Loading…
Reference in a new issue