7.1 Indentation

Sweep Prolog mode uses a bespoke indentation engine to determine the appropriate indentation of each line of Prolog code. The indentation engine analyses the syntactic context of a given line and decides how far it should be indented based on a set of indentation rules.

TAB
C-i

Indent the current line. If the region is active, indent all the lines within it (indent-for-tab-command).

Function: sweeprolog-indent-line

Indent the current line according to SWI-Prolog conventions. This function is used as the value of indent-line-function in Sweep Prolog mode buffers.

Command: sweeprolog-infer-indent-style

Infer the indentation style of the current buffer from its contents.

User Option: sweeprolog-indent-offset

Number of columns to indent nested code to in Sweep Prolog mode buffers.

The entry point of the indentation engine is the function sweeprolog-indent-line which takes no arguments and indents the line at point. Sweep Prolog mode cooperates with the standard Emacs interface for indentation by arranging for sweeprolog-indent-line to be called whenever a line should be indented, notably when you press TAB. For a full description of the available commands and options that pertain to indentation, See (emacs)Indentation.

The user option sweeprolog-indent-offset specifies how many columns Sweep keeps empty between every level of indentation. The standard Emacs variable indent-tabs-mode determines if indentation can use tabs or only spaces. You may sometimes want to adjust these options to match the indentation style used in an existing Prolog codebase. The command sweeprolog-infer-indent-style can do that for you by analyzing the contents of the current buffer and updating the buffer-local values of sweeprolog-indent-offset and indent-tabs-mode accordingly. Consider adding sweeprolog-infer-indent-style to sweeprolog-mode-hook to have it set up the indentation style automatically in all Sweep Prolog mode buffers:

(add-hook 'sweeprolog-mode-hook #'sweeprolog-infer-indent-style)