Standard ML is an ML dialect similar to OCaml. There is some work already done for Standard ML in spacemacs, however it is not very comprehensive. There is the sml-mode from ELPA. However, there is also a company component that uses a pluggable MLton feature to provide company completions.
https://github.com/MatthewFluet/company-mlton
This is not available yet on melpa/elpa.
If I can think of any other feature ideas, I will share them here.
Hi, I prepared the following for my workflow; it is working except for company-mlton, it does not start automatically; I start it after I open an sml file using M-x company-mlton-init. @hlissner do you know what i am doing wrong in add-hook 'sml-mode-hook #'company-mlton-init?
elisp
;;; packages.el
(package! sml-mode)
(package! company-mlton :recipe (:host github :repo "MatthewFluet/company-mlton"
:files ("*.el" "*.basis")))
```elisp
;;; config.el
(use-package! sml-mode
:mode "\\.\\(sml\\|sig\\)\\'"
:defer t
:commands run-sml
:init (autoload 'run-sml "sml-proc" "Run an inferior SML process." t)
:config
(progn
(defun my/sml-prog-proc-send-buffer-and-focus ()
"Send buffer to REPL and switch to it ininsert state'."
(interactive)
(sml-prog-proc-send-buffer t)
(evil-insert-state))
(defun my/sml-prog-proc-send-region-and-focus (start end)
"Send region to REPL and switch to it in `insert state'."
(interactive "r")
(sml-prog-proc-send-region start end t)
(evil-insert-state))
(defun my/sml-send-function-and-focus ()
"Send function at point to REPL and switch to it in `insert state'."
(interactive)
(sml-send-function t)
(evil-insert-state))
(define-key sml-mode-map (kbd "RET") 'reindent-then-newline-and-indent)
(define-key sml-mode-map (kbd "M-SPC") 'sml-electric-space)
(define-key sml-mode-map (kbd "|") 'sml-electric-pipe))
)
(with-eval-after-load 'smartparens
;; don't auto-close apostrophes (type 'a = foo) and backticks (Foo)
(sp-local-pair 'sml-mode "'" nil :actions nil)
(sp-local-pair 'sml-mode "" nil :actions nil))
(map!
(:map sml-mode-map
:desc "SML Mode" :localleader "'" #'run-sml
:prefix ("s" . "sml") (
:desc "Run buffer" "b" #'sml-prog-proc-send-buffer
:desc "Run buffer and Focus" "B" #'my/sml-prog-proc-send-buffer-and-focus
:desc "Run the paragraph" "f" #'sml-send-function
:desc "Run the paragraph and focus" "F" #'my/sml-send-function-and-focus
:desc "Run sml" "i" #'run-sml
:desc "Run region" "r" #'sml-prog-proc-send-region
:desc "Run region and focus" "R" #'my/sml-prog-proc-send-region-and-focus
:desc "Run buffer" "s" #'run-sml)))
(use-package! company-mlton
:after sml-mode
:config
(add-hook 'sml-mode-hook #'company-mlton-init))
````
As of 33b95c6 Doom now has a :lang sml module, so I'll consider this resolved, with @ferhaterata's config as the rough basis for it.
do you know what i am doing wrong in add-hook 'sml-mode-hook #'company-mlton-init?
@ferhaterata It is likely company-mlton-init wasn't running early enough. Give the new :lang sml module a try. company-mlton should work with it now.
On a separate note, I've omitted your send-function commands because they are redundant with the gr operator, which will send the target text to the REPL (and focus it) if it's open (open it in a popup with SPC o r, or the current window with SPC o R).
Hope that helps!
Thank you very much! You're the best!
I am going to install sml layer right now.
hi @hlissner
unfortunately there is a bug which prevents loading sml-mode.
File mode specification error: (error Key sequence M-SPC m ' starts with non-prefix key M-SPC)
evil-define-key*: Key sequence M-SPC m ' starts with non-prefix key M-SPC
M-x sml-mode also fires the same error.
@MatthewFluet. Just wanted to let you know about this :)
@ferhaterata This should be fixed in 378cab0c1
Thank you, great! let me use the new sml layer.
hi @hlissner, the mode properly loads but company-mlton does not. I load it by M-x company-mlton-init. Since I have to do that for each sml buffer, it is quite annoying. Could you possibly fix it?
company-mlton
@ferhaterata ca1044583 should hopefully fix that.
It's working! thank you!
Most helpful comment
As of 33b95c6 Doom now has a
:lang smlmodule, so I'll consider this resolved, with @ferhaterata's config as the rough basis for it.@ferhaterata It is likely
company-mlton-initwasn't running early enough. Give the new :lang sml module a try.company-mltonshould work with it now.On a separate note, I've omitted your send-function commands because they are redundant with the
groperator, which will send the target text to the REPL (and focus it) if it's open (open it in a popup withSPC o r, or the current window withSPC o R).Hope that helps!