Prolog mode is activated by loading a file that ends in the right extension. The default extension for Prolog files is .pl and it is therefore strongly adviced to give your Prolog sourcefiles the extension .pl.
Alternatively the editor may always be switched to Prolog mode using the Mode submenu of the File menu or using M-x mode RET prolog RET
PceEmacs Prolog mode provides support in the following areas
Layout support is provided by automatic indentation and placement of comments. This is achieved using the following commands:
head(Arg1, Arg2) :- subclause(with, arguments), ( if -> then ; else ), subclause(with, many, arguments).
After the user types a full-stop character not inside a string or comment, the system will parse the current clause and colourise it. If the syntax is not correct, the clause is not colourised and the Prolog warning is displayed in the PceEmacs status window. In addition, if the syntax is correct and the clause contains singleton variables a query-replace loop is started that allows the user to map each singleton to _ or _Name. A clause can be checked explictly using the \C-c\C-s command.
After a 2 seconds idle time, and if the file is shorter than the class-variable emacs_prolog_mode.auto_colourise_size_limit, PceEmacs performs a parsing, cross-referencing and colouring of the whole buffer. By default it will colour the following entities:
:- directive |
In addition, the argument to the file-loading directives are displayed in underlined blue if the file was found and in red otherwise. Found files have an associated popup to open them.
Colouring may be extended by defining rules for the multifile predicates emacs_prolog_colours:term_colours/2 and emacs_prolog_colours:goal_classification/2. This interface is rather immature. Please check the library file emacs/prolog_colour.pl for more information.
This section describes the most important commands for finding your way around.
The Prolog menu has various entries for loading the current file or a part thereof. The most commonly used option is Make, updating all loaded and modified files.
Over the years we have developed a discipline for working with Prolog projects. We share this knowledge with you in this section.
Every file, possibly except for load.pl and run.pl is declared as a module file. Why? It provides documentation and hiding at practically no cost. The same information makes PceEmacs cross-referencing work efficiently and providing the most relyable information.
Projects generally have four files for project maintenance. These are normal Prolog source-files helping you to load, run and maintain the project.
/* File load.pl */ :- multifile file_search_path/2. file_search_path(rules, rules). file_search_path(gui, xpce). :- use_module(infer).
/* File infer.pl */ :- module(infer, [ infer/2 % +Key, -Value ]). :- use_module(rules(rules)). ...
Having all this basic stuff in a file on their own is especially handy on MS-Windows, where double-clicking the right file in the explorer now satisfies for running, saving or debugging/developing the program. The load-file contains the common ground for these three functions.
On Unix, the same is achieved using pl -f <file>.
There are three reasonable options. The first, only applicable to Unix platyforms, is to start a PceEmacs server as part of the X11 setup and use this as a server. The details are in the general help on PceEmacs. The second option is to run PceEmacs in a separate Prolog and the final option is to use the same Prolog as for debugging your application.
Running in the same process is attractive, as it provides PceEmacs access to all resources for optimal browsing and relyable cross-referencing. Unfortunately you cannot edit if your program is actively running and fatal crashes of your program bring your editor down, loosing unsaved work, undo-information, open buffers, bookmarks, etc.
A good alternative is to run PceEmacs is a separate Prolog that has your program loaded, but is not used to run it. This provides PceEmacs with all required information without the risc for loosing information if you have to restart the Prolog holding your running program.
Which option is best depends on the nature of your program, your experience and discipline.
In any case, use the SWI-Prolog make/0 command to update the system after changing the sources.