Skip to content

Instantly share code, notes, and snippets.

@isoraqathedh
Created April 7, 2026 07:59
Show Gist options
  • Select an option

  • Save isoraqathedh/56480b2dc7dcd63998896f7dddc979c4 to your computer and use it in GitHub Desktop.

Select an option

Save isoraqathedh/56480b2dc7dcd63998896f7dddc979c4 to your computer and use it in GitHub Desktop.
Numbat mode for Emacs
(define-derived-mode numbat-ts-mode prog-mode "Numbat[ts]"
"Major mode for editing Numbat source code wtih tree-sitter."
(setq-local font-lock-defaults nil)
(when (treesit-ready-p 'numbat)
(treesit-parser-create 'numbat)
(numbat-ts-setup)))
(defun numbat-ts-setup ()
"Set up treesit for numbat-ts-mode"
(setq-local treesit-font-lock-feature-list
'((string)
(func var unit dimension cond decorator module_import)
(boolean)))
(setq-local numbat-ts-font-lock-rules
'(:language numbat :override t
:feature string
((string) @font-lock-string-face)
;; :language numbat :override t
;; :feature comment
;; ((:match "^[ \t]#.*$" @font-lock-comment-face))
:language numbat :override t
:feature func
((function_decl
"fn" @font-lock-keyword-face
(identifier) @font-lock-function-name-face
("<"
(identifier) @font-lock-type-face
">") :?
"("
(identifier) @font-lock-variable-name-face
(dimension_expr) :? @font-lock-type-face
(type_annotation) :? @font-lock-type-face
;;"where" :? @font-lock-keyword-face
))
:language numbat :override t
:feature var
((variable_decl
"let" @font-lock-keyword-face
(identifier) @font-lock-variable-name-face
":" :?
(type_annotation) :? @font-lock-type-face))
:language numbat :override t
:feature cond
((condition
"if" @font-lock-keyword-face
"then" @font-lock-keyword-face
"else" :? @font-lock-keyword-face))
:language numbat :override t
:feature unit
((unit_decl
"unit" @font-lock-keyword-face
[(identifier) @font-lock-variable-name-face ; apparently parse failure
(dimension_expr) :? @font-lock-type-face]
))
:language numbat :override t
:feature dimension
((dimension_decl
"dimension" @font-lock-keyword-face
(identifier) @font-lock-type-face))
:language numbat :override t
:feature boolean
((boolean) @font-lock-constant-face)
:language numbat :override t
:feature decorator
((decorator) @font-lock-constant-face
("("
(identifier) @font-lock-variable-name-face
(":"
"short" @font-lock-keyword-face) :?
")") :?)
:language numbat :override t
:feature module_import
((module_import) "use" @font-lock-keyword-face))
)
(setq-local treesit-font-lock-settings
(apply #'treesit-font-lock-rules
numbat-ts-font-lock-rules))
(treesit-major-mode-setup))
(provide 'numbat-ts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment