branch: elpa/typst-ts-mode commit d23140e91f9023043d151098c58a62fc9135c233 Author: Ziqi Yang <mr.ziqiy...@gmail.com> Commit: Ziqi Yang <mr.ziqiy...@gmail.com>
feat: add imenu support --- README.md | 17 ++++++++++++----- basic-syntax.typ | 2 +- typst-ts-mode.el | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8f074d559c..1040b8f8a2 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,19 @@ # typst-ts-mode - + [Project](https://git.sr.ht/~meow_king/typst-ts-mode) -[Public Inbox](https://lists.sr.ht/~meow_king/public-inbox): General Consults -[Sending a Patch](https://lists.sr.ht/~meow_king/dev) -[Discussion](https://lists.sr.ht/~meow_king/discussion): Questions and Feedback +[Public Inbox](https://lists.sr.ht/~meow_king/public-inbox): General Consults +[Sending a Patch](https://lists.sr.ht/~meow_king/dev) +[Discussion](https://lists.sr.ht/~meow_king/discussion): Questions and Feedback [Tickets](https://todo.sr.ht/~meow_king/typst-ts-mode) - https://github.com/uben0/tree-sitter-typst + +``` emacs-lisp +(setq + consult-imenu-config (append consult-imenu-config + '((typst-ts-mode :topLevel "Headings" :types + ((?h "Headings" typst-ts-markup-header-face) + (?f "Functions" font-lock-function-name-face)))))) +``` diff --git a/basic-syntax.typ b/basic-syntax.typ index ba0e56921b..0e2752cad4 100644 --- a/basic-syntax.typ +++ b/basic-syntax.typ @@ -1,4 +1,4 @@ -// This file only serves for testing highlight, and it is not a syntax completion test. +// This file only serves for testing highlight, and it is not a syntax completion test. // comment diff --git a/typst-ts-mode.el b/typst-ts-mode.el index 6205dfc0ac..3ec039fe02 100644 --- a/typst-ts-mode.el +++ b/typst-ts-mode.el @@ -430,6 +430,17 @@ TYPES." (group (or (syntax comment-end) (seq (+ "*") "/")))))) +(defun typst-ts-mode--imenu-function-defintion-p (node) + "Whether NODE is a function defintion node." + (let* ((parent-node (treesit-node-parent node)) + (grandparent-node (treesit-node-parent parent-node))) + (and (equal (treesit-node-type node) "ident") + (equal (treesit-node-type parent-node) "call") + (equal (treesit-node-type grandparent-node) "let")))) + +(defun typst-ts-mode--imenu-name-function (node) + "Generate name of NODE for displaying in Imenu." + (treesit-node-text node)) ;;;###autoload (define-derived-mode typst-ts-mode text-mode "Typst" @@ -464,6 +475,12 @@ TYPES." ;; Indentation (setq-local treesit-simple-indent-rules typst-ts-mode--indent-rules) + ;; Imenu + (setq-local treesit-simple-imenu-settings + `(("Functions" typst-ts-mode--imenu-function-defintion-p nil + typst-ts-mode--imenu-name-function) + ("Headings" "^heading$" nil typst-ts-mode--imenu-name-function))) + (treesit-major-mode-setup)) ;; TODO check consistence with typst-mode