Eglot extension for tinymist
  • Emacs Lisp 100%
Find a file
2026-07-16 01:05:42 +02:00
eglot-tinymist.el fix: auto-pin-main: 'Wrong type argument: stringp, nil' 2026-07-15 17:11:45 -04:00
LICENSE doc: add LICENSE 2026-01-11 20:47:54 +01:00
README.org docs: mandatory gif 2026-07-14 12:17:38 +02:00

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:

  1. multiple file project
  2. preview support

https://codeberg.org/Rathur421/eglot-tinymist/raw/branch/assets/output.gif

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

  1. eglot-tinymist-pin-main <<multiple-file>>

    1. Pin your main file when you use multiple files
    2. Use it with a prefix argument to choose which file to choose
  2. eglot-tinymist-start-default-preview <<preview-support>>

    1. Start the default preview process.
  3. eglot-tinymist-scroll-preview

    1. 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!

  1. How to support config via eglot-workspace-configuration
  2. A minor mode to handle

    • auto-pin on preview
    • scroll on save
    • mode-map
  3. Better detection to ensure we are using tinymist server and not another lsp?
  4. Publish to MELPA/ELPA or whatever
  5. export commands:

    1. request
    2. notification
  6. Preview status:

    1. simple message
    2. progress indicator in the mode bar?