From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill Newsgroups: gmane.emacs.devel Subject: Re: Tree-sitter api Date: Sat, 07 Aug 2021 20:40:34 +0200 Message-ID: References: <83r1f7hydn.fsf@gnu.org> <95F37923-5BF9-4D81-B361-267CF119FBCA@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34274"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , cpitclaudel@gmail.com, stephen_leake@stephe-leake.org, emacs-devel@gnu.org To: Stefan Monnier , Fu Yuan Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Aug 07 20:41:41 2021 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 1mCRGO-0008gj-4a for ged-emacs-devel@m.gmane-mx.org; Sat, 07 Aug 2021 20:41:41 +0200 Original-Received: from localhost ([::1]:52012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCRGM-0007WD-2x for ged-emacs-devel@m.gmane-mx.org; Sat, 07 Aug 2021 14:41:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52008) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCRFX-0006pt-8V for emacs-devel@gnu.org; Sat, 07 Aug 2021 14:40:47 -0400 Original-Received: from out1.migadu.com ([2001:41d0:2:863f::]:42042) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCRFT-00048m-QH; Sat, 07 Aug 2021 14:40:47 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1628361637; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=qzCDAn6HY3ioNMdF8tqqRqBTtzA+6hEnBjscd45pDes=; b=tkSTyN8kAiaQTntqtBOl4lLU5ISGl01HLdndNxrwUy1DuS9k5s26Npi9wOFVc97+4cbJIs zcVtvyZyFFjHjKUTUTe8WHpWSOFusjd6j3AQ8jsx8LQtnA0SJLRJadoEaKv4nigLEtnE65 l7T8Q4SoijiCI5iWQ0NI4roiRfJ05nm8vpeo2AiQMBDKgcr0fKIXQIgj1r5kVwltkzEha4 kfMW2wZjgxYuMbePHjNSkI8j4jPP+3/9EmEGW0qq9WJAZ3Ikk34B96y0Ievc9GwCT9zlzD 7LMz2Q5ibWg8uWdspT13vYT/SoN+wlJpXv3zCtZ1aIk30eh8Jmj6zO8UD5e9yw== In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: theo@thornhill.no Received-SPF: pass client-ip=2001:41d0:2:863f::; envelope-from=theo@thornhill.no; helo=out1.migadu.com 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.23 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" Xref: news.gmane.io gmane.emacs.devel:272175 Archived-At: Stefan Monnier writes: >> We should have a user option to control tree-sitter on major mode >> level. Maybe an alist where each car is a major node symbol and each cdr is >> a Boolean value toggling tree-sitter for that node. > > The more traditional approach is to use a buffer-local var set by the > major mode or set via (add-hook '-hook ...). > >> As for indentation, we could provide some infrastructure like we do for >> font-locking, or we can just let major modes implement their indent function >> with tree-sitter api. > > We should definitely provide the infrastructure (even if it's fairly > simple) so that major modes only have to provide some rules. > Yeah, though that quickly becomes not so simple, considering that different languages have their own idiosyncrasies with indentation. C#, for instance, is a rats nest of particularities. And this is not considering variations of style guides etc. It would be nice to get an api similar to what CC mode has. Font locking is an easier problem, since it's just "fontify from node-start to node-end". I'm not sure how to best provide this api, but I've worked a lot with CC mode and the new tree-sitter-indent [1]. It quickly gets confusing and reminds me of `display-buffer`. Providing both a `tree-sitter-indent-engine` mode as well as the low level api for major mode authors would be nice as well. Providing something too simple would just make people not use it, since the weirder cases won't be covered. -- Theo [1]: https://codeberg.org/FelipeLema/tree-sitter-indent.el