all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Ship Mints <shipmints@gmail.com>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>,
	Eli Zaretskii <eliz@gnu.org>,
	Vincenzo Pupillo <v.pupillo@gmail.com>,
	Emacs Devel <emacs-devel@gnu.org>,
	Stefan Kangas <stefankangas@gmail.com>,
	Dmitry Gutov <dmitry@gutov.dev>
Subject: Re: Tree-sitter central configuration variable
Date: Mon, 2 Dec 2024 22:40:56 -0800	[thread overview]
Message-ID: <DB185D61-13AB-4D2E-B951-CDEEC1498FB9@gmail.com> (raw)
In-Reply-To: <CAN+1Hbruy11_mmeW3fwgk2WoSZHQES7qxcjQSStQaOPhxu8A+g@mail.gmail.com>



> On Nov 29, 2024, at 9:22 AM, Ship Mints <shipmints@gmail.com> wrote:
> 
> Chiming in with my minor voice. I prefer my mode configurations generally self contained and not centralized as a single global configuration variable would encourage. When I share my configurations with others, it also suggests that if they adopt a global configuration variable on top of what I share, it will introduce subtle changes in behavior that I may not at first understand the source of when helping others. I definitely prefer proper lisp over an opaque configuration variable.
> 
> -Stephane
> 
> On Fri, Nov 29, 2024 at 12:04 PM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> > Since Emacs 29, I see many people ask about how to configure
> > tree-sitter modes by setting some variable.
> 
> This is not specific to tree-sitter.
> 
> > It seems that people much prefer setting a variable than adding
> > a major mode hook that calls some functions.
> 
> But that boxes them into the subset of possibilities that have been
> pre-imagined by those who designed the set of variables.
> 
> > What do you guys think about something like this:
> >
> > (setq treesit-global-configuration
> >       '((c-ts-mode
> >          ;; Set treesit-font-lock-level to 4
> >          (font-lock-level . 4)
> >          ;; Disable tree-sitter’s outline support
> >          (outline . disable)
> >          ;; Enable these features on top of the default ones.
> >          (font-lock-enable . (function property variable))
> >          ;; Disable these features.
> >          (font-lock-disable . (definition))
> >          ;; Add extra font-lock rules
> >          (font-lock-extra-rules
> >           ( :feature 'my-rules
> >             :language 'c
> >             ((some_query) @some-face)))
> >          (simple-indent-extra-rules
> >           (c
> >            (matcher anchor offset))
> >           (d
> >            (matcher anchor offset)))
> >          )))
> 
> Sounds to me like this is inventing a new programming language, just one
> that's a lot more restrictive than ELisp.
> 
> Is it really better than ELisp which could look like:
> 
>     (add-hook 'c-ts-mode-hook #'my-c-ts-mode-preferences)
>     (defun my-c-ts-mode-preferences ()
>       (setq-local treesit-font-lock-level 4)
>       (treesit-outline-mode -1)
>       (treesit-font-lock-enable '(function property variable))
>       (treesit-font-lock-disable '(definition))
>       (treesit-font-lock-add-rules
>        '( :feature 'my-rules
>           :language 'c
>           ((some_query) @some-face)))
>       (treesit-indent-add-rules
>        '((c
>           (matcher anchor offset))
>          (d
>           (matcher anchor offset)))
>       ))
> 
> Admittedly, the add-hook/defun dance could be improved, and that would
> benefit more than just tree-sitter.  E.g. a new macro like
> 
>     (defmacro custom-set-hook (hook &rest body)
>       (declare (indent 1) (debug (sexp def-body)))
>       (let ((funname (intern (format "custom-set-hook--%s" hook))))
>         `(progn (add-hook ',hook #',funnmame)
>                 (defun ,funname () ,@body))))
> 
> > One thing I don’t like is how it handles languages. In this POC
> > language-specific settings are nested under the mode. I’m ok with
> > mode-language hierarchy, but the nesting adds a lot of nesting levels
> > to the variable.  And the language nesting isn’t consistent, some
> > settings have language nesting, some don’t.
> 
> I don't really understand what you're referring to, but for
> `treesit-font-lock-add-rules` would could try and auto-add the `:language`?
> 
> 
>         Stefan
> 
> 

It seems that we’re getting a resounding no here, so I’m gonna drop this :) On a side note, I was planning to add a convenience function for adding font-lock rules, so users don’t need to do the append dance. Turns out I’ve already written one but then forgot about it :)

Maybe what we really need is a good guide/manual section on installing and configuring tree-sitter major modes. I wrote a detailed guide for writing tree-sitter major modes, but didn’t write one for installing and configuring tree-sitter major modes.

Yuan


  reply	other threads:[~2024-12-03  6:40 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-07 10:30 Define treesit-font-lock-level as buffer local Vincenzo Pupillo
2024-11-07 11:03 ` Eli Zaretskii
2024-11-07 11:08   ` Vincenzo Pupillo
2024-11-09  8:36     ` Yuan Fu
2024-11-09  8:54       ` Eli Zaretskii
2024-11-10  8:04         ` Yuan Fu
2024-11-23 12:20           ` Eli Zaretskii
2024-11-29  5:49             ` Tree-sitter central configuration variable Yuan Fu
2024-11-29  7:12               ` Eshel Yaron
2024-11-29  8:42                 ` Yuan Fu
2024-11-29  8:04               ` Eli Zaretskii
2024-11-29  9:07                 ` Yuan Fu
2024-11-29 12:02                   ` Eli Zaretskii
2024-11-29 17:01               ` Stefan Monnier
2024-11-29 17:22                 ` Ship Mints
2024-12-03  6:40                   ` Yuan Fu [this message]
2024-12-03 13:14                     ` Eli Zaretskii
2024-12-07 12:04             ` Define treesit-font-lock-level as buffer local Eli Zaretskii
2024-12-08  7:44               ` Yuan Fu
2024-12-14 11:14                 ` Vincenzo Pupillo
2024-12-17 11:31                   ` Vincenzo Pupillo
2024-12-17 21:37                     ` Yuan Fu

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DB185D61-13AB-4D2E-B951-CDEEC1498FB9@gmail.com \
    --to=casouri@gmail.com \
    --cc=dmitry@gutov.dev \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=shipmints@gmail.com \
    --cc=stefankangas@gmail.com \
    --cc=v.pupillo@gmail.com \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.