Subject: bug#77095: 31.0.50; Using fill-region doesn't produce commented lines in yaml-ts-mode

From: Randy Taylor <[email-masked]>
Date: Sat, 12 Apr 2025 20:04:50 +0000

On Thursday, April 10th, 2025 at 03:16, the_wurfkreuz <[email-masked]> wrote:
> 
> 
> I applied the patch and recompiled emacs. I don't see any changes.

Sorry, I must've turned another mode on or something by mistake. The
previous patch fixed the problem for fill-paragraph, and something
like electric-pair-mode being on fixes it for fill-region, too.

Anyway, I've attached an updated patch that should fix it for fill-region.

From 43ba5a78b560da6baef873597fff374ac163bedf Mon Sep 17 00:00:00 2001
From: Randy Taylor <[email-masked]>
Date: Sat, 5 Apr 2025 15:52:45 -0400
Subject: [PATCH] Fix yaml-ts-mode comment filling (Bug#77095)

* 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.
---
 lisp/textmodes/yaml-ts-mode.el | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/lisp/textmodes/yaml-ts-mode.el b/lisp/textmodes/yaml-ts-mode.el
index 7d11223aefa..06edfc62e31 100644
--- a/lisp/textmodes/yaml-ts-mode.el
+++ b/lisp/textmodes/yaml-ts-mode.el
@@ -129,18 +129,21 @@ yaml-ts-mode--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.
@@ -168,6 +171,7 @@ yaml-ts-mode
     ;; Comments.
     (setq-local comment-start "# ")
     (setq-local comment-end "")
+    (setq-local comment-start-skip "#+\\s-*")
 
     ;; Indentation.
     (setq-local indent-tabs-mode nil)
-- 
2.49.0