Search code examples
emacssmlsmlnjsml-mode

SML syntax is not recognised in Emacs despite having installed sml-mode


I have installed the package sml-mode (version 6.9) in Emacs (version 26.2) but when I try to open a .sml file I get the following error in the minibuffer: File mode specification error: (invalid-read-syntax ?). As such, SML syntax is not recognised by the editor, which is also clear for the fact that the current mode displays the Fundamental mode other than SML.

These are the steps I did to set up my environment:

  • I have first installed smlnj in usr/local/sml.
  • I have tried to install the preset sml-mode package (M-x list-packages). However this did not work out.
  • I then downloaded the content of sml-mode-6.9.el from https://elpa.gnu.org/packages/sml-mode.html in my machine and have installed it on Emacs (M-x package-install-file).
  • The list of packages in Emacs displays Installed next to the sml-mode package, but apparently doesn't work.

Using M-x toggle-debug-on-error gives the following stack trace:

Debugger entered--Lisp error: (invalid-read-syntax "?")
read(#<buffer  *load*>)
eval-buffer(#<buffer  *load*> nil "/home/Roberto/.emacs.d/elpa/sml-mode-6.9/sml-mode.el" nil t)  ; Reading at buffer position 9890
load-with-code-conversion("/home/Roberto/.emacs.d/elpa/sml-mode-6.9/sml-mode.el" "/home/Roberto/.emacs.d/elpa/sml-mode-6.9/sml-mode.el" nil t)
sml-mode()
set-auto-mode-0(sml-mode nil)
set-auto-mode()
normal-mode(t)
after-find-file(t t)
find-file-noselect-1(#<buffer test.sml> "~/test.sml" nil nil "~/test.sml" nil)
find-file-noselect("~/test.sml" nil nil t)
find-file("~/test.sml" t)
funcall-interactively(find-file "~/test.sml" t)
call-interactively(find-file nil nil)
command-execute(find-file)

Solution

  • The error message says that there is an error at position 9890 in the file. That is right next to a lambda character:

      '(("fn" . ?λ)
    

    As this is the first non-ASCII character in the file, I guess the file was downloaded with a garbled encoding or something. Not sure why M-x list-packages wouldn't work for you - I guess you'd be able to work around this by editing the file manually. Compare to this version on Github to see which characters are supposed to appear there.