Using prolog with emacs

牧云@^-^@ 提交于 2019-11-30 09:14:06

You are not using the intended advanced prolog.el, since your load path is wrong. It should read:

(setq load-path (cons "~/.emacs.d/site-lisp/prolog/" load-path))

notice that I removed prolog.el from the end of the path. Actually, it should even better read:

(add-to-list 'load-path  "~/.emacs.d/site-lisp/prolog/")

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.

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 shell consult(File).

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

  1. Read carefully the installation instructions for prolog.pl -- http://bruda.ca/emacs-prolog/install.html

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

  3. 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.

  4. 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.

  5. 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.

A.Robinson

Another alternative with a nice emacs mode is Ciao.

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.

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.

Go into swi-prolog command line and type:

emacs.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!