在 emacs 中使用 prolog
GNU Emacs 23.2.1
Fedora xfce 14
我开始接触 Prolog,我想使用我的 emacs 作为 Prolog 编程的 IDE。
目前我使用 emacs 来编写 c/c++。但不知道如何开始使用 Prolog。我知道 emacs 有一个用于在 emacs 中编程的内置库。然而,我研究了一下,发现它功能较少,即没有语法高亮、缩进等。
所以我下载了 emacs prackage Prolog.el。我已经使用 MX Load-library 加载了这个库。
但是,我不知道之后该做什么。如何编译我的 prolog 文件?在 emacs IDE 的菜单中没有 Prolog 的任何内容。
我还需要下载一些 Prolog 解释器或编译器吗? emacs 有编译命令吗?我在编译c代码时通常在emacs中使用make。
我做了一个 yum 搜索序言并得到了这些结果,所以有了所有这些选择,我需要哪一个?:
gprolog.x86_64 : GNU Prolog is a free Prolog compiler
pl.x86_64 : SWI-Prolog - Edinburgh compatible Prolog compiler
pl-static.x86_64 : Static library for SWI Prolog
ppl-gprolog.x86_64 : The GNU Prolog interface of the Parma Polyhedra Library
ppl-gprolog-static.x86_64 : The static archive for the GNU Prolog interface of the Parma Polyhedra Library
ppl-swiprolog.x86_64 : The SWI-Prolog interface of the Parma Polyhedra Library
ppl-swiprolog-static.x86_64 : The static archive for the SWI-Prolog interface of the Parma Polyhedra Library
ppl-yap.x86_64 : The YAP Prolog interface of the Parma Polyhedra Library
yap.i686 : High-performance Prolog Compiler
yap.x86_64 : High-performance Prolog Compiler
非常感谢您的任何建议,
================== 编辑 == ===================
我已经安装了以下 pl.x86_64
我已经下载了 prolog.el 并将其放在以下目录中
~/.emacs.d/site-lisp/prolog/prolog.el
:已使用以下内容配置我的 emacs:
;;; Prolog mode
(setq load-path (cons "~/.emacs.d/site-lisp/prolog/prolog.el" load-path))
(autoload 'run-prolog "prolog" "Start a Prolog sub-process." t)
(autoload 'prolog-mode "prolog" "Major mode for editing prolog programs." t)
(setq prolog-system 'swi) ; prolog-system below for possible values
(setq auto-mode-alist (append '(("\\.pl$" . prolog-mode))
auto-mode-alist))
因此,当我将文件另存为 *.pl 时,我会看到序言菜单选项。
因此,我编写了一些 prolog 代码,然后从 prolog 菜单中选择 运行交互式 prolog 会话
我打开了第二个空白缓冲区,其中显示 (Inferior Prolog:run Shell-Compile)
但是,我不确定现阶段我需要做什么。如何编译并运行 prolog 文件?
非常感谢您的进一步支持。
GNU Emacs 23.2.1
Fedora xfce 14
I starting to get into Prolog, and I want to use my emacs as the IDE for programming in Prolog.
Currently I use emacs for c/c++. But not sure how to get started with Prolog. I know that emacs has a built in library for programming in emacs. However, I have researched and found it is feature less, i.e. no syntax highlighting, indention, etc.
So I have download the emacs prackage Prolog.el. I have loaded this library using M-X Load-library
.
However, I am not sure what to do after that. How do I compile my prolog files? In the menu of the emacs IDE it has nothing for Prolog.
Do I also need to download some interpretor or compiler for Prolog? Is there an emacs command for compiling? I normally use make in emacs when compiling c code.
I did a yum search prolog and got these results, so with all these choices which one do I need?:
gprolog.x86_64 : GNU Prolog is a free Prolog compiler
pl.x86_64 : SWI-Prolog - Edinburgh compatible Prolog compiler
pl-static.x86_64 : Static library for SWI Prolog
ppl-gprolog.x86_64 : The GNU Prolog interface of the Parma Polyhedra Library
ppl-gprolog-static.x86_64 : The static archive for the GNU Prolog interface of the Parma Polyhedra Library
ppl-swiprolog.x86_64 : The SWI-Prolog interface of the Parma Polyhedra Library
ppl-swiprolog-static.x86_64 : The static archive for the SWI-Prolog interface of the Parma Polyhedra Library
ppl-yap.x86_64 : The YAP Prolog interface of the Parma Polyhedra Library
yap.i686 : High-performance Prolog Compiler
yap.x86_64 : High-performance Prolog Compiler
Many thanks for any suggestions,
================== EDIT =====================
I have installed the following pl.x86_64
I have download the prolog.el and put it the following directory:
~/.emacs.d/site-lisp/prolog/prolog.el
And I have configured my emacs with the following:
;;; Prolog mode
(setq load-path (cons "~/.emacs.d/site-lisp/prolog/prolog.el" load-path))
(autoload 'run-prolog "prolog" "Start a Prolog sub-process." t)
(autoload 'prolog-mode "prolog" "Major mode for editing prolog programs." t)
(setq prolog-system 'swi) ; prolog-system below for possible values
(setq auto-mode-alist (append '(("\\.pl$" . prolog-mode))
auto-mode-alist))
So when I save a file as *.pl I get the prolog menu options.
So I write some prolog code and from the prolog menu, I select Run interactive prolog session
I get a second blank buffer open which says (Inferior Prolog:run Shell-Compile)
However, I am not sure what I need to do at this stage. How do I compile and run the prolog files?
Many thanks for any further support.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您没有使用预期的高级
prolog.el
,因为您的加载路径错误。它应该显示为:请注意,我从路径末尾删除了
prolog.el
。实际上,它应该更好地阅读:然后再次启动 Emacs,它应该为您提供一个包含更多选项的菜单。 (尝试
Ch v prolog-mode-version
,它仅适用于高级模式,并显示其版本号。)然后您可以尝试
Cc Cb
来查阅缓冲区等还可以考虑使用 ediprolog,使用它可以直接在 Emacs 缓冲区中评估查询。另请注意,在最近的 Emacs 版本中,高级 Prolog 模式的变体是新的默认值,但不幸的是,它带有严重的回归和缺陷,因此我推荐 Stefan Bruda 维护的原始版本:https://bruda.ca/emacs/prolog_mode_for_emacs
有关 Prolog 和 Emacs 的更多信息,请参阅
将 SWI-Prolog 与 GNU Emacs 结合使用。
You are not using the intended advanced
prolog.el
, since your load path is wrong. It should read:notice that I removed
prolog.el
from the end of the path. Actually, it should even better read:Then start Emacs again, and it should give you a menu with many more options. (Try
C-h v prolog-mode-version
, which only works with the advanced mode, and shows its version number.)You can then try
C-c C-b
to consult the buffer etc. Also consider using ediprolog, with which you can evaluate queries directly in the Emacs buffer. Notice also that in recent Emacs versions, a variant of the advanced Prolog mode is the new default, but it unfortunately ships with severe regressions and flaws so that I recommend the original version maintained by Stefan Bruda:https://bruda.ca/emacs/prolog_mode_for_emacs
For more information about Prolog and Emacs, see
Using SWI-Prolog with GNU Emacs.
您需要 Prolog 环境,例如 SWI-Prolog、GNU-Prolog 或 YAP。我认为SWI很常用,但我不能说它是否比其他的更好。您无需编译 Prolog 文件即可运行它们 - Prolog 可以充当解释器(在某些情况下为交互式编译器)。要将文件加载到 Prolog 环境中,您需要查阅它。在 Prolog 模式下,emacs 可以使用
Cc Cf
来完成此操作。您还可以直接从 Prolog shellconsult(File)
中键入。You need a Prolog environment, such as SWI-Prolog, GNU-Prolog or YAP. I think that SWI is very commonly used, but I can't tell if it's better than others. You don't need to compile Prolog files in order to run them - Prolog can work as an interpreter (interactive compiler, in some cases). To load a file into the Prolog environment you need to consult it. When in Prolog mode, emacs can do that with
C-c C-f
. You can also type directly from the Prolog shellconsult(File)
.另一种具有良好 emacs 模式的替代方案是 Ciao。
Another alternative with a nice emacs mode is Ciao.
更完整的 Prolog 模式可以在这里找到:Prolog mode for (X)Emacs
如果您在 .el 文件中搜索字符串 prolog-mode-keybindings 或在 prolog 模式下执行 Ch b,您可以看到可用的内容。
如果安装pl.x86_64:
您还可以使用名为 PceEmacs 的 SWI Prolog 内置编辑器,请参阅此处:SWI-Prolog 内置编辑器:PceEmacs SWI Prolog 非常完整,除了图形调试器之外还包括基于文本的调试器图形跟踪器及其自己的GUI系统Prolog 的 XPCE GUI 系统 以及许多库。这是一个伟大的探索序言。如果您想将 SWI Prolog 与 emacs 结合使用,请参阅以下设置 将 SWI-Prolog 与 GNU 结合使用-Emacs
A more complete prolog mode can be found here: Prolog mode for (X)Emacs
If you search the .el file for the string prolog-mode-keybindings or do a C-h b while in prolog mode you can see what is available.
If you install pl.x86_64:
You can also use the SWI Prolog builtin editor called PceEmacs, see here: The SWI-Prolog builtin editor: PceEmacs SWI Prolog is very complete and includes a text-based debugger in addition to a graphical debugger The graphical tracer and its own GUI system The XPCE GUI system for Prolog plus a lot of libraries. It is a great prolog for exploration. If you want to instead use SWI Prolog with emacs, here is the setup Using SWI-Prolog with GNU-Emacs
仔细阅读 prolog.pl 的安装说明 -- http://bruda.ca/emacs -prolog/install.html
呼应“mat”在 3 月 20 日所写的内容,使用“add-to-list”而不是“setq”:
(添加到列表'加载路径“~/.emacs.d/site-lisp/prolog/”)
这是“现代”用法,对您来说应该比 `setq' 结构更清楚一些。
我还没有仔细阅读 bruda.ca 的 prolog.el 代码,但它看起来确实有点过时。然而,它看起来也比 GNU Emacs 中包含的代码有更多的功能。我不知道附加的功能是否会超过代码的老化。看来 bruda.ca 代码源自 GNU Emacs prolog.el 的早期版本,如 bruda.ca 代码中的注释所述。
一旦您更正了“load-path”变量的值(它类似于 PATH 环境变量),prolog.el 就应该正确加载。由于没有 prolog.el 的文档文件,因此您可以使用以下一些 Emacs 命令来开始探索 prolog 模式:
Ch m——这将显示帮助,列出为序言模式定义的键绑定,以及您可能有效的任何其他次要模式。
Ch a prolog -- 这将显示帮助以列出由 prolog 模式 (prolog.el) 定义的(交互式)命令。
如果您没有关闭菜单,那么每当您在 prolog 模式下打开文件时,prolog 的菜单项都应该可用。
最后,总是需要阅读 prolog.el(至少是文件顶部的描述性注释)。 (该文件的后半部分被列为实验代码。)如果可以更新并添加到 GNU Emacs 中包含的 prolog.el 中,那就太好了。
Read carefully the installation instructions for prolog.pl -- http://bruda.ca/emacs-prolog/install.html
Echoing what 'mat' wrote on March 20, use `add-to-list' instead of `setq':
(add-to-list 'load-path "~/.emacs.d/site-lisp/prolog/")
This is the "modern" usage, and should be a bit clearer to you than the `setq' construction.
I haven't read the prolog.el code from bruda.ca carefully, but it does look a little dated. However, it also looks like it has many more features than the code included with GNU Emacs. I do not know whether the additional features will outweigh the agedness of the code. It appears that the bruda.ca code is derived from an earlier version of the GNU Emacs prolog.el, as stated in the comments in the bruda.ca code.
Once you have corrected the value of the `load-path' variable (it is analogous to the PATH environment variable), prolog.el should load correctly. Because there is no documentation file for prolog.el, here are some Emacs commands you can use to begin exploring prolog mode:
C-h m -- This will display help to list the key bindings that have been defined for prolog-mode, as well as any other minor modes that you might have in effect.
C-h a prolog -- This will display help to list (interactive) commands that have been defined by prolog-mode (prolog.el).
If you have not turned off menus, then a menu entry for prolog should be available whenever you open a file in prolog mode.
Finally, there is always reading prolog.el (at the very least, the descriptive comments at the top of the file). (The second half of the file is listed as experimental code.) It would be good if this could be updated and added to the prolog.el that is included in GNU Emacs.
您需要 Prolog 编译器,因此您必须安装列出的编译器之一。然后,我假设您编写了一个 Makefile 并通过
Mxcompile
调用它。You need a compiler for Prolog, so you got to install one of the listed compilers. Then, I suppose you write a Makefile and call it through
M-x compile
.如果您使用的是 Emacs 包管理器,则可以键入
Mx package-install RET prolog
,然后重新加载 Emacs。简单又有效。
我使用 Fedora 15,但 Emacs 是它自己的操作系统。
If you're using the Emacs package manager, you can type
M-x package-install RET prolog
, and then reload Emacs.Simple and works.
I use Fedora 15, but Emacs is its own operating system.
进入 swi-prolog 命令行并输入:
Go into swi-prolog command line and type: