Skip to content

Commit

Permalink
2 bug fix (#10)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
norris-young authored Jun 28, 2024
1 parent 14e3f13 commit 41c13ff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion treesit-fold-indicators.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions treesit-fold.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 41c13ff

Please sign in to comment.