Subject: bug#78892: [PATCH] Fix yaml-ts-mode comment-start-skip to improve commenting/uncommenting

From: James Cherti <[email-masked]>
Date: Tue, 24 Jun 2025 13:55:48 -0400

This patch resolves an issue in yaml-ts-mode where the
comment-start-skip value caused some leading '-' characters
to remain uncommented when using the
comment-or-uncomment-region command on multiple indented
YAML blocks.

Reproduction steps:

1. Open a YAML file and switch the major mode to yaml-ts-mode.

2. Paste the following into that file:
     # - name: "Daily: script"
     #   cron:
     #     name: "script"
     #     job: "{{ system_home }}/scripts/script.sh >/dev/null"
     #     minute: "30"
     #     hour: "3"
     #
     # - name: "Ensure directories exist"
     #   file:
     #     state: directory
     #     path: "{{ item }}"
     #     mode: '0755'
     #   loop:
     #     - "{{ system_home }}/logs"
     #     - "{{ system_home }}/cache"
     #     - "{{ system_home }}/tmp"
     #
     # - name: "Deploy configuration files"
     #   ansible.builtin.template:
     #     dest: "{{ system_home }}/config/{{ item }}"
     #     src: "configs/{{ item }}"
     #     mode: '0644'
     #   loop: "{{ config_files }}"

3. Select the pasted text and invoke `M-x comment-or-uncomment-region`.

4. Issue observed after uncommenting:
     - name: "Daily: script"
       cron:
         name: "script"
         job: "{{ system_home }}/scripts/script.sh >/dev/null"
         minute: "30"
         hour: "3"

     # - name: "Ensure directories exist"
       file:
         state: directory
         path: "{{ item }}"
         mode: '0755'
       loop:
         - "{{ system_home }}/logs"
         - "{{ system_home }}/cache"
         - "{{ system_home }}/tmp"

     # - name: "Deploy configuration files"
       ansible.builtin.template:
         dest: "{{ system_home }}/config/{{ item }}"
         src: "configs/{{ item }}"
         mode: '0644'
       loop: "{{ config_files }}"

As demonstrated, some block items starting with '-' remain
commented, causing inconsistent comment handling in YAML
indented blocks.

This patch ensures the entire comment line, including
leading '-' characters, is properly toggled by modifying
the comment-start-skip regular expression.

--
James Cherti
GitHub: https://github.com/jamescherti
Website: https://www.jamescherti.com/
From 7153ed4db5085314b603b5ed78e1c0d038a9bc67 Mon Sep 17 00:00:00 2001
From: James Cherti <[email-masked]>
Date: Tue, 24 Jun 2025 13:25:40 -0400
Subject: [PATCH] Fix yaml-ts-mode comment-start-skip to improve
 commenting/uncommenting

    * lisp/textmodes/yaml-ts-mode.el: Fixed comment-start-skip value
      to resolve an issue when commenting/uncommenting using
      the comment-or-uncomment-region function.
      The previous comment-start-skip value left some "-" uncommented
      after commenting and uncommenting multiple YAML indented blocks.

Copyright-paperwork-exempt: yes
---
 lisp/textmodes/yaml-ts-mode.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/textmodes/yaml-ts-mode.el b/lisp/textmodes/yaml-ts-mode.el
index 58ed06de886..cadae19af1e 100644
--- a/lisp/textmodes/yaml-ts-mode.el
+++ b/lisp/textmodes/yaml-ts-mode.el
@@ -185,11 +185,11 @@ yaml-ts-mode
     (setq treesit-primary-parser (treesit-parser-create 'yaml))
 
     ;; Comments.
     (setq-local comment-start "# ")
     (setq-local comment-end "")
-    (setq-local comment-start-skip "#+\\s-*")
+    (setq-local comment-start-skip "#+ *")
 
     ;; Indentation.
     (setq-local indent-tabs-mode nil)
 
     ;; Font-lock.
-- 
2.50.0