From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#75122: Treesit support for show-paren-mode Date: Thu, 26 Dec 2024 20:31:24 +0200 Organization: LINKOV.NET Message-ID: <878qs2z477.fsf@mail.linkov.net> 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="23416"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) Cc: Yuan Fu To: 75122@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 26 19:40:14 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 1tQsmL-0005vM-Kg for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 26 Dec 2024 19:40:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tQsmD-0005wx-Ct; Thu, 26 Dec 2024 13:40:05 -0500 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 1tQsmA-0005uk-3J for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2024 13:40:02 -0500 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 1tQsm9-00029f-QU for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2024 13:40:01 -0500 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:Subject; bh=/p2nK3Xb0o1tob4H/qG8BYaxuc6rUy2lF61pZ0DhiV0=; b=CWOi8LsMojP4mvWijTD0Q/w4aoquYgD581h2mbNxDTqz6cqsGxWdooBQOKIirneovbLQgGrjmN29glQjXF4x0OcNi7u24mkNQ4FhIYJY04vv1Z0ImPCtUKiIftDcnY16OJbCW2r1GRZoOFoBu2CDAqjXgZQ8L36hsK9COPKzeMFkQnnP8LSSsgpQ8Rx8v5MjRczoasBuJXQMkz7DgJI+uT+MEawP0Y8K4AgZxejFsnXxvh2SPUQ8Mn4OMXwWU7WMx5QpHci6VZp0kWllKqz452ag9FCRiana5gT8RlGzFzauX4xj+axmVlOgmfqY3Mk6fcNeezTURvbofVZEzRmDaw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tQsm9-0003jw-La; Thu, 26 Dec 2024 13:40:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: casouri@gmail.com, bug-gnu-emacs@gnu.org Resent-Date: Thu, 26 Dec 2024 18:40:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 75122 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: Yuan Fu Original-Received: via spool by submit@debbugs.gnu.org id=B.173523836514315 (code B ref -1); Thu, 26 Dec 2024 18:40:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 26 Dec 2024 18:39:25 +0000 Original-Received: from localhost ([127.0.0.1]:42180 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tQslY-0003io-Ih for submit@debbugs.gnu.org; Thu, 26 Dec 2024 13:39:24 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:45928) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tQslW-0003ig-H8 for submit@debbugs.gnu.org; Thu, 26 Dec 2024 13:39:23 -0500 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 1tQslV-0005si-U5 for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2024 13:39:21 -0500 Original-Received: from relay1-d.mail.gandi.net ([2001:4b98:dc4:8::221]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tQslT-00021k-Cf for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2024 13:39:21 -0500 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 6CAB4240002 for ; Thu, 26 Dec 2024 18:39:13 +0000 (UTC) X-GND-Sasl: juri@linkov.net Received-SPF: pass client-ip=2001:4b98:dc4:8::221; envelope-from=juri@linkov.net; helo=relay1-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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:297778 Archived-At: --=-=-= Content-Type: text/plain For example, ruby-mode used smie-setup that sets buffer-local show-paren-data-function. This patch does the same for ts-modes: when point at the start/end of the sexp list, then both "def" and "end" are highlighted as opening and closing nodes: def method puts "This is method definition" end-!- This also indicates that implementing 'down-list' to move after the opening node will be the right thing to do (currently in progress). --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=treesit-show-paren-data.patch diff --git a/lisp/treesit.el b/lisp/treesit.el index 2616d16e800..a62f63d0d6c 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -3331,6 +3333,34 @@ treesit-outline-level (setq level (1+ level))) (if (zerop level) 1 level))) +;;; Show paren mode + +(defun treesit-show-paren-data () + "A function suitable for `show-paren-data-function' (which see)." + (let* ((node (treesit-thing-at (point) 'sexp-list)) + (beg (when node (treesit-node-start node))) + (end (when node (treesit-node-end node)))) + ;; When after the closing node, try the previous position inside the node + (unless (or (eq (point) beg) (eq (point) end) (bobp)) + (setq node (treesit-thing-at (1- (point)) 'sexp-list) + beg (when node (treesit-node-start node)) + end (when node (treesit-node-end node)))) + (when (or (eq (point) beg) (eq (point) end)) + (let ((beg-node (treesit-node-child node 0)) + (end-node (treesit-node-child node -1))) + (when (and beg-node end-node (not (eq beg-node end-node))) + (if (eq beg (point)) + (list (treesit-node-start beg-node) + (treesit-node-end beg-node) + (treesit-node-start end-node) + (treesit-node-end end-node) + nil) + (list (treesit-node-start end-node) + (treesit-node-end end-node) + (treesit-node-start beg-node) + (treesit-node-end beg-node) + nil))))))) + ;;; Activating tree-sitter (defun treesit-ready-p (language &optional quiet) @@ -3486,6 +3516,8 @@ treesit-major-mode-setup (setq-local outline-search-function #'treesit-outline-search outline-level #'treesit-outline-level)) + (setq-local show-paren-data-function 'treesit-show-paren-data) + ;; Remove existing local parsers. (dolist (ov (overlays-in (point-min) (point-max))) (when-let* ((parser (overlay-get ov 'treesit-parser))) --=-=-=--