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

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

[nongnu] elpa/sweeprolog 505d999cf6 2/3: Improve indentation for multi-l


From: ELPA Syncer
Subject: [nongnu] elpa/sweeprolog 505d999cf6 2/3: Improve indentation for multi-line comments
Date: Sat, 27 Jan 2024 13:00:33 -0500 (EST)

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

    Improve indentation for multi-line comments
    
    * sweeprolog.el (sweeprolog-indent-line): Indent multi-lines comment
    lines according to previous line.
    * sweeprolog-tests.el (indentation): Test it.
---
 sweeprolog-tests.el | 15 +++++++++++++++
 sweeprolog.el       | 20 +++++++++++++++++---
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/sweeprolog-tests.el b/sweeprolog-tests.el
index c3897e6e50..67fb6e4799 100644
--- a/sweeprolog-tests.el
+++ b/sweeprolog-tests.el
@@ -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 ()
diff --git a/sweeprolog.el b/sweeprolog.el
index 3e96ceb12c..643ed32f93 100644
--- a/sweeprolog.el
+++ b/sweeprolog.el
@@ -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)))))



reply via email to

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