mzte-nv: implement TypstWatch command

This commit is contained in:
LordMZTE 2024-11-15 16:10:55 +01:00
parent 95754797ec
commit 595680ef81
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
2 changed files with 19 additions and 1 deletions

View file

@ -1,3 +1,21 @@
;; Use 2-space indentation for typst
(set vim.o.shiftwidth 2)
(set vim.o.tabstop 2)
(let [cb (fn [p]
(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))
root ((lspc-util.root_pattern :.typstroot) file)
term (Terminal:new {:direction :horizontal
:cmd (if root
(.. "typst watch --root " root
" " file " " outfile)
(.. "typst watch " file " "
outfile))})]
(term:toggle)
(vim.uv.spawn :zathura {:args [outfile]}
(fn [code signal] (term:shutdown)))))]
(vim.api.nvim_create_user_command :TypstWatch cb {:nargs 0}))

View file

@ -1,3 +1,3 @@
(local tterm (require :toggleterm))
(tterm.setup {:size 64 :open_mapping :<C-t> :direction :vertical})
(tterm.setup {:open_mapping :<C-t> :direction :vertical})