From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Damien Cassou Newsgroups: gmane.emacs.bugs Subject: bug#71760: [PATCH] js-ts-mode: Fix filling of jsdoc blocks Date: Mon, 29 Jul 2024 21:36:02 +0200 Message-ID: <875xsoousd.fsf@cassou.me> References: <871q4mxf85.fsf@cassou.me> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9539"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yuan Fu To: 71760@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jul 29 21:37:10 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sYWBA-0002Fj-L3 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 29 Jul 2024 21:37:08 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sYWAt-0000o1-J2; Mon, 29 Jul 2024 15:36:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sYWAr-0000nZ-D4 for bug-gnu-emacs@gnu.org; Mon, 29 Jul 2024 15:36:49 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sYWAr-0002yW-1I for bug-gnu-emacs@gnu.org; Mon, 29 Jul 2024 15:36:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:In-Reply-To:References:Subject; bh=WbqEcNvt1nzZ16pweOYdXOyPZT0f0XAykAJIylG3Y9c=; b=T/8vBmwSOwI5Upo+zHS/9yynoi880Wz9UijfRtiAjKyyA6ZcLHqp/sNFTZ6mkO+4aO5PBLy4RaCDj8sWWAroJURhkWmyvFurDY1oUrBfniTwyecCQmgoSTHaWGKVFOZbyPUmSmIitCRIucHKTsKv9zSoI8y8ob170rJEZOrAtkQgFkBfFWVbpQpzYlv3dvyxPqLFa9epc5GmLiZzf/2+l7ap0OPwrhw+Q+/pF9lPCaInio+DLQ5iKaSb6EL/rjcvLxQezXX1uPPpJ2u4yYD6Qmi9bV8UtxHl/1YA7GyvnQmDLnNLaFVeX+Zmu0xlbsr5JjKiFT4fJbK5bC154+A8KQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sYWB4-0004vp-0N for bug-gnu-emacs@gnu.org; Mon, 29 Jul 2024 15:37:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <871q4mxf85.fsf@cassou.me> Resent-From: Damien Cassou Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 29 Jul 2024 19:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71760 X-GNU-PR-Package: emacs Original-Received: via spool by 71760-submit@debbugs.gnu.org id=B71760.172228181418944 (code B ref 71760); Mon, 29 Jul 2024 19:37:01 +0000 Original-Received: (at 71760) by debbugs.gnu.org; 29 Jul 2024 19:36:54 +0000 Original-Received: from localhost ([127.0.0.1]:46389 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sYWAv-0004vU-Hd for submit@debbugs.gnu.org; Mon, 29 Jul 2024 15:36:53 -0400 Original-Received: from mail.reprendre.net ([193.23.30.35]:54302) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sYWAr-0004vJ-IX for 71760@debbugs.gnu.org; Mon, 29 Jul 2024 15:36:52 -0400 Original-Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id DACBF2C0AFD; Mon, 29 Jul 2024 21:36:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cassou.me; s=dkim; t=1722281764; h=from:subject:date:message-id:to:cc:mime-version:content-type; bh=WbqEcNvt1nzZ16pweOYdXOyPZT0f0XAykAJIylG3Y9c=; b=loj1qI0YDFgWFHpULyU4+RcLUE4ZWF6L8y3IhlMKYmqK1pzR/zx0WJdy/hN7KtjRAUgMgT /cTpNfvfeSSMmt7jFS5gs0xjB47q3n6ccgeDqePVugf6fNkCO/bD7U9giyHpn//HOauiwd A4IPNOzvLJuKB2bzuQO+Z8Yfy18Pj9MS+k8m1khdJ42ajbJCPYk+DezwOQvU9151yHnxYM 5SbD8I+2EyJaRKV74IhQC29i/4OY5X8TbOudhJy1fyoSAuzz71I9ITAm/PXzt/gCDHl8h2 UrZUs5hVbrMPhO0HdfdcQeVBlVM0GrehcO36X7zvgmY2oVLGWUqiWsH/D4ETiQ== X-Last-TLS-Session-Version: TLSv1.3 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:289534 Archived-At: --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-js-ts-mode-Make-jsdoc-s-description-block-a-comment.patch >From e444692026cae97dfaecebf5972507ae95f5e488 Mon Sep 17 00:00:00 2001 From: Damien Cassou 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-c-ts-common-Don-t-insert-wrong-characters-during-fil.patch >From cf14e3b25245dac98adcf90723e4a0c601f65528 Mon Sep 17 00:00:00 2001 From: Damien Cassou 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 --=-=-=--