7.18 Code Completion

In Emacs, major modes for different programming languages provide in-buffer code completion via a standard generic command called completion-at-point (see (emacs)Symbol Completion). This command is normally bound to C-M-i and M-TAB. Sweep extends completion-at-point with context-aware completion for Prolog code in Prolog buffers.

When providing candidates for in-buffer completion, Sweep takes into account the code surrounding the cursor to determine what kind of completion makes most sense:

Variable name completion

If the text before point can be completed to one or more variable names that appear elsewhere in the current clause, completion-at-point suggests matching variable names as completion candidates.

Predicate completion

If point is at a callable position, completion-at-point suggests matching predicate calls. If the predicate you choose takes arguments, Sweep inserts holes in their places, and moves point to the first argument (see Holes).

Predicate option completion

If point is inside a predicate options list, completion-at-point suggests matching options or option values for the appropriate predicate.

Source file completion

If point is at a position where a source file specification should appear (such as the argument of use_module/1), completion-at-point suggests matching source file specifications.

Arithmetic function completion

If point is inside an arithmetic expression, completion-at-point suggests matching arithmetic functions.

Flag completion

If point is at a position where a Prolog flag should appear (such as the first argument of set_prolog_flag/2), completion-at-point suggests matching flags.

Atom completion

If point is at a non-callable position, completion-at-point suggests matching atoms and functors.