Prolog-mode Installation Guide

This is a detailed guide for installing prolog-mode. Oh well, I am not sure whether people really need this, but I am providing it just in case. A summary of these instructions is at the beginning of the source file. If you are familiar with Emacs then you are probably better off going directly there.

Note to Windows users: In the following, whenever I use the drive letter “C” I really mean the drive on which your running Windows is installed.

The Emacs init file

The init file is a file that is read and evaluated by Emacs upon startup. If you use GNU Emacs or XEmacs version 21.1 or lower, this file is called ~/.emacs. If you use XEmacs 21.4 or later, the init file is called init.el and is placed in the directory ~/.xemacs. In the following, I shall refer to both of these as the “init file,” with the understanding that the actual name of the file depends on the Emacs version used.

Where is my init file in Windows?

It is in the same place as in Unix, i.e., ~/.emacs (~/_emacs in some implementations) or ~/.xemacs/init.el (depending on your Emacs version, see above). Although the path separator in Windows is the backslash (\), Emacs understands the forward slash (/) as path separator too. In fact, Emacs works better if you specify paths using, Unix-style, the forward slash. So I recommend that you specify paths in Windows like this:

d:/program files/xemacs/site-lisp

Who is ~ you ask? It is actually system dependent, but most often it is C:\. To make sure, open your Emacs, select File → Open, enter ~, and press Enter. Emacs will show the actual name and the content of ~.

Installation

  • Put the file somewhere and convince Emacs to see it. This can be done in two ways:
    • The Emacs variable load-path contains the directories where Emacs looks for files to load. If you put the file in some directory (say /usr/share/emacs/prolog) you can then add this directory to load-path by inserting in your init file the following line:
      (setq load-path (cons "/usr/share/emacs/prolog" load-path))

      Of course, replace /usr/share/emacs/prolog with the name of the directory where you actually put the file.

    • Some directories are already included in load-path, so you can put the file in one of these. What directories are included depends on how Emacs is installed. For GNU Emacs, /usr/share/emacs/site-lisp is most likely to be in load-path, and it is also a good place to put the file in. For XEmacs, either /usr/lib/xemacs/site-lisp or /usr/local/lib/xemacs/site-lisp are likely to be included automatically in load-path: look for /usr/lib/xemacs or /usr/local/lib/xemacs, create if necessary the directory site-lisp in whichever of these exists, and place the file there.
      I believe that the equivalent of /usr/lib/xemacs/site-lisp or /usr/local/lib/xemacs/site-lisp in Windows is c:/program files/xemacs-version/xemacs/site-lisp, but I am not quite sure.
  • Compile the file. This is optional, but recommended for performance reasons. Open it with Emacs and choose Emacs-Lisp → Byte-Compile This File (Emacs) or Lisp → Byte-Compile This File (XEmacs). If using XEmacs, you can do this from the command line too: go into the directory in which you put the source file, and issue the command:
    xemacs -f batch-byte-compile -batch ./prolog.el
  • Open your init file and insert 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))

    Change swi to the system you are normally using. Possible choices are currently swi, gnu, sicstus, mercury, and eclipse. If you use something else, leave the variable prolog-system as is (i.e., erase the respective line altogether) for interaction with a “generic” inferior Prolog process.
    The last expression makes sure that files ending with .pl are assumed to be Prolog files and not Perl, which is the default Emacs setting. If this is not wanted, remove this line. It is then necessary to either

    • insert in your Prolog file the following comment as the first line:
      % -*- Mode: Prolog -*-

      and then the respective file will be opened in Prolog mode no matter its extension, or

    • manually switch to Prolog mode after opening a Prolog file, by typing M-x prolog-mode.
  • Specify where is your Prolog executable. This is likely not necessary in Unix, unless your Prolog system has a non-standard name or is not in the search path. If either of these hold, define the shell variable EPROLOG so that it contains the full path to your Prolog interpreter, or see below.
    Various Prolog settings are customizable in the usual way. The whole set of Prolog customization variables is grouped in the group “Prolog.” In particular, the subgroup “Prolog Inferior” contains the variable “Prolog Program Name” which specifies the name of the programs launched as inferior Prolog process. Change it to reflect your machine's configuration.
    In particular, Windows users should provide the full path to the Prolog executable. If you are using SWI Prolog, the correct executable to include here is not pl.exe, but plcon.exe. An example of “Prolog Program Name” would thus be
    (((getenv "EPROLOG")
    (eval
    (getenv "EPROLOG")))
      (eclipse "eclipse")
      (mercury nil)
      (sicstus "sicstus")
      (swi "c:/program files/swi prolog/bin/plcon.exe")
      (t "prolog"))

    Once you are satisfied with the changes do not forget to choose “Save for future sessions” so that your changes are recorded to disk.

  • Customize the mode (optional). Besides the name of the executable, there are many more customizable variables in the mentioned group (“Prolog”). I believe that the defaults are reasonable for most cases, but feel free to disagree :-). In particular, if something does not work to your liking, then the customizable variables are the first place to look for the place to change the default behaviour. To reach the Prolog customizable variables in XEmacs, choose Options → Advanced (Customize) → Group…, type prolog, and press return.
  • You are done, fire Emacs up, open a Prolog file, and enjoy.

Note on syntax highlighting

In earlier versions syntax highlighting was supported but disabled by default, so that you had to enable it by hand. Starting with version 0.1.41, both the Prolog source and the inferior Prolog buffers are fontified upon opening.