Eglot extension for tinymist
- Emacs Lisp 100%
| eglot-tinymist.el | ||
| LICENSE | ||
| README.org | ||
A set of action for tinymist preview using eglot
This is an attempt to extend eglot to provide some extra support for the tinymist lsp server
Especially I was interested in:

Vanilla Emacs
Here is basically how I am using this package
(use-package eglot-tinymist
:vc (:url "https://codeberg.org/Rathur421/eglot-tinymist")
:after (eglot typst-ts-mode)
:config
;; Register the tinymist LSP server for typst-ts-mode
(add-to-list 'eglot-server-programs
`((typst-ts-mode :language-id "typst")
. ("tinymist" "lsp")))
;; Ensure Eglot starts when typst-ts-mode is entered
(add-hook 'typst-ts-mode-hook #'eglot-ensure)
;; Auto-pin the main file after starting a preview
(advice-add 'eglot-tinymist-start-default-preview :after #'eglot-tinymist-auto-pin-main)
;; Keybindings in typst-ts-mode-map (local leader style)
(define-key typst-ts-mode-map (kbd "C-c p") #'eglot-tinymist-pin-main)
(define-key typst-ts-mode-map (kbd "C-c P") #'eglot-tinymist-auto-pin-main)
(define-key typst-ts-mode-map (kbd "C-c S") #'eglot-tinymist-start-default-preview)
(define-key typst-ts-mode-map (kbd "C-c s") #'eglot-tinymist-scroll-preview)
;; Scroll preview automatically after saving
(add-hook 'typst-ts-mode-hook
(lambda ()
(add-hook 'after-save-hook #'eglot-tinymist-scroll-preview nil t))))
DOOM
I am personnaly using Doomemacs so I do the following
In packages.el
(package! eglot-tinymist
:recipe (:host codeberg :repo "Rathur421/eglot-tinymist"))
In config.el
(use-package! eglot-tinymist
:after typst-ts-mode
:config
(add-to-list 'eglot-server-programs
`((typst-ts-mode :language-id "typst")
. ("tinymist" "lsp")))
(add-hook 'typst-ts-mode-hook #'eglot-ensure)
(advice-add 'eglot-tinymist-start-default-preview :after #'eglot-tinymist-auto-pin-main)
(map! :map typst-ts-mode-map
:localleader
:desc "Pin Current as main" "p" #'eglot-tinymist-pin-main
:desc "Pin Current as main" "P" #'eglot-tinymist-auto-pin-main
:desc "Start preview" "S" #'eglot-tinymist-start-default-preview
:desc "scroll preview" "s" #'eglot-tinymist-scroll-preview)
(add-hook! typst-ts-mode
(defun scroll-preview-on-save ()
(add-hook 'after-save-hook #'eglot-tinymist-scroll-preview nil t))))
Configuration
Just put the following in your .dir-locals.el
((typst-ts-mode . ((eglot-workspace-configuration ;; see more info https://myriad-dreamin.github.io/tinymist/config/neovim.html
. (:preview (:browsing (:args ["--data-plane-host=127.0.0.1:23635"
"--open"])
:invertColors "never")))))))
My basic workflow
-
eglot-tinymist-pin-main<<multiple-file>>- Pin your main file when you use multiple files
- Use it with a prefix argument to choose which file to choose
-
eglot-tinymist-start-default-preview<<preview-support>>- Start the default preview process.
-
eglot-tinymist-scroll-preview- Scroll preview to be at editor position
I'm not sure what some good keybindings for those commands could be, so I didn't add any by default.
Stuff leftover (for now):
Here's what I would like to see but that I don't know when I'll make it (or if I'll make it at all). If you want to see it sooner, make a PR!
- How to support config via
eglot-workspace-configuration -
A minor mode to handle
- auto-pin on preview
- scroll on save
- mode-map
- Better detection to ensure we are using tinymist server and not another lsp?
- Publish to MELPA/ELPA or whatever
-
export commands:
- request
- notification
-
Preview status:
- simple message
- progress indicator in the mode bar?