From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Phil Sainty Newsgroups: gmane.emacs.devel Subject: Re: Tree sitter: Should *-ts-modes derive from a common =?UTF-8?Q?base=3F?= Date: Thu, 23 Mar 2023 21:50:08 +1300 Message-ID: <1a6475dc05e83cf0d7721cc9d0548f62@webmail.orcon.net.nz> References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31934"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Orcon Webmail Cc: dgutov@yandex.ru, mardani29@yahoo.es To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Mar 23 10:37:36 2023 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 1pfHO4-000833-6X for ged-emacs-devel@m.gmane-mx.org; Thu, 23 Mar 2023 10:37:36 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pfHN9-00083H-IX; Thu, 23 Mar 2023 05:36:40 -0400 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 1pfGeL-0002U2-8I for emacs-devel@gnu.org; Thu, 23 Mar 2023 04:50:21 -0400 Original-Received: from smtp-3.orcon.net.nz ([60.234.4.44]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pfGeJ-0004DD-FC for emacs-devel@gnu.org; Thu, 23 Mar 2023 04:50:20 -0400 Original-Received: from [10.253.37.70] (port=22025 helo=webmail.orcon.net.nz) by smtp-3.orcon.net.nz with esmtpa (Exim 4.90_1) (envelope-from ) id 1pfGe8-0002D3-QX; Thu, 23 Mar 2023 21:50:09 +1300 Original-Received: from ip-180-148-124-51.kinect.net.nz ([180.148.124.51]) via [10.253.37.253] by webmail.orcon.net.nz with HTTP (HTTP/1.1 POST); Thu, 23 Mar 2023 21:50:08 +1300 In-Reply-To: X-Sender: psainty@orcon.net.nz X-GeoIP: -- Received-SPF: pass client-ip=60.234.4.44; envelope-from=psainty@orcon.net.nz; helo=smtp-3.orcon.net.nz 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 23 Mar 2023 05:36:37 -0400 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:304735 Archived-At: Dmitry Gutov wrote: > > (define-derived-mode css-base-mode prog-mode "CSS" > > (define-derived-mode css-mode css-base-mode "CSS" > > (define-derived-mode css-ts-mode css-base-mode "CSS" > > > > That could be refactored if this idea was a sensible one. > > How would you refactor it? We don't have multiple inheritance. My thought was simply to remove css-base-mode (which looks to have been added solely for the new css-mode/css-ts-mode split and is only being used for its body) and instead simply have css-ts-mode and css-mode both directly call a common function in their own body. > There's been a bunch of discussions on the bug tracker, and at > least one where the participants landed on the xxx-base-mode > design. I don't have the bug number at hand, though. Right, I figured it would have come up. I'll happily defer to conclusions made by people who've thought about this more. Daniel Martín wrote: > some major modes offer Tree-sitter functionality without introducing > a specific new Tree-sitter-based major mode, so having a common > inheritance wouldn't help here, I think. Ah, ok. Yes, agreed. > Aren't (treesit-parser-list BUFFER) and (treesit-parser-language > PARSER) the best ways to check if Tree-sitter can be used in a > particular buffer, for a particular language? I'll take your word for it. The stackexchange user I mentioned initially has done something slightly different: (defun treesit-enabled-p () "Checks if the current buffer has a treesit parser." (and (fboundp 'treesit-available-p) (treesit-available-p) (treesit-language-at (point)))) ( https://emacs.stackexchange.com/questions/76400 ) However using treesit-language-at or treesit-parser-language doesn't seem much less cumbersome -- they're not defined in my build of Emacs 29 (without tree-sitter support), so the fboundp is still needed at minimum. If that's the best we have right now, perhaps a standard predicate should be added for this. -Phil