Tree Sitter support for Typst. Minimum Emacs version requirement: 29.
Discussion on Zulip
Tickets: Issues, feature requests, etc.
Announce Announcements. Subscribe to it to receive the latest news for typst-ts-mode
.
Send a Patch
-
Emacs >= 29
-
Latest Typst.
typst 0.10.0 (70ca0d25)
-
Tree Sitter grammar for Typst: https://github.com/uben0/tree-sitter-typst
commit:3c3e5f8e0caeba6157e26a1bedf8321e1da62799 - Feb 28, 2024
To install the grammar, you can execute the following elisp code:(add-to-list 'treesit-language-source-alist '(typst "https://github.com/uben0/tree-sitter-typst")) (treesit-install-language-grammar 'typst)
Note there are also tree sitter modules, treesit-auto and treesit-langs for you to easily manage your tree sitter modes and grammars.
Example configuration.
(use-package typst-ts-mode
:ensure (:type git :host sourcehut :repo "meow_king/typst-ts-mode" :files (:defaults "*.el"))
:custom
;; don't add "--open" if you'd like `watch` to be an error detector
(typst-ts-mode-watch-options "--open")
;; experimental settings (I'm the main dev, so I enable these)
(typst-ts-mode-enable-raw-blocks-highlight t)
(typst-ts-mode-highlight-raw-blocks-at-startup t))
C-c C-c c : typst-ts-compile-and-preview
C-c C-c C : typst-ts-compile
C-c C-c w : typst-ts-watch-mode
C-c C-c p : typst-ts-mode-preview
M- : typst-ts-mode-heading-decrease
M- : typst-ts-mode-heading-increase
M- : typst-ts-mode-heading-up
M- : typst-ts-mode-heading-down
M-: typst-ts-mode-meta-return
: typst-ts-mode-return
TAB : typst-ts-mode-cycle
NOTE: outline-minor-mode
is enabled by typst-ts-mode
, so you can use command
defined by outline-minor-mode
such as outline-cycle
.
For customizable options: customize
-> typst-ts
.
Here are some options you may find useful:
- typst-ts-mode-indent-offset (default 4)
Use outline-indent-mode to behave likeorg-indent-mode
. - typst-ts-compile-executable-location
- typst-ts-watch-options.
Set this to--open
so typst will open the compiled file for you. - typst-ts-compile-options.
Note that setting--open
has no use for this customization variable. You can execute the shell commandtypst compile <file> --open && sleep 1
to view what is happening. - typst-ts-watch-auto-display-compilation-error. (default
t
)
so thetypst watch
process buffer appear when an error occurs, and disappear when there is no error. You may find sometimes there is only one error at a time, and it is because Typst itself do this style. You may findauto-save-visited-mode
, auto-save or super-save useful (or annoying). - typst-ts-compile-before-compilation-hook and typst-ts-compile-after-compilation-hook
- typst-ts-mode-return-autoincrement autoincrement lists when pressing RETURN (default
t
). - typst-ts-mode-grammar-location: used for grammar version check (may not be accurate every time)
- typst-ts-mode-fontification-precise-level (default
'middle
)
Available values:min
,middle
andmax
. Different level affects the precision of the fontification. For example,- item
, we may fontify the whole expression using one face, or two faces. Note it is related to the performance of fontification process, especially the first fontification process (when you open the file). - typst-ts-markup-header-same-height and typst-ts-markup-header-scale
Control header height. Note that it only works when typst-ts-mode-fontification-precise-level is set tomax
. - Override default font lock rules
Please see the documentation of typst-ts-mode-font-lock-rules, you can find how to override the whole font lock rules or only small part of the font lock rules.
This is an experimental feature
Note: currently only support Emacs 30 (master branch). But non-treesit font lock for raw block feature will be added soon (both 29 and 30).
Only support tree-sitter languages.
For more detailed documentation about raw block highlighting see
this documentation
- typst-ts-mode-enable-raw-blocks-highlight (default
nil
) - typst-ts-mode-highlight-raw-blocks-at-startup (default
nil
) - typst-ts-highlight-raw-block-langs-not-in-predefined-settings (default
t
)
If you use consult-iemnu
command consult, you way want this setting.
(setq
consult-imenu-config
(append consult-imenu-config
'((typst-ts-mode :topLevel "Headings" :types
((?h "Headings" typst-ts-markup-header-face)
(?f "Functions" font-lock-function-name-face))))))
- please work on
develop
branch, which will be combined intomain
branch every one week or so.
Here are some resources:
- Let’s Write a Tree-Sitter Major Mode - Matering Emacs
- ts-query-highlight
I wrote this package to highlight tree sitter queries. I use this package to help developingtypst-ts-mode
. - combobulate