From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#75122: Treesit support for show-paren-mode Date: Thu, 26 Dec 2024 22:07:12 +0200 Message-ID: <6b729636-accf-4872-9b5e-627ec18bb255@gutov.dev> References: <878qs2z477.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6078"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: Yuan Fu To: Juri Linkov , 75122@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 26 21:08:21 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 1tQu9c-0001R3-Gw for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 26 Dec 2024 21:08:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tQu9U-0002rp-FU; Thu, 26 Dec 2024 15:08:12 -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 1tQu9N-0002rW-45 for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2024 15:08:06 -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 1tQu9L-0003jz-1z for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2024 15:08:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=In-Reply-To:From:References:MIME-Version:Date:To:Subject; bh=QT+ckWaghtu0kLlDwI9zkUxg2glthgqAK2jrhE7At8s=; b=rz7kSrq+kJ6lF6iGw8DzRMN7IeIs4DpRL+wPdNK4C8L4eEI8rOc7tZWynFGuV5dTkLrqpzPg1p7IMbhadv0/CP3JGo3oZMsmvVD3kCjFs465mkuVrTS7CwN1boskjJ9YZb3bMO2WxqVQZRV3Z7rHYx3CeFdiT7A+5Vr1nwT9I1aPCeykPgFDSMVsQuYJUFM07SvpQz1Ggwhn2nNoQYwJrExtGmrQuS/P3wLED/vGv0hsDETLplJnRTfrE5dxopoPg2zXaCr0IBrkZGI6QTLjCru25Php5Yl2PQLBVpV0vH+D4CkM/17aXFHYXwf7C4EkGOuf3sn6iC3wsgHCXg9EgQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tQu9K-0007Z9-Kr for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2024 15:08:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 26 Dec 2024 20:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75122 X-GNU-PR-Package: emacs Original-Received: via spool by 75122-submit@debbugs.gnu.org id=B75122.173524364729033 (code B ref 75122); Thu, 26 Dec 2024 20:08:02 +0000 Original-Received: (at 75122) by debbugs.gnu.org; 26 Dec 2024 20:07:27 +0000 Original-Received: from localhost ([127.0.0.1]:42307 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tQu8k-0007YD-QR for submit@debbugs.gnu.org; Thu, 26 Dec 2024 15:07:27 -0500 Original-Received: from fhigh-b5-smtp.messagingengine.com ([202.12.124.156]:33165) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tQu8g-0007Xx-RY for 75122@debbugs.gnu.org; Thu, 26 Dec 2024 15:07:24 -0500 Original-Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.stl.internal (Postfix) with ESMTP id 159B525400B3; Thu, 26 Dec 2024 15:07:17 -0500 (EST) Original-Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Thu, 26 Dec 2024 15:07:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1735243636; x=1735330036; bh=QT+ckWaghtu0kLlDwI9zkUxg2glthgqAK2jrhE7At8s=; b= Y3L3G0Lk4D2Dx8chuPNXI27iUMleNbWuccHMbLlW9jEXqbQr1fJakhY+twMJ1PEC /lsH3O3GczrDAnSyxbxAcM/pE6xH1t20/CK1dk2HyyiqCpxmOPeA0oPPe/pJwZs/ yvaGK5VfNkovVKI90MwMf5lx4L+rV0TzwJKjSKDJPg3d7iq7BfCx3220pxML+R5I 5oDGVCge9fCjY2qMmyzxJOp16Ow+dn9StSjGuq++K5KdyzmbOWphw4oWog58H6Fw kX36rBrS9EoqpdNH7fvfc4JF2j3Fa+OdzDxOOo1FW47N9iwqtaetORfU/UrNMLjT +hYBFrwtlKJI3S7UDHZfGw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1735243636; x= 1735330036; bh=QT+ckWaghtu0kLlDwI9zkUxg2glthgqAK2jrhE7At8s=; b=T ftt42PN7K2XaZeIrXX1eaEGQBrdLCZUIzzM6dMAKz8R57zflmt96E0c7f4gt8SAq d+V08ncQblRQvKzb9vGJrsNRwZacPNNxbko2z01xg1ixtG10aGs266DwPhC1DlTC 2e/SO7430LwP951ID/lnNgUh1gSKcIX4AQtItiIMNarHzv9XaAALOemPqO7PDy/S K8hqX3ygKLb0ba0jb9/XR2JW0uMwwOEwytTD2hVTpuGbw4ZLzV5bXrwUrDAjyF6v hWQcdKeWX/Ykl6sIk+8xdAeUb9rg96DjkXryqY/sdRv2og97s4ue18X1fWSW7j1g wsivx113dmce+kBRw7xbg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddruddukedgudeffecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefkffggfgfuvfevfhfhjggtgfesthejredttddv jeenucfhrhhomhepffhmihhtrhihucfiuhhtohhvuceoughmihhtrhihsehguhhtohhvrd guvghvqeenucggtffrrghtthgvrhhnpeetudeljeegheetgfehgeejkeeuhedvveeikeeu fedtvddtveefhfdvveegudejheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpegumhhithhrhiesghhuthhovhdruggvvhdpnhgspghrtghpthht ohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepjhhurhhisehlihhnkhhovh drnhgvthdprhgtphhtthhopeejheduvddvseguvggssghughhsrdhgnhhurdhorhhgpdhr tghpthhtoheptggrshhouhhrihesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i07de48aa:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Dec 2024 15:07:14 -0500 (EST) Content-Language: en-US In-Reply-To: <878qs2z477.fsf@mail.linkov.net> 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:297782 Archived-At: Hi! On 26/12/2024 20:31, Juri Linkov wrote: > 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 is working great, thanks! Some comments below. > 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 The comment doesn't seem to correspond to the code, or anyway to all the cases the code might be handling? I might misunderstand, though. > + (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)))) Without getting into more details, it seems the user options show-paren-when-point-inside-paren and show-paren-when-point-in-periphery are not handled (don't have any effect). Not sure what's needed for that, but FWIW SMIE's show-paren integration seems to react to the value of the first of these options (even though it's never referenced directly in smie.el), while the second one is not supported there either.