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

435 views Asked by At

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)
2

There are 2 answers

1
legoscia On BEST ANSWER

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.

1
sshine On

Perhaps M-x package-list-packages did successfully install sml-mode, but subsequently it's not loaded.

Could you verify that the directory ~/.emacs.d/elpa/sml-mode-6.9 exists?

The only configuration I have for sml-mode is what the package installer added:

(require 'package)
(setq package-archives
      '(("gnu" . "http://elpa.gnu.org/packages/")
        ("marmalade" . "https://marmalade-repo.org/packages/")
        ("melpa" . "http://melpa.org/packages/")))
(package-initialize)

...

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 ...
 '(package-selected-packages
   (quote
    (... sml-mode ...))))

This should somehow reach the file ~/.emacs.d/elpa/sml-mode-6.9/sml-mode-autoloads.el which makes sml-mode load when opening the right kind of files.

Perhaps, could you also verify that sml-mode is similarly mentioned in your .emacs file?

I was using Emacs 25 and sml-mode-6.7 successfully without having done anything but what you did. If I upgrade to sml-mode-6.9 this setup still works. Unfortunately I'm unable to test that it also works with Emacs 26. I can unfortunately not say if there are any package manager discrepancies between 25 and 26 that could play in here.