emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Average-user-facing interface for tree-sitter


From: Yuan Fu
Subject: Average-user-facing interface for tree-sitter
Date: Tue, 11 Oct 2022 23:11:27 -0700

From the suggestions I collected from the old thread, here is my proposal:

We define a custom option treesit-settings (we can discuss the name later), which controls whether to enable/disable tree-sitter for each major mode, and the default preference, like this:

(defcustom treesit-settings '((t nil nil))
  "Tree-sitter toggles for major modes.

A list of (MODE ENABLE INHERIT).  MODE is a major mode, ENABLE
can be one of the following:

  demand => Demand the use of tree-sitter, warn if can't enable.
  t => Enable if available
  nil => Don't enable

If INHERIT is nil, the setting does't apply to derived modes of
MODE, if t, the setting does apply.

If MODE is t, the settings applies to all the modes which don't
have any setting.  INHERIT doesn't matter for this special
default setting."
  :type …)

I added the INHERIT flag because I had bad experience trying to enable eglot for python-mode but not for sage-mode, which derives from python-mode.

Then a major mode can just use (treesit-enable-p ‘python-mode ‘python) to check whether to use tree-sitter, this function checks that:
- tree-sitter is built with Emacs
- buffer size is within limit
- language definition is available
- tree-sitter is enabled for this mode according to treesit-settings

This function raises warnings w/ explanation if the user sets ‘demand for the mode and we can’t enable tree-sitter.

I attached a screenshot of treesit-settings in (my) Customize. This should be easy to use and understand for any average user (right?)

Yuan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]