emacs-diffs
[Top][All Lists]
Advanced

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

feature/tree-sitter a23aec59b3 3/3: Remove treesit-disabled-modes and ch


From: Yuan Fu
Subject: feature/tree-sitter a23aec59b3 3/3: Remove treesit-disabled-modes and change treesit-should-enable-p
Date: Wed, 7 Sep 2022 19:12:59 -0400 (EDT)

branch: feature/tree-sitter
commit a23aec59b3a6ed2e96a89dab18f51a6310f1ac7c
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Remove treesit-disabled-modes and change treesit-should-enable-p
    
    Per emacs-devel discussion, remove treesit-disabled-modes and let
    major modes to provide tree-sitter switches.  I also decided to add
    treesit-max-buffer-size to elisp manual despite it being a user
    option.  Though we should still add it to the user manual.
    
    * doc/lispref/parsing.texi (Parsing Program Source): Update manual to
    remove entries for treesit-diabled-modes and add
    treesit-max-buffer-size.  Also update treesit-should-enable-p.
    * lisp/treesit.el (treesit-disabled-modes): Remove user option.
    (treesit-maximum-size): Change to treesit-max-buffer-size.
    (treesit-should-enable-p): Change to treesit-can-enable-p and remove
    checks of treesit-disabled-modes.
---
 doc/lispref/parsing.texi | 24 +++++++++++++++---------
 lisp/treesit.el          | 27 +++++++--------------------
 2 files changed, 22 insertions(+), 29 deletions(-)

diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi
index 6d5c7b8dc2..7777ce9360 100644
--- a/doc/lispref/parsing.texi
+++ b/doc/lispref/parsing.texi
@@ -26,8 +26,21 @@ This function returns non-nil if tree-sitter features are 
available
 for this Emacs instance.
 @end defun
 
-For using tree-sitter features in font-lock and indentation,
-@pxref{Parser-based Font Lock}, @pxref{Parser-based Indentation}.
+@defvar treesit-max-buffer-size
+This variable contains the maximum size of buffers in which
+tree-sitter can be activated.  Major modes should check this value
+when deciding whether to enable tree-sitter features.
+@end defvar
+
+@defun treesit-can-enable-p
+This function checks whether the current buffer is suitable for
+activating tree-sitter features.  It basically checks
+@code{treesit-available-p} and @var{treesit-max-buffer-size}.
+@end defun
+
+For tree-sitter integration with existing Emacs features,
+@pxref{Parser-based Font Lock}, @ref{Parser-based Indentation}, and
+@ref{List Motion}.
 
 To access the syntax tree of the text in a buffer, we need to first
 load a language definition and create a parser with it.  Next, we can
@@ -321,13 +334,6 @@ parser.  In Emacs, each tree-sitter parser is associated 
with a
 buffer.  As we edit the buffer, the associated parser is automatically
 kept up-to-date.
 
-@defvar treesit-disabled-modes
-Before creating a parser, it is perhaps good to check whether we
-should use tree-sitter at all.  Sometimes a user don't want to use
-tree-sitter features for a major mode.  To turn-off tree-sitter for a
-mode, they add that mode to this variable.
-@end defvar
-
 @defvar treesit-maximum-size
 If users want to turn off tree-sitter for buffers larger than a
 particular size (because tree-sitter consumes memory ~10 times the
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 9c66f32ec2..83d80ac6da 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -35,11 +35,7 @@
   "Tree-sitter is an incremental parser."
   :group 'tools)
 
-(defcustom treesit-disabled-modes nil
-  "A list of major-modes for which tree-sitter support is disabled."
-  :type '(list symbol))
-
-(defcustom treesit-maximum-size (* 4 1024 1024)
+(defcustom treesit-max-buffer-size (* 4 1024 1024)
   "Maximum buffer size for enabling tree-sitter parsing."
   :type 'integer)
 
@@ -47,21 +43,12 @@
   "Return non-nil if tree-sitter features are available."
   (fboundp 'treesit-parser-create))
 
-(defun treesit-should-enable-p (&optional mode)
-  "Return non-nil if MODE should activate tree-sitter support.
-MODE defaults to the value of `major-mode'.  The result depends
-on the value of `treesit-disabled-modes',
-`treesit-maximum-size', and of course, whether tree-sitter is
-available on the system at all."
-  (let* ((mode (or mode major-mode))
-         (disabled (cl-loop
-                    for disabled-mode in treesit-disabled-modes
-                    if (provided-mode-derived-p mode disabled-mode)
-                    return t
-                    finally return nil)))
-    (and (treesit-available-p)
-         (not disabled)
-         (< (buffer-size) treesit-maximum-size))))
+(defun treesit-can-enable-p ()
+  "Return non-nil if current buffer can activate tree-sitter.
+Currently this function checks whether tree-sitter is available
+and the buffer size."
+  (and (treesit-available-p)
+       (< (buffer-size) treesit-maximum-size)))
 
 ;;; Parser API supplement
 



reply via email to

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