[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/tree-sitter f17ca55a0a 2/2: Remove treesit-settings
From: |
Yuan Fu |
Subject: |
feature/tree-sitter f17ca55a0a 2/2: Remove treesit-settings |
Date: |
Sat, 19 Nov 2022 21:55:18 -0500 (EST) |
branch: feature/tree-sitter
commit f17ca55a0a3c9de1061285763cbf0bd3754f6718
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Remove treesit-settings
Remove it since we are using separate major modes for tree-sitter and
native variant now.
* doc/lispref/parsing.texi (Tree-sitter major modes): Update manual.
* lisp/treesit.el (treesit-settings): Remove option.
(treesit--setting-for-mode): Remove function.
(treesit-ready-p): Don't check for user preference in treesit-settings.
---
doc/lispref/parsing.texi | 22 +++-----
lisp/treesit.el | 134 +++++++++++------------------------------------
2 files changed, 40 insertions(+), 116 deletions(-)
diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi
index 6a23b0feb3..bea358f2b0 100644
--- a/doc/lispref/parsing.texi
+++ b/doc/lispref/parsing.texi
@@ -1661,6 +1661,7 @@ integration for a major mode.
A major mode supporting tree-sitter features should roughly follow
this pattern:
+@c FIXME: Update this part once we settle on the exact format.
@example
@group
(define-derived-mode woomy-mode prog-mode "Woomy"
@@ -1679,26 +1680,19 @@ this pattern:
@end example
First, the major mode should use @code{treesit-ready-p} to determine
-whether the user wants to activate tree-sitter features for the mode,
-and whether tree-sitter can be activated in this mode.
+whether tree-sitter can be activated in this mode.
@defun treesit-ready-p mode language &optional quiet
This function checks for conditions for activating tree-sitter. It
-checks whether the user turned on tree-sitter for @var{mode}
-(according to @code{treesit-settings}), whether Emacs was built with
-tree-sitter, whether the buffer's size is not too large for
-tree-sitter to handle it, and whether the language definition for
-@var{language} is available on the system (@pxref{Language
-Definitions}).
-
-When the user sets @var{mode} to @var{demand} in @code{treesit-settings},
-this function emits a warning if tree-sitter cannot be activated. If
+checks whether Emacs was built with tree-sitter, whether the buffer's
+size is not too large for tree-sitter to handle it, and whether the
+language definition for @var{language} is available on the system
+(@pxref{Language Definitions}).
+
+This function emits a warning if tree-sitter cannot be activated. If
@var{quiet} is @code{message}, the warning is turned into a message;
if @var{quiet} is @code{nil}, no warning or message is displayed.
-If @var{mode} is nil, this function doesn't check user's preference in
-@code{treesit-settings}.
-
If all the necessary conditions are met, this function returns
non-@code{nil}; otherwise it returns @code{nil}.
@end defun
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 0c98d3167d..76cefbbaf3 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -99,35 +99,6 @@ indent, imenu, etc."
:type 'integer
:version "29.1")
-(defcustom treesit-settings '((t nil t))
- "Tree-sitter toggle settings for major modes.
-
-A list of (MODE ACTIVATE INHERIT) where MODE is a major mode, and
-ACTIVATE can be one of the following:
-
- `demand' Demand the use of tree-sitter, and warn if it can't
- be activated.
- t Enable tree-sitter if it is available.
- nil Don't enable tree-sitter.
-
-If INHERIT is t, the setting for MODE is inherited by all its
-derived modes. For a derived mode, closer ancestor mode's
-setting takes higher precedence.
-
-A special MODE, t, is considered the ancestor of every mode, and
-its INHERIT flag is ignored."
- :type '(repeat
- (list :tag "Setting"
- (symbol :tag "Mode")
- (choice :tag "Activate"
- (const :tag "No" nil)
- (const :tag "Yes" t)
- (const :tag "Demand" demand))
- (choice :tag "Inherit"
- (const :tag "Yes" t)
- (const :tag "No" nil))))
- :version "29.1")
-
;;; Parser API supplement
(defun treesit-parse-string (string language)
@@ -1485,89 +1456,48 @@ to `imenu-create-index-function'.")
;;; Activating tree-sitter
-(defun treesit--setting-for-mode (mode settings)
- "Get the setting for MODE in SETTINGS.
-MODE is a major mode symbol. SETTINGS should be `treesit-settings'."
- ;; A setting for exactly this MODE. The shape is (FLAG INHERIT).
- (let ((self (alist-get mode settings))
- ;; Fallback setting, shape is (FLAG INHERIT).
- (fallback (alist-get t settings))
- ;; Settings for ancestor modes of MODE. Its shape is
- ;; ((MODE . FLAG)...)
- (applicable (cl-loop for setting in settings
- for m = (nth 0 setting)
- for flag = (nth 1 setting)
- for inherit = (nth 2 setting)
- if (and (not (eq m t))
- (not (eq m mode))
- inherit
- (provided-mode-derived-p mode m))
- collect (cons m flag))))
- (cond
- (self (car self))
- ((null applicable) (car fallback))
- (t
- ;; After sort, the most specific setting is at the top.
- (setq applicable
- (cl-sort applicable
- (lambda (a b)
- ;; Major mode inheritance has a total ordering
- ;; right?
- (provided-mode-derived-p (car a) (car b)))))
- (cdar applicable)))))
-
-(defun treesit-ready-p (mode language &optional quiet)
+(defun treesit-ready-p (language &optional quiet)
"Check whether tree-sitter is ready to be used for MODE and LANGUAGE.
LANGUAGE is the language symbol to check for availability.
It can also be a list of language symbols.
-This function checks the user setting in `treesit-settings'. If the
-user has set `demand' for MODE, and tree-sitter is not ready, emit a
-warning and return nil. If the user has chosen to activate tree-sitter
-for MODE and tree-sitter is ready, return non-nil. If QUIET is t, don't
-emit warning in either case; if quiet is `message', display a message
-instead of emitting warning.
-
-If MODE is nil, don't check for user setting and assume the
-setting is t."
+If tree-sitter is not ready, emit a warning and return nil. If
+the user has chosen to activate tree-sitter for MODE and
+tree-sitter is ready, return non-nil. If QUIET is t, don't emit
+warning in either case; if quiet is `message', display a message
+instead of emitting warning."
(let ((language-list (if (consp language)
language
(list language)))
- (activate (if mode
- (treesit--setting-for-mode mode treesit-settings)
- t))
msg)
;; Check for each condition and set MSG.
- (if (null activate)
- nil
- (catch 'term
- (when (not (treesit-available-p))
- (setq msg "tree-sitter library is not compiled with Emacs")
- (throw 'term nil))
- (when (> (buffer-size) treesit-max-buffer-size)
- (setq msg "buffer larger than `treesit-max-buffer-size'")
- (throw 'term nil))
- (dolist (lang language-list)
- (pcase-let ((`(,available . ,err)
- (treesit-language-available-p lang t)))
- (when (not available)
- (setq msg (format "language definition for %s is unavailable
(%s): %s"
- lang (nth 0 err)
- (string-join
- (mapcar (lambda (x) (format "%s" x))
- (cdr err))
- " ")))
- (throw 'term nil)))))
- ;; Decide if all conditions met and whether emit a warning.
- (if (not msg)
- t
- (when (eq activate 'demand)
- (setq msg (concat "Cannot activate tree-sitter, because " msg))
- (pcase quiet
- ('nil (display-warning 'treesit msg))
- ('message (message "%s" msg))))
- nil))))
+ (catch 'term
+ (when (not (treesit-available-p))
+ (setq msg "tree-sitter library is not compiled with Emacs")
+ (throw 'term nil))
+ (when (> (buffer-size) treesit-max-buffer-size)
+ (setq msg "buffer larger than `treesit-max-buffer-size'")
+ (throw 'term nil))
+ (dolist (lang language-list)
+ (pcase-let ((`(,available . ,err)
+ (treesit-language-available-p lang t)))
+ (when (not available)
+ (setq msg (format "language definition for %s is unavailable (%s):
%s"
+ lang (nth 0 err)
+ (string-join
+ (mapcar (lambda (x) (format "%s" x))
+ (cdr err))
+ " ")))
+ (throw 'term nil)))))
+ ;; Decide if all conditions met and whether emit a warning.
+ (if (not msg)
+ t
+ (setq msg (concat "Cannot activate tree-sitter, because " msg))
+ (pcase quiet
+ ('nil (display-warning 'treesit msg))
+ ('message (message "%s" msg)))
+ nil)))
(defun treesit-major-mode-setup ()
"Activate tree-sitter to power major-mode features.