Author(s): Manuel Hermenegildo, Manuel C. Rodriguez, Daniel Cabeza, , The Computational logic, Languages, , Implementation, and Parallelism (CLIP) Group, webmaster@clip.dia.fi.upm.es, http://www.cliplab.org/, School of CS, Technical University of Madrid, CS and ECE Departments, University of New Mexico.
Version: 1.10#8 (2007/1/28, 17:30:3 CEST)
Version of last change: 1.9#323 (2004/3/8, 18:37:17 CET)
The Ciao/Prolog
emacs interface (or mode
in
emacs
terms) provides a rich, integrated user interface to the Ciao
program development environment components, including the
ciaosh
interactive top level and the
ciaopp
preprocessor. While most features of the Ciao development environment are available from the command line of the preprocessor and the top-level shell, using Ciao inside
emacs
is highly recommended. The facilities that this mode provides include:
lpdoc
.
info
format.
ciaopp
, the
Ciao preprocessor, running in its own
sub-shell. This allows easily performing certain kinds of
static checks (useful for finding errors in programs before running them), program analysis tasks, and
program transformations on source programs.
lpdoc
auto-documenter), and locating automatically the points in the source files where such errors occur.
lpdoc
auto-documenter.
This chapter explains how to use the Ciao/Prolog
emacs
interface and how to set up your
emacs
environment for correct operation. The Ciao
emacs
interface can also be used to work with other Prolog or CLP systems.
This is particularly important for the source-level debugger and the syntax-based coloring capabilities. This is due to the fact that it would be unrealistic to write a complete Prolog parser in Emacs lisp. These conventions are the following, in order of importance:
The following suggestion is not strictly necessary but can improve operation:
Comments which start with %
s are indented to the right if indentation is asked for.
For syntax-based highlighting to be performed font-lock must be available and not disabled (the Ciao mode enables it but it may be disabled elsewhere in, e.g., the
.emacs
file).
Typically, a complete pre-installation of the Ciao/Prolog
emacs
interface is completed during Ciao installation. To check that installation was done and sucessful, open a file with a .pl
ending. You should see that
emacs
enters Ciao/Prolog mode: the mode is identified in the
status bar below the
buffer and, if the
emacs menu bar is enabled, you should see the Ciao/Prolog menus. You should be able from the menu-bar, for example, to go to the Ciao manuals in the info or load the .pl
file that you just opened into a ciao top level.
If things don't work properly, see the section section Installation of the Ciao/Prolog emacs interface later in this chapter.
The following sections summarize the capabilities of the Ciao/Prolog emacs interface and the (default) key sequences used to access those capabilities. Most of these functions are accessible also from the menu bar.
Syntax-based highlighting (coloring) of code is provided automatically when opening Ciao/Prolog files. This includes also the assertions used by the preprocessor and the documentation strings used by the Ciao auto-documenter,
lpdoc
. The mode should be set to Ciao/Prolog and the Ciao mode menus should appear on the menu bar. The colors and fonts used can be changed through the
customize options in the help menu (see section Customization).
During editing this coloring may be refreshed by calling the appropriate function (see below).
Limited syntax-based auto-indentation and auto-fill of code and comments is also provided. Syntax highlighting and coloring is also available for the error and warning messages produced by the top level, preprocessor, and auto-documenter, and, in general, for the output produced by these tools.
Commands:
The following commands are useful for getting on-line help. This is done by accessing the
info
version of the Ciao manuals or the
emacs
built-in help strings. Note also that the
info
standard search
command (generally bound to s) can be used inside
info
buffers to search for a given string.
info
mode. Requires that the Ciao manuals in
info
format be installed and accessible to
emacs
(i.e., they should appear somewhere in the info directory when typing M-x info
). It also requires
word-help.el
, which is provided with Ciao. Refer to the installation instructions if this is not the case.
These commands allow loading programs, creating executables, etc. by issuing the appropriate commands to a Ciao/Prolog top level shell, running in its own buffer as a subprocess. See section The interactive top-level shell for details. The following commands implement the communication with the Ciao/Prolog top level:
main/0
or
main/1
predicate. Note that compiler options can be set to determine whether the libraries and auxiliary files used by the executable will be statically linked, dynamically linked, auto-loaded, etc.
activemod
library documentation for details).
The interactive top level and the preprocessor both are typically run in an iteractive buffer, in which it is possible to communicate with them in the same way as if they had been started from a standard shell. These interactive buffers run in the so-called Ciao/Prolog inferior mode. This is a particular version of the standard emacs shell package (comint) and thus all the commands typically available when running shells inside emacs also work in these buffers. In addition, many of the commands and key bindings available in buffers containing Ciao source code are also available in these interactive buffers, when applicable. The Ciao/Prolog-specific commands available include:
info
mode. Requires that the Ciao manuals in
info
format be installed and accessible to
emacs
(i.e., they should appear somewhere in the info directory when typing M-x info
). It also requires
word-help.el
, which is provided with Ciao. Refer to the installation instructions if this is not the case.
The following are some of the commands from the comint shell package which may be specially useful (type <f1> m
while in a Ciao interactive buffer for a complete list of commands):
These commands allow locating quickly the point in the source code corresponding to errors flagged by the compiler or preprocessor as well as performing several syntactic checks of assertions:
The following commands are intended to help in the process of writing programs:
chmod +x <file>
' in Unix). See section The script interpreter for details.
These commands allow marking modules for debugging by issuing the appropiate commands to a Ciao/Prolog top level shell, running in its own buffer as a subprocess. There are two differents types of debugging: traditional Prolog debugging (using the byrd-box model and spy-points) and source-level debugging (same as traditional debugging plus source tracing and breakpoints). In order to use breakpoints, source debugging must be on. The following commands implement comunication with the Ciao/Prolog top level:
trace.
command to the top-level shell). Conversely, if the module was already marked for source-level debugging then it will take the opposite actions, i.e., it unmarks the module for source-level debugging, reloads it, and sets the debugger to non-debug mode.
emacs
and using source debug.
These commands allow
preprocessing programs with
ciaopp
, the
Ciao preprocessor.
ciaopp
is the precompiler of the Ciao Prolog development environment.
ciaopp
can perform a number of program debugging, analysis and source-to-source transformation tasks on (Ciao) Prolog programs. These tasks include:
The information generated by analysis, the assertions in the system libraries, and the assertions optionally included in user programs as specifications are all written in the same
assertion language, which is in turn also used by the Ciao system documentation generator,
lpdoc
.
ciaopp
is distributed under the
GNU general public license.
See the preprocessor manual for details. The following commands implement the communication with the Ciao preprocessor:
The following commands can be used to carry out a simple but effective form of
version control by keeping a
log of changes on a file or a group of related files. Interestingly, this log is kept in a format that is understood by
lpdoc
, the Ciao documenter [Her99]. As a result, if these version comments are present, then
lpdoc
will be able to automatically assign up to date version numbers to the manuals that it generates. This way it is always possible to identify to which version of the software a manual corresponds. Also,
lpdoc
can create automatically sections describing the changes made since previous versions, which are extracted from the comments in the changelog entries.
The main effect of these commands is to automatically associate the following information to a set of changes performed in the file and/or in a set of related files:
1.2
, where 1
is the
major version number and 2
is the
minor version number),
4
in 1.2#4
),
1998/12/14,17:20*28+MET
),
The version numbering used can be local to a single file or common to a number of related files. A simple version numbering policy is implemented: when a relevant change is made, the user typically inserts a changelog entry for it, using the appropriate command (or selecting the corresponding option when prompted while saving a file). This will cause the patch number for the file (or for the whole system that the file is part of) to be incremented automatically and the corresponding machine-readable comment to be inserted in the file. Major and minor version numbers can also be changed, but this is always invoked by hand (see below).
The changelog entry is written in the form of a
comment/2
declaration. As mentioned before, the advantage of using this kind of changelog entries is that these declarations can be processed by the
lpdoc
automatic documenter (see the
lpdoc
reference manual [Her99] or the
assertions
library documentation for more details on these declarations).
Whether the user is asked or not to introduce such changelog entries, and how the patch and version numbers should be increased is controlled by the presence in the file of a
comment/2
declaration of the type:
:- comment(version_maintenance,<type>).
(note that this requires including the
assertions
library in the source file). These declarations themselves are also typically introduced automatically when using this mode (see below).
The version maintenance mode can also be set alternatively by inserting a comment such as:
%% Local Variables: %% mode: ciao %% update-version-comments: "off" %% End:
The lines above instruct emacs to put the buffer visiting the file in
emacs Ciao/Prolog mode and to turn version maintenance off. Setting the version maintenance mode in this way has the disadvantage that
lpdoc
, the auto-documenter, and other related tools will not be aware of the type of version maintenance being performed (the lines above are comments for Prolog). However, this can be useful in fact for setting the
version maintenance mode for packages and other files meant for inclusion in other files, since that way the settings will not affect the file in which the package is included.
The following commands implement the version control support:
emacs
command that saves a buffer by writing the contents into the associated .pl
file. However, in Ciao/Prolog mode this command can be set to ask the user before saving whether to introduce a changelog entry documenting the changes performed.
If the buffer does not already contain a comment specifying the
type of version control to be performed, and before saving the buffer, the Ciao/Prolog mode prompts the user to choose among the following options:
emacs
will not ask again while the buffer is loaded, but it will ask again next time you load the buffer.
:- comment(version_maintenance,off).
is added to the buffer and the file is saved.
emacs
will not perform any version control on this file until the line above is removed or modified (i.e., from now on C-x C-s simply saves the buffer).
on
<directory_name>
<directory_name>/GlobalPatch
) is atomically incremented and the changelog entry is added to the current file, associated to that patch number. Also, a small entry is added to a file <directory_name>/GlobalChangeLog
which points to the current file. This allows inspecting all changes sequentially by visiting all the files where the changes were made (see C-c C-n). This is obviously useful when maintaining a single thread of version and patch numbers for a set of files.
off
<directory_name>/GlobalChangeLog
file needs to be changed also, for the entry to be locatable later using C-c C-n.
GlobalChangeLog
file, and position the cursor at the corresponding entry. This allows browsing the previous and following changes made, which may perhaps reside in other files in the system.
GlobalChangeLog
file, look for the next entry in the file, and open in another window the source file in which the corresponding comment resides, positioning the corresponding comment at the top of the screen. This allows going through a section of the
GlobalChangeLog
file checking all the corresponding comments in the different files in which they occur.
These commands provide some bindings and facilities for generating and viewing the documentation corresponding to the current buffer. The documentation is generated in a temporary directory, which is created automatically. This is quite useful while modifying the documentation for a file, in order to check the output that will be produced, whithout having to set up a documentation directory by hand or to regenerate a large manual of which the file may be a part.
SETTINGS
file, sets MAIN
in SETTINGS
to the current buffer and then generates the documentation in a temporary directory. Note that for generating complex manuals the best approach is to set up a permanent documentation directory with the appropriate SETTINGS
and Makefile
files (see the LPdoc manual).
dvi
or to the environment variable LPDOCFORMAT
if it is defined.
SETTINGS
file (which controls all auto-documenter options).
SETTINGS
in the default format. This allows generating complex documents but it assumes that SETTINGS
exists and that the options that it contains (main file, component files, paths, etc.) have been set properly. Documentation is generated in a temporary directory. Note however that for generating complex manuals the best approach is to set up a permanent documentation directory with the appropriate SETTINGS
and Makefile
files (see the LPdoc manual).
/tmp
or to the environment variable LPDOCWDIR
if it is defined.
These commands allow changing the executables used when starting a Prolog top-level, the preprocessor, or the auto-documenter. They also allow changing the arguments that these executables take, and changing the path where the libraries reside. In the case of the top-level and preprocessor, this should be done only by users which understand the implications, but it is very useful if several versions of Ciao/Prolog or the preprocessor are available in the system. All these settings can be changed through the customize options in the help menu (see section Customization).
ciao
or, to the environment variable CIAO
if it is defined.
CIAOARGS
if it is defined.
ciaopp
or, to the environment variable CIAOPP
if it is defined.
CIAOPPARGS
if it is defined.
CIAOLIB
).
lpdoc
or to the environment variable LPDOC
if it is defined.
LPDOCARGS
if it is defined.
/home/clip/lib
or to the environment variable LPDOCLIB
if it is defined.
Some other commands which are active in the Ciao/Prolog mode:
These commands provide some bindings and facilities for loading programs, which are present in emacs Prolog modes of other Prolog systems (e.g., SICStus). This is useful mainly if the Ciao/Prolog emacs mode is used with such Prolog systems. Note that these commands (
compile/1
and
consult/1
) are deprecated in Ciao (due to the more advanced, separate compilation model in Ciao) and their use in the Ciao top-level is not recommended.
As mentioned previously, the Ciao/Prolog
emacs
interface can also be used to work with other Prolog or CLP systems. Also, the Ciao/Prolog
emacs
interface (mode) can coexist with other Prolog-related
emacs
interfaces (modes)
(such as, e.g., the
SICStus
Prolog interface). Only one of the interfaces can be active at a time for a given buffer (i.e., for each given file opened inside
emacs
). In order the change a buffer to a given interface, move the cursor to that buffer and type M-x ...-mode
(e.g., for the Ciao/Prolog mode, M-x ciao-mode
).
If several Prolog-related
emacs
interfaces are loaded, then typically the last one to be loaded takes precedence, in the sense that this will be the interface in which
emacs
will be set when opening files which have a .pl
ending (this depends a bit on how things are set up in your .emacs
file).
The capabilities (commands, coloring, error location, ...) which are active in the Ciao/Prolog inferior mode can also be made available in any standard command line shell which is being run within emacs. This can be enabled by going to the buffer in which the shell is running and typing "M-x ciao-inferior-mode
". This is very useful for example when running the stand-alone compiler, the
lpdoc
auto-documenter, or even certain user applications (those that use the standard error message library) in an emacs sub-shell. Turning the Ciao/Prolog inferior mode on on that sub-shell will highlight and color the error messages, and automatically find and visit the locations in the files in which the errors are reported.
Finally, one the most useful applications of this is when using the
embedded debugger (a version of the debugger which can be embedded into executables so that an interactive debugging session can be triggered at any time while running that executable without needing the top-level shell). If an application is run in a shell buffer which has been set with Ciao inferior mode (M-x ciao-inferior-mode
) and this application starts emitting output from the embedded debugger (i.e., which contains the embedded debugger and is debugging its code) then the Ciao emacs mode will be able to follow these messages, for example tracking execution in the source level code. This also works if the application is written in a combination of languages, provided the parts written in Ciao are compiled with the embedded debugger package and is thus a covenient way of debugging multi-language applications. The only thing needed is to make sure that the output messages appear in a shell buffer that is in Ciao inferior mode.
This section explains all variables used in the Ciao/Prolog emacs mode which can be customized by users. Such customization can be performed (in later versions of
emacs
) from the
emacs
menus (Help -> Customize -> Top-level Customization Group
), or also by adding a setq
expression in the .emacs
file. Such setq
expression should be similar to:
(setq <variable> <new_value>)
The following sections list the different variables which can be customized for
ciao
,
ciaopp
and
lpdoc
.
ciao-clip-logo
(file)
ciao-create-sample-file-on-startup
(boolean)
ciao-indent-width
(integer)
ciao-library-path
(string)
ciao-locate-also-note-messages
(boolean)
ciao-locate-errors-after-run
(boolean)
ciao-logo
(file)
ciao-main-filename
(string)
ciao-os-shell-prompt-pattern
(string)
ciao-query
(string)
ciao-system
(string)
ciao-system-args
(string)
ciao-toplevel-buffer-name
(string)
ciao-user-directives
(list)
ciao-ciaopp-buffer-name
(string)
ciao-ciaopp-system
(string)
ciao-ciaopp-system-args
(string)
ciao-lpdoc-buffer-name
(string)
ciao-lpdoc-docformat
(symbol)
ciao-lpdoc-libpath
(directory)
ciao-lpdoc-system
(string)
ciao-lpdoc-system-args
(string)
ciao-lpdoc-wdir-root
(directory)
ciao-face-answer-val
(face)
ciao-face-answer-var
(face)
ciao-face-builtin-directive
(face)
ciao-face-check-assrt
(face)
ciao-face-checked-assrt
(face)
ciao-face-ciaopp-option
(face)
ciao-face-clauseheadname
(face)
ciao-face-comment
(face)
ciao-face-comment-variable-pitch
(face)
ciao-face-concurrency-op
(face)
ciao-face-cut
(face)
ciao-face-debug-breakpoint
(face)
ciao-face-debug-call
(face)
ciao-face-debug-exit
(face)
ciao-face-debug-expansion
(face)
ciao-face-debug-fail
(face)
ciao-face-debug-mess
(face)
ciao-face-debug-redo
(face)
ciao-face-entry-assrt
(face)
ciao-face-error-mess
(face)
ciao-face-false-assrt
(face)
ciao-face-highlight-code
(face)
ciao-face-library-directive
(face)
ciao-face-lpdoc-bug-comment
(face)
ciao-face-lpdoc-command
(face)
ciao-face-lpdoc-comment
(face)
ciao-face-lpdoc-comment-variable-pitch
(face)
ciao-face-lpdoc-crossref
(face)
ciao-face-lpdoc-include
(face)
ciao-face-lpdoc-verbatim
(face)
ciao-face-lpdoc-version-comment
(face)
ciao-face-modedef-assrt
(face)
ciao-face-module-directive
(face)
ciao-face-no-answer
(face)
ciao-face-note-mess
(face)
ciao-face-other-mess
(face)
ciao-face-predicate-directive
(face)
ciao-face-prompt
(face)
ciao-face-prop-assrt
(face)
ciao-face-quoted-atom
(face)
ciao-face-regtype-assrt
(face)
ciao-face-script-header
(face)
ciao-face-startup-mess
(face)
ciao-face-string
(face)
ciao-face-true-assrt
(face)
ciao-face-trust-assrt
(face)
ciao-face-user-directive
(face)
ciao-face-variable
(face)
ciao-face-warning-mess
(face)
ciao-face-yes-answer
(face)
ciao-faces-use-variable-pitch-in-comments
(boolean)
If opening a file ending with .pl
puts emacs in another mode (such as
perl
mode, which is the --arguably incorrect-- default setting in some
emacs
distributions), then either the emacs mode was not installed or the installation settings are being overwritten by other settings in your .emacs
file or in some library. In any case, you can set things manually so that the Ciao/Prolog mode is loaded by default in your system. This can be done by including in your
.emacs
file a line such as:
(load <CIAOLIBDIR>/DOTemacs)
This loads the above mentioned file from the Ciao library, which contains the following lines (except that the paths are changed during installation to appropriate values for your system):
;; Ciao/Prolog mode initialization ;; ------------------------------- ;; (can normally be used with other Prolog modes and the default prolog.el) ;; (setq load-path (cons "<CIAOLIBDIR>" load-path)) (autoload 'run-ciao-toplevel "ciao" "Start a Ciao/Prolog top-level sub-process." t) (autoload 'ciao-startup "ciao" "The Ciao/Prolog program development system startup screens." t) (autoload 'ciao "ciao" "Start a Ciao/Prolog top-level sub-process." t) (autoload 'prolog "ciao" "Start a Ciao/Prolog top-level sub-process." t) (autoload 'run-ciao-preprocessor "ciao" "Start a Ciao/Prolog preprocessor sub-process." t) (autoload 'ciaopp "ciao" "Start a Ciao/Prolog preprocessor sub-process." t) (autoload 'ciao-mode "ciao" "Major mode for editing and running Ciao/Prolog" t) (autoload 'ciao-inferior-mode "ciao" "Major mode for running Ciao/Prolog, CiaoPP, LPdoc, etc." t) (setq auto-mode-alist (cons '("\\.pl$" . ciao-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\\.pls$" . ciao-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\\.lpdoc$" . ciao-mode) auto-mode-alist)) (setq completion-ignored-extensions (append '(".dep" ".itf" ".po" ".asr" ".cpx") completion-ignored-extensions)) ;; ------------------------------------------------------------------------ ;; In Un*x, the following (or similar) lines should be included in your ;; .cshrc or .profile to find the manuals (the Ciao installation leaves ;; in the Ciao library directory 'DOTcshrc' and 'DOTprofile' files with ;; the right paths which can be included directly in your startup scripts): ;; ;; setenv INFOPATH /usr/local/info:/usr/info:<LPDOCDIR> ;; ------------------------------------------------------------------------
If you would like to configure things in a different way, you can also copy the contents of this file to your
.emacs
file and make the appropriate changes. For example, if you do not want .pl
files to be put automatically in Ciao/Prolog mode, then comment out (or remove) the line:
(setq auto-mode-alist
... )
You will then need to switch manually to Ciao/Prolog mode by typing M-x ciao-mode
after opening a Prolog file.
If you are able to open the Ciao/Prolog menu but the Ciao manuals are not found or the
ciao
command (the top-level) is not found when loading .pl
files, the probable cause is that you do not have the Ciao paths in the INFOPATH
and MANPATH
environment variables (whether these variables are set automatically or not for users depends on how the Ciao system was installed). Under Un*x, you can add these paths easily by including the line:
source <CIAOLIBDIR>/DOTcshrc
in your .login
or .cshrc
files if you are using
csh
(or
tcsh
, etc.), or, alternatively, the line:
. <CIAOLIBDIR>/DOTprofile
in your .login
or .profile
files if you are using
sh
(or
bash
, etc.). See the Ciao installation instructions (section Installing Ciao from the source distribution or section Installing Ciao from a Win32 binary distribution) for details.
This mode is currently being developed within
GNU emacs
version 21.2. It should also (hopefully) work with all other 21.XX, 20.XX, and later 19.XX versions. We also try our best to keep things working under
xemacs
.
This code is derived from the 1993 version of the emacs interface for
&-Prolog by M. Hermenegildo, itself derived from the original
prolog.el
by
Masanobu Umeda with changes by
Johan Andersson,
Peter Olin,
Mats Carlsson, and
Johan Bevemyr of
SICS, Sweden. Other changes also by Daniel Cabeza and Manuel C. Rodriguez. See the changelog for details.
Go to the first, previous, next, last section, table of contents.