branch: elpa/typst-ts-mode
commit f5797e219b3f8735b5e6e5796cdc88bc8f17b593
Author: Meow King <mr.meowk...@anche.no>
Commit: Meow King <mr.meowk...@anche.no>

    refactor: introduce different level of fontification to address performance 
issue
---
 README.md        |  56 ++++---
 typst-ts-mode.el | 466 ++++++++++++++++++++++++++++++++++++-------------------
 2 files changed, 340 insertions(+), 182 deletions(-)

diff --git a/README.md b/README.md
index d7bac446e4..043df9e45a 100644
--- a/README.md
+++ b/README.md
@@ -67,7 +67,9 @@ For reference, this is my configuration.
 (use-package typst-ts-mode
   :elpaca (:type git :host sourcehut :repo "meow_king/typst-ts-mode")
   :custom
-  (typst-ts-mode-watch-options "--open"))
+  (typst-ts-mode-watch-options "--open")
+  (typst-ts-mode-enable-raw-blocks-highlight t)
+  (typst-ts-mode-highlight-raw-blocks-at-startup t))
 ```
 
 ## Keys
@@ -87,28 +89,42 @@ defined by `outline-minor-mode` such as `outline-cycle`.
 
 ## Customization Options
 
-`customize` -> `typst-ts`
-
-For some options you may find useful:
-1. `typst-ts-mode-indent-offset`
-2. `typst-ts-mode-executable-location`
-3. `typst-ts-mode-watch-options`. Set this to `--open` so typst will open the 
compiled
-file for you.
-4. `typst-ts-mode-compile-options`. Note that setting `--open` has no use for 
this
-customization variable. You can execute the shell command 
-`typst compile <file> --open && sleep 1` to view what is happening. 
-5. `typst-ts-mode-display-watch-process-bufer-automatically`. This is set to 
`t` by
-default, so the `typst 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 find `auto-save-visited-mode`,
-[auto-save](https://github.com/manateelazycat/auto-save) or 
-[super-save](https://github.com/bbatsov/super-save) useful (or annoying).
-6. `typst-ts-markup-header-same-height` and `typst-ts-markup-header-scale` to 
control header height. 
-7. `typst-ts-mode-before-compile-hook` and `typst-ts-mode-after-compile-hook`
+For customizable options: `customize` -> `typst-ts`.  
+
+Here are some options you may find useful:  
+1. `typst-ts-mode-indent-offset` (default 4)  
+2. `typst-ts-mode-executable-location`  
+3. `typst-ts-mode-watch-options`.  
+   Set this to `--open` so typst will open the compiled file for you.
+4. `typst-ts-mode-compile-options`.  
+   Note that setting `--open` has no use for this customization variable. 
+   You can execute the shell command `typst compile <file> --open && sleep 1`
+   to view what is happening. 
+5. `typst-ts-mode-display-watch-process-bufer-automatically`. (default `t`)  
+   so the `typst 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 find `auto-save-visited-mode`,
+   [auto-save](https://github.com/manateelazycat/auto-save) or 
+   [super-save](https://github.com/bbatsov/super-save) useful (or annoying).
+6. `typst-ts-mode-before-compile-hook` and `typst-ts-mode-after-compile-hook`  
+
+### Fontification
+1. `typst-ts-mode-fontification-precise-level` (default `'middle`)  
+   Available values: `min`, `middle` and `max`. 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).  
+2. `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 to `max`.
+3. 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.
 
 ### Raw block highlighting
 Only support tree-sitter languages.  
-This is an experimental feature, so it is disabled by default.
 For more detailed documentation about raw block highlighting see 
 [this documentation](./doc/raw-block-highlighing.md)  
 1. `typst-ts-mode-enable-raw-blocks-highlight` (default `nil`)  
diff --git a/typst-ts-mode.el b/typst-ts-mode.el
index 0bf1ecfcbc..1e99976922 100644
--- a/typst-ts-mode.el
+++ b/typst-ts-mode.el
@@ -27,9 +27,6 @@
 
 ;; Tree Sitter Support for Typst
 
-;; TODO
-;; add more treesit settings at startup like `treesit-thing-settings'
-
 ;;; Code:
 
 (require 'treesit)
@@ -54,6 +51,17 @@
   :type 'integer
   :group 'typst-ts)
 
+(defcustom typst-ts-mode-fontification-precision-level 'middle
+  "Whether to use precise face fontification.
+Note that precise face fontification will case performance degrading.
+The performance degrading is mainly on the first load of the file.  Since
+treesit incrementally fontifys regions (IMO), the later editing experience 
won't
+be noticeably affected probably."
+  :type '(choice (const :tag "Minimum level" min)
+                 (const :tag "Middle level" middle)
+                 (const :tag "Maximum level" max))
+  :group 'typst-ts)
+
 ;; TODO currently set nil as default, since it still needs refinement
 (defcustom typst-ts-mode-enable-raw-blocks-highlight nil
   "Whether to enable raw block highlighting."
@@ -140,7 +148,9 @@ is eliminated."
   "Hook runs after compile.")
 
 (defcustom typst-ts-markup-header-same-height t
-  "Whether to make header face in markup context share the same height."
+  "Whether to make header face in markup context share the same height.
+Note it only works when user choose `max' level of fontification precision
+level.  See `typst-ts-mode-fontification-precision-level'."
   :type 'boolean
   :group 'typst-ts-faces)
 
@@ -280,29 +290,41 @@ is eliminated."
   "Face for strong."
   :group 'typst-ts-faces)
 
+(defface typst-ts-markup-item-face
+  '((t :inherit shadow))
+  "Face for whole term, use in min and middle fontification level.
+See `typst-ts-mode-fontification-precision-level'."
+  :group 'typst-ts-faces)
+
 (defface typst-ts-markup-item-indicator-face
   '((t :inherit shadow))
   "Face for item."
   :group 'typst-ts-faces)
 
-(defface typst-ts-markup-item-face
+(defface typst-ts-markup-item-text-face
   '((t :inherit default))
   "Face for item."
   :group 'typst-ts-faces)
 
+(defface typst-ts-markup-term-face
+  '((t :inherit shadow))
+  "Face for whole term, use in min and middle fontification level.
+See `typst-ts-mode-fontification-precision-level'."
+  :group 'typst-ts-faces)
+
 (defface typst-ts-markup-term-indicator-face
   '((t :inherit shadow))
-  "Face for term."
+  "Face for term indicator."
   :group 'typst-ts-faces)
 
 (defface typst-ts-markup-term-term-face
   '((t :inherit bold))
-  "Face for term."
+  "Face for term text."
   :group 'typst-ts-faces)
 
 (defface typst-ts-markup-term-description-face
   '((t :inherit italic))
-  "Face for term."
+  "Face for term description."
   :group 'typst-ts-faces)
 
 (defface typst-ts-markup-quote-face ;; TODO better choice?
@@ -326,10 +348,16 @@ is eliminated."
   :group 'typst-ts-faces)
 
 (defface typst-ts-markup-raw-blob-face
-  '((t :inherit fixed-pitch))
+  '((t :inherit shadow))
   "Face for rawblock and rawspan blob."
   :group 'typst-ts-faces)
 
+(defface typst-ts-markup-rawblock-face
+  '((t :inherit shadow))
+  "Face for whole raw block, use in min and middle fontification level.
+See `typst-ts-mode-fontification-precision-level'."
+  :group 'typst-ts-faces)
+
 (defface typst-ts-markup-rawblock-indicator-face
   '((t :inherit typst-ts-markup-raw-indicator-face))
   "Face for rawblock indicator."
@@ -345,6 +373,12 @@ is eliminated."
   "Face for rawblock blob."
   :group 'typst-ts-faces)
 
+(defface typst-ts-markup-rawspan-face
+  '((t :inherit shadow))
+  "Face for whole raw span, use in min and middle fontification level.
+See `typst-ts-mode-fontification-precision-level'."
+  :group 'typst-ts-faces)
+
 (defface typst-ts-markup-rawspan-indicator-face
   '((t :inherit typst-ts-markup-raw-indicator-face))
   "Face for rawspan indicator."
@@ -394,7 +428,7 @@ is eliminated."
 
 (defvar typst-ts-mode-font-lock-rules
   nil
-  "You can customize this variable to override the default font lock rules.
+  "You can customize this variable to override the whole default font lock 
rules.
 Like this:
 
 (setq typst-ts-mode-font-lock-rules
@@ -403,162 +437,271 @@ Like this:
          \='(
            :language typst
            :type custom
-           ((el-psy-kongaroo) @el-psy-kongaroo))))")
+           ((el-psy-kongaroo) @el-psy-kongaroo))))
+
+However, if you only want to modify specific part of the font lock rules, 
please
+customize variables starts with `typst-ts-mode-font-lock-rules-'.  The trailing
+part of the name is in the `typst-ts-mode-font-lock-feature-list'.
+
+BTW, if you want to enable/disable specific font lock feature, please change
+`treesit-font-lock-level' or modify `typst-ts-mode-font-lock-feature-list'.")
+
+(defvar typst-ts-mode-font-lock-rules-comment nil
+  "See variable `typst-ts-mode-font-lock-rules'.")
+
+(defvar typst-ts-mode-font-lock-rules-common nil
+  "See variable `typst-ts-mode-font-lock-rules'.")
+
+(defvar typst-ts-mode-font-lock-rules-markup-basic nil
+  "See variable `typst-ts-mode-font-lock-rules'.")
+
+(defvar typst-ts-mode-font-lock-rules-code-basic nil
+  "See variable `typst-ts-mode-font-lock-rules'.")
+
+(defvar typst-ts-mode-font-lock-rules-math-basic nil
+  "See variable `typst-ts-mode-font-lock-rules'.")
+
+(defvar typst-ts-mode-font-lock-rules-markup-standard nil
+  "See variable `typst-ts-mode-font-lock-rules'.")
+
+(defvar typst-ts-mode-font-lock-rules-code-standard nil
+  "See variable `typst-ts-mode-font-lock-rules'.")
+
+(defvar typst-ts-mode-font-lock-rules-math-standard nil
+  "See variable `typst-ts-mode-font-lock-rules'.")
+
+(defvar typst-ts-mode-font-lock-rules-markup-extended nil
+  "See variable `typst-ts-mode-font-lock-rules'.")
+
+(defvar typst-ts-mode-font-lock-rules-code-extended nil
+  "See variable `typst-ts-mode-font-lock-rules'.")
+
+(defvar typst-ts-mode-font-lock-rules-math-extended nil
+  "See variable `typst-ts-mode-font-lock-rules'.")
 
 (defun typst-ts-mode-font-lock-rules ()
   "Generate font lock rules for `treesit-font-lock-rules'.
 If you want to customize the rules, please customize the same name variable
 `typst-ts-mode-font-lock-rules'."
-  `(;; Typst font locking
-    :language typst
-    :feature comment
-    ((comment) @font-lock-comment-face)
-
-    :language typst
-    :feature common
-    ((shorthand) @typst-ts-shorthand-face
-     (ERROR) @typst-ts-error-face)
-
-    :language typst
-    :feature markup-basic
-    (,@(if typst-ts-markup-header-same-height
-           '((heading "=" @typst-ts-markup-header-indicator-face
-                      (text) @typst-ts-markup-header-face)
-             (heading "==" @typst-ts-markup-header-indicator-face
-                      (text) @typst-ts-markup-header-face)
-             (heading "===" @typst-ts-markup-header-indicator-face
-                      (text) @typst-ts-markup-header-face)
-             (heading "====" @typst-ts-markup-header-indicator-face
-                      (text) @typst-ts-markup-header-face)
-             (heading "=====" @typst-ts-markup-header-indicator-face
-                      (text) @typst-ts-markup-header-face)
-             (heading "======" @typst-ts-markup-header-indicator-face
-                      (text) @typst-ts-markup-header-face))
-         '((heading "=" @typst-ts-markup-header-indicator-face-1
-                    (text) @typst-ts-markup-header-face-1)
-           (heading "==" @typst-ts-markup-header-indicator-face-2
-                    (text) @typst-ts-markup-header-face-2)
-           (heading "===" @typst-ts-markup-header-indicator-face-3
-                    (text) @typst-ts-markup-header-face-3)
-           (heading "====" @typst-ts-markup-header-indicator-face-4
-                    (text) @typst-ts-markup-header-face-4)
-           (heading "=====" @typst-ts-markup-header-indicator-face-5
-                    (text) @typst-ts-markup-header-face-5)
-           (heading "======" @typst-ts-markup-header-indicator-face-6
-                    (text) @typst-ts-markup-header-face-6)))
-     (emph
-      "_" @typst-ts-markup-emphasis-indicator-face
-      (text) @typst-ts-markup-emphasis-face
-      "_" @typst-ts-markup-emphasis-indicator-face)
-     (strong
-      "*" @typst-ts-markup-strong-indicator-face
-      (text) @typst-ts-markup-strong-face
-      "*" @typst-ts-markup-strong-indicator-face)
-     (item
-      "-" @typst-ts-markup-item-indicator-face
-      (text) @typst-ts-markup-item-face)
-     (term
-      "/" @typst-ts-markup-term-indicator-face
-      term: (text) @typst-ts-markup-term-term-face
-      ":" @typst-ts-markup-term-indicator-face
-      (text) @typst-ts-markup-term-description-face)
-     (escape) @typst-ts-markup-escape-face
-     (raw_span
-      "`" @typst-ts-markup-rawspan-indicator-face
-      (blob) @typst-ts-markup-rawspan-blob-face
-      "`" @typst-ts-markup-rawspan-indicator-face)
-     (raw_blck
-      "```" @typst-ts-markup-rawblock-indicator-face
-      (ident) :? @typst-ts-markup-rawblock-lang-face
-      ;; NOTE let embedded language fontify blob
-      ,@(if typst-ts-mode-enable-raw-blocks-highlight
-            '((blob))
-          '((blob) @typst-ts-markup-rawblock-blob-face))
-      "```" @typst-ts-markup-rawblock-indicator-face)
-     (label) @typst-ts-markup-label-face ;; TODO more precise highlight 
(upstream)
-     (ref) @typst-ts-markup-reference-face)
-
-    :language typst
-    :feature markup-standard
-    ((linebreak) @typst-ts-markup-linebreak-face
-     (quote) @typst-ts-markup-quote-face)
-
-    :language typst
-    :feature markup-extended
-    ((url) @typst-ts-markup-url-face)
-
-
-    ;; please note that some feature there also in the math mode
-    :language typst
-    :feature code-basic
-    ("#" @typst-ts-code-indicator-face
-     ;; "end" @typst-ts-code-indicator-face ;; "end" is nothing but only a 
indicator
-     (string) @font-lock-string-face
-     (bool) @font-lock-constant-face
-     (none) @font-lock-constant-face
-     (auto) @font-lock-constant-face
-
-     (in ["in" "not"] @font-lock-keyword-face)
-     (and "and" @font-lock-keyword-face)
-     (or "or" @font-lock-keyword-face)
-     (not "not" @font-lock-keyword-face)
-     (let "let" @font-lock-keyword-face)
-     (branch ["if" "else"] @font-lock-keyword-face)
-     (while "while" @font-lock-keyword-face)
-     (for ["for" "in"] @font-lock-keyword-face)
-     (import "import" @font-lock-keyword-face)
-     (as "as" @font-lock-keyword-face)
-     (include "include" @font-lock-keyword-face)
-     (show "show" @font-lock-keyword-face)
-     (set "set" @font-lock-keyword-face)
-     (return "return" @font-lock-keyword-face)
-     (flow ["break" "continue"] @font-lock-keyword-face)
-
-     (call ;; function
-      item: (ident) @font-lock-function-call-face)
-     (call ;; method
-      item: (field field: (ident) @font-lock-function-call-face))
-     (tagged field: (ident) @font-lock-variable-name-face)
-     (field field: (ident) @font-lock-constant-face))
-
-    :language typst
-    :feature code-standard
-    ((ident) @font-lock-variable-use-face
-     (builtin) @font-lock-builtin-face)
-
-    :language typst
-    :feature code-extended ;; TODO lambda symbol
-    ((number) @font-lock-number-face
-
-     (content ["[" "]"] @font-lock-punctuation-face)
-     (sign ["+" "-"] @font-lock-operator-face)
-     (add "+" @font-lock-operator-face)
-     (sub "-" @font-lock-operator-face)
-     (mul "*" @font-lock-operator-face)
-     (div "/" @font-lock-operator-face)
-     (cmp ["==" "<=" ">=" "!=" "<" ">"] @font-lock-operator-face)
-     (wildcard) @font-lock-operator-face
-
-     ["(" ")" "{" "}"] @font-lock-punctuation-face
-     ["," ";" ".." ":" "sep"] @font-lock-punctuation-face
-     "assign" @font-lock-punctuation-face
-     (field "." @font-lock-punctuation-face))
-
-    :language typst
-    :feature math-basic
-    ((math "$" @typst-ts-math-indicator-face))
-
-    :language typst
-    :feature math-standard
-    ((symbol) @font-lock-constant-face
-     (letter) @font-lock-constant-face)
-
-    :language typst
-    :feature math-extended
-    ((fraction "/" @font-lock-operator-face)
-     (fac "!" @font-lock-operator-face)
-     (attach ["^" "_"] @font-lock-operator-face)
-     (align) @font-lock-operator-face)))
+  (let ((markup-basic
+         (pcase typst-ts-mode-fontification-precision-level
+           ('min
+            `((heading) @typst-ts-markup-header-face
+              (emph) @typst-ts-markup-emphasis-face
+              (strong) @typst-ts-markup-strong-face
+              (item) @typst-ts-markup-item-face
+              (term) @typst-ts-markup-term-face
+              (raw_span) @typst-ts-markup-rawspan-face
+              ,@(if typst-ts-mode-enable-raw-blocks-highlight
+                    '((raw_blck
+                       "```" @typst-ts-markup-rawblock-indicator-face
+                       (ident) :? @typst-ts-markup-rawblock-lang-face
+                       (blob)
+                       "```" @typst-ts-markup-rawblock-indicator-face))
+                  '((raw_blck) @typst-ts-markup-rawblock-face))
+              (label) @typst-ts-markup-label-face
+              (ref) @typst-ts-markup-reference-face))
+           ('middle
+            `((heading) @typst-ts-markup-header-face
+              (emph) @typst-ts-markup-emphasis-face
+              (strong) @typst-ts-markup-strong-face
+              (item
+               "-" @typst-ts-markup-item-indicator-face
+               (text) @typst-ts-markup-item-text-face)
+              (term
+               "/" @typst-ts-markup-term-indicator-face
+               term: (text) @typst-ts-markup-term-term-face
+               ":" @typst-ts-markup-term-indicator-face
+               (text) @typst-ts-markup-term-description-face)
+              (raw_span
+               "`" @typst-ts-markup-rawspan-indicator-face
+               (blob) @typst-ts-markup-rawspan-blob-face
+               "`" @typst-ts-markup-rawspan-indicator-face)
+              (raw_blck
+               "```" @typst-ts-markup-rawblock-indicator-face
+               (ident) :? @typst-ts-markup-rawblock-lang-face
+               ;; NOTE let embedded language fontify blob
+               ,@(if typst-ts-mode-enable-raw-blocks-highlight
+                     '((blob))
+                   '((blob) @typst-ts-markup-rawblock-blob-face))
+               "```" @typst-ts-markup-rawblock-indicator-face)
+              (label) @typst-ts-markup-label-face
+              (ref) @typst-ts-markup-reference-face))
+           ('max
+            `(,@(if typst-ts-markup-header-same-height
+                    '((heading "=" @typst-ts-markup-header-indicator-face
+                               (text) @typst-ts-markup-header-face)
+                      (heading "==" @typst-ts-markup-header-indicator-face
+                               (text) @typst-ts-markup-header-face)
+                      (heading "===" @typst-ts-markup-header-indicator-face
+                               (text) @typst-ts-markup-header-face)
+                      (heading "====" @typst-ts-markup-header-indicator-face
+                               (text) @typst-ts-markup-header-face)
+                      (heading "=====" @typst-ts-markup-header-indicator-face
+                               (text) @typst-ts-markup-header-face)
+                      (heading "======" @typst-ts-markup-header-indicator-face
+                               (text) @typst-ts-markup-header-face))
+                  '((heading "=" @typst-ts-markup-header-indicator-face-1
+                             (text) @typst-ts-markup-header-face-1)
+                    (heading "==" @typst-ts-markup-header-indicator-face-2
+                             (text) @typst-ts-markup-header-face-2)
+                    (heading "===" @typst-ts-markup-header-indicator-face-3
+                             (text) @typst-ts-markup-header-face-3)
+                    (heading "====" @typst-ts-markup-header-indicator-face-4
+                             (text) @typst-ts-markup-header-face-4)
+                    (heading "=====" @typst-ts-markup-header-indicator-face-5
+                             (text) @typst-ts-markup-header-face-5)
+                    (heading "======" @typst-ts-markup-header-indicator-face-6
+                             (text) @typst-ts-markup-header-face-6)))
+              (emph
+               "_" @typst-ts-markup-emphasis-indicator-face
+               (text) @typst-ts-markup-emphasis-face
+               "_" @typst-ts-markup-emphasis-indicator-face)
+              (strong
+               "*" @typst-ts-markup-strong-indicator-face
+               (text) @typst-ts-markup-strong-face
+               "*" @typst-ts-markup-strong-indicator-face)
+              (item
+               "-" @typst-ts-markup-item-indicator-face
+               (text) @typst-ts-markup-item-text-face)
+              (term
+               "/" @typst-ts-markup-term-indicator-face
+               term: (text) @typst-ts-markup-term-term-face
+               ":" @typst-ts-markup-term-indicator-face
+               (text) @typst-ts-markup-term-description-face)
+              (escape) @typst-ts-markup-escape-face
+              (raw_span
+               "`" @typst-ts-markup-rawspan-indicator-face
+               (blob) @typst-ts-markup-rawspan-blob-face
+               "`" @typst-ts-markup-rawspan-indicator-face)
+              (raw_blck
+               "```" @typst-ts-markup-rawblock-indicator-face
+               (ident) :? @typst-ts-markup-rawblock-lang-face
+               ;; NOTE let embedded language fontify blob
+               ,@(if typst-ts-mode-enable-raw-blocks-highlight
+                     '((blob))
+                   '((blob) @typst-ts-markup-rawblock-blob-face))
+               "```" @typst-ts-markup-rawblock-indicator-face)
+              (label) @typst-ts-markup-label-face  ; TODO more precise 
highlight (upstream)
+              (ref) @typst-ts-markup-reference-face)
+            ))))
+    `(;; Typst font locking
+      :language typst
+      :feature comment
+      ,(if typst-ts-mode-font-lock-rules-comment
+           typst-ts-mode-font-lock-rules-comment
+         '((comment) @font-lock-comment-face))
+
+      :language typst
+      :feature common
+      ,(if typst-ts-mode-font-lock-rules-common
+           typst-ts-mode-font-lock-rules-common
+         '((shorthand) @typst-ts-shorthand-face
+           (ERROR) @typst-ts-error-face))
+
+      :language typst
+      :feature markup-basic
+      ,(if typst-ts-mode-font-lock-rules-markup-basic
+           typst-ts-mode-font-lock-rules-markup-basic
+         markup-basic)
+
+      :language typst
+      :feature markup-standard
+      ,(if typst-ts-mode-font-lock-rules-markup-standard
+           typst-ts-mode-font-lock-rules-markup-standard
+         '((linebreak) @typst-ts-markup-linebreak-face
+           (quote) @typst-ts-markup-quote-face))
+
+      :language typst
+      :feature markup-extended
+      ,(if typst-ts-mode-font-lock-rules-markup-extended
+           typst-ts-mode-font-lock-rules-markup-extended
+         '((url) @typst-ts-markup-url-face))
+
+      ;; please note that some feature there also in the math mode
+      :language typst
+      :feature code-basic
+      ,(if typst-ts-mode-font-lock-rules-code-basic
+           typst-ts-mode-font-lock-rules-code-basic
+         '("#" @typst-ts-code-indicator-face
+           ;; "end" @typst-ts-code-indicator-face ;; "end" is nothing but only 
a indicator
+           (string) @font-lock-string-face
+           (bool) @font-lock-constant-face
+           (none) @font-lock-constant-face
+           (auto) @font-lock-constant-face
+
+           (in ["in" "not"] @font-lock-keyword-face)
+           (and "and" @font-lock-keyword-face)
+           (or "or" @font-lock-keyword-face)
+           (not "not" @font-lock-keyword-face)
+           (let "let" @font-lock-keyword-face)
+           (branch ["if" "else"] @font-lock-keyword-face)
+           (while "while" @font-lock-keyword-face)
+           (for ["for" "in"] @font-lock-keyword-face)
+           (import "import" @font-lock-keyword-face)
+           (as "as" @font-lock-keyword-face)
+           (include "include" @font-lock-keyword-face)
+           (show "show" @font-lock-keyword-face)
+           (set "set" @font-lock-keyword-face)
+           (return "return" @font-lock-keyword-face)
+           (flow ["break" "continue"] @font-lock-keyword-face)
+
+           (call ;; function
+            item: (ident) @font-lock-function-call-face)
+           (call ;; method
+            item: (field field: (ident) @font-lock-function-call-face))
+           (tagged field: (ident) @font-lock-variable-name-face)
+           (field field: (ident) @font-lock-constant-face)))
+
+      :language typst
+      :feature code-standard
+      ,(if typst-ts-mode-font-lock-rules-code-standard
+           typst-ts-mode-font-lock-rules-code-standard
+         '((ident) @font-lock-variable-use-face
+           (builtin) @font-lock-builtin-face))
+
+      :language typst
+      :feature code-extended
+      ,(if typst-ts-mode-font-lock-rules-code-extended
+           typst-ts-mode-font-lock-rules-code-extended
+         ;; TODO lambda symbol
+         '((number) @font-lock-number-face
+
+           (content ["[" "]"] @font-lock-punctuation-face)
+           (sign ["+" "-"] @font-lock-operator-face)
+           (add "+" @font-lock-operator-face)
+           (sub "-" @font-lock-operator-face)
+           (mul "*" @font-lock-operator-face)
+           (div "/" @font-lock-operator-face)
+           (cmp ["==" "<=" ">=" "!=" "<" ">"] @font-lock-operator-face)
+           (wildcard) @font-lock-operator-face
+
+           ["(" ")" "{" "}"] @font-lock-punctuation-face
+           ["," ";" ".." ":" "sep"] @font-lock-punctuation-face
+           "assign" @font-lock-punctuation-face
+           (field "." @font-lock-punctuation-face)))
+
+      :language typst
+      :feature math-basic
+      ,(if typst-ts-mode-font-lock-rules-math-basic
+           typst-ts-mode-font-lock-rules-math-basic
+         '((math "$" @typst-ts-math-indicator-face)))
+
+      :language typst
+      :feature math-standard
+      ,(if typst-ts-mode-font-lock-rules-math-standard
+           typst-ts-mode-font-lock-rules-math-standard
+         '((symbol) @font-lock-constant-face
+           (letter) @font-lock-constant-face))
+
+      :language typst
+      :feature math-extended
+      ,(if typst-ts-mode-font-lock-rules-math-extended
+           typst-ts-mode-font-lock-rules-math-extended
+         '((fraction "/" @font-lock-operator-face)
+           (fac "!" @font-lock-operator-face)
+           (attach ["^" "_"] @font-lock-operator-face)
+           (align) @font-lock-operator-face)))))
 
 (defconst typst-ts-mode-font-lock-feature-list
   '((comment common)
@@ -1126,7 +1269,6 @@ See `treesit-language-at-point-function'."
                          (?\$ . ?\$)))
 
   ;; Font Lock
-  (setq-local treesit-font-lock-level 4)
   (setq-local treesit-font-lock-settings
               (apply #'treesit-font-lock-rules (if 
typst-ts-mode-font-lock-rules
                                                    
typst-ts-mode-font-lock-rules

Reply via email to