branch: elpa/typst-ts-mode
commit 04c2cbab75b547cb13cb11ae3926794cee11a184
Author: Meow King <[email protected]>
Commit: Meow King <[email protected]>
sync upstream
---
.gitignore | 1 +
justfile | 11 ++-
side/sync_with_upstream.typ | 101 ++++++++++++++++++++++
test/basic-syntax.pdf | Bin 0 -> 179508 bytes
basic-syntax.typ => test/basic-syntax.typ | 47 +++++-----
test/dumb_import.typ | 2 +
indentation-test.typ => test/indentation-test.typ | 0
typst-ts-mode.el | 19 ++--
8 files changed, 141 insertions(+), 40 deletions(-)
diff --git a/.gitignore b/.gitignore
index 26b0e1402c..4c0e86d826 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
*.elc
+/side/*.pdf
/makem.sh
# Added by cargo
diff --git a/justfile b/justfile
index ed05277fd6..57c3887583 100644
--- a/justfile
+++ b/justfile
@@ -1,11 +1,10 @@
els-settings-test:
- emacs --batch -l ./typst-ts-embedding-lang-settings.el \
- -l ~/.emacs.d/.local/elpaca/repos/emacs-kotlin-ts-mode/kotlin-ts-mode.el \
- -l ~/.emacs.d/.local/elpaca/repos/mermaid-ts-mode/mermaid-ts-mode.el \
+ emacs --batch -l ./typst-ts-utils.el \
+ -l ./typst-ts-embedding-lang-settings.el \
+ -l
~/.config/emacs/.local/elpaca/repos/emacs-kotlin-ts-mode/kotlin-ts-mode.el \
+ -l ~/.config/emacs/.local/elpaca/repos/mermaid-ts-mode/mermaid-ts-mode.el \
--eval "(typst-ts-embedding-lang-settings-test)"
lint:
+ # makem: https://github.com/alphapapa/makem.sh
./makem.sh lint
-
-lint-29:
- ./makem.sh lint -E ~/myBin/emacs29.2
diff --git a/side/sync_with_upstream.typ b/side/sync_with_upstream.typ
new file mode 100644
index 0000000000..877f59db8d
--- /dev/null
+++ b/side/sync_with_upstream.typ
@@ -0,0 +1,101 @@
+#import "@preview/cheq:0.1.0": unchecked-sym, checked-sym
+
+#let yes = checked-sym(fill: luma(95%), stroke: blue, radius: .2em)
+#let todo = unchecked-sym(fill: luma(95%), stroke: blue, radius: .2em)
+
+#let cyan = rgb("EAF2F5")
+#set table(fill: (_, y) => if y == 0 { cyan })
+#let tableSep(content) = table.cell(fill: cyan, colspan: 2, text(content))
+
+#link("https://github.com/uben0/tree-sitter-typst?tab=readme-ov-file")[tree-sitter-typst]
+
+Grammar File Path: `/queries/typst/highlights.scm`
+
+Corresponding Commit: `4610172f312e8ce5184e6882be5ad1a1cd800fbe`
+
+Use `git diff` or `git blame` to get the grammar change.
+
+#table(
+ columns: 2,
+ table.header[*Rule*][*Status*],
+ [`(call item: (ident) @function)`] , yes,
+ [`(call item: (field field: (ident) @function.method))`] , yes,
+ [`(tagged field: (ident) @tag)`] , yes,
+ [`(field field: (ident) @tag)`] , yes,
+ [`(comment) @comment`] , yes,
+
+ tableSep([_Control_]),
+ [`(let "let" @keyword.storage.type)`] , yes,
+ [`(branch ["if" "else"] @keyword.control.conditional)`] , yes,
+ [`(while "while" @keyword.control.repeat)`] , yes,
+ [`(for ["for" "in"] @keyword.control.repeat)`] , yes,
+ [`(import "import" @keyword.control.import)`] , yes,
+ [`(as "as" @keyword.operator)`] , yes,
+ [`(include "include" @keyword.control.import)`] , yes,
+ [`(show "show" @keyword.control)`] , yes,
+ [`(set "set" @keyword.control)`] , yes,
+ [`(return "return" @keyword.control)`] , yes,
+ [`(flow ["break" "continue"] @keyword.control)`] , yes,
+
+ tableSep([_OPERATOR_]),
+ [`(in ["in" "not"] @keyword.operator)`] , yes,
+ [`(context "context" @keyword.control)`] , yes,
+ [`(and "and" @keyword.operator)`] , yes,
+ [`(or "or" @keyword.operator)`] , yes,
+ [`(not "not" @keyword.operator)`] , yes,
+ [`(sign ["+" "-"] @operator)`] , yes,
+ [`(add "+" @operator)`] , yes,
+ [`(sub "-" @operator)`] , yes,
+ [`(mul "*" @operator)`] , yes,
+ [`(div "/" @operator)`] , yes,
+ [`(cmp ["==" "<=" ">=" "!=" "<" ">"] @operator)`] , yes,
+ [`(fraction "/" @operator)`] , yes,
+ [`(fac "!" @operator)`] , yes,
+ [`(attach ["^" "_"] @operator)`] , yes,
+ [`(wildcard) @operator`] , yes,
+
+ tableSep([_VALUE_]),
+ [#raw("(raw_blck \"```\" @operator) @markup.raw.block")] , yes,
+ [```(raw_span "`" @operator) @markup.raw.block```] , yes,
+ [`(raw_blck lang: (ident) @tag)`] , yes,
+ [`(label) @tag`] , yes,
+ [`(ref) @tag`] , yes,
+ [`(number) @constant.numeric`] , yes,
+ [`(string) @string`] , yes,
+ [`(content ["[" "]"] @operator)`] , yes,
+ [`(bool) @constant.builtin.boolean`] , yes,
+ [`(none) @constant.builtin`] , yes,
+ [`(auto) @constant.builtin`] , yes,
+
+ tableSep([_MARKUP_]),
+ [`(item "-" @markup.list)`] , yes,
+ [`(term ["/" ":"] @markup.list)`] , yes,
+ [`(heading "=" @markup.heading.marker) @markup.heading.1`] , yes,
+ [`(heading "==" @markup.heading.marker) @markup.heading.2`] , yes,
+ [`(heading "===" @markup.heading.marker) @markup.heading.3`] , yes,
+ [`(heading "====" @markup.heading.marker) @markup.heading.4`] , yes,
+ [`(heading "=====" @markup.heading.marker) @markup.heading.5`] , yes,
+ [`(heading "======" @markup.heading.marker) @markup.heading.6`] , yes,
+ [`(url) @tag`] , yes,
+ [`(emph) @markup.italic`] , yes,
+ [`(strong) @markup.bold`] , yes,
+ [`(symbol) @constant.character`] , yes,
+ [`(shorthand) @constant.builtin`] , yes,
+ [`(quote) @markup.quote`] , yes,
+ [`(align) @operator`] , yes,
+ [`(letter) @constant.character`] , yes,
+ [`(linebreak) @constant.builtin`] , yes,
+
+ tableSep([_MATH_]),
+ [`(math "$" @operator)`] , yes,
+ [`"#" @operator`] , yes,
+ [`"end" @operator`] , [ HAVEN'T ADDED since it isn't visual (for
highlighting) and doesn't affect indentation ],
+
+ tableSep([ _MISCELLANEOUS_ ]),
+ [`(escape) @constant.character.escape`] , yes,
+ [`["(" ")" "{" "}"] @punctuation.bracket`] , yes,
+ [`["," ";" ".." ":" "sep"] @punctuation.delimiter`], yes,
+ [`"assign" @punctuation`] , yes,
+ [`(field "." @punctuation)`] , yes,
+)
+
diff --git a/test/basic-syntax.pdf b/test/basic-syntax.pdf
new file mode 100644
index 0000000000..057159ea37
Binary files /dev/null and b/test/basic-syntax.pdf differ
diff --git a/basic-syntax.typ b/test/basic-syntax.typ
similarity index 60%
rename from basic-syntax.typ
rename to test/basic-syntax.typ
index 46b30275e1..bc22804348 100644
--- a/basic-syntax.typ
+++ b/test/basic-syntax.typ
@@ -1,11 +1,19 @@
// This file only serves for testing highlight, and it is not a syntax
completion test.
+#let a = 1
+#let b = 2
+#let c = 3
+#let t = true
+#let f = false
+#let values = (1, 7, 4, -3, 2)
+#set heading(numbering: "1")
+
// comment
-? $ -> $ // shorthand
// header face
-= headline
+= headline _emph_
https://www.google.com // url
_emph_ // emphasis
*strong* // strong
@@ -18,8 +26,8 @@ hello \ // line break
```bash
sudo rm -rf *
```
-<label> // label
-@reference // reference
+= hi <label> // label
+@label // reference
Hello\nWorld // escape
@@ -29,35 +37,35 @@ Hello\nWorld // escape
#[El Psy Kongraoo] // content
#true #false // boolean
#sym.bar.h // builtin
-#set text(a: 0) // call & builtin
+#set text(lang: "zh") // 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
+#("0" in "0" and "0" not in "1") // in
+#(t and f or not t) // 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
+#import "dumb_import.typ": * // wildcard
#let a = b // let
-#if b {} else {} // branch
-#while n < 10 { // while
- (n,)
+#if f {} else {} // branch
+#while a < 10 { // while
+ a += 1
}
-#for i in a {} // for
-#import "a": a, b // import
-#import "a.lib" as b // as
-#include "a" // include
+#for i in (a, b, c) {} // for
+#import "dumb_import.typ": x, y as yyy // import
+#include "dumb_import.typ" // include
#show: columns.with(2) // show
-#set text(a: 0) // set
+#set text(lang: "en") // set
#let a() = { // return
return 2
}
+#context text.lang // context
#for letter in "abc nope" { // flow
if letter == " " {
break
@@ -67,13 +75,12 @@ Hello\nWorld // escape
letter
}
-#a()() // function
-#range().map // builtin function
-#l.zip(r).map( // method
+#range(5).zip(range(10)).map( // method
((a,b)) => a + b // TODO lambda
)
-#(a, c: b) // tagged
-#a.b // field
+#range(20, step: 10) // tagged
+
+#values.0 // field
$ a $ // math
$ 1 + 1 = 2 $
diff --git a/test/dumb_import.typ b/test/dumb_import.typ
new file mode 100644
index 0000000000..d9c8134dc7
--- /dev/null
+++ b/test/dumb_import.typ
@@ -0,0 +1,2 @@
+#let x = 1;
+#let y = 2;
diff --git a/indentation-test.typ b/test/indentation-test.typ
similarity index 100%
rename from indentation-test.typ
rename to test/indentation-test.typ
diff --git a/typst-ts-mode.el b/typst-ts-mode.el
index 8e46c64f4c..e89a28d715 100644
--- a/typst-ts-mode.el
+++ b/typst-ts-mode.el
@@ -177,7 +177,7 @@ If you want to customize the rules, please customize the
same name variable
(let ((markup-basic
(pcase typst-ts-mode-fontification-precision-level
('min
- `((heading) @typst-ts-markup-header-face
+ `((heading _ @typst-ts-markup-header-indicator-face (text)
@typst-ts-markup-header-face)
(emph) @typst-ts-markup-emphasis-face
(strong) @typst-ts-markup-strong-face
(item) @typst-ts-markup-item-face
@@ -193,7 +193,7 @@ If you want to customize the rules, please customize the
same name variable
(label) @typst-ts-markup-label-face
(ref) @typst-ts-markup-reference-face))
('middle
- `((heading) @typst-ts-markup-header-face
+ `((heading _ @typst-ts-markup-header-indicator-face (text)
@typst-ts-markup-header-face)
(emph) @typst-ts-markup-emphasis-face
(strong) @typst-ts-markup-strong-face
(item
@@ -219,18 +219,7 @@ If you want to customize the rules, please customize the
same name variable
(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 (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
@@ -243,6 +232,7 @@ If you want to customize the rules, please customize the
same name variable
(text) @typst-ts-markup-header-face-5)
(heading "======" @typst-ts-markup-header-indicator-face-6
(text) @typst-ts-markup-header-face-6)))
+ ;; TODO performance enhancement
(emph
"_" @typst-ts-markup-emphasis-indicator-face
(text) @typst-ts-markup-emphasis-face
@@ -332,6 +322,7 @@ If you want to customize the rules, please customize the
same name variable
(include "include" @font-lock-keyword-face)
(show "show" @font-lock-keyword-face)
(set "set" @font-lock-keyword-face)
+ (context "context" @font-lock-keyword-face)
(return "return" @font-lock-keyword-face)
(flow ["break" "continue"] @font-lock-keyword-face)