branch: elpa/treesit-fold
commit 41c13ff0e24b8c382f455db5c78d8c7b9b8c95a4
Author: norris <[email protected]>
Commit: GitHub <[email protected]>

    2 bug fix (#10)
    
    * fix: call treesit-fold-mode only when treesit-fold-ready-p
    
    If `treesit-fold-ready-p` is false, `(treesit-fold-mode -1)` will get an
    error since it will call `treesit-fold-open-all`.
    
    * fix: Ignore errors for the filter when indicators refresh
    
    When the buffer is being edited, the node might change and become
    invalid which will cause errors. And these errors should be ignored or
    they will infect other post command hooks.
---
 treesit-fold-indicators.el | 3 ++-
 treesit-fold.el            | 7 ++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/treesit-fold-indicators.el b/treesit-fold-indicators.el
index 379c311f6c..ebd032f6d7 100644
--- a/treesit-fold-indicators.el
+++ b/treesit-fold-indicators.el
@@ -353,7 +353,8 @@ Optional arguments WEND and WSTART are the range for 
caching."
           (wstart (window-start))
           (nodes-to-fold
            (cl-remove-if-not (lambda (node)
-                               (treesit-fold-indicators--within-window (cdr 
node) wend wstart))
+                               (ignore-errors
+                                 (treesit-fold-indicators--within-window (cdr 
node) wend wstart)))
                              nodes-to-fold))
           (mode-ranges (alist-get major-mode treesit-fold-range-alist))
           (nodes-to-fold
diff --git a/treesit-fold.el b/treesit-fold.el
index fd3c40e660..e063f3eca1 100644
--- a/treesit-fold.el
+++ b/treesit-fold.el
@@ -292,9 +292,10 @@ For example, Lua, Ruby, etc."
 
 (defun treesit-fold--trigger ()
   "Toggle `treesit-fold-mode' when the current mode is treesit-fold 
compatible."
-  (if (and (treesit-fold-ready-p) (treesit-fold-usable-mode-p))
-      (treesit-fold-mode 1)
-    (treesit-fold-mode -1)))
+  (when (treesit-fold-ready-p)
+    (if (treesit-fold-usable-mode-p)
+        (treesit-fold-mode 1)
+      (treesit-fold-mode -1))))
 
 ;;;###autoload
 (define-minor-mode treesit-fold-mode

Reply via email to