A variant of this very code now comes bundled with Emacs (23 and above). The bundled version includes extra features such as SMIE integration (which in turn handles correctly and completely Prolog's 0' construct). Therefore if you are using a newer Emacs you may be better off just using what comes bundled with it.

This being said, some people consider this version superior in several ways. It is also the case that the new, bundled version is not available to older Emacsen, while this version works with any reasonably new version of Emacs and XEmacs. For these two reasons this page will continue to exist, and the code herein will continue to be maintained for the foreseeable future.

This Prolog mode has all the features one would expect, including syntax highlighting, auto indent, and full interaction with an inferior Prolog process.

This mode supports in principle any Prolog system, though I am primarily maintaining it with SWI Prolog in mind. It also has some special tweaks for GNU Prolog (starting from version 1.4) and SICStus Prolog, and explicitly supports Prolog's close relatives Eclipse, Mercury, and XSB (starting from version 1.23).

Downloads

Installation

In a nutshell, place the downloaded file where Emacs can see it, and insert into your ~/.emacs or ~/.xemacs/init.el the following lines:

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

See the comments at the beginning of the source file for the gory details, and this installation guide for an even more detailed explanation.

Note that the default behaviour of prolog-insert-predicate-template has changed in version 1.15. The new behaviour is to just insert the predicate name followed by a parenthesis (as opposed to the old behaviour of inserting the predicate name, matching parentheses, and enough commata to separate all the arguments). Indeed, it seems more productive to just type those commata and closing parenthesis. If the old behaviour is desired, set prolog-electric-dot-full-predicate-template (group “Prolog Keyboard”) to non-nil.

Starting from version 1.25 “ansi-color” is required (since most Prolog interpreters seem to use ANSI escape sequences). The variable prolog-inferior-ansi-color controls whether the ANSI escape sequences are translated into text properties (non-nil, default) or filtered out (nil).

One new customizable variable has been added in version 1.28:

Two new customizable variables have been added in version 1.9:

Further note that some more customizable variables have been added (and might be added in future versions), please check the changelog provided at the beginning of the source file.