As a means of automating common Prolog code editing tasks, such as
adding new clauses to an existing predicate, Sweep Prolog mode
provides the “do what I mean” command
sweeprolog-insert-term-dwim, bound by default to C-M-m
(or equivalently, M-RET). This command inserts a new term in
the current buffer according to the context in which you invoke it.
Insert an appropriate Prolog term in the current buffer, based on the
current context (
List of functions for
sweeprolog-insert-term-dwim to try for
inserting a Prolog term based on the current context.
To determine which term to insert and exactly where, the command
sweeprolog-insert-term-dwim calls the functions in the list
sweeprolog-insert-term-functions one after the other until one
of them succeeds. The functions on this list are called term
insertion functions, each insertion function takes two
arguments—the position where you invoke
sweeprolog-insert-term-dwim and the prefix argument you give
it, if any—and returns non-
nil after performing its specific
insertion if it is applicable in the current context.
sweeprolog-insert-term-functions contains the
following insertion functions:
If the region is active and selects a goal, extract the selected goal into a separate predicate. With a prefix argument, also suggest replacing other goals in the buffer that the selected goal subsumes with invocations of the new predicate that this function creates. See Extracting Goals to Separate Predicates.
If the last token before point is a fullstop ending a predicate clause, insert a new clause below it.
If point is over a call to an undefined predicate, insert a definition
for that predicate. By default, the new predicate definition is
inserted right below the last clause of the current predicate
definition. You can customize the user option
sweeprolog-new-predicate-location-function to control where in
the buffer this function inserts new predicate definitions.
This command inserts holes as placeholders for the body term and the head’s arguments, if any. See Holes.