branch: elpa/typst-ts-mode commit ce4142e1efd37218500316edd2fd5eb2dca81ef4 Author: Ziqi Yang <mr.ziqiy...@gmail.com> Commit: Ziqi Yang <mr.ziqiy...@gmail.com>
feat: add electric auto pair pairs --- basic-syntax.typ | 2 +- typst-ts-mode.el | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/basic-syntax.typ b/basic-syntax.typ index 5628099a0e..ba0e56921b 100644 --- a/basic-syntax.typ +++ b/basic-syntax.typ @@ -77,5 +77,5 @@ Hello\nWorld // escape $a$ // math $ 1 + 1 = 2 $ $ E = m * c^2 $ -$eq.not(0)$ +$ eq.not(0) $ $ cal(A) := { x in RR | x "is natural" } $ diff --git a/typst-ts-mode.el b/typst-ts-mode.el index cbb4dcf7cc..3d75478289 100644 --- a/typst-ts-mode.el +++ b/typst-ts-mode.el @@ -241,7 +241,6 @@ "Face for math indicator $." :group 'typst-ts-faces) - (defvar typst-ts-mode-font-lock-rules '(;; Typst font locking :language typst @@ -335,15 +334,20 @@ :language typst :feature math ((math "$" @typst-ts-math-indicator-face) - + (fraction "/" @font-lock-operator-face) (fac "!" @font-lock-operator-face) (attach ["^" "_"] @font-lock-operator-face) (align) @font-lock-operator-face - + (symbol) @font-lock-constant-face (letter) @font-lock-constant-face))) +(defvar typst-ts-mode--indent-rules + `((typst + (no-node parent 0))) + "Tree-sitter indent rules for `rust-ts-mode'.") + (defun typst-ts-mode-comment-setup() "Setup comment related stuffs for typst-ts-mode." ;; stolen from `c-ts-common-comment-setup' @@ -373,19 +377,29 @@ (typst-ts-mode-comment-setup) ;; Electric - (setq-local electric-indent-chars - (append "{}()[]" electric-indent-chars)) - - ;; Font Lock TODO + (setq-local electric-indent-chars (append "{}()[]$" electric-indent-chars) + electric-pair-pairs '((?\" . ?\") + (?\{ . ?\}) + (?\( . ?\)) + (?\[ . ?\]) + (?\$ . ?\$))) + + ;; Font Lock (setq-local treesit-font-lock-settings (apply #'treesit-font-lock-rules typst-ts-mode-font-lock-rules)) (setq-local treesit-font-lock-feature-list ;; TODO '((comment common markup code math))) + ;; Indentation + (setq-local treesit-simple-indent-rules typst-ts-mode--indent-rules) + (treesit-major-mode-setup)) +;; TODO check consistence with typst-mode ;;;###autoload (add-to-list 'auto-mode-alist '("\\.typ\\'" . typst-ts-mode)) (provide 'typst-ts-mode) + +;;; typst-ts-mode.el ends here