Home Contents Index Summary Previous Next

3.3 Listing Predicates and Editor Interface

SWI-Prolog offers an interface to the Unix vi editor and the GNU Emacs invocations emacs and emacsclient. Which editor is used is determined by the Unix environment variable EDITOR, which should hold the full pathname of the editor. If this variable is not defined, vi is used. (12)

After the user quits the editor, make/0 is invoked to reload all modified source files using consult/1. If the editor can be quit such that an exit status non-equal to 0 is returned make/0 will not be invoked. top can do this by typing control-C, vi cannot do this.

A predicate specification is either a term with the same functor and arity as the predicate wanted, a term of the form Functor/Arity or a single atom. In the latter case the database is searched for a predicate of this name and arbitrary arity (see current_predicate/2). When more than one such predicate exists the system will prompt for confirmation on each of the matched predicates. Predicates specifications are given to the `Do What I Mean' system (see dwim_predicate/2) if the requested predicate does not exist.

ed(+Pred)
Invoke the user's preferred editor on the source file of Pred, providing a search specification which searches for the predicate at the start of a line.

ed
Invoke ed/1 on the predicate last edited using ed/1. Asks the user to confirm before starting the editor.

edit(+File)
Invoke the user's preferred editor on File. File is a file specification as for consult/1 (but not a list). Note that the file should exist.

edit
Invoke edit/1 on the file last edited using edit/1. Asks the user to confirm before starting the editor.

listing(+Pred)
List specified predicates (when an atom is given all predicates with this name will be listed). The listing is produced on the basis of the internal representation, thus loosing user's layout and variable name information. See also portray_clause/1.

listing
List all predicates of the database using listing/1.

portray_clause(+Clause)
Pretty print a clause as good as we can. A clause should be specified as a term `<Head> :- <Body>' (put brackets around it to avoid operator precedence problems). Facts are represented as `<Head> :- true'.

edit_source(+Spec)
A hook that may be defined in the module user to specify how the predicates ed/1 and edit/1 call the editor. If ed/1 is invoking this hook, Spec is a term of the format

File:LineNo:Name/Arity

Where File and LineNo represents the location of the predicate remembered by Prolog, and Name and Arity specify the predicate. If invoked by edit/1, Spec is an atom denoting the name of the file to be edited. This hook is defined by the library library(swi_prolog) distributed with the XPCE package for using XPCE to edit Prolog files.