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
;; 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)
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 fact.pl.
pelleas% emacs fact.pl
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.