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
uses its internal defaults, which are defined by the Prolog flag editor
and/or the environment variable
EDITOR
. The following rules apply. If the Prolog flag editor
is of the format $
<name>, the editor is
determined by the environment variable <name>. Else, if
this flag is pce_emacs
or built_in
and XPCE is loaded or can be loaded, the built-in Emacs clone
is used. Else, if the environment EDITOR
is set, this
editor is used. Finally,
vi is used as default on Unix systems and notepad on
Windows.
See the default user preferences file dotfiles/dotplrc
for examples.
%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>
'. Facts are represented as `<Head>
:- true
' or simply <Head>
.
Variables in the clause are written as A, B, ... .
Singleton variables are written as _
. See also portray_clause/2.