unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Phil Sainty <psainty@orcon.net.nz>
To: emacs-devel@gnu.org
Cc: dgutov@yandex.ru, mardani29@yahoo.es
Subject: Re: Tree sitter: Should *-ts-modes derive from a common base?
Date: Thu, 23 Mar 2023 21:50:08 +1300	[thread overview]
Message-ID: <1a6475dc05e83cf0d7721cc9d0548f62@webmail.orcon.net.nz> (raw)
In-Reply-To: <fff8b2192f0fc9cdae233acd54f8faed@webmail.orcon.net.nz>

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




      parent reply	other threads:[~2023-03-23  8:50 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
2023-03-23  8:50 ` Phil Sainty [this message]

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=1a6475dc05e83cf0d7721cc9d0548f62@webmail.orcon.net.nz \
    --to=psainty@orcon.net.nz \
    --cc=dgutov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    --cc=mardani29@yahoo.es \
    /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).