From: "Daniel Martín" <mardani29@yahoo.es>
To: Phil Sainty <psainty@orcon.net.nz>
Cc: emacs-devel@gnu.org
Subject: Re: Tree sitter: Should *-ts-modes derive from a common base?
Date: Wed, 22 Mar 2023 11:07:02 +0100 [thread overview]
Message-ID: <m1lejp9k1l.fsf@yahoo.es> (raw)
In-Reply-To: <fff8b2192f0fc9cdae233acd54f8faed@webmail.orcon.net.nz> (Phil Sainty's message of "Tue, 21 Mar 2023 22:30:52 +1300")
Phil Sainty <psainty@orcon.net.nz> writes:
> WRT
> https://emacs.stackexchange.com/questions/76400/how-do-i-check-if-the-current-buffer-has-a-treesit-parser
>
> I wondered whether derived-mode-p could conveniently establish
> some kind of base ts-mode, but that doesn't appear to be the case
> (or at least not for the examples I looked at).
>
> I was pondering something like this:
>
> (define-derived-mode prog-ts-mode prog-mode "Prog(TS)"
> "Major mode for editing source code with tree-sitter support.")
>
> And then all the *-ts-mode derivatives of prog-mode changed like so:
>
> - (define-derived-mode cmake-ts-mode prog-mode "CMake"
> + (define-derived-mode cmake-ts-mode prog-ts-mode "CMake"
>
> The case I've spotted thus far which wouldn't work is the CSS modes,
> where we have this:
>
> (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"
>
Adding a common Tree-sitter base mode might be useful for some use cases
we'd need to describe in more detail, but I don't think it's the best
solution for the problem of checking if a Tree-sitter parser is
available or not. For example, 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.
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?
next prev parent reply other threads:[~2023-03-22 10:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-21 9:30 Tree sitter: Should *-ts-modes derive from a common base? Phil Sainty
2023-03-22 7:32 ` Dmitry Gutov
2023-03-25 9:16 ` João Távora
2023-03-22 10:07 ` Daniel Martín [this message]
2023-03-23 8:50 ` Phil Sainty
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1lejp9k1l.fsf@yahoo.es \
--to=mardani29@yahoo.es \
--cc=emacs-devel@gnu.org \
--cc=psainty@orcon.net.nz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).