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's0' construct). Therefore if you are using a newer Emacs you are better off just using what comes bundled with it; this code will still work, but the bundled version will work just as well or better. The reason that this page still exists (and the code herein is still maintained) is to offer a good Prolog mode that remains compatible with XEmacs and older version of Emacs.

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

prolog.el version 1.25 [gzipped] works with Emacs 20 and above and reasonably recent versions of XEmacs (tested on 21.1 and higher). For a change log see the beginning of the source file.

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

Note that two new customizable variables have been added in version 1.9:

prolog-paren-indent-p (group “Prolog Indentation”) governs how parenthesis expressions (other than compound terms) are indented. If the variable is nil (default) then components are indented one underneath the other (just as for compount terms); otherwise the second and subsequent lines are indented `prolog-paren-indent' characters to the right (old behaviour).

prolog-char-quote-workaround (group “Prolog Other”) allows for a somehow correct handling of the 0' character escape by setting 0 as a quote character (when non-nil); setting the variable to nil (default) ignores the 0' construct.
This should not be customizable (the character escape should be recognized as such no matter what) but the current implementation is kludgy (and I have no idea how to do it better) so for the time being I provide a way to disable the whole thing. Please let me know about any idea to do this better and most importantly about any breakage caused by the current implementation.

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.