7.1.1 Indentation rules

Sweep Prolog mode indents lines according to the following rules:

  1. If the current line starts inside a string or a multi-line comment, do not indent.
  2. If the current line starts with a top term, do not indent.
  3. If the current line starts with a closing parenthesis and the matching opening parenthesis is part of a functor, indent to the column of the opening parenthesis if any arguments appear on the same line as the functor, otherwise indent to the start of the functor.

    This rule yields the following layouts:

    some_functor(
        some_arg
    ).
    
    some_functor( some_arg
                ).
    
  4. If the current line is the first non-comment line of a clause body, indent to the starting column of the head term plus the value of the user option sweeprolog-indent-offset (by default, four extra columns).

    As an example, this rule yields the following layouts when sweeprolog-indent-offset is set to the default value of four columns:

    some_functor(arg1, arg2) :-
        body_term.
    
    asserta( some_functor(arg1, arg2) :-
                 body_term
           ).
    
  5. If the current line starts with the right hand side operand of an infix operator, indent to the starting column of the first operand in the chain of infix operators of the same precedence.

    This rule yields the following layouts:

    head :- body1, body2, body3,
            body4, body5.
    
    A is 1 * 2 ^ 3 * 4 *
         5.
    
    A is 1 * 2 + 3 * 4 *
                 5.
    
  6. If the last non-comment line ends with a functor and its opening parenthesis, indent to the starting column of the functor plus sweeprolog-indent-offset.

    This rule yields the following layout:

    some_functor(
        arg1, ...
    
  7. If the last non-comment line ends with a prefix operator, indent to starting column of the operator plus sweeprolog-indent-offset.

    This rule yields the following layout:

    :- multifile
           predicate/3.