]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix c-ts-common--fill-paragraph for C
authorYuan Fu <casouri@gmail.com>
Sat, 27 Apr 2024 02:55:37 +0000 (19:55 -0700)
committerEshel Yaron <me@eshelyaron.com>
Mon, 29 Apr 2024 15:03:15 +0000 (17:03 +0200)
This should fix the failing filling test for c-ts-mode.

* lisp/progmodes/c-ts-common.el (c-ts-common--fill-paragraph): Don't
go back to indentation.

(cherry picked from commit 53333132e47589c59331a7b8b3afb5ce964aed99)

lisp/progmodes/c-ts-common.el

index cc8254c5701438ce3cce8946b7df7ef23e469247..b1520db22e945e887322d3bddbd0807aeecf659f 100644 (file)
@@ -123,12 +123,16 @@ ARG is passed to `fill-paragraph'."
     (let ((node (treesit-node-at (point))))
       (when (string-match-p c-ts-common--comment-regexp
                             (treesit-node-type node))
-        (if (save-excursion
-              (goto-char (treesit-node-start node))
-              ;; In rust, NODE will be the body of a comment excluding
-              ;; the //, so we need to go to BOL to check for //.
-              (back-to-indentation)
-              (looking-at "//"))
+        (if (or (save-excursion
+                  (goto-char (treesit-node-start node))
+                  (looking-at "//"))
+                ;; In rust, NODE will be the body of a comment, and the
+                ;; parent will be the whole comment.
+                (if-let ((start (treesit-node-start
+                                 (treesit-node-parent node))))
+                    (save-excursion
+                      (goto-char start)
+                      (looking-at "//"))))
             (fill-comment-paragraph arg)
           (c-ts-common--fill-block-comment arg)))
       ;; Return t so `fill-paragraph' doesn't attempt to fill by