SWI-Prolog offers an extensible interface which allows the user to edit objects of the program: predicates, modules, files, etc. The editor interface is implemented by edit/1 and consists of three parts: locating, selecting and starting the editor.
Any of these parts may be extended or redefined by adding clauses to
various multi-file (see multifile/1)
predicates defined in the module
prolog_edit
.
The built-in edit specifications for edit/1 (see prolog_edit:locate/3) are described below.
Fully specified objects | |
<Module>:<Name>/<Arity> | Refers a predicate |
module(<Module>) | Refers to a module |
file(<Path>) | Refers to a file |
source_file(<Path>) | Refers to a loaded source-file |
Ambiguous specifications | |
<Name>/<Arity> | Refers this predicate in any module |
<Name> | Refers to (1) named predicate in any module with any arity, (2) a (source) file or (3) a module. |
file(Path)
or Name/Arity.
Location is a list of attributes of the location.
Normally, this list will contain the term file(File)
and
---if available--- the term line(Line)
.
If it fails, edit/1
will invoke an external editor. The editor to be invoked is determined
from the evironment variable EDITOR
, which may be set from
the operating system or from the Prolog initialisation file using setenv/2.
If no editor is defined,
vi is the default in Unix systems, and notepad on Windows.
The predicate prolog_edit:edit_command/2 defines how the editor will be invoked.
%f
is replaced by the full file-name of the location, and
%d
by the line number. If the editor can deal with starting
at a specified line, two clauses should be provided, one holding only
the %f
pattern, and one holding both patterns.
The default contains definitions for vi, emacs, emacsclient, vim and notepad (latter without line-number version).
Please contribute your specifications to jan@swi.psy.uva.nl.
library(swi_edit)
,
containing definitions to locate classes and methods as well as to bind
this package to the PceEmacs built-in editor.
:- multifile prolog_edit:load/0. prolog_edit:load :- ensure_loaded(library(swi_edit)). |
<Head> :- <Body>
'
(put brackets around it to avoid operator precedence problems). Facts
are represented as `<Head> :- true
'.