GNU bug report logs - #78892
[PATCH] Fix yaml-ts-mode comment-start-skip to improve commenting/uncommenting

Previous Next

Package: emacs;

Reported by: James Cherti <contact <at> jamescherti.com>

Date: Tue, 24 Jun 2025 17:57:02 UTC

Severity: normal

Tags: patch

Fixed in version 31.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 78892 in the body.
You can then email your comments to 78892 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#78892; Package emacs. (Tue, 24 Jun 2025 17:57:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to James Cherti <contact <at> jamescherti.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 24 Jun 2025 17:57:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: James Cherti <contact <at> jamescherti.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Fix yaml-ts-mode comment-start-skip to improve
 commenting/uncommenting
Date: Tue, 24 Jun 2025 13:55:48 -0400
[Message part 1 (text/plain, inline)]
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/
[0001-Fix-yaml-ts-mode-comment-start-skip.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#78892; Package emacs. (Wed, 25 Jun 2025 17:18:02 GMT) Full text and rfc822 format available.

Message #8 received at 78892 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: James Cherti <contact <at> jamescherti.com>
Cc: 78892 <at> debbugs.gnu.org
Subject: Re: bug#78892: [PATCH] Fix yaml-ts-mode comment-start-skip to
 improve commenting/uncommenting
Date: Wed, 25 Jun 2025 20:13:13 +0300
> 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.

> -    (setq-local comment-start-skip "#+\\s-*")
> +    (setq-local comment-start-skip "#+ *")

Since yaml-mode uses "#+ *", yaml-ts-mode could use the same.
So this patch could be pushed for compatibility with yaml-mode.

But I really don't see a difference between "#+\\s-*" and "#+ *".
One matches any whitespace, and another just the space character.
I don't understand how this could affect block items starting with '-'.
While trying your test case, I can't reproduce the problem:
everything is uncommented correctly.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#78892; Package emacs. (Wed, 25 Jun 2025 18:20:03 GMT) Full text and rfc822 format available.

Message #11 received at 78892 <at> debbugs.gnu.org (full text, mbox):

From: James Cherti <contact <at> jamescherti.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 78892 <at> debbugs.gnu.org
Subject: Re: bug#78892: [PATCH] Fix yaml-ts-mode comment-start-skip to improve
 commenting/uncommenting
Date: Wed, 25 Jun 2025 14:19:10 -0400
Hello Juri,

For some reason, "#+\s-*" causes issues with commenting and
uncommenting, whereas "#+ *" does not.

The pattern "#+ *" is sufficient for YAML, as the YAML
specification disallows tabs and permits only spaces.

--
James Cherti
GitHub: https://github.com/jamescherti
Website: https://www.jamescherti.com/

On 2025-06-25 13:13, Juri Linkov wrote:
>> 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.
> 
>> -    (setq-local comment-start-skip "#+\\s-*")
>> +    (setq-local comment-start-skip "#+ *")
> 
> Since yaml-mode uses "#+ *", yaml-ts-mode could use the same.
> So this patch could be pushed for compatibility with yaml-mode.
> 
> But I really don't see a difference between "#+\\s-*" and "#+ *".
> One matches any whitespace, and another just the space character.
> I don't understand how this could affect block items starting with '-'.
> While trying your test case, I can't reproduce the problem:
> everything is uncommented correctly.
> 
> 
> 





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#78892; Package emacs. (Wed, 25 Jun 2025 18:53:03 GMT) Full text and rfc822 format available.

Message #14 received at 78892 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: James Cherti <contact <at> jamescherti.com>
Cc: 78892 <at> debbugs.gnu.org
Subject: Re: bug#78892: [PATCH] Fix yaml-ts-mode comment-start-skip to
 improve commenting/uncommenting
Date: Wed, 25 Jun 2025 21:50:38 +0300
close 78892 31.0.50
thanks

> For some reason, "#+\s-*" causes issues with commenting and
> uncommenting, whereas "#+ *" does not.
>
> The pattern "#+ *" is sufficient for YAML, as the YAML
> specification disallows tabs and permits only spaces.

Agreed.  So now pushed and closed as fixed.




bug marked as fixed in version 31.0.50, send any further explanations to 78892 <at> debbugs.gnu.org and James Cherti <contact <at> jamescherti.com> Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Wed, 25 Jun 2025 18:53:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 24 Jul 2025 11:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 22 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.