GNU logs - #75609, boring messages


Message sent to casouri@HIDDEN, bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#75609: Hideshow support for treesitter
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: casouri@HIDDEN, bug-gnu-emacs@HIDDEN
Resent-Date: Thu, 16 Jan 2025 17:50:01 +0000
Resent-Message-ID: <handler.75609.B.17370497593874 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: report 75609
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: 75609 <at> debbugs.gnu.org
Cc: Yuan Fu <casouri@HIDDEN>
X-Debbugs-Original-To: bug-gnu-emacs@HIDDEN
X-Debbugs-Original-Xcc: Yuan Fu <casouri@HIDDEN>
Received: via spool by submit <at> debbugs.gnu.org id=B.17370497593874
          (code B ref -1); Thu, 16 Jan 2025 17:50:01 +0000
Received: (at submit) by debbugs.gnu.org; 16 Jan 2025 17:49:19 +0000
Received: from localhost ([127.0.0.1]:34556 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tYTza-00010O-LQ
	for submit <at> debbugs.gnu.org; Thu, 16 Jan 2025 12:49:19 -0500
Received: from lists.gnu.org ([2001:470:142::17]:50564)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1tYTzX-000105-TT
 for submit <at> debbugs.gnu.org; Thu, 16 Jan 2025 12:49:16 -0500
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 <juri@HIDDEN>) id 1tYTzP-0005Pc-ID
 for bug-gnu-emacs@HIDDEN; Thu, 16 Jan 2025 12:49:07 -0500
Received: from relay3-d.mail.gandi.net ([217.70.183.195])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <juri@HIDDEN>) id 1tYTzM-0004jL-1b
 for bug-gnu-emacs@HIDDEN; Thu, 16 Jan 2025 12:49:06 -0500
Received: by mail.gandi.net (Postfix) with ESMTPSA id 1A2A86000A
 for <bug-gnu-emacs@HIDDEN>; Thu, 16 Jan 2025 17:48:58 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
Organization: LINKOV.NET
Date: Thu, 16 Jan 2025 19:45:11 +0200
Message-ID: <87tt9yu00k.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-GND-Sasl: juri@HIDDEN
Received-SPF: pass client-ip=217.70.183.195; envelope-from=juri@HIDDEN;
 helo=relay3-d.mail.gandi.net
X-Spam_score_int: -25
X-Spam_score: -2.6
X-Spam_bar: --
X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7,
 RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001,
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001,
 SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.3 (/)

--=-=-=
Content-Type: text/plain

Tags: patch

Now that we have the new list thing in tree-sitter, it became possible
to implement the hideshow support to hide the list things, i.e.
exactly what hs-minor-mode did in non-ts modes:


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline; filename=treesit-hideshow.patch

diff --git a/lisp/treesit.el b/lisp/treesit.el
index ac34edaf84d..0e48fb91b44 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -3420,6 +3420,65 @@ treesit-outline-level
       (setq level (1+ level)))
     (if (zerop level) 1 level)))
 
+;;; Hideshow mode
+
+(defun treesit-hs-block-end ()
+  (let* ((pred 'list)
+         (thing (treesit-thing-at
+                 (if (bobp) (point) (1- (point))) pred))
+         (end (when thing (treesit-node-end thing)))
+         (last (when thing (treesit-node-child thing -1)))
+         (beg (if last (treesit-node-start last)
+                (if (bobp) (point) (1- (point))))))
+    (when (and thing (eq (point) end))
+      (set-match-data (list beg end))
+      t)))
+
+(defun treesit-hs-find-block-beginning ()
+  (let* ((pred 'list)
+         (thing (treesit-thing-at (point) pred))
+         (thing (or thing (treesit-parent-until (treesit-node-at (point)) pred)))
+         (beg (when thing (treesit-node-start thing)))
+         (end (when thing (treesit-node-end thing))))
+    (when thing
+      (goto-char beg)
+      (set-match-data (list beg end))
+      t)))
+
+(defun treesit-hs-find-next-block (_regexp _maxp comments)
+  (let* ((pred (if comments '(or list "comment") 'list))
+         ;; `treesit-navigate-thing' can't find a thing at bobp,
+         ;; so use `treesit-thing-at' to match at bobp.
+         (current (treesit-thing-at (point) pred))
+         (beg (or (and current (eq (point) (treesit-node-start current)) (point))
+                  (treesit-navigate-thing (point) 1 'beg pred)))
+         (thing (when beg (treesit-thing-at beg pred)))
+         (end (when thing (treesit-node-end thing))))
+    (when thing
+      (goto-char end)
+      (set-match-data
+       (if (and comments (equal (treesit-node-type thing) "comment"))
+           (list beg end nil nil beg end)
+         (list beg end beg end)))
+      t)))
+
+(defun treesit-hs-looking-at-block-start-p ()
+  (let* ((pred 'list)
+         (thing (treesit-thing-at (point) pred))
+         (beg (when thing (treesit-node-start thing)))
+         (first (when thing (treesit-node-child thing 0)))
+         (end (if first (treesit-node-end first) (1+ (point)))))
+    (when (and thing (eq (point) beg))
+      (set-match-data (list beg end))
+      t)))
+
+(defun treesit-hs-inside-comment-p ()
+  (let ((thing (or (treesit-thing-at (point) "comment")
+                   (unless (bobp)
+                     (treesit-thing-at (1- (point)) "comment")))))
+    (when thing
+      (list (treesit-node-start thing) (treesit-node-end thing)))))
+
 ;;; Show paren mode
 
 (defun treesit-show-paren-data--categorize (pos &optional end-p)
@@ -3603,7 +3662,17 @@ treesit-major-mode-setup
     (setq-local forward-list-function #'treesit-forward-list)
     (setq-local down-list-function #'treesit-down-list)
     (setq-local up-list-function #'treesit-up-list)
-    (setq-local show-paren-data-function 'treesit-show-paren-data))
+    (setq-local show-paren-data-function #'treesit-show-paren-data)
+    (setq hs-block-start-regexp nil
+          hs-block-start-mdata-select 0
+          hs-block-end-regexp #'treesit-hs-block-end
+          hs-c-start-regexp nil
+          hs-forward-sexp-func #'forward-list
+          hs-adjust-block-beginning nil
+          hs-find-block-beginning-func #'treesit-hs-find-block-beginning
+          hs-find-next-block-func #'treesit-hs-find-next-block
+          hs-looking-at-block-start-p-func #'treesit-hs-looking-at-block-start-p
+          hs-inside-comment-p-func #'treesit-hs-inside-comment-p))
 
   (when (treesit-thing-defined-p 'sentence nil)
     (setq-local forward-sentence-function #'treesit-forward-sentence))
diff --git a/lisp/progmodes/hideshow.el b/lisp/progmodes/hideshow.el
index 823eb0527c6..ea7bc738a4d 100644
--- a/lisp/progmodes/hideshow.el
+++ b/lisp/progmodes/hideshow.el
@@ -259,14 +259,11 @@ hs-special-modes-alist
   ;; to the mode hierarchy.
   (mapcar #'purecopy
   '((c-mode "{" "}" "/[*/]" nil nil)
-    (c-ts-mode "{" "}" "/[*/]" nil nil)
     (c++-mode "{" "}" "/[*/]" nil nil)
-    (c++-ts-mode "{" "}" "/[*/]" nil nil)
     (bibtex-mode ("@\\S(*\\(\\s(\\)" 1))
     (java-mode "{" "}" "/[*/]" nil nil)
     (java-ts-mode "{" "}" "/[*/]" nil nil)
     (js-mode "{" "}" "/[*/]" nil)
-    (js-ts-mode "{" "}" "/[*/]" nil)
     (lua-ts-mode "{\\|\\[\\[" "}\\|\\]\\]" "--" nil)
     (mhtml-mode "{\\|<[^/>]*?" "}\\|</[^/>]*[^/]>" "<!--" mhtml-forward nil)
     ;; Add more support here.
@@ -481,6 +478,9 @@ hs-looking-at-block-start-p-func
 Python, where `looking-at' and `syntax-ppss' check is not enough
 to check if the point is at the block start.")
 
+(defvar-local hs-inside-comment-p-func nil
+  "Function used to check if point is inside a comment.")
+
 (defvar hs-headline nil
   "Text of the line where a hidden block begins, set during isearch.
 You can display this in the mode line by adding the symbol `hs-headline'
@@ -625,9 +625,13 @@ hs-hide-block-at-point
 	  (setq p (line-end-position)))
 	;; `q' is the point at the end of the block
 	(hs-forward-sexp mdata 1)
-	(setq q (if (looking-back hs-block-end-regexp nil)
-		    (match-beginning 0)
-		  (point)))
+	(setq q (cond ((and (stringp hs-block-end-regexp)
+                            (looking-back hs-block-end-regexp nil))
+		       (match-beginning 0))
+                      ((functionp hs-block-end-regexp)
+                       (funcall hs-block-end-regexp)
+                       (match-beginning 0))
+		      (t (point))))
         (when (and (< p q) (> (count-lines p q) 1))
           (cond ((and hs-allow-nesting (setq ov (hs-overlay-at p)))
                  (delete-overlay ov))
@@ -644,6 +648,9 @@ hs-inside-comment-p
 beginning.  If we are inside of a comment but this condition is not met,
 we return a list having a nil as its car and the end of comment position
 as cdr."
+  (cond ((functionp hs-inside-comment-p-func)
+         (funcall hs-inside-comment-p-func))
+  (t
   (save-excursion
     ;; the idea is to look backwards for a comment start regexp, do a
     ;; forward comment, and see if we are inside, then extend
@@ -692,7 +699,7 @@ hs-inside-comment-p
           (skip-chars-backward " \t\n\f")
           (end-of-line)
           (when (>= (point) q)
-            (list (and hideable p) (point))))))))
+            (list (and hideable p) (point))))))))))
 
 (defun hs-grok-mode-type ()
   "Set up hideshow variables for new buffers.
@@ -704,7 +711,7 @@ hs-grok-mode-type
            (bound-and-true-p comment-end))
       (let* ((lookup (assoc major-mode hs-special-modes-alist))
              (start-elem (or (nth 1 lookup) "\\s(")))
-        (if (listp start-elem)
+        (if (consp start-elem)
             ;; handle (START-REGEXP MDATA-SELECT)
             (setq hs-block-start-regexp (car start-elem)
                   hs-block-start-mdata-select (cadr start-elem))
@@ -850,14 +857,16 @@ hs-hide-all
      (syntax-propertize (point-max))
      (let ((spew (make-progress-reporter "Hiding all blocks..."
                                          (point-min) (point-max)))
-           (re (concat "\\("
-                       hs-block-start-regexp
-                       "\\)"
-                       (if hs-hide-comments-when-hiding-all
-                           (concat "\\|\\("
-                                   hs-c-start-regexp
-                                   "\\)")
-                         ""))))
+           (re (when (stringp hs-block-start-regexp)
+                 (concat "\\("
+                         hs-block-start-regexp
+                         "\\)"
+                         (if (and hs-hide-comments-when-hiding-all
+                                  (stringp hs-c-start-regexp))
+                             (concat "\\|\\("
+                                     hs-c-start-regexp
+                                     "\\)")
+                           "")))))
        (while (funcall hs-find-next-block-func re (point-max)
                        hs-hide-comments-when-hiding-all)
          (if (match-beginning 1)
@@ -869,7 +878,9 @@ hs-hide-all
 			 (hs-hide-block-at-point t))
 		 ;; Go to end of matched data to prevent from getting stuck
 		 ;; with an endless loop.
-                 (when (looking-at hs-block-start-regexp)
+                 (when (if (stringp hs-block-start-regexp)
+                           (looking-at hs-block-start-regexp)
+                         (eq (point) (match-beginning 0)))
 		   (goto-char (match-end 0)))))
            ;; found a comment, probably
            (let ((c-reg (hs-inside-comment-p)))
@@ -1008,7 +1019,8 @@ hs-minor-mode
   (setq hs-headline nil)
   (if hs-minor-mode
       (progn
-        (hs-grok-mode-type)
+        (unless (buffer-local-value 'hs-inside-comment-p-func (current-buffer))
+          (hs-grok-mode-type))
         ;; Turn off this mode if we change major modes.
         (add-hook 'change-major-mode-hook
                   #'turn-off-hideshow

--=-=-=--




Message sent:


Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-Mailer: MIME-tools 5.505 (Entity 5.505)
Content-Type: text/plain; charset=utf-8
X-Loop: help-debbugs@HIDDEN
From: help-debbugs@HIDDEN (GNU bug Tracking System)
To: Juri Linkov <juri@HIDDEN>
Subject: bug#75609: Acknowledgement (Hideshow support for treesitter)
Message-ID: <handler.75609.B.17370497593874.ack <at> debbugs.gnu.org>
References: <87tt9yu00k.fsf@HIDDEN>
X-Gnu-PR-Message: ack 75609
X-Gnu-PR-Package: emacs
X-Gnu-PR-Keywords: patch
Reply-To: 75609 <at> debbugs.gnu.org
Date: Thu, 16 Jan 2025 17:50:01 +0000

Thank you for filing a new bug report with debbugs.gnu.org.

This is an automatically generated reply to let you know your message
has been received.

Your message is being forwarded to the package maintainers and other
interested parties for their attention; they will reply in due course.

As you requested using X-Debbugs-CC, your message was also forwarded to
  Yuan Fu <casouri@HIDDEN>
(after having been given a bug report number, if it did not have one).

Your message has been sent to the package maintainer(s):
 bug-gnu-emacs@HIDDEN

If you wish to submit further information on this problem, please
send it to 75609 <at> debbugs.gnu.org.

Please do not send mail to help-debbugs@HIDDEN unless you wish
to report a problem with the Bug-tracking system.

--=20
75609: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D75609
GNU Bug Tracking System
Contact help-debbugs@HIDDEN with problems


Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#75609: Hideshow support for treesitter
Resent-From: Yuan Fu <casouri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sat, 18 Jan 2025 07:41:02 +0000
Resent-Message-ID: <handler.75609.B75609.173718604118163 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 75609
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 75609 <at> debbugs.gnu.org
Received: via spool by 75609-submit <at> debbugs.gnu.org id=B75609.173718604118163
          (code B ref 75609); Sat, 18 Jan 2025 07:41:02 +0000
Received: (at 75609) by debbugs.gnu.org; 18 Jan 2025 07:40:41 +0000
Received: from localhost ([127.0.0.1]:39794 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tZ3Rh-0004is-4r
	for submit <at> debbugs.gnu.org; Sat, 18 Jan 2025 02:40:41 -0500
Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:50683)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <casouri@HIDDEN>) id 1tZ3Rd-0004iY-PU
 for 75609 <at> debbugs.gnu.org; Sat, 18 Jan 2025 02:40:38 -0500
Received: by mail-pl1-x62c.google.com with SMTP id
 d9443c01a7336-2161eb95317so55568085ad.1
 for <75609 <at> debbugs.gnu.org>; Fri, 17 Jan 2025 23:40:37 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1737186031; x=1737790831; darn=debbugs.gnu.org;
 h=to:references:message-id:content-transfer-encoding:cc:date
 :in-reply-to:from:subject:mime-version:from:to:cc:subject:date
 :message-id:reply-to;
 bh=f/KkueBlApzwAeL4WC0oBoGL7jUU4EI5OyA6BZnAlCo=;
 b=VhJtjrb0Mgj2EdGwKtLW4a2fOAo9aFqMO/CoSQakYMa7tqfAohZE0L6vpLaC4fqZyR
 dR9j3dTLABmbQLid/kXtm1ztb5KKjNwPjNDUbBvJ7X/wvfoxrrm55+oAfDUYzb+sarHB
 5vnK6WBFxDrx0CZT+Q8U5XTsQQ/WvblfpO/rHCf5VwfwvbZkbm2dpBGv+xbcFnHc4bak
 Qo3V5e9esj5KIfEY/IGjlJ7clkZkVPBQwsWYjVv+bcfgOux/VUjE0+AWVosMvHci52J2
 Vnc1o/Kbs773qub9jhzacUchTidzW0dqK+D9vQMKSf5oluL1uLHPl7iVKXrzEqFAMmOi
 UhVQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1737186031; x=1737790831;
 h=to:references:message-id:content-transfer-encoding:cc:date
 :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=f/KkueBlApzwAeL4WC0oBoGL7jUU4EI5OyA6BZnAlCo=;
 b=wHPzsK8wOZsjKfwIPtM08tEEWMoifSLKATO7wk1keBLSZ8IoY8VsClPLZI6Y7WORGS
 VeHS750rlNU9DxIO/islTvhs5sXncvdGcHdTpNm7I2SeSRsPNv4x9ZSoxogmq930MTau
 qna9RqitlWaQch04hQNQZFk3FT2/mkY5/QpHDp4LCZ72E75oAFsKsPOGGMdQnAJK43DF
 y9nrlcGESzGoEgVXt3C5qLqZeiTyckTkPmIh/NFqbPfBolwZvAdOPcg/RA7EfvVaHDsQ
 PiOy64C3kbJGGK1WPUjib7mF/Y9I8zt5WERAUXLQl51TifkdK/0AdzGSXLRZ9mE0cQ1P
 MAcw==
X-Gm-Message-State: AOJu0YzLvZFM6eH4apV804UDk/nYi4u6cYLjiJmsCB6/ePvXdOOAwOfH
 wh5AsyU+PiSNPvvhH0ZQ6utdfWOcoJLXhoUJifNw5pYH376rgOgk
X-Gm-Gg: ASbGncvMT26nrMJO8rIYh361oJmTc7sLmoP7oYimk510Qsn4V3w+ZaFqtaBmfXh3fka
 kLDtzN+5ieYhLPrM3cHgT0F65yZ7KCZZXy4TBOop+QOqC4qHt/Oy71cvRYZVt4qsbWLj4YDARbY
 wWLdwJhfsM3+prxbm9mIANi/rQuhF60/A07flUE2ubKtbfyYiF8zwdd3H+Ew+Fzulir66UIZEPQ
 XYgRWqKOvFBHrnCi6VGhcGeYx8qOvcaMaNmWCVuPNEfe8JfTilykFL5C3R/YNE6dQxy6zbrwRc=
X-Google-Smtp-Source: AGHT+IEUbmVaXBNhzCR2RwOZMejOnUTSkIPodrD4kLnSi0O/zMlEk2KeHGxQC2vxuok6tMTintMiCQ==
X-Received: by 2002:a17:902:f60f:b0:215:8270:77e2 with SMTP id
 d9443c01a7336-21c34cb5bf8mr98269265ad.0.1737186031193; 
 Fri, 17 Jan 2025 23:40:31 -0800 (PST)
Received: from smtpclient.apple ([2406:da14:40a:c900:b51c:c5cf:684f:70e8])
 by smtp.gmail.com with ESMTPSA id
 d9443c01a7336-21c2ce9ff84sm26869015ad.29.2025.01.17.23.40.29
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Fri, 17 Jan 2025 23:40:30 -0800 (PST)
Content-Type: text/plain;
	charset=utf-8
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\))
From: Yuan Fu <casouri@HIDDEN>
In-Reply-To: <87tt9yu00k.fsf@HIDDEN>
Date: Fri, 17 Jan 2025 23:40:16 -0800
Content-Transfer-Encoding: quoted-printable
Message-Id: <2999991B-3A95-4CC7-92BE-9A6B8F18BADE@HIDDEN>
References: <87tt9yu00k.fsf@HIDDEN>
X-Mailer: Apple Mail (2.3776.700.51)
X-Spam-Score: 0.0 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)



> On Jan 16, 2025, at 9:45=E2=80=AFAM, Juri Linkov <juri@HIDDEN> =
wrote:
>=20
> Tags: patch
>=20
> Now that we have the new list thing in tree-sitter, it became possible
> to implement the hideshow support to hide the list things, i.e.
> exactly what hs-minor-mode did in non-ts modes:

Awesome! Thanks :-) Some comments below:

>=20
> diff --git a/lisp/treesit.el b/lisp/treesit.el
> index ac34edaf84d..0e48fb91b44 100644
> --- a/lisp/treesit.el
> +++ b/lisp/treesit.el
> @@ -3420,6 +3420,65 @@ treesit-outline-level
>       (setq level (1+ level)))
>     (if (zerop level) 1 level)))
>=20
> +;;; Hideshow mode
> +
> +(defun treesit-hs-block-end ()
> +  (let* ((pred 'list)
> +         (thing (treesit-thing-at
> +                 (if (bobp) (point) (1- (point))) pred))
> +         (end (when thing (treesit-node-end thing)))
> +         (last (when thing (treesit-node-child thing -1)))
> +         (beg (if last (treesit-node-start last)
> +                (if (bobp) (point) (1- (point))))))
> +    (when (and thing (eq (point) end))
> +      (set-match-data (list beg end))
> +      t)))
> +
> +(defun treesit-hs-find-block-beginning ()
> +  (let* ((pred 'list)
> +         (thing (treesit-thing-at (point) pred))
> +         (thing (or thing (treesit-parent-until (treesit-node-at =
(point)) pred)))
> +         (beg (when thing (treesit-node-start thing)))
> +         (end (when thing (treesit-node-end thing))))
> +    (when thing
> +      (goto-char beg)
> +      (set-match-data (list beg end))
> +      t)))
> +
> +(defun treesit-hs-find-next-block (_regexp _maxp comments)
> +  (let* ((pred (if comments '(or list "comment") 'list))
> +         ;; `treesit-navigate-thing' can't find a thing at bobp,
> +         ;; so use `treesit-thing-at' to match at bobp.
> +         (current (treesit-thing-at (point) pred))
> +         (beg (or (and current (eq (point) (treesit-node-start =
current)) (point))
> +                  (treesit-navigate-thing (point) 1 'beg pred)))
> +         (thing (when beg (treesit-thing-at beg pred)))
> +         (end (when thing (treesit-node-end thing))))
> +    (when thing
> +      (goto-char end)
> +      (set-match-data
> +       (if (and comments (equal (treesit-node-type thing) "comment"))
> +           (list beg end nil nil beg end)
> +         (list beg end beg end)))
> +      t)))
> +
> +(defun treesit-hs-looking-at-block-start-p ()
> +  (let* ((pred 'list)
> +         (thing (treesit-thing-at (point) pred))
> +         (beg (when thing (treesit-node-start thing)))
> +         (first (when thing (treesit-node-child thing 0)))
> +         (end (if first (treesit-node-end first) (1+ (point)))))
> +    (when (and thing (eq (point) beg))
> +      (set-match-data (list beg end))
> +      t)))
> +
> +(defun treesit-hs-inside-comment-p ()
> +  (let ((thing (or (treesit-thing-at (point) "comment")
> +                   (unless (bobp)
> +                     (treesit-thing-at (1- (point)) "comment")))))
> +    (when thing
> +      (list (treesit-node-start thing) (treesit-node-end thing)))))
> +

FYI some grammar calls comments line_comment and block_comment. Maybe =
use the comment thing first, and then match =E2=80=9Ccomment=E2=80=9D =
with the node type?

> ;;; Show paren mode
>=20
> (defun treesit-show-paren-data--categorize (pos &optional end-p)
> @@ -3603,7 +3662,17 @@ treesit-major-mode-setup
>     (setq-local forward-list-function #'treesit-forward-list)
>     (setq-local down-list-function #'treesit-down-list)
>     (setq-local up-list-function #'treesit-up-list)
> -    (setq-local show-paren-data-function 'treesit-show-paren-data))
> +    (setq-local show-paren-data-function #'treesit-show-paren-data)
> +    (setq hs-block-start-regexp nil
> +          hs-block-start-mdata-select 0
> +          hs-block-end-regexp #'treesit-hs-block-end
> +          hs-c-start-regexp nil
> +          hs-forward-sexp-func #'forward-list
> +          hs-adjust-block-beginning nil
> +          hs-find-block-beginning-func =
#'treesit-hs-find-block-beginning
> +          hs-find-next-block-func #'treesit-hs-find-next-block
> +          hs-looking-at-block-start-p-func =
#'treesit-hs-looking-at-block-start-p
> +          hs-inside-comment-p-func #'treesit-hs-inside-comment-p))
>=20
>   (when (treesit-thing-defined-p 'sentence nil)
>     (setq-local forward-sentence-function #'treesit-forward-sentence))
> diff --git a/lisp/progmodes/hideshow.el b/lisp/progmodes/hideshow.el
> index 823eb0527c6..ea7bc738a4d 100644
> --- a/lisp/progmodes/hideshow.el
> +++ b/lisp/progmodes/hideshow.el
> @@ -259,14 +259,11 @@ hs-special-modes-alist
>   ;; to the mode hierarchy.
>   (mapcar #'purecopy
>   '((c-mode "{" "}" "/[*/]" nil nil)
> -    (c-ts-mode "{" "}" "/[*/]" nil nil)
>     (c++-mode "{" "}" "/[*/]" nil nil)
> -    (c++-ts-mode "{" "}" "/[*/]" nil nil)
>     (bibtex-mode ("@\\S(*\\(\\s(\\)" 1))
>     (java-mode "{" "}" "/[*/]" nil nil)
>     (java-ts-mode "{" "}" "/[*/]" nil nil)
>     (js-mode "{" "}" "/[*/]" nil)
> -    (js-ts-mode "{" "}" "/[*/]" nil)
>     (lua-ts-mode "{\\|\\[\\[" "}\\|\\]\\]" "--" nil)
>     (mhtml-mode "{\\|<[^/>]*?" "}\\|</[^/>]*[^/]>" "<!--" =
mhtml-forward nil)
>     ;; Add more support here.
> @@ -481,6 +478,9 @@ hs-looking-at-block-start-p-func
> Python, where `looking-at' and `syntax-ppss' check is not enough
> to check if the point is at the block start.")
>=20
> +(defvar-local hs-inside-comment-p-func nil
> +  "Function used to check if point is inside a comment.")
> +
> (defvar hs-headline nil
>   "Text of the line where a hidden block begins, set during isearch.
> You can display this in the mode line by adding the symbol =
`hs-headline'
> @@ -625,9 +625,13 @@ hs-hide-block-at-point
>  (setq p (line-end-position)))
> ;; `q' is the point at the end of the block
> (hs-forward-sexp mdata 1)
> - (setq q (if (looking-back hs-block-end-regexp nil)
> -    (match-beginning 0)
> -  (point)))
> + (setq q (cond ((and (stringp hs-block-end-regexp)
> +                            (looking-back hs-block-end-regexp nil))
> +       (match-beginning 0))
> +                      ((functionp hs-block-end-regexp)
> +                       (funcall hs-block-end-regexp)
> +                       (match-beginning 0))
> +      (t (point))))
>         (when (and (< p q) (> (count-lines p q) 1))
>           (cond ((and hs-allow-nesting (setq ov (hs-overlay-at p)))
>                  (delete-overlay ov))
> @@ -644,6 +648,9 @@ hs-inside-comment-p
> beginning.  If we are inside of a comment but this condition is not =
met,
> we return a list having a nil as its car and the end of comment =
position
> as cdr."
> +  (cond ((functionp hs-inside-comment-p-func)
> +         (funcall hs-inside-comment-p-func))
> +  (t

Did you do this indentation on purpose to make a easier-to-read diff?

>   (save-excursion
>     ;; the idea is to look backwards for a comment start regexp, do a
>     ;; forward comment, and see if we are inside, then extend
> @@ -692,7 +699,7 @@ hs-inside-comment-p
>           (skip-chars-backward " \t\n\f")
>           (end-of-line)
>           (when (>=3D (point) q)
> -            (list (and hideable p) (point))))))))
> +            (list (and hideable p) (point))))))))))
>=20
> (defun hs-grok-mode-type ()
>   "Set up hideshow variables for new buffers.
> @@ -704,7 +711,7 @@ hs-grok-mode-type
>            (bound-and-true-p comment-end))
>       (let* ((lookup (assoc major-mode hs-special-modes-alist))
>              (start-elem (or (nth 1 lookup) "\\s(")))
> -        (if (listp start-elem)
> +        (if (consp start-elem)
>             ;; handle (START-REGEXP MDATA-SELECT)
>             (setq hs-block-start-regexp (car start-elem)
>                   hs-block-start-mdata-select (cadr start-elem))
> @@ -850,14 +857,16 @@ hs-hide-all
>      (syntax-propertize (point-max))
>      (let ((spew (make-progress-reporter "Hiding all blocks..."
>                                          (point-min) (point-max)))
> -           (re (concat "\\("
> -                       hs-block-start-regexp
> -                       "\\)"
> -                       (if hs-hide-comments-when-hiding-all
> -                           (concat "\\|\\("
> -                                   hs-c-start-regexp
> -                                   "\\)")
> -                         ""))))
> +           (re (when (stringp hs-block-start-regexp)
> +                 (concat "\\("
> +                         hs-block-start-regexp
> +                         "\\)"
> +                         (if (and hs-hide-comments-when-hiding-all
> +                                  (stringp hs-c-start-regexp))
> +                             (concat "\\|\\("
> +                                     hs-c-start-regexp
> +                                     "\\)")
> +                           "")))))
>        (while (funcall hs-find-next-block-func re (point-max)
>                        hs-hide-comments-when-hiding-all)
>          (if (match-beginning 1)
> @@ -869,7 +878,9 @@ hs-hide-all
> (hs-hide-block-at-point t))
> ;; Go to end of matched data to prevent from getting stuck
> ;; with an endless loop.
> -                 (when (looking-at hs-block-start-regexp)
> +                 (when (if (stringp hs-block-start-regexp)
> +                           (looking-at hs-block-start-regexp)
> +                         (eq (point) (match-beginning 0)))
>   (goto-char (match-end 0)))))
>            ;; found a comment, probably
>            (let ((c-reg (hs-inside-comment-p)))
> @@ -1008,7 +1019,8 @@ hs-minor-mode
>   (setq hs-headline nil)
>   (if hs-minor-mode
>       (progn
> -        (hs-grok-mode-type)
> +        (unless (buffer-local-value 'hs-inside-comment-p-func =
(current-buffer))
> +          (hs-grok-mode-type))
>         ;; Turn off this mode if we change major modes.
>         (add-hook 'change-major-mode-hook
>                   #'turn-off-hideshow





Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#75609: Hideshow support for treesitter
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sat, 18 Jan 2025 17:45:02 +0000
Resent-Message-ID: <handler.75609.B75609.173722226814275 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 75609
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Yuan Fu <casouri@HIDDEN>
Cc: 75609 <at> debbugs.gnu.org
Received: via spool by 75609-submit <at> debbugs.gnu.org id=B75609.173722226814275
          (code B ref 75609); Sat, 18 Jan 2025 17:45:02 +0000
Received: (at 75609) by debbugs.gnu.org; 18 Jan 2025 17:44:28 +0000
Received: from localhost ([127.0.0.1]:43638 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tZCs0-0003iA-Cp
	for submit <at> debbugs.gnu.org; Sat, 18 Jan 2025 12:44:28 -0500
Received: from relay9-d.mail.gandi.net ([2001:4b98:dc4:8::229]:55777)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1tZCrw-0003hs-4h
 for 75609 <at> debbugs.gnu.org; Sat, 18 Jan 2025 12:44:25 -0500
Received: by mail.gandi.net (Postfix) with ESMTPSA id 09ECDFF803;
 Sat, 18 Jan 2025 17:44:15 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
In-Reply-To: <2999991B-3A95-4CC7-92BE-9A6B8F18BADE@HIDDEN> (Yuan Fu's
 message of "Fri, 17 Jan 2025 23:40:16 -0800")
Organization: LINKOV.NET
References: <87tt9yu00k.fsf@HIDDEN>
 <2999991B-3A95-4CC7-92BE-9A6B8F18BADE@HIDDEN>
Date: Sat, 18 Jan 2025 19:43:19 +0200
Message-ID: <87ikqc3tmw.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

>> +(defun treesit-hs-inside-comment-p ()
>> +  (let ((thing (or (treesit-thing-at (point) "comment")
>> +                   (unless (bobp)
>> +                     (treesit-thing-at (1- (point)) "comment")))))
>> +    (when thing
>> +      (list (treesit-node-start thing) (treesit-node-end thing)))))
>> +
>
> FYI some grammar calls comments line_comment and block_comment.
> Maybe use the comment thing first, and then match “comment” with the node type?

We need to introduce the new thing named "comment".
It's necessary to add treesit support for 'forward-comment'
that is used in many packages including 'hideshow'.

This means adding the variable 'forward-comment-function'
with the default value 'forward-comment-default-function'.
Then will override it with 'treesit-forward-comment' that
uses the comment thing.

>> @@ -644,6 +648,9 @@ hs-inside-comment-p
>> beginning.  If we are inside of a comment but this condition is not met,
>> we return a list having a nil as its car and the end of comment position
>> as cdr."
>> +  (cond ((functionp hs-inside-comment-p-func)
>> +         (funcall hs-inside-comment-p-func))
>> +  (t
>
> Did you do this indentation on purpose to make a easier-to-read diff?

Indeed, this was to make it easier-to-read.  And in the next patch
I will just rename the default function to 'hs-inside-comment-p--default'.




Message received at control <at> debbugs.gnu.org:


Received: (at control) by debbugs.gnu.org; 21 Jan 2025 02:26:39 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Jan 20 21:26:39 2025
Received: from localhost ([127.0.0.1]:52622 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ta3yQ-0004RG-Ow
	for submit <at> debbugs.gnu.org; Mon, 20 Jan 2025 21:26:38 -0500
Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]:58459)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <stefankangas@HIDDEN>)
 id 1ta3yO-0004Qs-Fv
 for control <at> debbugs.gnu.org; Mon, 20 Jan 2025 21:26:37 -0500
Received: by mail-ed1-x52a.google.com with SMTP id
 4fb4d7f45d1cf-5d414b8af7bso10612031a12.0
 for <control <at> debbugs.gnu.org>; Mon, 20 Jan 2025 18:26:36 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1737426390; x=1738031190; darn=debbugs.gnu.org;
 h=to:subject:message-id:date:mime-version:from:from:to:cc:subject
 :date:message-id:reply-to;
 bh=opMHct7xgf+y8ykcUD0JHkMgES7WHB8/9gxrTpeGCjc=;
 b=GTORlAIyCdq5Gcw6sogsBkXP2V+MsCnC9lGtHpyEtUvoWP7HWLHBNRzMXUOceB24TY
 XHUA2+L6NWlcUB4N2+GS5Ttyw4nmKDrGAxWnrl9lR7X1hJB+UwgTQbY+kUCsVDFPbPRG
 uWd5y4xoMgDSpKA6otsy83j9zZ1o73/c9fmNeQF7Ski/9AXJlAE93uHbjzVS1h+bR0fT
 95nayAsaygxSt0eNjb72+PsF7UXxRtptUF3zth0RY2KVfFvar6pHU5yonAr0d02DBbpc
 29Fj8fh/vBmh7MJ6v+z2zoGoGzCWMud4gj8bsHVN6elYr6Zpx63aVIRhYOP4U7RpVJy8
 czGA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1737426390; x=1738031190;
 h=to:subject:message-id:date:mime-version:from:x-gm-message-state
 :from:to:cc:subject:date:message-id:reply-to;
 bh=opMHct7xgf+y8ykcUD0JHkMgES7WHB8/9gxrTpeGCjc=;
 b=cT91MoIGOS682AiUi8vw9um0ADKHDfYj0RYCyZRBFs6Fi3aIol93tO1xReN1iXVUN8
 H9sdCD995yhh2khRdiaCWnuf1ljjVgaehSfTdB27E+V2lgfArakbqeYbuoJXLhctke8l
 EDHHxaKWMPPbk5La447sHUalXZzlegt22hKh7XC9frHxCnKxUW/XtrJVtEM77JPQbJFL
 ahQ+rFZU1tbv3vVugqT5Nv2WiwQlo/EtEWA5218GOequ8x3nnNO3y+zrpIwZm9aRC6kz
 izFHPIn9v52Dcz/fGMLGqVUo2yNM0om2JodTXRsppK6eBI7e6Zr+NRrR2O+cADfzBkHE
 hbcA==
X-Gm-Message-State: AOJu0YzD0j70zHEA2C1OQoDZjK8zrktVko44Og19YyVp7xaPF2Q4iXX9
 3gSvbuguxpe3eqVSdbjdzrw03bI9DU8X/WUyQwYRnwOquSnudn3JY3pKdzYihj1KFW7svQBCKQR
 Lndw4FZ69Z/1L9TxlLA+xWIV2Uk5FEX1C
X-Gm-Gg: ASbGncvMYlFOPMetjqMdK+YAbeQaZ4iamy4VJJUHZh4wa3BUAJ8pYnTKEk3inG8JQ8Z
 20c4Pbpo33d0EopP/v7PIPPdNtIcEKCfBmQZixhgSnZw8hEMxjDOI8A==
X-Google-Smtp-Source: AGHT+IHeKTMv50lIIKpXzh5uhWHli/wfj+sSntxDtxk5ZW6unWWjmhlHlx8KG/ziJ2VREkl7CxsA7HiMi60Hm8q43Nw=
X-Received: by 2002:a05:6402:35c2:b0:5cf:3dc3:7a3f with SMTP id
 4fb4d7f45d1cf-5db7d2d9803mr14784847a12.5.1737426390303; Mon, 20 Jan 2025
 18:26:30 -0800 (PST)
Received: from 753933720722 named unknown by gmailapi.google.com with
 HTTPREST; Mon, 20 Jan 2025 20:26:30 -0600
From: Stefan Kangas <stefankangas@HIDDEN>
MIME-Version: 1.0
Date: Mon, 20 Jan 2025 20:26:30 -0600
X-Gm-Features: AbW1kvYIDTzmPS4l0kZpOhlyo0u4H3Rp3IWZPY9LL2JWWw_8xzHBsu89HzOtNJs
Message-ID: <CADwFkmmkGk5KVm6cYnWtSqTs0nGTNbcJFuFRsU_DTZTBB=0vPw@HIDDEN>
Subject: control message for bug #75609
To: control <at> debbugs.gnu.org
Content-Type: text/plain; charset="UTF-8"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: control
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

severity 75609 wishlist
quit




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#75609: Hideshow support for treesitter
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Thu, 23 Jan 2025 07:37:01 +0000
Resent-Message-ID: <handler.75609.B75609.173761778610291 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 75609
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Yuan Fu <casouri@HIDDEN>
Cc: 75609 <at> debbugs.gnu.org
Received: via spool by 75609-submit <at> debbugs.gnu.org id=B75609.173761778610291
          (code B ref 75609); Thu, 23 Jan 2025 07:37:01 +0000
Received: (at 75609) by debbugs.gnu.org; 23 Jan 2025 07:36:26 +0000
Received: from localhost ([127.0.0.1]:38926 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tarlJ-0002fu-QQ
	for submit <at> debbugs.gnu.org; Thu, 23 Jan 2025 02:36:26 -0500
Received: from relay3-d.mail.gandi.net ([217.70.183.195]:34661)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1tarlH-0002fV-42
 for 75609 <at> debbugs.gnu.org; Thu, 23 Jan 2025 02:36:23 -0500
Received: by mail.gandi.net (Postfix) with ESMTPSA id 2131F60008;
 Thu, 23 Jan 2025 07:36:13 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
In-Reply-To: <87ikqc3tmw.fsf@HIDDEN> (Juri Linkov's message of "Sat, 
 18 Jan 2025 19:43:19 +0200")
Organization: LINKOV.NET
References: <87tt9yu00k.fsf@HIDDEN>
 <2999991B-3A95-4CC7-92BE-9A6B8F18BADE@HIDDEN>
 <87ikqc3tmw.fsf@HIDDEN>
Date: Thu, 23 Jan 2025 09:34:34 +0200
Message-ID: <877c6masqd.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

>> Maybe use the comment thing first, and then match “comment” with the node type?
>
> We need to introduce the new thing named "comment".
> It's necessary to add treesit support for 'forward-comment'
> that is used in many packages including 'hideshow'.
>
> This means adding the variable 'forward-comment-function'
> with the default value 'forward-comment-default-function'.
> Then will override it with 'treesit-forward-comment' that
> uses the comment thing.

So here is the treesit implementation for the new
variable forward-comment-function:


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline; filename=treesit-forward-comment.patch

diff --git a/lisp/treesit.el b/lisp/treesit.el
index 8d86d142e3f..894608bde81 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -2945,6 +2945,29 @@ treesit-forward-sentence
      (if (> arg 0) #'treesit-end-of-thing #'treesit-beginning-of-thing)
      'sentence (abs arg))))
 
+(defun treesit-forward-comment (&optional count)
+  "Tree-sitter `forward-comment-function' implementation.
+
+COUNT is the same as in `forward-comment'."
+  (let ((res t) thing)
+    (while (> count 0)
+      (skip-syntax-forward " >")
+      (setq thing (treesit-thing-at (point) 'comment))
+      (if (and thing (eq (point) (treesit-node-start thing)))
+          (progn
+            (goto-char (min (1+ (treesit-node-end thing)) (point-max)))
+            (setq count (1- count)))
+        (setq count 0 res nil)))
+    (while (< count 0)
+      (skip-syntax-backward " >")
+      (setq thing (treesit-thing-at (max (1- (point)) (point-min)) 'comment))
+      (if (and thing (eq (point) (treesit-node-end thing)))
+          (progn
+            (goto-char (treesit-node-start thing))
+            (setq count (1+ count)))
+        (setq count 0 res nil)))
+    res))
+
 (defun treesit-default-defun-skipper ()
   "Skips spaces after navigating a defun.
 This function tries to move to the beginning of a line, either by
@@ -3654,6 +3736,9 @@ treesit-major-mode-setup
   (when (treesit-thing-defined-p 'sentence nil)
     (setq-local forward-sentence-function #'treesit-forward-sentence))
 
+  (when (treesit-thing-defined-p 'comment nil)
+    (setq-local forward-comment-function #'treesit-forward-comment))
+
   ;; Imenu.
   (when (or treesit-aggregated-simple-imenu-settings
             treesit-simple-imenu-settings)
diff --git a/src/syntax.c b/src/syntax.c
index 6ffa8a94c7f..e25618ee03d 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -2434,6 +2434,9 @@ DEFUN ("forward-comment", Fforward_comment, Sforward_comment, 1, 1, 0,
   int dummy2;
   unsigned short int quit_count = 0;
 
+  if (!NILP (Vforward_comment_function))
+    return calln (Vforward_comment_function, count);
+
   CHECK_FIXNUM (count);
   count1 = XFIXNUM (count);
   stop = count1 > 0 ? ZV : BEGV;
@@ -3796,6 +3799,11 @@ syms_of_syntax (void)
   DEFSYM (Qcomment_end_can_be_escaped, "comment-end-can-be-escaped");
   Fmake_variable_buffer_local (Qcomment_end_can_be_escaped);
 
+  DEFVAR_LISP ("forward-comment-function", Vforward_comment_function,
+	       doc: /* If non-nil, `forward-comment' delegates to this function.
+Should take the same arguments and behave similarly to `forward-comment'.  */);
+  Vforward_comment_function = Qnil;
+
   defsubr (&Ssyntax_table_p);
   defsubr (&Ssyntax_table);
   defsubr (&Sstandard_syntax_table);

--=-=-=--




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#75609: Hideshow support for treesitter
Resent-From: Eli Zaretskii <eliz@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Thu, 23 Jan 2025 09:21:02 +0000
Resent-Message-ID: <handler.75609.B75609.17376240089392 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 75609
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>, Stefan Monnier <monnier@HIDDEN>
Cc: 75609 <at> debbugs.gnu.org, casouri@HIDDEN
Received: via spool by 75609-submit <at> debbugs.gnu.org id=B75609.17376240089392
          (code B ref 75609); Thu, 23 Jan 2025 09:21:02 +0000
Received: (at 75609) by debbugs.gnu.org; 23 Jan 2025 09:20:08 +0000
Received: from localhost ([127.0.0.1]:39270 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tatNf-0002RQ-Sg
	for submit <at> debbugs.gnu.org; Thu, 23 Jan 2025 04:20:08 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:42398)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tatNd-0002Qf-TF
 for 75609 <at> debbugs.gnu.org; Thu, 23 Jan 2025 04:20:06 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tatNV-0005Zt-V5; Thu, 23 Jan 2025 04:19:57 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=tgcRkeWw7qGpZNMJhzz+faXqST5WXG/Eb8PKSHNpJ+A=; b=m9fc9lXf4GJp
 AhmnHWs3TZD+rmipbgI5by5KLEeZco0AV948z5wz0bdRHSEQ5/tvA9oJ9bdJe1YJqEyObSVai0a11
 saJzmthLw7JXMbs89LLtippzhVHZOSNMFssFGVsxwWMd7YSi0NKN9E12FhaHLxlOD6G06gtQ2hfgb
 Rqr343J6jPGjUK8M1IVKGihiy6EGwi0YB64dJGS8+sJuI89beb2wEdeuJQt5YKqZ6uAgCu0gtL1Cl
 CoyNeJjmBC1f6YY0FNF7xnPzOiSAd+rlBkWsrLzNIgtREs73KXj1nTaW3ViTOTo8AfywHiVG+31kK
 TiRoHOh3+vhxIdT8+04DkQ==;
Date: Thu, 23 Jan 2025 11:19:44 +0200
Message-Id: <86o6zx28gf.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
In-Reply-To: <877c6masqd.fsf@HIDDEN> (message from Juri Linkov on
 Thu, 23 Jan 2025 09:34:34 +0200)
References: <87tt9yu00k.fsf@HIDDEN>
 <2999991B-3A95-4CC7-92BE-9A6B8F18BADE@HIDDEN>
 <87ikqc3tmw.fsf@HIDDEN> <877c6masqd.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> Cc: 75609 <at> debbugs.gnu.org
> From: Juri Linkov <juri@HIDDEN>
> Date: Thu, 23 Jan 2025 09:34:34 +0200
> 
> +(defun treesit-forward-comment (&optional count)
> +  "Tree-sitter `forward-comment-function' implementation.
> +
> +COUNT is the same as in `forward-comment'."
> +  (let ((res t) thing)
> +    (while (> count 0)
> +      (skip-syntax-forward " >")
> +      (setq thing (treesit-thing-at (point) 'comment))
> +      (if (and thing (eq (point) (treesit-node-start thing)))
> +          (progn
> +            (goto-char (min (1+ (treesit-node-end thing)) (point-max)))
> +            (setq count (1- count)))
> +        (setq count 0 res nil)))
> +    (while (< count 0)
> +      (skip-syntax-backward " >")
> +      (setq thing (treesit-thing-at (max (1- (point)) (point-min)) 'comment))
> +      (if (and thing (eq (point) (treesit-node-end thing)))
> +          (progn
> +            (goto-char (treesit-node-start thing))
> +            (setq count (1+ count)))
> +        (setq count 0 res nil)))
> +    res))

I'm curious: why do you have to use skip-syntax-forward/backward when
tree-sitter already should know where a comment starts and ends?
ideally, features that use tree-sitter should not need to consult any
syntax tables set up by the major mode.  Or what am I missing?




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#75609: Hideshow support for treesitter
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Thu, 23 Jan 2025 17:41:01 +0000
Resent-Message-ID: <handler.75609.B75609.173765403011974 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 75609
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Eli Zaretskii <eliz@HIDDEN>
Cc: 75609 <at> debbugs.gnu.org, casouri@HIDDEN, Stefan Monnier <monnier@HIDDEN>
Received: via spool by 75609-submit <at> debbugs.gnu.org id=B75609.173765403011974
          (code B ref 75609); Thu, 23 Jan 2025 17:41:01 +0000
Received: (at 75609) by debbugs.gnu.org; 23 Jan 2025 17:40:30 +0000
Received: from localhost ([127.0.0.1]:42193 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tb1Bu-000373-CW
	for submit <at> debbugs.gnu.org; Thu, 23 Jan 2025 12:40:30 -0500
Received: from relay8-d.mail.gandi.net ([2001:4b98:dc4:8::228]:52147)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1tb1Bm-00036c-O3
 for 75609 <at> debbugs.gnu.org; Thu, 23 Jan 2025 12:40:29 -0500
Received: by mail.gandi.net (Postfix) with ESMTPSA id 5C7FB1BF203;
 Thu, 23 Jan 2025 17:40:14 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
In-Reply-To: <86o6zx28gf.fsf@HIDDEN> (Eli Zaretskii's message of "Thu, 23 Jan
 2025 11:19:44 +0200")
Organization: LINKOV.NET
References: <87tt9yu00k.fsf@HIDDEN>
 <2999991B-3A95-4CC7-92BE-9A6B8F18BADE@HIDDEN>
 <87ikqc3tmw.fsf@HIDDEN> <877c6masqd.fsf@HIDDEN>
 <86o6zx28gf.fsf@HIDDEN>
Date: Thu, 23 Jan 2025 19:39:17 +0200
Message-ID: <875xm55t16.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

>> +(defun treesit-forward-comment (&optional count)
>> +  "Tree-sitter `forward-comment-function' implementation.
>> +
>> +COUNT is the same as in `forward-comment'."
>> +  (let ((res t) thing)
>> +    (while (> count 0)
>> +      (skip-syntax-forward " >")
>> +      (setq thing (treesit-thing-at (point) 'comment))
>> +      (if (and thing (eq (point) (treesit-node-start thing)))
>> +          (progn
>> +            (goto-char (min (1+ (treesit-node-end thing)) (point-max)))
>> +            (setq count (1- count)))
>> +        (setq count 0 res nil)))
>> +    (while (< count 0)
>> +      (skip-syntax-backward " >")
>> +      (setq thing (treesit-thing-at (max (1- (point)) (point-min)) 'comment))
>> +      (if (and thing (eq (point) (treesit-node-end thing)))
>> +          (progn
>> +            (goto-char (treesit-node-start thing))
>> +            (setq count (1+ count)))
>> +        (setq count 0 res nil)))
>> +    res))
>
> I'm curious: why do you have to use skip-syntax-forward/backward when
> tree-sitter already should know where a comment starts and ends?
> ideally, features that use tree-sitter should not need to consult any
> syntax tables set up by the major mode.  Or what am I missing?

tree-sitter has no information about whitespace, but whitespace is
essential part of the behavior according to the docstring of
'forward-comment':

  Stop scanning if we find something other than a comment or whitespace.
  If COUNT comments are found as expected, with nothing except whitespace
  between them, return t; otherwise return nil.

So treesit should be able to skip whitespace as well:

default implementation = skip whitespace + check syntax table
treesit implementation = skip whitespace + check syntax tree




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#75609: Hideshow support for treesitter
Resent-From: Eli Zaretskii <eliz@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Thu, 23 Jan 2025 18:09:01 +0000
Resent-Message-ID: <handler.75609.B75609.173765570817089 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 75609
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 75609 <at> debbugs.gnu.org, casouri@HIDDEN, monnier@HIDDEN
Received: via spool by 75609-submit <at> debbugs.gnu.org id=B75609.173765570817089
          (code B ref 75609); Thu, 23 Jan 2025 18:09:01 +0000
Received: (at 75609) by debbugs.gnu.org; 23 Jan 2025 18:08:28 +0000
Received: from localhost ([127.0.0.1]:42278 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tb1cx-0004RY-Ga
	for submit <at> debbugs.gnu.org; Thu, 23 Jan 2025 13:08:27 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:54082)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tb1cu-0004RG-Gv
 for 75609 <at> debbugs.gnu.org; Thu, 23 Jan 2025 13:08:25 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tb1cn-00072J-G9; Thu, 23 Jan 2025 13:08:17 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=+V3D6oTeAJGt0cbL+KswXkabIrlXxcQCr6slQVZi1lc=; b=mGfOsydQNQXz
 c/2AtYvxavieP3Mt+00KJBNcqyL6718mQO8j7lZCrAIKVVe2f2xn+ax4NyMClvZjNFxsJ+nT1HUNu
 4QdEpG2zxEw+egQl6TabmopeabdMKaS+JRTacbS6rYKKt2w3oh1hsJEAyQnbpN5wF4ulr3bfTQpQp
 mu32FeST+ESpQiXdeWGvkv3G0DPs+s/T/RWNWK3HKcNomJ5gJC5L3K79+o0dXoV96i5/EoaMiADUg
 xuhdZorLey7CnMhQ5cjtMXiwyELa1ORBg7J1RZBly/FfgngXlWvH9NqZfgiGf3j5WsXXRsrP8mg5q
 NtOoM353h7nxVKRBAdX8fg==;
Date: Thu, 23 Jan 2025 20:08:14 +0200
Message-Id: <86ikq5z9m9.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
In-Reply-To: <875xm55t16.fsf@HIDDEN> (message from Juri Linkov on
 Thu, 23 Jan 2025 19:39:17 +0200)
References: <87tt9yu00k.fsf@HIDDEN>
 <2999991B-3A95-4CC7-92BE-9A6B8F18BADE@HIDDEN>
 <87ikqc3tmw.fsf@HIDDEN> <877c6masqd.fsf@HIDDEN>
 <86o6zx28gf.fsf@HIDDEN> <875xm55t16.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Juri Linkov <juri@HIDDEN>
> Cc: Stefan Monnier <monnier@HIDDEN>,  casouri@HIDDEN,
>   75609 <at> debbugs.gnu.org
> Date: Thu, 23 Jan 2025 19:39:17 +0200
> 
> > I'm curious: why do you have to use skip-syntax-forward/backward when
> > tree-sitter already should know where a comment starts and ends?
> > ideally, features that use tree-sitter should not need to consult any
> > syntax tables set up by the major mode.  Or what am I missing?
> 
> tree-sitter has no information about whitespace, but whitespace is
> essential part of the behavior according to the docstring of
> 'forward-comment':
> 
>   Stop scanning if we find something other than a comment or whitespace.
>   If COUNT comments are found as expected, with nothing except whitespace
>   between them, return t; otherwise return nil.
> 
> So treesit should be able to skip whitespace as well:
> 
> default implementation = skip whitespace + check syntax table
> treesit implementation = skip whitespace + check syntax tree

I'm confused: are you saying that (skip-syntax-forward " >") skips
whitespace?  AFAIU, it skips not just whitespace.  And to skip
whitespace we don't need syntax-tables, do we?  I'm probably missing
something.




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#75609: Hideshow support for treesitter
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Thu, 23 Jan 2025 18:58:02 +0000
Resent-Message-ID: <handler.75609.B75609.173765863226205 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 75609
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Eli Zaretskii <eliz@HIDDEN>
Cc: 75609 <at> debbugs.gnu.org, casouri@HIDDEN, monnier@HIDDEN
Received: via spool by 75609-submit <at> debbugs.gnu.org id=B75609.173765863226205
          (code B ref 75609); Thu, 23 Jan 2025 18:58:02 +0000
Received: (at 75609) by debbugs.gnu.org; 23 Jan 2025 18:57:12 +0000
Received: from localhost ([127.0.0.1]:42378 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tb2O7-0006ob-Is
	for submit <at> debbugs.gnu.org; Thu, 23 Jan 2025 13:57:11 -0500
Received: from relay8-d.mail.gandi.net ([217.70.183.201]:58701)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1tb2O4-0006oM-RN
 for 75609 <at> debbugs.gnu.org; Thu, 23 Jan 2025 13:57:09 -0500
Received: by mail.gandi.net (Postfix) with ESMTPSA id C29F31BF203;
 Thu, 23 Jan 2025 18:56:58 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
In-Reply-To: <86ikq5z9m9.fsf@HIDDEN> (Eli Zaretskii's message of "Thu, 23 Jan
 2025 20:08:14 +0200")
Organization: LINKOV.NET
References: <87tt9yu00k.fsf@HIDDEN>
 <2999991B-3A95-4CC7-92BE-9A6B8F18BADE@HIDDEN>
 <87ikqc3tmw.fsf@HIDDEN> <877c6masqd.fsf@HIDDEN>
 <86o6zx28gf.fsf@HIDDEN> <875xm55t16.fsf@HIDDEN>
 <86ikq5z9m9.fsf@HIDDEN>
Date: Thu, 23 Jan 2025 20:56:01 +0200
Message-ID: <87tt9p4awu.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

>> > I'm curious: why do you have to use skip-syntax-forward/backward when
>> > tree-sitter already should know where a comment starts and ends?
>> > ideally, features that use tree-sitter should not need to consult any
>> > syntax tables set up by the major mode.  Or what am I missing?
>> 
>> tree-sitter has no information about whitespace, but whitespace is
>> essential part of the behavior according to the docstring of
>> 'forward-comment':
>> 
>>   Stop scanning if we find something other than a comment or whitespace.
>>   If COUNT comments are found as expected, with nothing except whitespace
>>   between them, return t; otherwise return nil.
>> 
>> So treesit should be able to skip whitespace as well:
>> 
>> default implementation = skip whitespace + check syntax table
>> treesit implementation = skip whitespace + check syntax tree
>
> I'm confused: are you saying that (skip-syntax-forward " >") skips
> whitespace?  AFAIU, it skips not just whitespace.  And to skip
> whitespace we don't need syntax-tables, do we?  I'm probably missing
> something.

Probably it would be fine to use just (skip-chars-forward " \t\n")
if I correctly understand the documentation of 'forward-comment'.




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#75609: Hideshow support for treesitter
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Mon, 27 Jan 2025 19:16:01 +0000
Resent-Message-ID: <handler.75609.B75609.173800532714205 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 75609
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Yuan Fu <casouri@HIDDEN>
Cc: 75609 <at> debbugs.gnu.org
Received: via spool by 75609-submit <at> debbugs.gnu.org id=B75609.173800532714205
          (code B ref 75609); Mon, 27 Jan 2025 19:16:01 +0000
Received: (at 75609) by debbugs.gnu.org; 27 Jan 2025 19:15:27 +0000
Received: from localhost ([127.0.0.1]:34496 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tcUZz-0003h3-4i
	for submit <at> debbugs.gnu.org; Mon, 27 Jan 2025 14:15:27 -0500
Received: from relay8-d.mail.gandi.net ([217.70.183.201]:50997)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1tcUZu-0003fN-WF
 for 75609 <at> debbugs.gnu.org; Mon, 27 Jan 2025 14:15:24 -0500
Received: by mail.gandi.net (Postfix) with ESMTPSA id 737F71BF209;
 Mon, 27 Jan 2025 19:15:14 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
In-Reply-To: <2999991B-3A95-4CC7-92BE-9A6B8F18BADE@HIDDEN> (Yuan Fu's
 message of "Fri, 17 Jan 2025 23:40:16 -0800")
Organization: LINKOV.NET
References: <87tt9yu00k.fsf@HIDDEN>
 <2999991B-3A95-4CC7-92BE-9A6B8F18BADE@HIDDEN>
Date: Mon, 27 Jan 2025 21:11:59 +0200
Message-ID: <87o6zsul4w.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

>> +(defun treesit-hs-inside-comment-p ()
>> +  (let ((thing (or (treesit-thing-at (point) "comment")
>> +                   (unless (bobp)
>> +                     (treesit-thing-at (1- (point)) "comment")))))
>> +    (when thing
>> +      (list (treesit-node-start thing) (treesit-node-end thing)))))
>> +
>
> FYI some grammar calls comments line_comment and block_comment.  Maybe
> use the comment thing first, and then match “comment” with the node type?

Now this tries to use the comment thing first, and then falls back to “comment”.


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline; filename=treesit-hideshow.patch

diff --git a/lisp/treesit.el b/lisp/treesit.el
index e08aa52ca50..de86b847177 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -3489,6 +3489,82 @@ treesit-outline-level
       (setq level (1+ level)))
     (if (zerop level) 1 level)))
 
+;;; Hideshow mode
+
+(defun treesit-hs-block-end ()
+  "Tree-sitter implementation of `hs-block-end-regexp'."
+  (let* ((pred 'list)
+         (thing (treesit-thing-at
+                 (if (bobp) (point) (1- (point))) pred))
+         (end (when thing (treesit-node-end thing)))
+         (last (when thing (treesit-node-child thing -1)))
+         (beg (if last (treesit-node-start last)
+                (if (bobp) (point) (1- (point))))))
+    (when (and thing (eq (point) end))
+      (set-match-data (list beg end))
+      t)))
+
+(defun treesit-hs-find-block-beginning ()
+  "Tree-sitter implementation of `hs-find-block-beginning-func'."
+  (let* ((pred 'list)
+         (thing (treesit-thing-at (point) pred))
+         (thing (or thing (treesit-parent-until (treesit-node-at (point)) pred)))
+         (beg (when thing (treesit-node-start thing)))
+         (end (when thing (treesit-node-end thing))))
+    (when thing
+      (goto-char beg)
+      (set-match-data (list beg end))
+      t)))
+
+(defun treesit-hs-find-next-block (_regexp _maxp comments)
+  "Tree-sitter implementation of `hs-find-next-block-func'."
+  (when (not comments)
+    (forward-comment (point-max)))
+  (let* ((comment-pred
+          (when comments
+            (if (treesit-thing-defined-p 'comment (treesit-language-at (point)))
+                'comment "comment")))
+         (pred (if comment-pred (append '(or list) (list comment-pred)) 'list))
+         ;; `treesit-navigate-thing' can't find a thing at bobp,
+         ;; so use `treesit-thing-at' to match at bobp.
+         (current (treesit-thing-at (point) pred))
+         (beg (or (and current (eq (point) (treesit-node-start current)) (point))
+                  (treesit-navigate-thing (point) 1 'beg pred)))
+         ;; Check if we found a list or a comment
+         (list-thing (when beg (treesit-thing-at beg 'list)))
+         (comment-thing (when beg (treesit-thing-at beg comment-pred)))
+         (comment-p (and comment-thing (eq beg (treesit-node-start comment-thing))))
+         (thing (if comment-p comment-thing list-thing))
+         (end (if thing (min (1+ (treesit-node-start thing)) (point-max)))))
+    (when end
+      (goto-char end)
+      (set-match-data
+       (if (and comments comment-p)
+           (list beg end nil nil beg end)
+         (list beg end beg end)))
+      t)))
+
+(defun treesit-hs-looking-at-block-start-p ()
+  "Tree-sitter implementation of `hs-looking-at-block-start-p-func'."
+  (let* ((pred 'list)
+         (thing (treesit-thing-at (point) pred))
+         (beg (when thing (treesit-node-start thing)))
+         (end (min (1+ (point)) (point-max))))
+    (when (and thing (eq (point) beg))
+      (set-match-data (list beg end))
+      t)))
+
+(defun treesit-hs-inside-comment-p ()
+  "Tree-sitter implementation of `hs-inside-comment-p-func'."
+  (let* ((comment-pred
+          (if (treesit-thing-defined-p 'comment (treesit-language-at (point)))
+              'comment "comment"))
+         (thing (or (treesit-thing-at (point) comment-pred)
+                    (unless (bobp)
+                      (treesit-thing-at (1- (point)) comment-pred)))))
+    (when thing
+      (list (treesit-node-start thing) (treesit-node-end thing)))))
+
 ;;; Show paren mode
 
 (defun treesit-show-paren-data--categorize (pos &optional end-p)
@@ -3672,7 +3748,17 @@ treesit-major-mode-setup
     (setq-local forward-list-function #'treesit-forward-list)
     (setq-local down-list-function #'treesit-down-list)
     (setq-local up-list-function #'treesit-up-list)
-    (setq-local show-paren-data-function #'treesit-show-paren-data))
+    (setq-local show-paren-data-function #'treesit-show-paren-data)
+    (setq-local hs-c-start-regexp nil
+                hs-block-start-regexp nil
+                hs-block-start-mdata-select 0
+                hs-block-end-regexp #'treesit-hs-block-end
+                hs-forward-sexp-func #'forward-list
+                hs-adjust-block-beginning nil
+                hs-find-block-beginning-func #'treesit-hs-find-block-beginning
+                hs-find-next-block-func #'treesit-hs-find-next-block
+                hs-looking-at-block-start-p-func #'treesit-hs-looking-at-block-start-p
+                hs-inside-comment-p-func #'treesit-hs-inside-comment-p))
 
   (when (treesit-thing-defined-p 'sentence nil)
     (setq-local forward-sentence-function #'treesit-forward-sentence))
diff --git a/lisp/progmodes/hideshow.el b/lisp/progmodes/hideshow.el
index 823eb0527c6..d96efde991f 100644
--- a/lisp/progmodes/hideshow.el
+++ b/lisp/progmodes/hideshow.el
@@ -481,6 +481,9 @@ hs-looking-at-block-start-p-func
 Python, where `looking-at' and `syntax-ppss' check is not enough
 to check if the point is at the block start.")
 
+(defvar-local hs-inside-comment-p-func nil
+  "Function used to check if point is inside a comment.")
+
 (defvar hs-headline nil
   "Text of the line where a hidden block begins, set during isearch.
 You can display this in the mode line by adding the symbol `hs-headline'
@@ -625,9 +628,13 @@ hs-hide-block-at-point
 	  (setq p (line-end-position)))
 	;; `q' is the point at the end of the block
 	(hs-forward-sexp mdata 1)
-	(setq q (if (looking-back hs-block-end-regexp nil)
-		    (match-beginning 0)
-		  (point)))
+	(setq q (cond ((and (stringp hs-block-end-regexp)
+                            (looking-back hs-block-end-regexp nil))
+		       (match-beginning 0))
+                      ((functionp hs-block-end-regexp)
+                       (funcall hs-block-end-regexp)
+                       (match-beginning 0))
+		      (t (point))))
         (when (and (< p q) (> (count-lines p q) 1))
           (cond ((and hs-allow-nesting (setq ov (hs-overlay-at p)))
                  (delete-overlay ov))
@@ -644,6 +651,11 @@ hs-inside-comment-p
 beginning.  If we are inside of a comment but this condition is not met,
 we return a list having a nil as its car and the end of comment position
 as cdr."
+  (if (functionp hs-inside-comment-p-func)
+      (funcall hs-inside-comment-p-func)
+    (hs-inside-comment-p--default)))
+
+(defun hs-inside-comment-p--default ()
   (save-excursion
     ;; the idea is to look backwards for a comment start regexp, do a
     ;; forward comment, and see if we are inside, then extend
@@ -704,7 +716,7 @@ hs-grok-mode-type
            (bound-and-true-p comment-end))
       (let* ((lookup (assoc major-mode hs-special-modes-alist))
              (start-elem (or (nth 1 lookup) "\\s(")))
-        (if (listp start-elem)
+        (if (consp start-elem)
             ;; handle (START-REGEXP MDATA-SELECT)
             (setq hs-block-start-regexp (car start-elem)
                   hs-block-start-mdata-select (cadr start-elem))
@@ -850,14 +862,16 @@ hs-hide-all
      (syntax-propertize (point-max))
      (let ((spew (make-progress-reporter "Hiding all blocks..."
                                          (point-min) (point-max)))
-           (re (concat "\\("
-                       hs-block-start-regexp
-                       "\\)"
-                       (if hs-hide-comments-when-hiding-all
-                           (concat "\\|\\("
-                                   hs-c-start-regexp
-                                   "\\)")
-                         ""))))
+           (re (when (stringp hs-block-start-regexp)
+                 (concat "\\("
+                         hs-block-start-regexp
+                         "\\)"
+                         (if (and hs-hide-comments-when-hiding-all
+                                  (stringp hs-c-start-regexp))
+                             (concat "\\|\\("
+                                     hs-c-start-regexp
+                                     "\\)")
+                           "")))))
        (while (funcall hs-find-next-block-func re (point-max)
                        hs-hide-comments-when-hiding-all)
          (if (match-beginning 1)
@@ -869,7 +883,9 @@ hs-hide-all
 			 (hs-hide-block-at-point t))
 		 ;; Go to end of matched data to prevent from getting stuck
 		 ;; with an endless loop.
-                 (when (looking-at hs-block-start-regexp)
+                 (when (if (stringp hs-block-start-regexp)
+                           (looking-at hs-block-start-regexp)
+                         (eq (point) (match-beginning 0)))
 		   (goto-char (match-end 0)))))
            ;; found a comment, probably
            (let ((c-reg (hs-inside-comment-p)))
@@ -1008,7 +1024,10 @@ hs-minor-mode
   (setq hs-headline nil)
   (if hs-minor-mode
       (progn
-        (hs-grok-mode-type)
+        ;; Use such heuristics that if one buffer-local variable
+        ;; is already defined, don't overwrite other variables too.
+        (unless (buffer-local-value 'hs-inside-comment-p-func (current-buffer))
+          (hs-grok-mode-type))
         ;; Turn off this mode if we change major modes.
         (add-hook 'change-major-mode-hook
                   #'turn-off-hideshow

--=-=-=--




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#75609: Hideshow support for treesitter
Resent-From: Yuan Fu <casouri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Tue, 28 Jan 2025 01:53:02 +0000
Resent-Message-ID: <handler.75609.B75609.173802914628221 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 75609
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 75609 <at> debbugs.gnu.org
Received: via spool by 75609-submit <at> debbugs.gnu.org id=B75609.173802914628221
          (code B ref 75609); Tue, 28 Jan 2025 01:53:02 +0000
Received: (at 75609) by debbugs.gnu.org; 28 Jan 2025 01:52:26 +0000
Received: from localhost ([127.0.0.1]:34990 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tcamA-0007L7-GH
	for submit <at> debbugs.gnu.org; Mon, 27 Jan 2025 20:52:26 -0500
Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:56603)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <casouri@HIDDEN>) id 1tcam8-0007Kt-Da
 for 75609 <at> debbugs.gnu.org; Mon, 27 Jan 2025 20:52:25 -0500
Received: by mail-pj1-x1035.google.com with SMTP id
 98e67ed59e1d1-2ee786b3277so6819675a91.1
 for <75609 <at> debbugs.gnu.org>; Mon, 27 Jan 2025 17:52:24 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1738029138; x=1738633938; darn=debbugs.gnu.org;
 h=to:references:message-id:content-transfer-encoding:cc:date
 :in-reply-to:from:subject:mime-version:from:to:cc:subject:date
 :message-id:reply-to;
 bh=w0CkcmAFbb0dRi6xEF3h6yjXmkgyfDAGtdWRJ2/KHuk=;
 b=dUvCpTPBx+nK4M9YCXpK0I6eLSAVxAFrQd0V+x0Cxa05awwgby//tekJURsXh5/cZ5
 ozsOcw95ZajaZp3Fkyi+yS/gs7Akhlb3wZNzkyjRyqvAdGlCoqBYa6pN1kefKtg5vFyE
 Js2hPWAOIlQtCZVhHhiL5Uq1WnelXxk9EWi9OUMXe3c3eJH1gvi4JC81RNPmqwbNVA9K
 j75vVx9Pfwng83MSLqm2vqPb9vxE0mNi/jXqJb6g5uRhc4bHDGISWPSh0ELax5MRgicl
 M1fr1CRt0Suu3YbvzRj9m1FXXYkfWUs1ZSWPLWzHFvbtTBUWr+iW2Zsc13ZHd83W71gT
 AXgA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1738029138; x=1738633938;
 h=to:references:message-id:content-transfer-encoding:cc:date
 :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=w0CkcmAFbb0dRi6xEF3h6yjXmkgyfDAGtdWRJ2/KHuk=;
 b=utlTWfrUxLKHntay6T296NuMUv8J4itf8syNhxGkh1A42Q1K31nU9tk/P4NNs3jf2d
 UjltxXhlmjZzMECjG+lT48tuvZgUhJOAN04PIT0xNnmK6ZqozRp3+RZ9JJD+5xgAtUJE
 Z5Nqz5KtfKuX9A2BEJCotnS6ZlZbujrVWlHp0fIPFme7mJk3vm2YbJHUi97HaLdyego3
 et0wtGA3/JogO8F7v7h6jaLhNVClGyruxCkcXn2UeX4RjYEoeaWB89SIzAAk4DeK57CL
 tbi6CanDKm2phXvSzvUF/TXLzKwLlbaCe/6cRQpeF2uZ0Vum76AHqS76OdPq7Qo9h3QI
 rKUw==
X-Gm-Message-State: AOJu0YwbpQGeeWUJ1qLH5UJnjGRHferTkLIQmbsyVzFKqDBPpe1s9lsl
 9ro+O63FBsVt6fMKwmikhVT3ToUtq6/z5g9UQF/2PGgLD2wdnznk
X-Gm-Gg: ASbGncuPuH99dJgJAIeZwrnz6OaK9IKyuh1HD7gHjOD5ddAovzOdHodEG9TbCdQexwk
 pjzZbtOT9GMkFfdndUINqMOWnLYfJ3IcTZctAq0IIddTtoKwRolS1BCSnluzzW84BIJgel19pJ9
 nnEmjqvpCEnlfHjdgEYlqVqYEd5UMlqROmazQo4zyEVtps/oGdq7owvkiDS/zRKd8EWOclxHWak
 2GF00vKL2CSczU+PEf02oVh1WxNCBdvsb3wj2VexING71rG+5ve8lDhsYVFRNrIYPP4Dg4PVMEk
 dETiaCgElMiWKckA/xA/v2ImTNPw
X-Google-Smtp-Source: AGHT+IFzSiprHQ0ukshMKbz5a9WSU7rthdnqZAbMN8yjlzI1e89AUcKMwf4kDzirxY674AlzIRhP2w==
X-Received: by 2002:a17:90b:1f8e:b0:2ef:114d:7bf8 with SMTP id
 98e67ed59e1d1-2f782c4ff33mr56198679a91.6.1738029138267; 
 Mon, 27 Jan 2025 17:52:18 -0800 (PST)
Received: from smtpclient.apple ([2601:646:8f81:6120:954a:ef64:25ce:1e3c])
 by smtp.gmail.com with ESMTPSA id
 98e67ed59e1d1-2f7ffa56198sm8024246a91.16.2025.01.27.17.52.17
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Mon, 27 Jan 2025 17:52:17 -0800 (PST)
Content-Type: text/plain;
	charset=utf-8
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\))
From: Yuan Fu <casouri@HIDDEN>
In-Reply-To: <87o6zsul4w.fsf@HIDDEN>
Date: Mon, 27 Jan 2025 17:52:06 -0800
Content-Transfer-Encoding: quoted-printable
Message-Id: <71C40261-9556-4035-B714-1A6A4E0EB803@HIDDEN>
References: <87tt9yu00k.fsf@HIDDEN>
 <2999991B-3A95-4CC7-92BE-9A6B8F18BADE@HIDDEN>
 <87o6zsul4w.fsf@HIDDEN>
X-Mailer: Apple Mail (2.3776.700.51)
X-Spam-Score: -0.0 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)



> On Jan 27, 2025, at 11:11=E2=80=AFAM, Juri Linkov <juri@HIDDEN> =
wrote:
>=20
>>> +(defun treesit-hs-inside-comment-p ()
>>> +  (let ((thing (or (treesit-thing-at (point) "comment")
>>> +                   (unless (bobp)
>>> +                     (treesit-thing-at (1- (point)) "comment")))))
>>> +    (when thing
>>> +      (list (treesit-node-start thing) (treesit-node-end thing)))))
>>> +
>>=20
>> FYI some grammar calls comments line_comment and block_comment.  =
Maybe
>> use the comment thing first, and then match =E2=80=9Ccomment=E2=80=9D =
with the node type?
>=20
> Now this tries to use the comment thing first, and then falls back to =
=E2=80=9Ccomment=E2=80=9D.

FWIW I don=E2=80=99t have other comments :)

Yuan=




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#75609: Hideshow support for treesitter
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Tue, 28 Jan 2025 19:10:02 +0000
Resent-Message-ID: <handler.75609.B75609.17380913553478 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 75609
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Yuan Fu <casouri@HIDDEN>
Cc: 75609 <at> debbugs.gnu.org
Received: via spool by 75609-submit <at> debbugs.gnu.org id=B75609.17380913553478
          (code B ref 75609); Tue, 28 Jan 2025 19:10:02 +0000
Received: (at 75609) by debbugs.gnu.org; 28 Jan 2025 19:09:15 +0000
Received: from localhost ([127.0.0.1]:38600 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tcqxW-0000u1-HA
	for submit <at> debbugs.gnu.org; Tue, 28 Jan 2025 14:09:14 -0500
Received: from relay7-d.mail.gandi.net ([2001:4b98:dc4:8::227]:33009)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>)
 id 1tcqxT-0000ta-9G; Tue, 28 Jan 2025 14:09:12 -0500
Received: by mail.gandi.net (Postfix) with ESMTPSA id DC80720003;
 Tue, 28 Jan 2025 19:09:01 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
In-Reply-To: <71C40261-9556-4035-B714-1A6A4E0EB803@HIDDEN> (Yuan Fu's
 message of "Mon, 27 Jan 2025 17:52:06 -0800")
Organization: LINKOV.NET
References: <87tt9yu00k.fsf@HIDDEN>
 <2999991B-3A95-4CC7-92BE-9A6B8F18BADE@HIDDEN>
 <87o6zsul4w.fsf@HIDDEN>
 <71C40261-9556-4035-B714-1A6A4E0EB803@HIDDEN>
Date: Tue, 28 Jan 2025 21:07:46 +0200
Message-ID: <87msfa92pp.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

close 75609 31.0.50
thanks

>>>> +(defun treesit-hs-inside-comment-p ()
>>>> +  (let ((thing (or (treesit-thing-at (point) "comment")
>>>> +                   (unless (bobp)
>>>> +                     (treesit-thing-at (1- (point)) "comment")))))
>>>> +    (when thing
>>>> +      (list (treesit-node-start thing) (treesit-node-end thing)))))
>>>> +
>>> 
>>> FYI some grammar calls comments line_comment and block_comment.  Maybe
>>> use the comment thing first, and then match “comment” with the node type?
>> 
>> Now this tries to use the comment thing first, and then falls back to “comment”.
>
> FWIW I don’t have other comments :)

Thanks, so now pushed to master and closed.




Message received at control <at> debbugs.gnu.org:


Received: (at control) by debbugs.gnu.org; 28 Jan 2025 19:09:15 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Jan 28 14:09:15 2025
Received: from localhost ([127.0.0.1]:38602 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tcqxW-0000u3-Ux
	for submit <at> debbugs.gnu.org; Tue, 28 Jan 2025 14:09:15 -0500
Received: from relay7-d.mail.gandi.net ([2001:4b98:dc4:8::227]:33009)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>)
 id 1tcqxT-0000ta-9G; Tue, 28 Jan 2025 14:09:12 -0500
Received: by mail.gandi.net (Postfix) with ESMTPSA id DC80720003;
 Tue, 28 Jan 2025 19:09:01 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Yuan Fu <casouri@HIDDEN>
Subject: Re: bug#75609: Hideshow support for treesitter
In-Reply-To: <71C40261-9556-4035-B714-1A6A4E0EB803@HIDDEN> (Yuan Fu's
 message of "Mon, 27 Jan 2025 17:52:06 -0800")
Organization: LINKOV.NET
References: <87tt9yu00k.fsf@HIDDEN>
 <2999991B-3A95-4CC7-92BE-9A6B8F18BADE@HIDDEN>
 <87o6zsul4w.fsf@HIDDEN>
 <71C40261-9556-4035-B714-1A6A4E0EB803@HIDDEN>
Date: Tue, 28 Jan 2025 21:07:46 +0200
Message-ID: <87msfa92pp.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-GND-Sasl: juri@HIDDEN
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: control
Cc: 75609 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

close 75609 31.0.50
thanks

>>>> +(defun treesit-hs-inside-comment-p ()
>>>> +  (let ((thing (or (treesit-thing-at (point) "comment")
>>>> +                   (unless (bobp)
>>>> +                     (treesit-thing-at (1- (point)) "comment")))))
>>>> +    (when thing
>>>> +      (list (treesit-node-start thing) (treesit-node-end thing)))))
>>>> +
>>> 
>>> FYI some grammar calls comments line_comment and block_comment.  Maybe
>>> use the comment thing first, and then match “comment” with the node type?
>> 
>> Now this tries to use the comment thing first, and then falls back to “comment”.
>
> FWIW I don’t have other comments :)

Thanks, so now pushed to master and closed.





Last modified: Tue, 28 Jan 2025 19:15:01 UTC

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