-
Notifications
You must be signed in to change notification settings - Fork 74
Integrating tree-sitter-mode directly into a new major-mode #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yes, definitely!
A basic major mode would look like this: (require 'tree-sitter)
(require 'tree-sitter-hl)
;;;###autoload
(define-derived-mode wat-mode prog-mode "WAT"
;; It's up to the major mode to set this. It plays a role similar to that of
;; `font-lock-defaults'.
(setq tree-sitter-hl-default-patterns
[["module" "func" "param"] @keyword
(module_field_func (identifier) @function)])
(tree-sitter-hl-mode))
;;;###autoload
(progn
;; There are 3 ways to register/load the compiled grammar.
;;
;; 1. `wat-mode' distributes the compiled grammar files on its own:
;;
;; (tree-sitter-load 'wat PATH-TO-COMPILED-WAT-GRAMMAR)
;;
;; 2. Same as above, but with lazy loading:
;;
;; (add-to-list 'tree-sitter-load-path PATH-TO-DIR-OF-COMPILED-WAT-GRAMMAR)
;;
;; 3. `tree-sitter-langs' distributes the compiled grammar (not the queries):
;; Do nothing.
;; Register the association with `tree-sitter-mode'.
(add-to-list 'tree-sitter-major-mode-language-alist '(wat-mode . wat))
(add-to-list 'auto-mode-alist '("\\.wat\\'" . wat-mode)))
(provide 'wat-mode)
;;; wat-mode.el ends here Compiling, packaging, and distributing grammars (for all major platforms) would be a hassle though, so you may want to rely on |
Thanks for the info! I think that clarifies things enough for me to get started. The suggestion to use I'll go ahead and make a PR to add the WebAssembly grammars shortly. |
I'm writing a new major mode for WebAssembly text formats and would like to use the WebAssembly tree-sitter grammar (here) for highlighting.
Since this is a new mode being written from scratch, it sounds like it might be better to integrate support for the tree-sitter mode directly into this new major mode, rather than including the queries and other definitions in this repository.
However, I'm not quite sure what I need to do in order to build the tree-sitter functionality in this new mode. The documentation doesn't seem to have much to say about that.
Is it currently feasible to include support directly into a new mode? If so, can you give a description for how I need to set things up for that?
The text was updated successfully, but these errors were encountered: