【问题标题】:SML syntax is not recognised in Emacs despite having installed sml-mode尽管安装了 sml-mode,但 Emacs 无法识别 SML 语法
【发布时间】:2020-01-14 08:14:50
【问题描述】:

我已经在 Emacs(版本 26.2)中安装了包 sml-mode(版本 6.9),但是当我尝试打开一个 .sml 文件时,我在 minibuffer 中收到以下错误:File mode specification error: (invalid-read-syntax ?) .因此,编辑器无法识别 SML 语法,这一点也很清楚,因为当前模式显示 Fundamental 模式而不是 SML

这些是我设置环境的步骤:

  • 我先在usr/local/sml安装了smlnj。
  • 我已经尝试安装预设的sml-mode 包(M-x list-packages)。然而这并没有成功。
  • 然后我在我的机器上从https://elpa.gnu.org/packages/sml-mode.html 下载了sml-mode-6.9.el 的内容,并将其安装在Emacs 上(M-x package-install-file)。
  • Emacs 中的软件包列表在 sml-mode 软件包旁边显示 Installed,但显然不起作用。

使用 M-x toggle-debug-on-error 会给出以下堆栈跟踪:

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)

【问题讨论】:

  • 调用 sml 模式时出现问题。试试M-x toggle-debug-on-error - 这样你应该得到一个堆栈跟踪,指出错误发生的位置。然后edit您的问题并添加堆栈跟踪(格式化为代码块)。
  • 谢谢我用堆栈跟踪编辑了问题

标签: emacs sml smlnj sml-mode


【解决方案1】:

也许M-x package-list-packages 确实成功安装了sml-mode,但随后没有加载。

您能否验证目录~/.emacs.d/elpa/sml-mode-6.9 是否存在?

我对@9​​87654324@ 的唯一配置是软件包安装程序添加的内容:

(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 ...))))

这应该以某种方式到达文件~/.emacs.d/elpa/sml-mode-6.9/sml-mode-autoloads.el,从而在打开正确类型的文件时加载sml-mode

也许,您能否验证一下您的.emacs 文件中是否同样提到了sml-mode

我成功地使用了 Emacs 25 和 sml-mode-6.7,除了你所做的,我什么也没做。如果我升级到sml-mode-6.9,这个设置仍然有效。不幸的是,我无法测试它是否也适用于 Emacs 26。很遗憾,我不能说 25 和 26 之间是否有任何包管理器差异可以在这里发挥作用。

【讨论】:

  • 感谢您的回复。我确实有文件夹~/.emacs.d/elpa/sml-mode-6.9,其中包含以下三个文件:sml-mode-autoloads.elsml-mode.elsml-mode-pkg.el。这是没有 cmets 的 .emacs 文件的内容:(package-initialize) (custom-set-variables '(package-selected-packages (quote (sml-mode)))) (custom-set-faces )
【解决方案2】:

错误消息表明文件中的位置 9890 存在错误。就在 lambda 字符旁边:

  '(("fn" . ?λ)

由于这是文件中的第一个非 ASCII 字符,我猜该文件是用乱码编码或其他东西下载的。不知道为什么M-x list-packages 对你不起作用——我想你可以通过手动编辑文件来解决这个问题。与this version on Github 比较,看看哪些字符应该出现在那里。

【讨论】:

  • 谢谢,我确实对文件有一些编码问题,而不是 lambda 符号我有另一个符号。我已经粘贴了您链接的文件的内容,并且效果很好。抱歉回复晚了。
猜你喜欢
  • 2018-11-30
  • 1970-01-01
  • 2013-01-31
  • 2017-11-20
  • 2021-07-24
  • 2022-09-16
  • 1970-01-01
  • 2021-11-26
  • 1970-01-01
相关资源
最近更新 更多