unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Damien Cassou <damien@cassou.me>
To: 71760@debbugs.gnu.org
Cc: Yuan Fu <casouri@gmail.com>
Subject: bug#71760: [PATCH] js-ts-mode: Fix filling of jsdoc blocks
Date: Wed, 31 Jul 2024 10:25:51 +0200	[thread overview]
Message-ID: <87sevqx90w.fsf@cassou.me> (raw)
In-Reply-To: <875xsoousd.fsf@cassou.me>

Hi,

after today's fix on c-ts-mode by Yuan Fu, the only patch still
necessary to apply for js-ts-mode to properly fill jsdoc descriptions
is 0001-js-ts-mode-Make-jsdoc-s-description-block-a-comment.patch.

Damien Cassou <damien@cassou.me> writes:

> Tags: patch
>
> Hi,
>
> the attached patches
>
> 1. add "description" (the kind of treesit node used for texts by the
> jsdoc parser) to `c-ts-common--comment-regexp' in js-ts-mode;
>
> 2. make `c-ts-common--fill-block-comment' only remove a mask if it has
> added it in the first place.
>
> Best
>
> -- 
> Damien Cassou
>
> "Success is the ability to go from one failure to another without
> losing enthusiasm." --Winston Churchill
> From e444692026cae97dfaecebf5972507ae95f5e488 Mon Sep 17 00:00:00 2001
> From: Damien Cassou <damien@cassou.me>
> Date: Sun, 21 Jul 2024 21:32:34 +0200
> Subject: [PATCH 1/2] js-ts-mode: Make jsdoc's "description" block a comment
>
> * lisp/progmodes/js.el (js-ts-mode): Add "description" to
> `c-ts-common--comment-regexp'.
> ---
>  lisp/progmodes/js.el | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
> index f8140c14a49..75c8111035c 100644
> --- a/lisp/progmodes/js.el
> +++ b/lisp/progmodes/js.el
> @@ -3946,7 +3946,9 @@ js-ts-mode
>                     :embed 'jsdoc
>                     :host 'javascript
>                     :local t
> -                   `(((comment) @capture (:match ,js--treesit-jsdoc-beginning-regexp @capture))))))
> +                   `(((comment) @capture (:match ,js--treesit-jsdoc-beginning-regexp @capture)))))
> +
> +      (setq c-ts-common--comment-regexp (rx (or "comment" "line_comment" "block_comment" "description"))))
>  
>      ;; Imenu
>      (setq-local treesit-simple-imenu-settings
> -- 
> 2.45.2
>
> From cf14e3b25245dac98adcf90723e4a0c601f65528 Mon Sep 17 00:00:00 2001
> From: Damien Cassou <damien@cassou.me>
> Date: Sun, 21 Jul 2024 21:33:59 +0200
> Subject: [PATCH 2/2] c-ts-common: Don't insert wrong characters during filling
>
> * lisp/progmodes/c-ts-common.el (c-ts-common--fill-block-comment): If
> masking hasn't been done, don't unmask.
> ---
>  lisp/progmodes/c-ts-common.el | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/lisp/progmodes/c-ts-common.el b/lisp/progmodes/c-ts-common.el
> index 3882a697c48..14dd29e07e2 100644
> --- a/lisp/progmodes/c-ts-common.el
> +++ b/lisp/progmodes/c-ts-common.el
> @@ -151,7 +151,9 @@ c-ts-common--fill-block-comment
>           (orig-point (point-marker))
>           (start-marker (point-marker))
>           (end-marker nil)
> -         (end-len 0))
> +         (end-len 0)
> +         (start-mask-done nil)
> +         (end-mask-done nil))
>      (move-marker start-marker start)
>      ;; We mask "/*" and the space before "*/" like
>      ;; `c-fill-paragraph' does.
> @@ -162,6 +164,7 @@ c-ts-common--fill-block-comment
>                              (group "/") "*"))
>          (goto-char (match-beginning 1))
>          (move-marker start-marker (point))
> +        (setq start-mask-done t)
>          (replace-match " " nil nil nil 1))
>  
>        ;; Include whitespaces before /*.
> @@ -179,6 +182,7 @@ c-ts-common--fill-block-comment
>          (goto-char (match-beginning 1))
>          (setq end-marker (point-marker))
>          (setq end-len (- (match-end 1) (match-beginning 1)))
> +        (setq end-mask-done t)
>          (replace-match (make-string end-len ?x)
>                         nil nil nil 1))
>  
> @@ -206,11 +210,11 @@ c-ts-common--fill-block-comment
>          (fill-region (max start-marker para-start) (min end para-end) arg))
>  
>        ;; Unmask.
> -      (when start-marker
> +      (when (and start-mask-done start-marker)
>          (goto-char start-marker)
>          (delete-char 1)
>          (insert "/"))
> -      (when end-marker
> +      (when (and end-mask-done start-marker)
>          (goto-char end-marker)
>          (delete-region (point) (+ end-len (point)))
>          (insert (make-string end-len ?\s)))
> -- 
> 2.45.2
>

-- 
Damien Cassou

"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill





  reply	other threads:[~2024-07-31  8:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-24 20:23 bug#71760: 31.0.50; Filling jsdoc text doesn't work in js-ts-mode Damien Cassou
2024-07-29 19:36 ` bug#71760: [PATCH] js-ts-mode: Fix filling of jsdoc blocks Damien Cassou
2024-07-31  8:25   ` Damien Cassou [this message]
2024-08-01  1:00     ` Dmitry Gutov
2024-08-01  1:07       ` Yuan Fu
2024-08-01  7:36         ` Yuan Fu
2024-08-01 10:26           ` Damien Cassou
2024-08-01 21:26           ` Dmitry Gutov
2024-08-03  7:34             ` Yuan Fu
2024-08-03 15:14               ` Dmitry Gutov
2024-08-04  3:05                 ` Yuan Fu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sevqx90w.fsf@cassou.me \
    --to=damien@cassou.me \
    --cc=71760@debbugs.gnu.org \
    --cc=casouri@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).