emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/sweeprolog 201a54fe70: * (sweeprolog-align-spaces): extend


From: ELPA Syncer
Subject: [nongnu] elpa/sweeprolog 201a54fe70: * (sweeprolog-align-spaces): extend to also work in comments
Date: Fri, 9 Dec 2022 10:59:41 -0500 (EST)

branch: elpa/sweeprolog
commit 201a54fe70af84d3c6915f0d9cdb2ce8011b7083
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>

    * (sweeprolog-align-spaces): extend to also work in comments
---
 sweeprolog-tests.el | 18 +++++++++++++++++-
 sweeprolog.el       | 18 ++++++++++++++++--
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/sweeprolog-tests.el b/sweeprolog-tests.el
index 43abff1745..eb08bcc8b4 100644
--- a/sweeprolog-tests.el
+++ b/sweeprolog-tests.el
@@ -1020,6 +1020,21 @@ scasp_and_show(Q, Model, Tree) :-
     (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
@@ -1104,7 +1119,8 @@ foo :-
   (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))))
 
diff --git a/sweeprolog.el b/sweeprolog.el
index 742b42a15f..2161dc5aef 100644
--- a/sweeprolog.el
+++ b/sweeprolog.el
@@ -3457,14 +3457,28 @@ non-exported predicates defined in the current buffer."
           (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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]