Using Ciao inside GNU emacs
Author(s): Manuel Hermenegildo, Manuel C. Rodriguez, Daniel Cabeza.
The Ciao 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, the lpdoc documentation generator, the testing system, and the ciaopp preprocessor. Most features of these Ciao development environment components are available from the command line of the top-level shell and the preprocessor and as standalone tools. However, using Ciao from inside emacs is highly recommended. The facilities that this mode provides include:
- Syntax-based highlighting (coloring), auto-indentation, auto-fill, etc. of code. This includes the assertions used by the preprocessor and the documentation strings used by the Ciao auto-documenter, lpdoc.
- Providing automatic access to on-line help for all predicates by accessing the Ciao system manuals in info format.
- Starting and communicating with the Ciao top-level, running in its own sub-shell. This facilitates loading programs, checking the syntax of programs (and of assertions within programs), marking and unmarking modules for interactive debugging, tracing the source code during debugging, making stand-alone executables, compiling modules to dynamically linkable Ciao objects, compiling modules to active objects, etc.
- Starting and communicating with lpdoc, the Ciao auto-documenter, running in its own sub-shell. This allows generating in a very convenient way manuals for any file(s) being edited, in a variety of output formats, and is very useful for quickly checking how the auto-generated documentation will look.
- Running unit tests on files or applications.
- Starting and communicating with 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.
- Syntax highlighting and coloring of the error and warning messages produced by the top level, unit testing, preprocessor, or any other tool using the same message format (such as the lpdoc auto-documenter), and locating automatically the points in the source files where such errors occur.
- This mode also includes a very simple automatic version control system which allows keeping a changelog for individual files or for whole applications. This is done by automatically including changelog entries in source files, which can then be processed by the lpdoc auto-documenter. This is useful for smaller projects that are not stored in a repository and can also be used for maintaining changelogs even for projects that are repository-based.
This chapter explains how to use the Ciao emacs interface (and how to set up your emacs environment for correct operation, even though this is normally done automatically by the installation process). The Ciao emacs interface can also be used to work with traditional Prolog or CLP systems.
Conventions for writing Ciao programs under Emacs
There are currently a number of syntactic conventions for Ciao programs which greatly help operation of the Emacs development environment. These conventions are particularly important for the source-level debugger and the syntax-based coloring capabilities. The need for such conventions comes from the fact that it would be unrealistic to write a complete Ciao parser in Emacs lisp. These conventions are the following, more or less in order of importance:
- Clauses should begin on the first column (this is used to recognize the beginning of a clause).
- C style comments should not be used in a clause, but can be used outside any clause.
The following suggestions are not strictly necessary but can improve operation. In particular, they allow much greater precision in the location of program points during source-level debugging (for line by line tracing, when marking breakpoints, etc.):
- Body literals should be indented.
- There should be no more than one literal per line.
Other issues:
- Comments which start with %s are indented to the right if indentation is requested.
- 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).
Checking the installation
Typically, a complete pre-installation of the Ciao emacs interface is performed during Ciao installation. To check that installation was completed sucessfully, open a file with a .pl ending. You should see that emacs enters Ciao 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 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 Installation of the Ciao emacs interface later in this chapter.
Functionality and associated key sequences (bindings)
The following sections summarize the capabilities of the Ciao emacs interface and the (default) key sequences used to access those capabilities. Note however that most of these functions are also accessible from the menu bar, so learning these key combinations is not necessary: the list is provided mainly for illustration of the capabilities available, as well as completeness and documentation.
Syntax coloring and syntax-based editing
Syntax-based highlighting (coloring) of code is provided automatically when opening Ciao 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 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 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:
- C-c h
- Undate (recompute) syntax-based highlighting (coloring).
- TAB
- Indent current line as Ciao code. With argument, indent any additional lines of the same clause rigidly along with this one.
Getting on-line help
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.
- C-c TAB
- Find help for the symbol (e.g., predicate, directive, declaration, property, type, etc.) that is currently under the cursor. Opens a (hopefully) relevant part of the Ciao manuals in 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.
- C-c /
- Find a completion for the symbol (e.g., predicate, directive, declaration, type, etc.) that is currently under the cursor. Uses for completion the contents of the indices of the Ciao manuals. Same requirements as for finding help for the symbol.
- C-c RET
- Go to the part of the info directory containing the Ciao manuals.
- C-h m
- Show a short description of the Ciao emacs mode, including all key bindings.
Loading and compiling programs
These commands allow loading programs, creating executables, etc. by issuing the appropriate commands to a Ciao top level shell, running in its own buffer as a subprocess. See The interactive top-level shell for details. The following commands implement the communication with the Ciao top level:
- C-c t
- Ensure that an inferior Ciao top-level process is running.
This opens a top-level window (if one did not exist already) where queries can be input directly. Programs can be loaded into this top level by typing the corresponding commands in this window (such as use_module, etc.), or, more typically, by opening the file to be loaded in an emacs window (where it can be edited) and issuing a load command (such as C-c l or C-c L) directly from there (see the loading commands of this mode and their bindings).
Note that many useful commands (e.g., to repeat and edit previous commands, interrupt jobs, locate errors, automatic completions, etc.) are available in this top-level window (see Commands available in toplevel and preprocessor buffers).
Often, it is not necessary to use this function since execution of any of the other functions related to the top level (e.g., loading buffers into the top level) ensures that a top level is started (starting one if required).
- C-c l
- Load the current buffer (and any auxiliary files it may use) into the top level.
The type of compilation performed (compiling or interpreting) is selected automatically depending on whether the buffer has been marked for debugging or not -- see below. In case you try to load a file while in the middle of the debugging process the debugger is first aborted and then the buffer is loaded. Also, if there is a defined query, the user is asked whether it should be called.
- C-c f
- Load CiaoPP and then the current buffer (and any auxiliary files it may use) into the top level. Use CiaoPP auto_check_assrt predicate to check current buffer assertions and then load the buffer if there was no error.
- C-c x
- Make an executable from the code in the current buffer. The buffer must contain a 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.
- C-c o
- Make a Ciao object (.po) file from the code in the current buffer. This is useful for example while debugging during development of a very large application which is compiled into an excutable, and only one or a few files are modified. If the application executable is dynamically linked, i.e., the component .po files are loaded dynamically during startup of the application, then this command can be used to recompile only the file or files which have changed, and the correct version will be loaded dynamically the next time the application is started. However, note that this must be done with care since it only works if the inter-module interfaces have not changed. The recommended, much safer way is to generate the executable again, letting the Ciao compiler, which is inherently incremental, determine what needs to be recompiled.
- C-c a
- Make an active module executable from the code in the current buffer. An active module is a remote procedure call server (see the activemod library documentation for details).
- C-c s
- Set the current buffer as the principal file in a multiple module programming environment.
- C-c L
- Load the module designated as main module (and all related files that it uses) into the top level. If no main module is defined it will load the current buffer.
The type of compilation performed (compiling or interpreting) is selected automatically depending on whether the buffer has been marked for debugging or not -- see below. In case you try to load a file while in the middle of the debugging process the debugger is first aborted and then the buffer is loaded. Also, if there is a defined query, the user is asked whether it should be called.
Commands available in toplevel and preprocessor buffers
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 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-specific commands available include:
- C-c TAB
- Find help for the symbol (e.g., predicate, directive, declaration, property, type, etc.) that is currently under the cursor. Opens a (hopefully) relevant part of the Ciao manuals in 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.
- C-c /
- Find a completion for the symbol (e.g., predicate, directive, declaration, type, etc.) that is currently under the cursor. Uses for completion the contents of the indices of the Ciao manuals. Same requirements as for finding help for the symbol.
- C-c `
- Go to the location in the source file containing the next error reported by the last Ciao subprocess (preprocessor or toplevel) which was run.
- C-c e
- Remove error marks from last run (and also debugging marks if present). This finish the error finding session.
- C-c q
- Set a default query. This may be useful specially during debugging sessions. However, as mentioned elsewhere, note that commands that repeat previous queries are also available.
This query can be recalled at any time using C-c Q. It is also possible to set things up so that this query will be issued automatically any time a program is (re)loaded. The functionality is available in the major mode (i.e., from a buffer containing a source file) and in the inferior mode (i.e., from the buffer running the top-level shell). When called from the major mode (i.e., from window containing a source file) then the user is prompted in the minibuffer for the query. When called from the inferior mode (i.e., from a top-level window) then the query on the current line, following the Ciao prompt, is taken as the default query.
To clear the default query use M-x ciao-clear-query or simply set it to an empty query: i.e., in a source buffer select C-c q and enter an empty query. In an inferior mode simply select C-c q on a line that contains only the system prompt.
- C-c Q
- Issue predefined query.
- C-c C-v
- Show last output file produced by Ciao preprocessor. The preprocessor works by producing a file which is a transformed and/or adorned (with assertions) version of the input file. This command is often used after running the preprocessor in order to visit the output file and see the results from running the preprocessor.
- C-c v
- Report the version of the emacs Ciao mode.
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):
- M-p
- Cycle backwards through input history, saving input.
(fn ARG)
- M-n
- Cycle forwards through input history.
(fn ARG)
- M-r
- Search for a regular expression backward in input history using Isearch.
(fn)
- TAB
- Dynamically find completion of the item at point. Note that this completion command refers generally to filenames (rather than, e.g., predicate names, as in the previous functions).
- M-?
- List all (filename) completions of the item at point.
- RET
- Return at any point of the a line at the end of a buffer sends that line as input. Return not at end copies the rest of the current line to the end of the buffer and sends it as input.
- ^D
- Delete ARG characters forward or send an EOF to subprocess. Sends an EOF only if point is at the end of the buffer and there is no input.
(fn ARG)
- ^C ^U
- Kill all text from last stuff output by interpreter to point.
(fn)
- ^C ^W
- Kill characters backward until encountering the beginning of a word. With argument ARG, do this that many times.
(fn ARG)
- ^C ^C
- Interrupt the current subjob. This command also kills the pending input between the process mark and point.
(fn)
- ^C ^Z
- Stop the current subjob. This command also kills the pending input between the process mark and point.
WARNING: if there is no current subjob, you can end up suspending the top-level process running in the buffer. If you accidentally do this, use M-x comint-continue-subjob to resume the process. (This is not a problem with most shells, since they ignore this signal.)
(fn)
- ^C ^\
- Send quit signal to the current subjob. This command also kills the pending input between the process mark and point.
(fn)
Locating errors and checking the syntax of assertions
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:
- C-c `
- Go to the location in the source file containing the next error reported by the last Ciao subprocess (preprocessor or toplevel) which was run.
- C-c e
- Remove error marks from last run (and also debugging marks if present). This finish the error finding session.
- C-c E
- Check the syntax of the code and assertions in the current buffer, as well as imports and exports. This uses the standard top level (i.e., does not call the preprocessor and thus does not require the preprocessor to be installed). Note that full (semantic) assertion checking must be done with the preprocessor.
Commands which help typing in programs
The following commands are intended to help in the process of writing programs:
- C-c I S
- Insert a (Unix) header at the top of the current buffer so that the Ciao script interpreter will be called on this file if run from the command line. It also makes the file “executable” (e.g., 'chmod +x <file>' in Unix). See The script interpreter for details.
- C-c i
- Indent a Ciao or Prolog file using `plindent'.
Debugging programs
These commands allow marking modules for debugging by issuing the appropiate commands to a Ciao top level shell, running in its own buffer as a subprocess. There are two differents types of debugging: traditional 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 top level:
- C-c d
- Debug (or stop debugging) buffer source. This is a shortcut which is particularly useful when using the source debugger on a single module. It corresponds to several lower-level actions. Those lower-level actions depend on how the module was selected for debugging. In case the module was not marked for source-level debugging, it marks the module corresponding to the current buffer for source-level debugging, reloads it to make sure that it is loaded in the correct way for debugging (same as C-c l), and sets the debugger in trace mode (i.e., issues the 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.
- C-c m
- Mark, or unmark, the current buffer for debugging (traditional debugging or source debugging). Note that if the buffer has already been loaded while it was unmarked for debugging (and has therefore been loaded in “compile” mode) it has to be loaded again. The minibuffer shows how the module is loaded now and allows selecting another mode for it. There are three posibilities: N for no debug, S for source debug and D for traditional debug.
- C-c M-m
- Visits all Ciao files which are currently open in a buffer allowing selecting for each of them whether to debug them or not and the type of debugging performed. When working on a multiple module program, it is possible to have many modules open at a time. In this case, you will navigate through all open Ciao files and select the debug mode for each of them (same as doing C-c m for each).
- C-c S b
- Set a breakpoint on the current literal (goal). This can be done at any time (while debugging or not). The cursor must be on the predicate symbol of the literal. Breakpoints are only useful when using source-level debugging.
- C-c S v
- Remove a breakpoint from the current literal (goal). This can be done at any time (while debugging or not). The cursor must be on the predicate symbol of the literal.
- C-c S n
- Remove all breakpoints. This can be done at any time (while debugging or not).
- C-c S l
- Redisplay breakpoints in all Ciao buffers. This ensures that the marks in the source files and the Ciao toplevel are synchronized.
- C-c S r
- Remove breakpoint coloring in all Ciao files.
- C-c S t
- Set the debugger to the trace state. In this state, the program is executed step by step.
- C-c S d
- Set the debugger to the debug state. In this state, the program will only stop in breakpoints and spypoints. Breakpoints are specially supported in emacs and using source debug.
- C-c r
- Load the current region (between the cursor and a previous mark) into the top level. Since loading a region of a file is typically done for debugging and/or testing purposes, this command always loads the region in debugging mode (interpreted).
- C-c p
- Load the predicate around the cursor into the top level. Since loading a single predicate is typically done for debugging and/or testing purposes, this command always loads the predicate in debugging mode (interpreted).
Testing programs
These commands allow testing predicates and modules, based on interactively defined queryies or more sophisticated tests specified within the source code.
- C-c q
- Set a default query. This may be useful specially during debugging sessions. However, as mentioned elsewhere, note that commands that repeat previous queries are also available.
This query can be recalled at any time using C-c Q. It is also possible to set things up so that this query will be issued automatically any time a program is (re)loaded. The functionality is available in the major mode (i.e., from a buffer containing a source file) and in the inferior mode (i.e., from the buffer running the top-level shell). When called from the major mode (i.e., from window containing a source file) then the user is prompted in the minibuffer for the query. When called from the inferior mode (i.e., from a top-level window) then the query on the current line, following the Ciao prompt, is taken as the default query.
To clear the default query use M-x ciao-clear-query or simply set it to an empty query: i.e., in a source buffer select C-c q and enter an empty query. In an inferior mode simply select C-c q on a line that contains only the system prompt.
- C-c Q
- Issue predefined query.
- C-c u
- Run the test over the current buffer.
The test should be specified using a test assertion in the module.
- C-c U
- Run the test over the current buffer and the assertions of exported predicates.
The test should be specified using a test assertion in the module.
Preprocessing programs
These commands allow preprocessing programs with ciaopp, the Ciao preprocessor.
CiaoPP is the abstract interpretation-based preprocessor of the Ciao multi-paradigm program development environment. CiaoPP can perform a number of program debugging, analysis, and source-to-source transformation tasks on (Ciao) Prolog programs. These tasks include:
- Inference of properties of the predicates and literals of the program, including types, modes and other variable instantiation properties, non-failure, determinacy, bounds on computational cost, bounds on sizes of terms in the program, etc.
- Certain kinds of static debugging and verification, finding errors before running the program. This includes checking how programs call system library predicates and also checking the assertions present in the program or in other modules used by the program. Such assertions represent essentially partial specifications of the program.
- Several kinds of source to source program transformations such as program specialization, slicing, partial evaluation of a program, program parallelization (taking granularity control into account), inclusion of run-time tests for assertions which cannot be checked completely at compile-time, etc.
- The abstract model of the program inferred by the analyzers is used in the system to certify that an untrusted mobile code is safe w.r.t. the given policy (i.e., an abstraction-carrying code approach to mobile code safety).
The information generated by analysis, the assertions in the system 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:
- C-c A
- Call the preprocessor to perform a number of pre-selected analyses on the current buffer (and related modules).
- C-c T
- Call the preprocessor to perform compile-time checking of the assertions (types, modes, determinacy, nonfailure, cost, ...) in the current buffer (and against those in related modules).
- C-c O
- Uses the preprocessor to perform optimizations (partial evaluation, abstract specialization, parallelization, ...) on the current buffer (and related modules).
- C-c M
- Browse and select (using the preprocessor menus) the actions to be performed by the preprocessor when performing analisys used by M-x ciao- C-c A, C-c T, C-c O, and the corresponding toolbar buttons.
- C-c C-v
- Show last output file produced by Ciao preprocessor. The preprocessor works by producing a file which is a transformed and/or adorned (with assertions) version of the input file. This command is often used after running the preprocessor in order to visit the output file and see the results from running the preprocessor.
- C-c C-r
- Ensure that an inferior Ciao preprocessor process is running.
This opens a preprocessor top-level window (if one did not exist already) where preprocessing commands and preprocessing menu options can be input directly. Programs can be preprocessed by typing commands in this window, or, more typically, by opening the file to be preprocessed in an emacs window (where it can be edited) and issuing a command (such as C-c A, C-c T, C-c O, or C-c M) directly from there (see the preprocessing commands of this mode and their bindings).
Note that many useful commands (e.g., to repeat and edit previous commands, interrupt jobs, locate errors, automatic completions, etc.) are available in this top-level window (see Commands available in toplevel and preprocessor buffers).
Often, it is not necessary to use this function since execution of any of the other functions related to the top level (e.g., loading buffers into the top level) ensures that a top level is started (starting one if required).
Version control
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:
- a version number (such as, e.g., 1.2, where 1 is the major version number and 2 is the minor version number),
- a patch number (such as, e.g., the 4 in 1.2#4),
- a time stamp (such as, e.g., 1998/12/14,17:20*28+MET),
- the author of the change, and
- a comment explaining the change.
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:
:- doc(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 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 Ciao). 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:
- C-c C-a
- Used to turn on or off version control for the file being visited in the current buffer. The user will be prompted to choose among the following options:
- y
- Turn version control on for this file.
- n
- Turn version control off for this file. A version control comment such as:
:- doc(version_maintenance,off).
will be added to the buffer and the file saved. No version control will be performed on this file until the line above is removed or modified (i.e., from now on C-x C-s simply saves the buffer).
- q
- Turn off prompting for the introduction of changelog entries for now. emacs will not ask again while the buffer is loaded, but it may ask again when saving after the next time you load the buffer (if ciao-ask-for-version-maintenance-type is set to yes).
If y is selected, then the system prompts again regarding how and where the version and patch number information is to be maintained. The following options are available:
- on
- All version control information will be contained within this file. When saving a buffer (C-x C-s) emacs will ask if a changelog entry should be added to the file before saving. If a comment is entered by the user, a new patch number is assigned to it and the comment is added to the file. This patch number will be the one that follows the most recent changelog entry already in the file. This is obviously useful when maintaining version numbers individually for each file.
- <directory_name>
- Global version control will be performed coherently on several files. When saving a buffer (C-x C-s) emacs will ask if a changelog entry should be added to the file before saving. If a comment is given, the global patch number (which will be kept in the file: <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
- Turns off version control: C-x C-s then simply saves the file as usual.
Some useful tips:
- If a changelog entry is in fact introduced, the cursor is left at the point in the file where the comment was inserted and the mark is left at the original file point. This allows inspecting (and possibly modifying) the changelog entry, and then returning to the original point in the file by simply typing C-x C-x.
- The first changelog entry is entered by default at the end of the buffer. Later, the changelog entries can be moved anywhere else in the file. New changelog entries are always inserted just above the first changelog entry which appears in the file.
- The comments in changelog entries can be edited at any time.
- If a changelog entry is moved to another file, and version numbers are shared by several files through a directory, the corresponding file pointer in the <directory_name>/GlobalChangeLog file needs to be changed also, for the entry to be locatable later using C-c C-n.
- C-x C-s
- This is the standard emacs command that saves a buffer by writing the contents into the associated .pl file. However, in the Ciao mode, if version control is set to on for ths file, then this command will ask the user before saving whether to introduce a changelog entry documenting the changes performed.
In addition, if:
- the buffer does not already contain a comment specifying the type of version control to be performed,
- and the customizable variable ciao-ask-for-version-maintenance-type is set to yes (go to the Ciao options menu, LPdoc area to change this, which is by default set to no),
then, before saving a buffer, the user will be also automatically asked to choose which kind of version control is desired for the file, as in C-c C-a.
- C-c C-s
- Same as C-x C-s except that it forces prompting for inclusion of a changelog entry even if the buffer is unmodified.
- C-c n
- Force a move to a new major/minor version number (the user will be prompted for the new numbers). Only applicable if using directory-based version maintenance. Note that otherwise it suffices with introducing a changelog entry in the file and changing its version number by hand.
- C-c C-n
- When a unique version numbering is being maintained across several files, this command allows inspecting all changes sequentially by visiting all the files in which the changes were made:
- If in a source file, find the next changelog entry in the source file, open in another window the corresponding 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.
- If in a 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.
Generating program documentation
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.
- C-c D B
- Generate the documentation for the current buffer in the default format. This allows generating a simple document for the current buffer. Basically, it creates a simple, default SETTINGS.pl file, sets mainfile in SETTINGS.pl to the current buffer file and then generates the documentation in a temporary directory. This is useful for seeing how the documentation of a file will format. Note that for generating manuals the best approach is to set up a permanent documentation directory with the appropriate SETTINGS.pl file (see the LPdoc manual).
- C-c D F
- Change the default output format used by the LPdoc auto-documenter. It is set by default to html or to the environment variable LPDOCFORMAT if it is defined.
- C-c D S
- Visit, or create, the SETTINGS.pl file (which controls all auto-documenter options) for the current buffer.
- C-c D G
- Generate the documentation according to SETTINGS.pl in the default format. This allows generating complex documents but it assumes that SETTINGS.pl 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.pl (see the LPdoc manual).
- C-c D V
- Start a viewer on the documentation for the current buffer in the default format.
- C-c D W
- Change the root directory of the scratchpad for temporal source files. This is used, e.g., by the LPdoc auto-documenter when generating temporal configuration files and documentation for buffers. It is set by default to a new dir under /tmp or to the environment variable CIAOSCRATCHDIR if it is defined.
Setting top level preprocessor and documenter executables
These commands allow changing the executables used when starting the 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 or the preprocessor are available in the system. All these settings can be changed through the customize options in the help menu (see Customization).
- C-c S A
- C-c S C
- Change the Ciao executable used to run the top level. It is set by default to ciao or, to the environment variable CIAO if it is defined.
- C-c S C-c
- Change the arguments passed to the Ciao executable. They are set by default to none or, to the environment variable CIAOARGS if it is defined.
- C-c S P
- Change the executable used to run the Ciao Preprocessor toplevel. It is set by default to ciaopp or, to the environment variable CIAOPP if it is defined.
- C-c S C-p
- Change the arguments passed to the Ciao preprocessor executable. They are set by default to none or to the environment variable CIAOPPARGS if it is defined.
- C-c S L
- Change the location of the Ciao library paths (changes the environment variable CIAOLIB).
- C-c S D
- Change the executable used to run the LPdoc auto-documenter. It is set by default to lpdoc or to the environment variable LPDOC if it is defined.
- C-c S C-d
- Change the arguments passed to the LPdoc auto-documenter. They are set by default to none or to the environment variable LPDOCARGS if it is defined.
- C-c S C-l
- Change the path in which the LPdoc library is installed. It is set by default to /home/clip/lib or to the environment variable LPDOCLIB if it is defined.
Other commands
Some other commands which are active in the Ciao mode:
- C-c C-l
- Recenter the most recently used Ciao inferior process buffer (e.g., top level, preprocessor, etc.).
Traditional Prolog Mode Commands
These commands provide some bindings and facilities for loading programs, which are present in emacs Prolog modes of traditional Prolog systems (e.g., SICStus). This is useful mainly if the Ciao 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.
- C-c K
- Compile the entire buffer.
- C-c k
- Compile a given region.
- C-c C-k
- Compile the predicate around point.
- C-c C
- Consult the entire buffer.
- C-c c
- Consult a given region.
- C-c C-c
- Consult the predicate around point.
Coexistence with other Prolog-like interfaces
As mentioned previously, the Ciao emacs interface can also be used to work with traditional Prolog or CLP systems. Also, the Ciao 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 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).
Using Ciao mode capabilities in standard shells
The capabilities (commands, coloring, error location, ...) which are active in the Ciao 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 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.
Customization
This section explains all variables used in the Ciao 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 general variables
- ciao-ask-for-version-maintenance-type (string)
- If turned to yes the system asks prompts to set version control when saving files that do not set a version control system explicitly within the file.
- ciao-create-sample-file-on-startup (boolean)
- When starting the Ciao environment using ciao-startup two buffers are opened: one with a toplevel and another with a sample file. This toggle controls whether the sample file, meant for novice users, is created or not. Set by default, non-novice users will probably want to turn it off.
- ciao-first-indent-width (integer)
- First level indentation for a new goal.
- ciao-indent-width (integer)
- Indentation for a new goal.
- ciao-inhibit-toolbar (boolean)
- *Non-nil means don't use the specialized Ciao toolbar.
- ciao-library-path (string)
- Path to the Ciao System libraries (reads/sets the CIAOLIB environment variable ). Typically left empty, since ciao executables know which library to use.
- ciao-locate-also-note-messages (boolean)
- If set, also when errors of type NOTE are detected the corresponding file is visited and the location marked. It is set to nil by default because sometimes the user prefers not to take any action with respect to these messages (for example, many come from the documenter, indicating that adding certain declarations the documentation would be improved).
- ciao-locate-errors-after-run (boolean)
- If set, location of any errors produced when running Ciao tools (loading or preprocessing code, running the documenter, etc.) will be initiated automatically. I.e., after running a command, the system will automatically highlight any error messages and the corresponding areas in source files if possible. If set to nil this location will only happen after typing C-c ` or accessing the corresponding menu or tool bar button.
- ciao-os-shell-prompt-pattern (string)
- Regular expression used to describe typical shell prompt patterns (csh and bash), so that error location works in inferior shells. This is useful for example so that errors are located when generating documentation, and also when using the embedded debugger or any other application in a shell. It is best to be as precise as possible when defining this so that the standard Ciao error location does not get confused.
- ciao-scratchpad-root (directory)
- Name of root directory of the scratchpad for temporal source files and directories.
- ciao-system (string)
- Name of Ciao executable which runs the classical top level.
- ciao-system-args (string)
- Arguments passed to Ciao toplevel executable.
- ciao-toplevel-buffer-name (string)
- Basic name of the buffer running the Ciao toplevel inferior process.
- ciao-user-directives (list)
- List of identifiers of any directives defined by users which you would like highlighted (colored). Be careful, since wrong entries may affect other syntax highlighting.
CiaoPP variables
- ciao-ciaopp-buffer-name (string)
- Basic name of the buffer running the Ciao preprocessor inferior process.
- ciao-ciaopp-gmenu-buffer-name (string)
- Name of the buffer running the Ciao preprocessor graphical menu interface.
- ciao-ciaopp-system (string)
- Name of Ciao preprocessor executable.
- ciao-ciaopp-system-args (string)
- Arguments passed to Ciao preprocessor executable.
- ciao-ciaopp-use-graphical-menu (boolean)
- If set, an interactive graphical menu is used for controlling CiaoPP, instead of asking ascii questions in the CiaoPP buffer.
LPdoc variables
- ciao-lpdoc-buffer-name (string)
- Basic name of the buffer running the auto-documenter inferior process.
- ciao-lpdoc-docformat (symbol)
- Name of default output format used by LPdoc.
- ciao-lpdoc-libpath (directory)
- Path in which the LPdoc library is installed.
- ciao-lpdoc-system (string)
- Name of LPdoc auto-documenter executable.
- ciao-lpdoc-system-args (string)
- Arguments passed to LPdoc executable.
Faces used in syntax-based highlighting (coloring)
- ciao-button-pressed-widget-face (face)
- Face used for documentation text.
- ciao-button-widget-face (face)
- Face used for documentation text.
- ciao-edit-widget-face (face)
- Face used for documentation text.
- ciao-face-answer-val (face)
- Face to use for answer values in top level.
- ciao-face-answer-var (face)
- Face to use for answer variables in top level.
- ciao-face-builtin-directive (face)
- Face to use for the standard directives.
- ciao-face-check-assrt (face)
- Face to use for check assertions.
- ciao-face-checked-assrt (face)
- Face to use for checked assertions.
- ciao-face-ciaopp-option (face)
- Face to use for CiaoPP option menus.
- ciao-face-clauseheadname (face)
- Face to use for clause head functors.
- ciao-face-comment (face)
- Face to use for code comments using fixed pitch (double %).
- ciao-face-comment-variable-pitch (face)
- Face to use for code comments using variable pitch (single %).
- ciao-face-concurrency-op (face)
- Face to use for concurrency operators.
- ciao-face-condcode-directive (face)
- Face to use for the conditional code directives.
- ciao-face-cut (face)
- Face to use for cuts.
- ciao-face-debug-breakpoint (face)
- Face to use with breakpoints in source debugger.
- ciao-face-debug-call (face)
- Face to use when at call port in source debugger.
- ciao-face-debug-exit (face)
- Face to use when at exit port in source debugger.
- ciao-face-debug-expansion (face)
- Face to use in source debugger when source literal not located.
- ciao-face-debug-fail (face)
- Face to use when at fail port in source debugger.
- ciao-face-debug-mess (face)
- Face to use for debug messages.
- ciao-face-debug-redo (face)
- Face to use when at redo port in source debugger.
- ciao-face-entry-assrt (face)
- Face to use for entry assertions.
- ciao-face-error-mess (face)
- Face to use for error messages.
- ciao-face-false-assrt (face)
- Face to use for false assertions.
- ciao-face-fontify-sectioning (symbol)
- Whether to fontify sectioning macros with varying height or a color face.
If it is a number, use varying height faces. The number is used for scaling starting from `ciao-face-sectioning-5-face'. Typically values from 1.05 to 1.3 give best results, depending on your font setup. If it is the symbol `color', use `font-lock-type-face'.
Caveats: Customizing the scaling factor applies to all sectioning faces unless those face have been saved by customize. Setting this variable directly does not take effect unless you call `ciao-face-update-sectioning-faces' or restart Emacs.
Switching from `color' to a number or vice versa does not take effect unless you call M-x font-lock-fontify-buffer or restart Emacs.
- ciao-face-funexp-atom (face)
- Face to use for atoms in functional notation.
- ciao-face-highlight-code (face)
- Face to use for highlighting code areas (e.g., when locating the code area that an error message refers to).
- ciao-face-library-directive (face)
- Face to use for directives defined in the library.
- ciao-face-lpdoc-bug-comment (face)
- Face to use for LPdoc bug comments.
- ciao-face-lpdoc-command (face)
- Face to use LPdoc commands inserted in documentation text.
- ciao-face-lpdoc-comment (face)
- Face to use for LPdoc textual comments.
- ciao-face-lpdoc-comment-variable-pitch (face)
- Face to use for LPdoc textual comments in variable pitch.
- ciao-face-lpdoc-crossref (face)
- Face to use for LPdoc cross-references.
- ciao-face-lpdoc-include (face)
- Face to use for LPdoc include commands.
- ciao-face-lpdoc-verbatim (face)
- Face to use for LPdoc verbatim text.
- ciao-face-lpdoc-version-comment (face)
- Face to use for LPdoc version comments.
- ciao-face-modedef-assrt (face)
- Face to use for modedef definitions.
- ciao-face-module-directive (face)
- Face to use for the module-related directives.
- ciao-face-no-answer (face)
- Face to use for no answer in top level.
- ciao-face-note-mess (face)
- Face to use for note messages.
- ciao-face-other-mess (face)
- Face to use for other messages.
- ciao-face-predicate-directive (face)
- Face to use for the predicate-related directives.
- ciao-face-prompt (face)
- Face to use for prompts in top-level and shells.
- ciao-face-prop-assrt (face)
- Face to use for property definitions.
- ciao-face-quoted-atom (face)
- Face to use for quoted atoms.
- ciao-face-script-header (face)
- Face to use for script headers.
- ciao-face-sectioning-0-face (face)
- Face for sectioning commands at level 0.
Probably you don't want to customize this face directly. Better change the base face `ciao-face-sectioning-5-face' or customize the variable `ciao-face-fontify-sectioning'.
- ciao-face-sectioning-1-face (face)
- Face for sectioning commands at level 1.
Probably you don't want to customize this face directly. Better change the base face `ciao-face-sectioning-5-face' or customize the variable `ciao-face-fontify-sectioning'.
- ciao-face-sectioning-2-face (face)
- Face for sectioning commands at level 2.
Probably you don't want to customize this face directly. Better change the base face `ciao-face-sectioning-5-face' or customize the variable `ciao-face-fontify-sectioning'.
- ciao-face-sectioning-3-face (face)
- Face for sectioning commands at level 3.
Probably you don't want to customize this face directly. Better change the base face `ciao-face-sectioning-5-face' or customize the variable `ciao-face-fontify-sectioning'.
- ciao-face-sectioning-4-face (face)
- Face for sectioning commands at level 4.
Probably you don't want to customize this face directly. Better change the base face `ciao-face-sectioning-5-face' or customize the variable `ciao-face-fontify-sectioning'.
- ciao-face-sectioning-5-face (face)
- Face for sectioning commands at level 5.
- ciao-face-startup-message (face)
- Face to use for system splash message.
- ciao-face-string (face)
- Face to use for strings.
- ciao-face-test-assrt (face)
- Face to use for test assertions.
- ciao-face-texec-assrt (face)
- Face to use for texec assertions.
- ciao-face-true-assrt (face)
- Face to use for true assertions.
- ciao-face-trust-assrt (face)
- Face to use for trust assertions.
- ciao-face-type-assrt (face)
- Face to use for type definitions.
- ciao-face-user-directive (face)
- Face to use for directives defined by the user (see ciao-user-directives custom variable to add new ones).
- ciao-face-variable (face)
- Face to use for variables.
- ciao-face-warning-mess (face)
- Face to use for warning messages.
- ciao-face-yes-answer (face)
- Face to use for yes answer in top level.
- ciao-faces-use-variable-pitch-in-comments (boolean)
- Controls whether variable pitch fonts are used when highlighting comments. Unset by default. After changing this you must exit and reinitialize for the change to take effect.
- ciao-menu-error-widget-face (face)
- Face used for menu error representation in graphical interface.
- ciao-menu-note-widget-face (face)
- Face used for menu note representation in graphical interface.
- ciao-mouse-widget-face (face)
- Face used for documentation text.
- ciao-text-widget-face (face)
- Face used for documentation text.
- ciao-title-widget-face (face)
- Face to use for interactive menu title.
Installation of the Ciao emacs interface
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 mode is loaded by default in your system. This can be done by including in your .emacs file a line such as:
(load <CIAOLIBDIR>/ciao-mode-init)
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):
; -*- mode: emacs-lisp; -*- ;;; ciao-config.el --- Configuration parameters for this installation ;; Copyright (C) 1986-2012 Free Software Foundation, Inc. and ;; M. Hermenegildo and others (herme@fi.upm.es, UPM-CLIP, Spain). ;; This file is not part of GNU Emacs. ;; This file is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; This file is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;; In emacs this is done most reliably by setting INFOPATH (done in ;; Ciao installation). xemacs does need it for finding the Ciao ;; manuals (does not seem to read INFOPATH). (defvar ciao-bin-dir <v>CIAOBINDIR</v> "Where the actual Ciao binaries are.") (defvar ciao-config `(:version "<v>CIAODE_VERSION</v>" ;; Paths :bin-dir <v>CIAOBINDIR</v> :real-lib-dir <v>CIAOREALLIBDIR</v> :lpdoc-lib-dir <v>LPDOCLIBDIR</v> :lpdoc-dir <v>LPDOCDIR</v> ;; Manuals :ciaosys-name-version "<v>CIAO_NAME_VERSION</v>" :ciaopp-name-version "<v>CIAOPP_NAME_VERSION</v>" :lpdoc-name-version "<v>LPDOC_NAME_VERSION</v>" ;; Binaries :ciaosh-bin ,<v>CIAOSHELL</v> :ciaopp-bin ,<v>CIAOPPSHELL</v> :lpdoc-bin ,<v>LPDOCEXEC</v> :plindent-bin ,<v>PLINDENT</v> )) (defun ciao-get-config (prop) "Obtain configuration property `prop'" (plist-get ciao-config prop)) ;; Provide ourselves: (provide 'ciao-config) ;;; ciao-config.el ends here
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 mode, then comment out (or remove) the line:
(setq auto-mode-alist ... )
You will then need to switch manually to Ciao mode by typing M-x ciao-mode after opening a Ciao file.
If you are able to open the Ciao 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 (Installing Ciao from the source distribution or Installing Ciao from a Win32 binary distribution) for details.
Emacs version compatibility
This mode is currently being developed within GNU emacs version 24.1. It should also (hopefully) work with all other 23.XX, 22.XX, 21.XX, 20.XX, and later 19.XX versions. We also try our best to keep things working under xemacs and under some emacs native ports for the mac.Acknowledgments (ciao.el)
This code is derived from the 1993 version of the emacs interface for &-Prolog by Manuel 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, Manuel C. Rodriguez, David Trallero, and Jose Morales. See the changelogs for details.