diff --git a/modules/lang/sml/README.org b/modules/lang/sml/README.org index 745651e02..1b2b3be7e 100644 --- a/modules/lang/sml/README.org +++ b/modules/lang/sml/README.org @@ -4,17 +4,23 @@ #+since: 21.12.0 * Description :unfold: -THis module adds [[https://smlfamily.github.io/][SML (Standard ML) programming language]] support to Doom Emacs. +This module adds [[https://smlfamily.github.io/][SML (Standard ML) programming language]] support to Doom Emacs. ** Maintainers *This module needs a maintainer.* [[doom-contrib-maintainer:][Become a maintainer?]] ** Module flags -/This module has no flags./ +- +lsp :: + Enable LSP support for ~sml-mode~/~sml-ts-mode~. Requires [[doom-module::tools lsp]] + and a langserver (supports [[https://github.com/azdavis/millet][millet-ls]]). +- +tree-sitter :: + Leverages tree-sitter for better syntax highlighting and structural text + editing. Requires [[doom-module::tools tree-sitter]]. ** Packages - [[doom-package:company-mlton]] if [[doom-module::completion company]] - [[doom-package:sml-mode]] +- [[doom-package:sml-ts-mode]] if [[doom-module:+tree-sitter]] ** Hacks /No hacks documented for this module./ diff --git a/modules/lang/sml/config.el b/modules/lang/sml/config.el index 9755cd33e..81493bfcc 100644 --- a/modules/lang/sml/config.el +++ b/modules/lang/sml/config.el @@ -3,11 +3,14 @@ (use-package! sml-mode :mode "\\.s\\(?:ml\\|ig\\)\\'" :config - (set-repl-handler! 'sml-mode #'run-sml) - (set-formatter! 'smlformat '("smlformat") :modes '(sml-mode)) + (set-repl-handler! '(sml-mode sml-ts-mode) #'run-sml) + (set-formatter! 'smlformat '("smlformat") :modes '(sml-mode sml-ts-mode)) + + (when (modulep! +lsp) + (add-hook 'sml-mode-local-vars-hook #'lsp! 'append)) ;; don't auto-close apostrophes (type 'a = foo) and backticks (`Foo) - (sp-with-modes 'sml-mode + (sp-with-modes '(sml-mode sml-ts-mode) (sp-local-pair "'" nil :actions nil) (sp-local-pair "`" nil :actions nil)) @@ -23,6 +26,19 @@ :desc "Run region" "r" #'sml-prog-proc-send-region)) +;; TODO: Mirror sml-mode keybinds to ts-mode +(use-package! sml-ts-mode + :when (modulep! +tree-sitter) + :when (fboundp 'treesit-available-p) + :defer t + :init + (set-tree-sitter! 'sml-mode 'sml-ts-mode + '((sml :url "https://github.com/MatthewFluet/tree-sitter-sml"))) + :config + (when (modulep! +lsp) + (add-hook 'sml-ts-mode-local-vars-hook #'lsp! 'append))) + + (use-package! company-mlton :when (modulep! :completion company) :hook (sml-mode . company-mlton-init) diff --git a/modules/lang/sml/doctor.el b/modules/lang/sml/doctor.el index de483c420..eb21317a5 100644 --- a/modules/lang/sml/doctor.el +++ b/modules/lang/sml/doctor.el @@ -1,5 +1,9 @@ ;;; lang/sml/doctor.el -*- lexical-binding: t; -*- +(assert! (or (not (modulep! +tree-sitter)) + (modulep! :tools tree-sitter)) + "This module requires (:tools tree-sitter)") + (when (modulep! :editor format) (unless (executable-find "smlformat") (warn! "Couldn't find smlformat. Formatting will be disabled."))) diff --git a/modules/lang/sml/packages.el b/modules/lang/sml/packages.el index 08879072e..3322c9f8a 100644 --- a/modules/lang/sml/packages.el +++ b/modules/lang/sml/packages.el @@ -6,3 +6,5 @@ (package! company-mlton :recipe (:host github :repo "MatthewFluet/company-mlton" :files ("*.el" "*.basis")) :pin "9b09d209b4767a2af24784fb5321390ed1d445bf")) +(when (modulep! +tree-sitter) + (package! sml-ts-mode :pin "d2dabcc9d8f91eeee7048641e4c80fabb3583194"))