[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/treesit-fold 2bb351bcf3 385/417: feat: Add on fold hook
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/treesit-fold 2bb351bcf3 385/417: feat: Add on fold hook |
Date: |
Mon, 1 Jul 2024 10:03:08 -0400 (EDT) |
branch: elpa/treesit-fold
commit 2bb351bcf3f2ac1d67740102d38b6335aed2ad2e
Author: JenChieh <jcs090218@gmail.com>
Commit: JenChieh <jcs090218@gmail.com>
feat: Add on fold hook
---
treesit-fold.el | 47 +++++++++++++++++++++++++++++++----------------
1 file changed, 31 insertions(+), 16 deletions(-)
diff --git a/treesit-fold.el b/treesit-fold.el
index d4e2db61e4..4e038b5082 100644
--- a/treesit-fold.el
+++ b/treesit-fold.el
@@ -164,6 +164,11 @@ the fold in a cons cell. See
`treesit-fold-range-python-def' for an example."
:type 'hook
:group 'treesit-fold)
+(defcustom treesit-fold-on-fold-hook nil
+ "Hook runs on folding."
+ :type 'hook
+ :group 'treesit-fold)
+
(defcustom treesit-fold-on-next-line t
"If non-nil, we leave ending keywords on the next line.
@@ -380,7 +385,8 @@ If no NODE is found in point, do nothing."
(when-let* ((ov (treesit-fold-overlay-at node)))
(delete-overlay ov))
(when-let* ((range (treesit-fold--get-fold-range node)))
- (treesit-fold--create-overlay range)))))
+ (treesit-fold--create-overlay range)
+ (run-hooks 'treesit-fold-on-fold-hook)))))
;;;###autoload
(defun treesit-fold-open ()
@@ -391,6 +397,7 @@ If the current node is not folded or not foldable, do
nothing."
(when-let* ((node (treesit-fold--foldable-node-at-pos))
(ov (treesit-fold-overlay-at node)))
(delete-overlay ov)
+ (run-hooks 'treesit-fold-on-fold-hook)
t)))
;;;###autoload
@@ -403,32 +410,37 @@ If the current node is not folded or not foldable, do
nothing."
(end (tsc-node-end-position node)))
(thread-last (overlays-in beg end)
(seq-filter (lambda (ov) (eq (overlay-get ov 'invisible)
'treesit-fold)))
- (mapc #'delete-overlay)))))
+ (mapc #'delete-overlay))
+ (run-hooks 'treesit-fold-on-fold-hook))))
;;;###autoload
(defun treesit-fold-close-all ()
"Fold all foldable syntax nodes in the buffer."
(interactive)
(treesit-fold--ensure-ts
- (let* ((treesit-fold-indicators-mode)
- (node (tsc-root-node tree-sitter-tree))
- (patterns (seq-mapcat (lambda (fold-range) `((,(car fold-range))
@name))
- (alist-get major-mode
treesit-fold-range-alist)
- 'vector))
- (query (tsc-make-query tree-sitter-language patterns))
- (nodes-to-fold (tsc-query-captures query node #'ignore)))
- (thread-last nodes-to-fold
- (mapcar #'cdr)
- (mapc #'treesit-fold-close)))))
+ (let (nodes)
+ (let* ((treesit-fold-indicators-mode)
+ (treesit-fold-on-fold-hook)
+ (node (tsc-root-node tree-sitter-tree))
+ (patterns (seq-mapcat (lambda (fold-range) `((,(car fold-range))
@name))
+ (alist-get major-mode
treesit-fold-range-alist)
+ 'vector))
+ (query (tsc-make-query tree-sitter-language patterns)))
+ (setq nodes (tsc-query-captures query node #'ignore))
+ (thread-last nodes
+ (mapcar #'cdr)
+ (mapc #'treesit-fold-close)))
+ (when nodes
+ (run-hooks 'treesit-fold-on-fold-hook)))))
;;;###autoload
(defun treesit-fold-open-all ()
"Unfold all syntax nodes in the buffer."
(interactive)
(treesit-fold--ensure-ts
- (thread-last (overlays-in (point-min) (point-max))
- (seq-filter (lambda (ov) (eq (overlay-get ov 'invisible)
'treesit-fold)))
- (mapc #'delete-overlay))))
+ (when-let ((nodes (treesit-fold--overlays-in 'invisible 'treesit-fold)))
+ (mapc #'delete-overlay nodes)
+ (run-hooks 'treesit-fold-on-fold-hook))))
;;;###autoload
(defun treesit-fold-toggle ()
@@ -438,7 +450,10 @@ If the current syntax node is not foldable, do nothing."
(treesit-fold--ensure-ts
(if-let* ((node (treesit-fold--foldable-node-at-pos (point)))
(ov (treesit-fold-overlay-at node)))
- (progn (delete-overlay ov) t)
+ (progn
+ (delete-overlay ov)
+ (run-hooks 'treesit-fold-on-fold-hook)
+ t)
(treesit-fold-close))))
(defun treesit-fold--after-command (&rest _)
- [nongnu] elpa/treesit-fold fb91989a94 238/417: Setup node is no longer required, (continued)
- [nongnu] elpa/treesit-fold fb91989a94 238/417: Setup node is no longer required, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold f581febc6f 243/417: Update README (#39), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold a5ba7ce60b 248/417: README.md: fix typo (#43), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 5b0535c1af 256/417: test(Makefile); Ignore package-lint test, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold cde9c90b07 259/417: docs(README.md): Metnion YAML support, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 5ebe65e85d 262/417: docs: Fix more typo, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 8386b5b714 280/417: feat: Add Markdown support (#67), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 630b896b3f 277/417: feat: Add Haskell support (#65), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 08abd98ba4 272/417: feat: Add Dart support (#62), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold d20c3663f9 380/417: Update desc, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 2bb351bcf3 385/417: feat: Add on fold hook,
ELPA Syncer <=
- [nongnu] elpa/treesit-fold c14893d4ff 343/417: perf: Use built-in function for indentation, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 858fb6fe1c 325/417: Update CHANGELOG.md, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 581af904c1 286/417: feat: Add GDScript support (#72), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 07da6590aa 348/417: feat: Add LLVM MIR support, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 03644fb5fa 341/417: fix(indicators): Rely on range itself, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 6ec049b140 310/417: feat: Add Make support (#90), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 75e72c658a 332/417: feat: Add Org support, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 9b25eeeb0b 404/417: chore: Update mouse face docstring, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 6b759ca36e 402/417: Update README.org (#4), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold a9d4c2ec53 296/417: feat: Add XML support (#80), ELPA Syncer, 2024/07/01