]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix 'yaml-ts-mode' filling of comments (Bug#77095)
authorRandy Taylor <dev@rjt.dev>
Sat, 5 Apr 2025 19:52:45 +0000 (15:52 -0400)
committerEshel Yaron <me@eshelyaron.com>
Sat, 26 Apr 2025 17:31:12 +0000 (19:31 +0200)
* lisp/textmodes/yaml-ts-mode.el (yaml-ts-mode--fill-paragraph):
Handle comment filling differently than block_scalars.
(yaml-ts-mode): Set 'comment-start-skip'.

(cherry picked from commit 417ee3a7f7c66f6c23c9bab7228bfb64014573dd)

lisp/textmodes/yaml-ts-mode.el

index 26b7655acba5c3eacd823a5bdc3a8351c1673868..3338044652b03f8a567929fc8fdd55811b29d43e 100644 (file)
@@ -134,18 +134,21 @@ boundaries.  JUSTIFY is passed to `fill-paragraph'."
   (save-restriction
     (widen)
     (let ((node (treesit-node-at (point))))
-      (if (member (treesit-node-type node) '("block_scalar" "comment"))
-        (let* ((start (treesit-node-start node))
-               (end (treesit-node-end node))
-               (start-marker (point-marker))
-               (fill-paragraph-function nil))
-          (save-excursion
-            (goto-char start)
-            (forward-line)
-            (move-marker start-marker (point))
-            (narrow-to-region (point) end))
-          (fill-region start-marker end justify))
-        t))))
+      (pcase (treesit-node-type node)
+        ("block_scalar"
+         (let* ((start (treesit-node-start node))
+                (end (treesit-node-end node))
+                (start-marker (point-marker))
+                (fill-paragraph-function nil))
+           (save-excursion
+             (goto-char start)
+             (forward-line)
+             (move-marker start-marker (point))
+             (narrow-to-region (point) end))
+           (fill-region start-marker end justify)))
+        ("comment"
+         (fill-comment-paragraph justify))))
+    t))
 
 (defun yaml-ts-mode--defun-name (node)
   "Return the defun name of NODE.
@@ -173,6 +176,7 @@ Return nil if there is no name or if NODE is not a defun node."
     ;; Comments.
     (setq-local comment-start "# ")
     (setq-local comment-end "")
+    (setq-local comment-start-skip "#+\\s-*")
 
     ;; Indentation.
     (setq-local indent-tabs-mode nil)