~eshel/sweep

505d999cf68bbfa51d7cec2bf86d682d8be23ef8 — Eshel Yaron 10 months ago 0f2f7d9
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.
2 files changed, 32 insertions(+), 3 deletions(-)

M sweeprolog-tests.el
M sweeprolog.el
M sweeprolog-tests.el => sweeprolog-tests.el +15 -0
@@ 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 ()

M sweeprolog.el => sweeprolog.el +17 -3
@@ 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)))))