(sweeprolog-end-of-top-term)
(should (= (point) 252))))
+(ert-deftest align-spacs-in-line-comment ()
+ "Test using `sweeprolog-align-spaces' in a line comment."
+ (with-temp-buffer
+ (sweeprolog-mode)
+ (insert "
+%! foo is det.
+%
+%")
+ (sweeprolog-align-spaces)
+ (should (string= (buffer-string)
+ "
+%! foo is det.
+%
+% "))))
+
(ert-deftest electric-layout ()
"Test `sweeprolog-electric-layout-mode'."
(with-temp-buffer
(with-temp-buffer
(sweeprolog-mode)
(insert given)
- (indent-region-line-by-line (point-min) (point-max))
+ (let ((inhibit-message t))
+ (indent-region-line-by-line (point-min) (point-max)))
(should (string= (buffer-substring-no-properties (point-min) (point-max))
expected))))
(user-error "No export list found"))))))
(defun sweeprolog-align-spaces (&optional _)
- "Adjust in-line whitespace between the previous next Prolog tokens.
+ "Adjust in-line spaces between the previous and next Prolog tokens.
This command ensures that the next token starts at a column
distanced from the beginning of the previous by a multiple of
four columns, which accommodates the convetional alignment for
-if-then-else constructs in SWI-Prolog."
+if-then-else constructs and other common layouts in SWI-Prolog."
(interactive "" sweeprolog-mode)
(let ((bol (line-beginning-position)))
+ (if (nth 4 (syntax-ppss))
+ (combine-after-change-calls
+ (delete-horizontal-space)
+ (let* ((lend (point))
+ (lbeg (save-excursion
+ (while (and (< bol (point))
+ (not (= (char-syntax (char-before))
+ ? )))
+ (forward-char -1))
+ (point)))
+ (num (- 4 (% (- lend lbeg) 4))))
+ (insert (make-string (if (< 0 num)
+ num
+ 4) ? )))))
(pcase (sweeprolog-last-token-boundaries)
(`(,_ ,lbeg ,lend)
(when (<= bol lend)