branch: elpa/typst-ts-mode commit a5f094dd1d1ce992e9ad290e4838779b2dd5809a Author: Meow King <mr.meowk...@anche.no> Commit: Meow King <mr.meowk...@anche.no>
fix: emacs 29 compability problem (`treesit-node-get`) --- #basic-syntax.typ# | 82 ------------------------------------------------------ typst-ts-mode.el | 2 +- typst-ts-utils.el | 22 +++++++++++++++ 3 files changed, 23 insertions(+), 83 deletions(-) diff --git a/#basic-syntax.typ# b/#basic-syntax.typ# deleted file mode 100644 index 1ba0179ca5..0000000000 --- a/#basic-syntax.typ# +++ /dev/null @@ -1,82 +0,0 @@ -// 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/typst-ts-mode.el b/typst-ts-mode.el index b3fbe64d24..19781d48c5 100644 --- a/typst-ts-mode.el +++ b/typst-ts-mode.el @@ -1142,7 +1142,7 @@ When prefix ARG is non-nil, call global return function." ((and (eolp) (setq node (typst-ts-mode--item-on-line-p)) (string= (treesit-node-type node) "item") - (not (string= (treesit-node-get node '((child -1 nil) (type))) "linebreak"))) + (not (string= (typst-ts-utils-node-get node '((child -1 nil) (type))) "linebreak"))) (if (> (treesit-node-child-count node) 1) (typst-ts-mode-insert--item node) ;; no text means delete the item on current line diff --git a/typst-ts-utils.el b/typst-ts-utils.el index 2db1544971..b817742974 100644 --- a/typst-ts-utils.el +++ b/typst-ts-utils.el @@ -57,6 +57,28 @@ BEG END LANGUAGE WITH-HOST." (push (if with-host (cons parser host-parser) parser) res)))) (nreverse res)))) +(defun typst-ts-utils-node-get (node instructions) + "Get things from NODE by INSTRUCTIONS. +It's a copy of Emacs 30's `treesit-node-get' function." + (declare (indent 1)) + (if (>= emacs-major-version 30) + (treesit-node-get node instructions) + (while (and node instructions) + (pcase (pop instructions) + ('(field-name) (setq node (treesit-node-field-name node))) + ('(type) (setq node (treesit-node-type node))) + (`(child ,idx ,named) (setq node (treesit-node-child node idx named))) + (`(parent ,n) (dotimes (_ n) + (setq node (treesit-node-parent node)))) + (`(text ,no-property) (setq node (treesit-node-text node no-property))) + (`(children ,named) (setq node (treesit-node-children node named))) + (`(sibling ,step ,named) + (dotimes (_ (abs step)) + (setq node (if (> step 0) + (treesit-node-next-sibling node named) + (treesit-node-prev-sibling node named))))))) + node)) + (provide 'typst-ts-utils) ;;; typst-ts-utils.el ends here