7.4.1 Inserting the Right Number of Spaces

Command: sweeprolog-align-spaces

Insert or remove spaces around point to such that the next Prolog token starts at a column distanced from the beginning of the previous token by a multiple of four columns.

User Option: sweeprolog-enable-cycle-spacing

Whether to add sweeprolog-align-spaces as the first element of cycle-spacing-actions in Sweep Prolog mode buffers. Defaults to t.

To insert or update whitespace around point, use the command M-x sweeprolog-align-spaces. As an example, consider a Sweep Prolog mode buffer with the following contents, where ∗ designates the location of the cursor:

foo :-
    (   if
    ;

Calling M-x sweeprolog-align-spaces inserts three spaces, to yield the expected layout:

foo :-
    (   if
    ;

In Emacs 29, you can extend the command M-x cycle-spacing via a list of callback functions specified by the variable cycle-spacing-actions. Sweep leverages this facility and adds sweeprolog-align-spaces as the first action of cycle-spacing. To inhibit sweeprolog-mode from doing so, set the user option sweeprolog-enable-cycle-spacing to nil.

Moreover, in Emacs 29 cycle-spacing is bound by default to M-SPC, which means that all you need to do to align if-then-else and similar constructs is to type M-SPC after the first token.

In Emacs prior to version 29, you can bind sweeprolog-align-spaces to M-SPC directly by adding the following lines to Emacs’s initialization file (see (emacs)Init File).

(eval-after-load 'sweeprolog
  '(define-key sweeprolog-mode-map (kbd "M-SPC") #'sweeprolog-align-spaces))