关于 emacs 奇怪行为的 ediprolog

ediprolog on emacs strange behaviour

我刚开始使用 emacs 并对其进行自定义。

我正在尝试安装 ediprolog

我的 .emacs 文件是:

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.
 '(inhibit-startup-screen t))
(custom-set-faces
 ;; custom-set-faces 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.
 )

(global-set-key [f10] 'ediprolog-dwim)

(setq load-path (cons "/home/sam/Documents/emacs/prolog" load-path))
(autoload 'run-prolog "prolog" "Start a Prolog sub-process." t)
(autoload 'prolog-mode "prolog" "Major mode for editing Prolog programs." t)
(autoload 'mercury-mode "prolog" "Major mode for editing Mercury programs." t)
(setq prolog-system 'swi)
(setq auto-mode-alist (append '(("\.pl\'" . prolog-mode)
                                ("\.m\'" . mercury-mode))
                               auto-mode-alist))

我用 M-x package-install RET ediprolog RET

安装了 ediprolog

我已经用 %?- member(X,[a,b,c]). 创建了一个测试文件 如果我在这个查询中按 F10space space space 我会得到以下输出:

%?- member(X,[a,b,c]).
%@  member(X,[a,b,c]^H^H^H^H^H^H^H[a,b,c])^H^H^H^H^H^H^H^H^H^H^H(X,[a,b,c]).^M
%@ X = a ;^M
%@ X = b ;^M
%@ X = c.^M
%@^M

这显然是不正确的,因为我有所有这些额外的 ^H^M 个字符。

此外,如果我按照指示将行 (require 'ediprolog) 添加到我的 .emacs,我在启动 emacs 时会收到以下错误:

Warning (initialization): An error occurred while loading `/home/sam/.emacs':

File error: Cannot open load file, no such file or directory, ediprolog

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the `--debug-init' option to view a complete error backtrace.

我还按照 https://bruda.ca/emacs/prolog-mode_installation_guide 中的说明安装了相关的序言模式。

这是由于 SWI-Prolog 最近切换到 editline 库造成的,而它以前默认使用 readline .

问题现已解决。

SWI-Prolog 7.5.1 及更高版本包含使 ediprolog 再次工作的 change,无需对 Emacs 或 ediprolog.[= 进行任何升级或配置更改。 22=]

SWI-Prolog 即将发布的稳定版 (7.4) 也包含此更改。

因此,只有极少数版本(主要是 7.5.0 和 7.4-rc1)受到此问题的影响。


如果您使用的是出现此问题的 SWI-Prolog 版本,以下是可能的解决方法:

解决此问题的一种方法是将以下内容放入 ~/.swiplrc 初始化文件中:

:- set_prolog_flag(readline, readline).

这应该会产生一个工作 ediprolog,假设你已经安装了 readline

或者,您也可以输入:

:- set_prolog_flag(readline, false).

在您的 ~/.swiplrc 初始化文件中。但是,如果您在系统终端上调用它,这将完全 禁用 SWI-Prolog 的行编辑功能。在这种情况下,您当然可以使用 -f none 来忽略初始化文件。

或者,您也可以在 .emacs 中输入以下内容:

(setq ediprolog-program-switches '("-g" "set_prolog_flag(readline, false)"))

如果您的 SWI-Prolog 版本足够新,则不再需要这些解决方法。

对于 (require 'ediprolog) 的问题,您只需在 ~/.emacs 中更早地添加 (package-initialize)(最近的 Emacsen 会为您完成此操作)。但是,由于您是从 ELPA 安装的,因此您不需要 require 明确地设置它:ediprolog-dwim 无论如何都应该为您自动加载。