]> git.eshelyaron.com Git - sweep.git/commitdiff
Improve indentation for multi-line comments
authorEshel Yaron <me@eshelyaron.com>
Fri, 26 Jan 2024 09:20:29 +0000 (10:20 +0100)
committerEshel Yaron <me@eshelyaron.com>
Fri, 26 Jan 2024 09:20:29 +0000 (10:20 +0100)
* sweeprolog.el (sweeprolog-indent-line): Indent multi-lines comment
lines according to previous line.
* sweeprolog-tests.el (indentation): Test it.

sweeprolog-tests.el
sweeprolog.el

index c3897e6e50cffc5fd794e76a4c2a3aca6affe179..67fb6e4799b6c295e879946a4815ffdf53682747 100644 (file)
@@ -1846,6 +1846,21 @@ body.
 head,
   right_hand_context -->
     body.
+")
+  (sweeprolog-test-indentation
+   "/** <module> Foo
+
+This module provides foo bar
+ baz spam
+  foo bar baz
+*/
+"
+   "/** <module> Foo
+
+This module provides foo bar
+baz spam
+foo bar baz
+*/
 "))
 
 (sweeprolog-deftest forward-sexp-with-adjacent-operators ()
index 3e96ceb12c4692b6c2077d9c518598f26a757564..643ed32f9316358469b387a056cb1942c4f90401 100644 (file)
@@ -5297,12 +5297,26 @@ accordingly."
           col)))))
 
 (defun sweeprolog-indent-line ()
-  "Indent the current line in a `sweeprolog-mode' buffer."
+  "Indent the current line in a Sweep Prolog mode buffer."
   (interactive)
   (let ((pos (- (point-max) (point))))
     (back-to-indentation)
-    (let ((column (if (nth 8 (syntax-ppss))
-                      'noindent
+    (let ((column (if-let ((ppss (syntax-ppss))
+                           (open (nth 8 ppss)))
+                      ;; Inside a comment or a string.
+                      (if (nth 4 ppss)
+                          ;; It's a comment.  Indent like
+                          ;; `indent--default-inside-comment'.
+                          (save-excursion
+                            (forward-line -1)
+                            (skip-chars-forward " \t")
+                            (when (< (1- (point)) open (line-end-position))
+                              (goto-char open)
+                              (when (looking-at comment-start-skip)
+                                (goto-char (match-end 0))))
+                            (current-column))
+                        ;; It's a string.  Don't indent.
+                        'noindent)
                     (if-let ((open (and (not (eobp))
                                         (= (sweeprolog-syntax-class-at (point)) 5)
                                         (nth 1 (syntax-ppss)))))