7.5 Term-based editing and motion commands

Emacs includes many useful features for operating on syntactic units in source code buffer, such as marking, transposing and moving over expressions. By default, these features are geared towards working with Lisp expressions, or S-expressions. Sweep extends Emacs’s notion of syntactic expressions to accommodate for Prolog terms, which allows the standard S-expression based commands to operate on Prolog terms seamlessly.

The Emacs manual covers the most important commands that operate on S-expressions, and by extension on Prolog terms. See (emacs)Expressions. Another useful command for Prolog programmers is M-x kill-backward-up-list, bound by default to C-M-^ in Sweep Prolog mode buffers.


Kill the Prolog term containing the current term, leaving the current term itself (kill-backward-up-list).

This command replaces the parent term containing the term at point with the term itself. To illustrate the utility of this command, consider the following clause:

head :-

Now with point anywhere inside goal2, calling kill-backward-up-list removes the setup_call_cleanup/3 term leaving goal2 to be called directly:

head :-