Using SICStus Prolog within emacs

Editing your Prolog programs within emacs gives you many advantages of which the best for a beginner is being able to see the structure of your program clearly shown by the use of colour. emacs will allow you to have two buffers (window areas): one is your Prolog program; the second is the Prolog interpreter. You edit your program in one window and load and run your program in the other window.

Before you use emacs for the first time, you must provide emacs with instructions as to how you want your Prolog programs to appear on the screen. To do this, you need to edit the emacs initialisation file.

Follow these instructions before you use Prolog/emacs for the first time

Change to your top-level directory
Just enter the command: cd
Create a file
Using an editor (eg emacs), open a file called .emacs.
(This file may already exist in your user area and, if so, it will almost certainly have some code already in it. If the code given below is in it, then you don't need to add it again. So, you can exit the editor and move on to editing Prolog programs.)

Write the set-up code
Copy and paste the following lines into your editor.

;;  These lines makes Emacs use this Prolog mode automatically
;;  when editing files with a .pl extension: 

(setq load-path (cons "/bham/com/packages/sicstus-3.11.2/lib/sicstus-3.11.2/emacs" 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-use-sicstus-sd t)
(setq auto-mode-alist (cons '("\\.pl$" . prolog-mode) auto-mode-alist))

;;  Syntax highlighting

(global-font-lock-mode t)       
(setq font-lock-maximum-decoration t)
Save the .emacs file
Exit from your editor. Now you are ready to use Prolog in emacs.

To write a Prolog program or to edit a program you have already written, simply type emacs followed by the filename at the Unix/linux prompt. This example assume you want to edit a program called

     pelleas% emacs

At first you will see only your program in a single window. If you choose the "consult" option from the "Prolog" menu, your program will be loaded into Prolog.

This is what you might see:

When you make changes in your Prolog program, you should save them and then choose "consult" from the "Prolog" menu to load the latest version of your program.

As you learn more Prolog, you will want to explore more of emacs' functionality, and this can be done quite easily, partly by trying menus to see what they will do and partly by reading the sources of help.