The minor mode sweeprolog-electric-layout-mode adjusts
whitespace around point automatically as you type:
Toggle automatic whitespace adjustment according to SWI-Prolog conventions.
It works by examining the context of point whenever a character is inserted in the current buffer, and applying the following layout rules:
Insert two consecutive spaces after the %! or %%
starting a ‘PlDoc’ predicate documentation structured comment.
Insert spaces after a part of an if-then-else
constructs such that point is positioned four columns after its
beginning. The specific tokens that trigger this rule are the
opening parenthesis ( and the operators ;, -> and *->, and only if
they are inserted in a callable context, where an if-then-else
construct would normally appear.
To enable this mode in a Sweep Prolog mode buffer, type M-x
sweeprolog-electric-layout-mode RET. You can automate this
step by adding sweeprolog-electric-layout-mode to
sweeprolog-mode-hook in your Emacs configuration:
(add-hook 'sweeprolog-mode-hook #'sweeprolog-electric-layout-mode)