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

    fix: emacs 29 incompatiability
    
    
    Fixes: https://todo.sr.ht/~meow_king/typst-ts-mode/39
    Signed-off-by: Meow King <mr.meowk...@anche.no>
---
 #basic-syntax.typ#                  |  82 +++++++++++++++
 README.md                           |   1 +
 q                                   | 201 ------------------------------------
 typst-ts-embedding-lang-settings.el |   9 +-
 typst-ts-mode.el                    |  48 +++++----
 typst-ts-utils.el                   |  62 +++++++++++
 6 files changed, 178 insertions(+), 225 deletions(-)

diff --git a/#basic-syntax.typ# b/#basic-syntax.typ#
new file mode 100644
index 0000000000..1ba0179ca5
--- /dev/null
+++ b/#basic-syntax.typ#
@@ -0,0 +1,82 @@
+// This file only serves for testing highlight, and it is not a syntax 
completion test.
+
+// comment
+
+-? $ -> $ // shorthand
+
+// header face
+= headline
+https://www.google.com // url
+_emph_ // emphasis
+*strong* // strong
+- item // item
+/ term1: value
+"El Psy Kongraoo" // quote
+hello \ // line break
+`El Psy Kongraoo` // raw span
+// raw block
+```bash
+sudo r
+```
+<LABEL> // label
+@reference // reference
+   
+Hello\nWorld // escape
+
+
+#(4.2) // number
+#"El Psy Kongaroo" // string
+#[El Psy Kongraoo] // content
+#true #false  // boolean
+#sym.bar.h  // builtin
+#set text(a: 0) // call & builtin
+#none // none
+#auto // auto
+#(a + b) // ident
+
+#(0 in "0" not in a) // in
+#(a and b or not c) // and, or, not
+#(2 + - 1) #(2 - -1) // sign
+#(1 + 1) // add
+#(1 - 1) // sub
+#(1 * 1) // mul
+#(1 / 1) // div
+#if 2 > 1 [] // cmp
+#import "a": * // wildcard
+
+#let a = b  // let
+#if b {} else {} // branch
+#while n < 10 { // while
+    (n,)
+}
+#for i in a {} // for
+#import "a": a, b // import
+#import "a.lib" as b // as
+#include "a" // include
+#show: columns.with(2) // show
+#set text(a: 0) // set
+#let a() = { // return
+    return 2
+}
+#for letter in "abc nope" { // flow
+    if letter == " " {
+        break
+    } else if letter == "a" {
+        continue
+    }
+    letter
+}
+
+#a()() // function
+#range().map // builtin function
+#l.zip(r).map( // method
+    ((a,b)) => a + b // TODO lambda
+)
+#(a, c: b) // tagged
+#a.b // field
+
+$ a $ // math
+$ 1 + 1 = 2 $
+$ E = m * c^2 $
+$ eq.not(0) $
+$ cal(A) := { x in RR | x "is natural" } $
diff --git a/README.md b/README.md
index e6862c78d3..ae6ebdcf06 100644
--- a/README.md
+++ b/README.md
@@ -100,6 +100,7 @@ Here are some options you may find useful:
 
 ### Raw block highlighting
 _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](./doc/raw-block-highlighing.md)  
diff --git a/q b/q
deleted file mode 100644
index c638dccff9..0000000000
--- a/q
+++ /dev/null
@@ -1,201 +0,0 @@
-@    nntkyolq Meow King 
<mr.meowk...@anche.no> 2024-02-26 21:10:53.000 
+08:00 main 24d00958
-├─╮  (empty) merge `develop` branch
-◉ │  xvmmykpq Meow King 
<mr.meowk...@anche.no> 2024-02-26 20:56:15.000 
+08:00 develop HEAD@git 
7c9c69f4
-├─╯  doc: update README
-◉  kokrvpqy Meow King 
<mr.meowk...@anche.no> 2024-02-26 20:46:21.000 
+08:00 bfa4f61e
-│  fix: some errors of `lsp-bridge-inlay-hint` and 
`typst-ts-mode-insert--item` function
-◉  llxqrvvt Meow King 
<mr.meowk...@anche.no> 2024-02-26 10:33:13.000 
+08:00 2d25a0ac
-│  refactor: `typst-ts-mode-insert--item`
-◉  ntvwnzrk Meow King 
<mr.meowk...@anche.no> 2024-02-21 23:19:17.000 
+08:00 c6e5e6b5
-│  doc: update README
-◉  wyumsvwp Meow King 
<mr.meowk...@anche.no> 2024-02-21 22:50:53.000 
+08:00 3d373bba
-│  fix: fix outline recognization error when section indent offset is not nil
-◉  nzslwnzm Meow King 
<mr.meowk...@anche.no> 2024-02-21 22:19:28.000 
+08:00 4c580a1c
-│  fix: typst-ts-mode-indent-offset-section wrong defcustom type
-◉  lzuuxznt Meow King 
<mr.meowk...@anche.no> 2024-02-17 11:02:17.000 
+08:00 123b7c99
-│  feat(raw-block-highlighting): assign default face for those block whose 
language is missing or not-loadable
-◉  yuomurot Meow King 
<mr.meowk...@anche.no> 2024-02-17 10:11:41.000 
+08:00 dc378979
-│  fix(raw-block-highlighting): don't emit error when editing a raw block of 
the language of uninstalled ts-parser.
-◉  rpunvysx Huan Nguyen 
<nguyenthieuh...@gmail.com> 2024-02-04 20:20:30.000 
+01:00 feat/autoincrement 
6a35d230
-│  fix: Autoincrement should indent as well.
-◉    vvmsxron Huan Nguyen 
<nguyenthieuh...@gmail.com> 2024-02-04 20:11:21.000 
+01:00 a161507d
-├─╮  Merge branch 'main' into feat/autoincrement
-│ ◉  koqnmxqy Meow King 
<mr.meowk...@anche.no> 2024-02-04 22:54:30.000 
+08:00 078b2efb
-│ │  fix: disable echoing indentation debug information
-│ ◉  suvukvno Meow King 
<mr.meowk...@anche.no> 2024-02-04 21:50:01.000 
+08:00 96f587be
-│ │  doc: update README
-│ ◉  xsnwvlwp Meow King 
<mr.meowk...@anche.no> 2024-02-04 21:48:11.000 
+08:00 74eeca77
-│ │  doc: update README
-│ ◉  qrskumto Meow King 
<mr.meowk...@anche.no> 2024-02-04 21:36:45.000 
+08:00 327266f8
-│ │  refactor: enhance indentation
-│ ◉  ymzlvsym Meow King 
<mr.meowk...@anche.no> 2024-02-04 18:16:13.000 
+08:00 54f21785
-│ │  refactor: enhance raw block indentation
-│ ◉  mzxuuvmu Meow King 
<mr.meowk...@anche.no> 2024-02-04 12:54:10.000 
+08:00 f1ca0765
-│ │  feat: Add customizable option for indenting section (header)
-◉ │  skvrsomv Huan Nguyen 
<nguyenthieuh...@gmail.com> 2024-02-04 14:55:59.000 
+01:00 d799bdff
-│ │  doc: Rename variable and add it to documentation.
-◉ │  pyptlprm Huan Nguyen 
<nguyenthieuh...@gmail.com> 2024-02-04 14:52:27.000 
+01:00 0454e449
-│ │  feat: Autoincrement on enter and fix heading insertion.
-◉ │  tspxlwrl Huan Nguyen 
<nguyenthieuh...@gmail.com> 2024-02-04 13:42:08.000 
+01:00 49a39810
-│ │  fix: Only search for the current line.
-◉ │  vxznqmzt Huan Nguyen 
<nguyenthieuh...@gmail.com> 2024-02-04 13:25:09.000 
+01:00 74d210c8
-│ │  fix: Indent the inserted heading.
-◉ │  zyonronm Huan Nguyen 
<nguyenthieuh...@gmail.com> 2024-02-04 13:14:50.000 
+01:00 f0916578
-│ │  feat: new customize variable that controls behavior of enter key
-◉ │  zxxsuvwr Huan Nguyen 
<nguyenthieuh...@gmail.com> 2024-02-04 13:14:16.000 
+01:00 f58e7449
-│ │  style: reindent
-◉ │  xsnlmmlq Huan Nguyen 
<nguyenthieuh...@gmail.com> 2024-02-04 13:12:22.000 
+01:00 cb69c982
-│ │  fix: point must be on list item and having no section should not error
-◉ │  qwvpktkm Huan Nguyen 
<nguyenthieuh...@gmail.com> 2024-02-03 10:32:54.000 
+01:00 d6cd6d72
-│ │  feat: Also auto insert numbered list.
-◉ │  opmtvnkn Huan Nguyen 
<nguyenthieuh...@gmail.com> 2024-02-03 10:06:23.000 
+01:00 06a6c6f5
-│ │  style: .dir-locals.el to turn off indent-tabs-mode
-◉ │  symwyznw Huan Nguyen 
<nguyenthieuh...@gmail.com> 2024-02-02 22:12:07.000 
+01:00 4662986a
-│ │  feat: Autoincrement list or insert new heading.
-◉ │  ymwvvlzq Huan Nguyen 
<nguyenthieuh...@gmail.com> 2024-02-02 22:12:04.000 
+01:00 f997d273
-├─╯  fix: Item indentation fixed?
-◉  nqpmlrky Meow King 
<mr.meowk...@anche.no> 2024-01-20 17:50:18.000 
+08:00 f5797e21
-│  refactor: introduce different level of fontification to address performance 
issue
-◉  wsqnrqpq Meow King 
<mr.meowk...@anche.no> 2024-01-19 23:18:33.000 
+08:00 8ab7a3e6
-│  disable raw block highlighting by default
-◉  kuwutzup Meow King 
<mr.meowk...@anche.no> 2024-01-19 19:37:59.000 
+08:00 2dbf17da
-│  feat(face): more precise face for some markup elements
-◉  qswslzrm Meow King 
<mr.meowk...@anche.no> 2024-01-19 10:46:09.000 
+08:00 fded7649
-│  fix(els): remove language tag map duplication
-◉  uxpyullv Meow King 
<mr.meowk...@anche.no> 2024-01-18 17:40:31.000 
+08:00 feature/raw-block-highlighting 
7e3f11e6
-│  feat: add detailed documentation
-◉  tokurkyq Meow King 
<mr.meowk...@anche.no> 2024-01-18 10:45:36.000 
+08:00 f56803a3
-│  feat(face): more flexible face settings for raw block
-◉  yrmzyytu Meow King 
<mr.meowk...@anche.no> 2024-01-17 23:00:48.000 
+08:00 271cedb1
-│  feat: add customization option to enable raw block highlighting
-◉  zwunvllu Meow King 
<mr.meowk...@anche.no> 2024-01-17 22:45:32.000 
+08:00 75561540
-│  feat: add more predefined embedding language settings
-◉  okqrtlmu Meow King 
<mr.meowk...@anche.no> 2024-01-17 19:55:53.000 
+08:00 5f3e28be
-│  feat: add utility function to modify language tags relationship
-◉  rvpkukpq Meow King 
<mr.meowk...@anche.no> 2024-01-17 16:55:26.000 
+08:00 28b8da2f
-│  feat: add more predefined language settings
-◉  mwvsukok Meow King 
<mr.meowk...@anche.no> 2024-01-17 15:03:42.000 
+08:00 cd6e40ff
-│  feat: enable highlighting at startup
-◉  kqnsozqp Meow King 
<mr.meowk...@anche.no> 2024-01-17 14:15:03.000 
+08:00 61ca4cfd
-│  feat: support raw block language name <-> tree sitter setting entry mapping
-◉  qvwwtrmn Meow King 
<mr.meowk...@anche.no> 2024-01-14 23:16:33.000 
+08:00 7bdda683
-│  doc: README.md
-◉  loossmru Meow King 
<mr.meowk...@anche.no> 2024-01-13 23:30:51.000 
+08:00 f43cba25
-│  feat: capable to correctly highlight regions
-◉  ylypwotv Meow King 
<mr.meowk...@anche.no> 2024-01-01 20:34:08.000 
+08:00 208aa360
-│  feat: almost done, have some bugs
-◉  mtxspovv Meow King 
<mr.meowk...@anche.no> 2024-01-01 17:05:25.000 
+08:00 7646790a
-│  feat: load embedding language settings dynamically
-◉  zukkwvlt Meow King 
<mr.meowk...@anche.no> 2023-12-31 11:34:15.000 
+08:00 70bcc781
-│  fix: toggle list(item) indentation on first line error
-◉  ukknktvt Meow King 
<mr.meowk...@anche.no> 2023-12-31 11:25:36.000 
+08:00 13d32bef
-│  fix: toggle indentation bug for list (item)
-◉  yoxpnxxw Meow King 
<mr.meowk...@anche.no> 2023-12-31 10:59:06.000 
+08:00 645c08e9
-│  fix: wrong list(item) indentation
-◉  rxlosmsm Meow King 
<mr.meowk...@anche.no> 2023-12-31 00:53:10.000 
+08:00 dc4678aa
-│  fix(indentation): edge conditions
-◉  knqvroyy Meow King 
<mr.meowk...@anche.no> 2023-12-30 23:33:17.000 
+08:00 1c2b4bd6
-│  feat: toggle indentation for list(item)
-◉  txkvzlnz Meow King 
<mr.meowk...@anche.no> 2023-12-30 20:36:42.000 
+08:00 6c0c55f4
-│  feat: add indentation rule for item with linebreak at ending
-◉  yplnltmu Meow King 
<mr.meowk...@anche.no> 2023-12-25 13:41:03.000 
+08:00 eb4bcb0a
-│  doc: update README
-◉  yynuwnrz Huan Nguyen 
<nguyenthieuh...@gmail.com> 2023-12-23 16:39:19.000 
+01:00 feat/heading-operations 
aad1cde1
-│  refactor: Use outline library for headings.
-◉  uqksukvo Meow King 
<mr.meowk...@anche.no> 2023-12-23 21:47:30.000 
+08:00 74856118
-│  style: change all tab into white space & add editorconfig file
-◉  ovrtlzvz Meow King 
<mr.meowk...@anche.no> 2023-12-23 21:28:23.000 
+08:00 33940994
-│  refactor: typst-ts-mode-heading--at-point-p
-◉    opulrtnx Meow King 
<mr.meowk...@anche.no> 2023-12-23 21:04:33.000 
+08:00 0d40d36c
-├─╮  (empty) Merge branch 'main' into feat/heading-operations
-│ ◉  nkwzoyvk Meow King 
<mr.meowk...@anche.no> 2023-12-23 21:04:00.000 
+08:00 89ee0735
-│ │  chore
-│ ◉  vqwwnvlu Meow King 
<mr.meowk...@anche.no> 2023-12-23 21:01:51.000 
+08:00 946b056f
-│ │  feat: update to v0.10.0
-◉ │  mtlnppwr Huan Nguyen 
<nguyenthieuh...@gmail.com> 2023-12-19 20:17:42.000 
+01:00 14affa17
-│ │  refactor: Renamed function that finds next higher/same level heading.
-◉ │  krslxnyx Huan Nguyen 
<nguyenthieuh...@gmail.com> 2023-12-19 11:51:12.000 
+01:00 3ba9c737
-│ │  doc: Added new feature and its keybinding to readme.
-◉ │  swstxrzm Huan Nguyen 
<nguyenthieuh...@gmail.com> 2023-12-19 11:49:46.000 
+01:00 b4b64449
-│ │  feat: Move heading and it contents down or up.
-◉ │  lyqqntty Huan Nguyen 
<nguyenthieuh...@gmail.com> 2023-12-19 01:37:21.000 
+01:00 181caafe
-│ │  feat: Exchange current heading with above heading.
-◉ │  xpxtqmpn Huan Nguyen 
<nguyenthieuh...@gmail.com> 2023-12-18 21:29:55.000 
+01:00 21f263b3
-│ │  doc: Fix flymake warnings.
-◉ │  qlvqvrmw Huan Nguyen 
<nguyenthieuh...@gmail.com> 2023-12-18 21:28:24.000 
+01:00 6a6ab91f
-├─╯  refactor: Refactored heading increase/decrease functions.
-◉  mpzmlpzq Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-12-18 15:35:43.000 
+08:00 53bc7cf2
-│  doc(README): update co-maintainer information
-◉  smltoqzt Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-12-18 15:31:58.000 
+08:00 5700854a
-│  doc: update README
-◉  nrsyspzz Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-12-13 18:18:33.000 
+08:00 ebdce771
-│  doc: update README
-◉  oqyusmsx huanie 
<nguyenthieuh...@gmail.com> 2023-12-13 17:50:39.000 
+08:00 73f6273b
-│  feat: Incrase/Decrase heading level.
-◉  tvqmllyn Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-12-06 17:08:02.000 
+08:00 361dfe60
-│  fix: allow dynamic indentation offset
-◉  twtsvkuu Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-12-02 00:28:29.000 
+08:00 78cc8594
-│  feat: add typst watch mode-line indicator
-◉  vztxokmq Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-12-01 22:19:00.000 
+08:00 7b3b3da7
-│  doc: update README
-◉  rvmkzkkp Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-12-01 21:48:39.000 
+08:00 35b3e2fa
-│  feat: add error face
-◉  zoknpmmt Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-11-06 14:57:40.000 
+08:00 39a9e63c
-│  feat: Typst v0.9.0
-◉  uvqvroxs Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-10-31 22:43:13.000 
+08:00 bbac54c3
-│  doc: update README
-◉  wuysttws Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-10-28 13:55:53.000 
+08:00 4c26bf91
-│  doc: update README
-◉  xorzrytu Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-10-27 19:06:49.000 
+08:00 86492f07
-│  doc: update README
-◉  xvtpsykp Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-10-12 11:27:20.000 
+08:00 5ff1b21a
-│  fix(compilation + watch) error regexp error
-◉  kroxnryn Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-10-11 14:46:18.000 
+08:00 004ec937
-│  fix: `typst-ts-markup-header-scale` custom setting function error
-◉  wsqkyqnl Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-10-01 15:28:02.000 
+08:00 9d1adbcb
-│  feat: adopt update stream parser syntax change and add dynamic height for 
headers
-◉  oozputpn Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-24 14:03:52.000 
+08:00 439deb4b
-│  fix(preview): open non-english character file name
-◉  oqnxtkry Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-24 11:34:33.000 
+08:00 ea69e2f7
-│  fix: don't indent content inside raw block
-◉  ouqwzxym Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-23 20:22:35.000 
+08:00 b16762ce
-│  doc: README
-◉  uooruyqr Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-23 17:25:24.000 
+08:00 bfff448d
-│  fix: deleting watch process window error when stop watching
-◉  vwlqyvqp Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-23 17:19:19.000 
+08:00 01ef0d45
-│  feat: better functionality for typst watch process
-◉  uwyyzzlk Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-23 11:27:31.000 
+08:00 c059a85f
-│  feat: add preview command and fix after-compile hook issue
-◉  owvmyyuo Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-22 21:13:41.000 
+08:00 bb9c2d7d
-│  feat: add convenient commands
-◉  mmumvrqu Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-22 20:24:58.000 
+08:00 c92cdbe9
-│  feate: more precise font lock feature levels
-◉  xromvmps Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-22 20:00:52.000 
+08:00 1285fc3b
-│  feat: add a syntax table
-◉  nnvwpnrq Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-22 19:47:38.000 
+08:00 d23140e9
-│  feat: add imenu support
-◉  ktnqqznl Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-22 17:58:56.000 
+08:00 c4a3c02c
-│  feat: indentation rules
-◉  xksryuwo Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-21 23:18:30.000 
+08:00 ce4142e1
-│  feat: add electric auto pair pairs
-◉  suxxrqxq Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-21 20:49:56.000 
+08:00 5ee0e336
-│  feat: math fontification support
-◉  rxvzlttq Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-21 20:17:49.000 
+08:00 2a27ed3b
-│  feat: add more fontification rules to code section
-◉  vpyvznpm Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-21 19:52:24.000 
+08:00 6e5c7f11
-│  feat: fontify control flow in code section
-◉  ynukkwnw Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-21 19:40:23.000 
+08:00 adeb7bc7
-│  feat: add operator for code
-◉  xswwsmvp Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-21 17:08:40.000 
+08:00 5e644c21
-│  feat: label and reference fontify in markup
-◉  rytpsull Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-21 17:01:59.000 
+08:00 204202bf
-│  feat: rawspan and rawblock in markup
-◉  uuqxuzzn Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-21 15:36:19.000 
+08:00 5ac2801a
-│  feat: add tests and more faces for markup mode
-◉  tlwtuppt Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-20 23:24:37.000 
+08:00 87966568
-│  feat: add more fontification rules for markup
-◉  trkykspw Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-20 20:19:16.000 
+08:00 52d8241e
-│  feat: add header faces
-◉  nqutstxz Ziqi Yang 
<mr.ziqiy...@gmail.com> 2023-09-19 23:16:29.000 
+08:00 3a3c9810
-│  init
-◉  zzzzzzzz root() 
00000000
diff --git a/typst-ts-embedding-lang-settings.el 
b/typst-ts-embedding-lang-settings.el
index 40dc846885..d73ccc98c7 100644
--- a/typst-ts-embedding-lang-settings.el
+++ b/typst-ts-embedding-lang-settings.el
@@ -21,6 +21,7 @@
 
 ;;; Code:
 (require 'treesit)
+(require 'typst-ts-utils)
 
 (defcustom typst-ts-highlight-raw-block-langs-not-in-predefined-settings t
   "Whether to highlight raw block of language that is not in settings.
@@ -714,7 +715,9 @@ case-sensitive."
 
 (defun typst-ts-els--treesit-range-rules (lang)
   "Get the treesit range rules for LANG.
-LANG: language symbol."
+LANG: language symbol.
+NOTE this function is only meant to be used in Emacs 30 since Emacs 29 doesn't
+have `:local t' flag and if without it, the all the highlight gone."
   (treesit-range-rules
    :embed lang
    :host 'typst
@@ -773,7 +776,7 @@ Use this function as one notifier of 
`treesit-parser-notifiers'."
            (mapcar #'treesit-parser-language (treesit-parser-list))
            ;; parsers created by `treesit-range-settings'
            (mapcar #'treesit-parser-language
-                   (treesit-local-parsers-on (point-min) (point-max))))))
+                   (typst-ts-utils-local-parsers-on (point-min) 
(point-max))))))
         lang-ts-mode settings)
     (dolist (lang parser-langs)
       (unless (member lang typst-ts-els--include-languages)
@@ -799,7 +802,7 @@ Use this function as one notifier of 
`treesit-parser-notifiers'."
                        ;; delete top level parsers, so range rules works (i.e. 
local parsers)
                        ;; so that highlighting will not exceed the desired 
range
                        (mapc #'treesit-parser-delete (treesit-parser-list nil 
lang))
-
+                       
                        ;; find and merge settings
                        (setq lang-ts-mode
                              (intern (concat (symbol-name lang) "-ts-mode")))
diff --git a/typst-ts-mode.el b/typst-ts-mode.el
index 4885655b77..b3fbe64d24 100644
--- a/typst-ts-mode.el
+++ b/typst-ts-mode.el
@@ -34,6 +34,7 @@
 (require 'outline)
 
 (require 'typst-ts-embedding-lang-settings)
+(require 'typst-ts-utils)
 
 (defgroup typst-ts nil
   "Tree Sitter enabled Typst Writing."
@@ -76,7 +77,8 @@ be noticeably affected probably."
 
 ;; 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."
+  "Whether to enable raw block highlighting.
+NOTE: currently only support Emacs 30 (master branch)."
   :type 'boolean
   :group 'typst-ts)
 
@@ -333,7 +335,7 @@ See `typst-ts-mode-fontification-precision-level'."
   "Face for term description."
   :group 'typst-ts-faces)
 
-(defface typst-ts-markup-quote-face ;; TODO better choice?
+(defface typst-ts-markup-quote-face
   '((t :inherit shadow))
   "Face for quote."
   :group 'typst-ts-faces)
@@ -494,7 +496,8 @@ NODE."
         (ne (treesit-node-end node))
         (lang-node (treesit-node-prev-sibling node))
         lang)
-    (if (not (equal (treesit-node-type lang-node) "ident"))
+    (if (or (< emacs-major-version 30)
+            (not (equal (treesit-node-type lang-node) "ident")))
         (put-text-property ns ne 'face 'typst-ts-markup-rawblock-blob-face)
       (setq lang (gethash
                   (downcase (treesit-node-text lang-node))
@@ -543,10 +546,10 @@ If you want to customize the rules, please customize the 
same name variable
                "`" @typst-ts-markup-rawspan-indicator-face)
               (raw_blck
                "```" @typst-ts-markup-rawblock-indicator-face
-               (ident) :? @typst-ts-mode-highlight-raw-block-fn
+               (ident) :? @typst-ts-markup-rawblock-lang-face
                ;; NOTE let embedded language fontify blob
                ,@(if typst-ts-mode-enable-raw-blocks-highlight
-                     '((blob) @typst-ts-mode-highlight-block-fn)
+                     '((blob) @typst-ts-mode-highlight-raw-block-fn)
                    '((blob) @typst-ts-markup-rawblock-blob-face))
                "```" @typst-ts-markup-rawblock-indicator-face)
               (label) @typst-ts-markup-label-face
@@ -599,10 +602,10 @@ If you want to customize the rules, please customize the 
same name variable
                "`" @typst-ts-markup-rawspan-indicator-face)
               (raw_blck
                "```" @typst-ts-markup-rawblock-indicator-face
-               (ident) :? @typst-ts-mode-highlight-raw-block-fn
+               (ident) :? @typst-ts-markup-rawblock-lang-face
                ;; NOTE let embedded language fontify blob
                ,@(if typst-ts-mode-enable-raw-blocks-highlight
-                     '((blob) @typst-ts-mode-highlight-block-fn)
+                     '((blob) @typst-ts-mode-highlight-raw-block-fn)
                    '((blob) @typst-ts-markup-rawblock-blob-face))
                "```" @typst-ts-markup-rawblock-indicator-face)
               (label) @typst-ts-markup-label-face  ; TODO more precise 
highlight (upstream)
@@ -936,7 +939,7 @@ NODE, PARENT and BOL see `treesit-indent-function'."
     (error "Variable `typst-ts-mode-indent-function' shouldn't be null!"))
   (let ((res (funcall typst-ts-mode-indent-function node parent bol)))
     ;; if it is a highlighted raw block region (i.e. contains at least one 
local parser)
-    (when (treesit-local-parsers-at (treesit-node-start node))
+    (when (typst-ts-utils-local-parsers-at (treesit-node-start node))
       ;; when there is no matching rules
       (unless (car res)
         (setcar res bol)
@@ -1528,8 +1531,10 @@ typst tree sitter grammar (at least %s)!" 
(current-time-string min-time))
               t))
   
   ;; it seems like the following code only works after-hook
-  (when (and typst-ts-mode-enable-raw-blocks-highlight
-             typst-ts-mode-highlight-raw-blocks-at-startup)
+  (when (and
+         (>= emacs-major-version 30)
+         typst-ts-mode-enable-raw-blocks-highlight
+         typst-ts-mode-highlight-raw-blocks-at-startup)
     ;; since currently local parsers haven't created, we cannot only load
     ;; those necessary parsers
     (cl-loop for setting in typst-ts-embedding-lang-settings
@@ -1600,18 +1605,19 @@ typst tree sitter grammar (at least %s)!" 
(current-time-string min-time))
             (file-name-nondirectory buffer-file-name)
             typst-ts-mode-compile-options))
 
-  (if (not typst-ts-mode-enable-raw-blocks-highlight)
+  (when (>= emacs-major-version 30)
+    (if (not typst-ts-mode-enable-raw-blocks-highlight)
+        (setq-local treesit-range-settings
+                    (typst-ts-mode--treesit-range-rules '(typst)))
+      (setq-local treesit-language-at-point-function
+                  'typst-ts-mode--language-at-point)
       (setq-local treesit-range-settings
-                  (typst-ts-mode--treesit-range-rules '(typst)))
-    (setq-local treesit-language-at-point-function
-                'typst-ts-mode--language-at-point)
-    (setq-local treesit-range-settings
-                (typst-ts-mode--treesit-range-rules
-                 (append
-                  (cl-loop for setting in typst-ts-embedding-lang-settings
-                           when (treesit-ready-p (car setting) t)
-                           collect (car setting))
-                  '(typst)))))
+                  (typst-ts-mode--treesit-range-rules
+                   (append
+                    (cl-loop for setting in typst-ts-embedding-lang-settings
+                             when (treesit-ready-p (car setting) t)
+                             collect (car setting))
+                    '(typst))))))
 
   ;; Outline
   (if nil  ; (>= emacs-major-version 30)
diff --git a/typst-ts-utils.el b/typst-ts-utils.el
new file mode 100644
index 0000000000..2db1544971
--- /dev/null
+++ b/typst-ts-utils.el
@@ -0,0 +1,62 @@
+;;; typst-ts-utils.el --- utility functions for typst-ts-mode -*- 
lexical-binding: t; -*-
+;; Copyright (C) 2024 Meow King <mr.meowk...@anche.no>
+
+;; This file is NOT part of Emacs.
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Utility functions for typst-ts-mode
+
+;;; Code:
+
+(require 'treesit)
+
+;; code is from treesit.el inside Emacs Source
+(defun typst-ts-utils-local-parsers-at (&optional pos language with-host)
+  "Return all the local parsers at POS.
+It's a copy of Emacs 30's `treesit-local-parsers-at' function.
+POS LANGUAGE WITH-HOST."
+  (if (>= emacs-major-version 30)
+      (funcall #'treesit-local-parsers-at pos language with-host)
+    (let ((res nil))
+      (dolist (ov (overlays-at (or pos (point))))
+        (when-let ((parser (overlay-get ov 'treesit-parser))
+                   (host-parser (overlay-get ov 'treesit-host-parser)))
+          (when (or (null language)
+                    (eq (treesit-parser-language parser)
+                        language))
+            (push (if with-host (cons parser host-parser) parser) res))))
+      (nreverse res))))
+
+;; code is from treesit.el inside Emacs Source
+(defun typst-ts-utils-local-parsers-on (&optional beg end language with-host)
+  "Return all the local parsers between BEG END.
+It's a copy of Emacs 30's `treesit-local-parsers-on' function.
+BEG END LANGUAGE WITH-HOST."
+  (if (>= emacs-major-version 30)
+      (funcall #'treesit-local-parsers-on beg end language with-host)
+    (let ((res nil))
+      (dolist (ov (overlays-in (or beg (point-min)) (or end (point-max))))
+        (when-let ((parser (overlay-get ov 'treesit-parser))
+                   (host-parser (overlay-get ov 'treesit-host-parser)))
+          (when (or (null language)
+                    (eq (treesit-parser-language parser)
+                        language))
+            (push (if with-host (cons parser host-parser) parser) res))))
+      (nreverse res))))
+
+(provide 'typst-ts-utils)
+
+;;; typst-ts-utils.el ends here


Reply via email to