From cb243ddfff5dd1be1924fc4a3dee1b5b6b0f5b02 Mon Sep 17 00:00:00 2001 From: Randy Taylor Date: Sat, 5 Apr 2025 15:52:45 -0400 Subject: [PATCH] Fix 'yaml-ts-mode' filling of comments (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'. (cherry picked from commit 417ee3a7f7c66f6c23c9bab7228bfb64014573dd) --- 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 26b7655acba..3338044652b 100644 --- a/lisp/textmodes/yaml-ts-mode.el +++ b/lisp/textmodes/yaml-ts-mode.el @@ -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) -- 2.39.5