From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Perry Smith Newsgroups: gmane.emacs.devel Subject: Creating a paradigm for leveraging Tree Sitter's power Date: Fri, 23 Dec 2022 19:32:13 -0600 Message-ID: <948662B3-F284-4E89-BFE2-4BCB5007D4EA@easesoftware.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.200.110.1.12\)) Content-Type: multipart/signed; boundary="Apple-Mail=_C5BDC17A-D662-4306-B9A6-2B8F0E3AF3A0"; protocol="application/pgp-signature"; micalg=pgp-sha256 Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7685"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Dec 24 02:34:18 2022 Return-path: Envelope-to: ged-emacs-devel@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 1p8tQW-0001mP-Rj for ged-emacs-devel@m.gmane-mx.org; Sat, 24 Dec 2022 02:34:17 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8tPx-0002I5-Gz; Fri, 23 Dec 2022 20:33:42 -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 1p8tPs-0002Hw-Jb for emacs-devel@gnu.org; Fri, 23 Dec 2022 20:33:36 -0500 Original-Received: from caracal.birch.relay.mailchannels.net ([23.83.209.30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p8tPo-00006N-C8 for emacs-devel@gnu.org; Fri, 23 Dec 2022 20:33:34 -0500 X-Sender-Id: a2hosting|x-authuser|pedz+easesoftware.com@mi3-ss4.a2hosting.com Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 16E53501574 for ; Sat, 24 Dec 2022 01:32:32 +0000 (UTC) Original-Received: from mi3-ss4.a2hosting.com (unknown [127.0.0.6]) (Authenticated sender: a2hosting) by relay.mailchannels.net (Postfix) with ESMTPA id 95645501252 for ; Sat, 24 Dec 2022 01:32:27 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1671845547; a=rsa-sha256; cv=none; b=TEp48qi1Ula7+sZfW0PYrHNE+RoAIOeWoOVEtNvKiwOEQXMTJ88xttOC3I8D/lGQ5Scefg bKjvxU+RmuTuDsOpVe+H+zMme67m2k+4Y3vKxvpbQeveZgYBBje4zNXR4ZA97PN5Y6XXdm 4DsawAlMU/z3brTcj5N13lFQQmMh0x5HRwVgJ4u5l1JoOgiDGk6YlME1OwIznHjLDhp5p/ IuCMi/iCYe2TiycTPpwkGTh8Q4CUkQ1/qYmJ98HZFa5azjuOO1OWB9tzane9IbXa6pOHd8 mqBWtPQo4DPLtK2/fzS+wks+vzjo0DcDqkm5KGOJ+fVBKCAmJnbp71foR+5K/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1671845547; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: dkim-signature; bh=DA5rdkABGxhGB+p83NGdT4vAj70RTlCrWQ8wHrMEUuw=; b=ci3JU+WFcuM7RDLr4wz4uPlvdRUzMN4oPrCE2sCZq7ox4kwU3XosiuCKdN/xpIEuiVpkJD x2lCjur08nO5jDqj2oUE6gJ/CXyV4ekrbZ/sfvpVWmTGY9X98H7McJqpU/4mQmKbMlEoG5 X6RAdcFCh/o4MyQx+j+dnFGBHpDgc9AOFJVJJ/+lZE/6Xc0C2lzF63ylURRTACjyFAzdqm 8Lz8ifHyLJFMxDFfD9c0u2JaJLNwlFRc5EJAMwcbx2d1fdvHDf3tS+dt4WDopxHDB+Z/bt EtpZ9UIr11OQ/a/Xkqgg2na61PNB0JU37wAN6WJRm+d89fwOVMV3pYFBPm2COg== ARC-Authentication-Results: i=1; rspamd-896578cf5-pn9t4; auth=pass smtp.auth=a2hosting smtp.mailfrom=pedz@easesoftware.com X-Sender-Id: a2hosting|x-authuser|pedz+easesoftware.com@mi3-ss4.a2hosting.com X-MC-Relay: Neutral X-MailChannels-SenderId: a2hosting|x-authuser|pedz+easesoftware.com@mi3-ss4.a2hosting.com X-MailChannels-Auth-Id: a2hosting X-Bubble-Shoe: 637b641f4822caed_1671845551765_39909602 X-MC-Loop-Signature: 1671845551765:3854851620 X-MC-Ingress-Time: 1671845551764 Original-Received: from mi3-ss4.a2hosting.com (mi3-ss4.a2hosting.com [68.66.200.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.116.179.68 (trex/6.7.1); Sat, 24 Dec 2022 01:32:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=easesoftware.com; s=default; h=To:Date:Message-Id:Subject:Mime-Version: Content-Type:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=DA5rdkABGxhGB+p83NGdT4vAj70RTlCrWQ8wHrMEUuw=; b=Hq8TG60J2x8tUE+e6bzLHhhYOm sBlMnHADJxJxorlDKJemGn2l0AIZvAaT6HwDgwpU4POjHmQsxpdfc4WqP4lMBPBwl+uVXkNLiJ46n tJmj4I+YFDRgEnKDclil/+y+2s5eax19ielh7k3TAC3RgwmNlSfenMs8wGRIWiSxu8DN9HxoGQaIk nmGDNKKsJSCIZSwItosRpgoEMY6SB7h7vCa5sVHIJZAngQyOnyUSHM8pl0btitl2RllrnxJ6f+pBm s9NDxP4OBf7YluayszcmdNHs3ZKozDMd95jTqO8g5aUx8KDQT/ZGuU6OIVaE74IV3HNGw9C+/vupn +rvqrW0A==; Original-Received: from cpe-70-94-128-193.satx.res.rr.com ([70.94.128.193]:52110 helo=smtpclient.apple) by mi3-ss4.a2hosting.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1p8tOk-00BfLZ-I3 for emacs-devel@gnu.org; Fri, 23 Dec 2022 20:32:26 -0500 X-Mailer: Apple Mail (2.3731.200.110.1.12) X-AuthUser: pedz+easesoftware.com@mi3-ss4.a2hosting.com Received-SPF: pass client-ip=23.83.209.30; envelope-from=pedz@easesoftware.com; helo=caracal.birch.relay.mailchannels.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:301821 Archived-At: --Apple-Mail=_C5BDC17A-D662-4306-B9A6-2B8F0E3AF3A0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii I've seen on this list talk about "adding" Tree Sitter concepts to such things as mark-defun and other existing Emacs commands. I've just spent a few days writing rtsn-mark-method that I intend on adding to ruby-ts-mode which implements all the features of mark-defun but I did it from scratch. This is mostly out of ignorance on how to leverage existing Emacs features and facilities. One more concrete reason is mark-defun will include the comments before the defun. I wanted the same for mark-method but (as far as I can tell) the hooks back into mark-defun and its associated routines are simple regular expressions and that, to me, walks away form the power that Tree Sitter is providing. I've got rtsn-mark-method working but I plan to rework it over the next few days. The "arg" as well as the "interactive" features of mark-defun which I also put into rtsn-mark-method I believe can be pulled out to a wrapper routine. There is actually quite a few features in the code that I did not know about. For example, if mark-defun is called with -1 (or -N) it marks N back. Ok. But now if it is called again with no argument, mark-defun knows to go backwards to add in the previous defun. The same is true in the forward direction as well. (Although it does have a subtle bug in my opinion but I digress.) To repeat myself, I believe these higher level features could be separated into a wrapper function so that all that would be needed for the language specific piece is a routine that would be passed a point and a direction. I'll call this the "primitive routine". The routine would be responsible for returning a beginning and end (in a cons cell) and it would be the routine's responsibility to make sure that the beginning and end lie after (in the forward case) or before (in the backward case) the point that is passed in. The wrapper routine would then know how to properly adjust the mark and point, execute counts, add to regions, catch errors, etc. Broadening the picture: navigation, transpose, and other Emacs commands could likewise call the same primitive routine to provide transpose-method, forward-method, etc. And, broadening the picture once more: primitive routines could be written not just for methods (defun) but also for statements, arguments, expressions, classes, etc. In all cases, the primitive routine would be relatively simple. It would be given a point and return a ( begin . end ) cons cell leaving all the harder work of expanding the region, remembering the direction, etc to the wrapper routines. To be clear, there would be a wrapper routine for mark, a wrapper for forward, transpose, etc. We would end up with the classic: For A + B number of routines we would have A x B number of commands. Does this strike others as a good idea or insanity? Perry --Apple-Mail=_C5BDC17A-D662-4306-B9A6-2B8F0E3AF3A0 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEE5yOa/gCtQpb3oCpljxzk9yzE+MAFAmOmVp0ACgkQjxzk9yzE +MDktRAA0W0koyxkS+nmaf03IXiplHhWA2oSr+Zdn5vRHI7RAm0NoRLUJ9tgychN qhQU8ryT1eN3aCv2P1z9AtH9myLsACRjCDFKLIh4i9LjhgABR74H4qexzM3yuLgE cMo4M215lXRj9ZLUjIT4GJbOJ1z/QwRmmXehIksDYQOIhGggJnAwjboaa06u0A0F JxH+OWurNZc/UpNaZiY66v0schS+BRkH/OeDWXusgb65reMHXsnOlOVMU47OaWyW NIfQxNLZ13gCi+15aYXOeSpeRiqS6eSKFcGzb2WzhM7tMh72UoiIjDWdowWkIC1E kBqE1W62vxrp4GTUCWhenErb/cCO/FcpItFOowMLY56cDP1osR/yBWWe9YAJ9d9U mF4kQuBoBK8KXVplrHFFZhKLeMJiNhuwDFdAjqIgYAzx5doP4pEnrGYn1qRLDJpx +Vp6zz5isGaN8g6FA6KRLHlT0pXjJsq3eoCS4RKlEJYlgr3gURo2b7OMSI1Cm5eH BjYVy93GSakU6O+z8EIXlsPzsHWgUjotG4+EvpCjLpVUgKG2E+0VqziVHVWIEPDB Cn0bZEQ6kS9MPYBB1fOnsOTyjZVmTl8NENx1IGkmHxnoh1xrDXP5Nwn0lSNQ6uGi vbeHebEyUHHwX6nxbbZ2uAoOIOYcpfpI5rqklJmeUgHwHHOWg+A= =S6Vv -----END PGP SIGNATURE----- --Apple-Mail=_C5BDC17A-D662-4306-B9A6-2B8F0E3AF3A0--