aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuan Fu2023-01-08 20:30:07 -0800
committerYuan Fu2023-01-08 21:22:28 -0800
commit1f8ad353d9fbf8fb7706e91dda336dfd650b57cc (patch)
treeb8f7293d9b72cbbf5b938a12b4dac2ec3fe134fa
parentef87c75566018b546e56f64f66f665ebfd8da305 (diff)
downloademacs-1f8ad353d9fbf8fb7706e91dda336dfd650b57cc.tar.gz
emacs-1f8ad353d9fbf8fb7706e91dda336dfd650b57cc.zip
Minor improvement for tree-sitter explorer
If you open an empty python buffer and type 1 + 2 a b Currently the explorer only displays the top-level node at point, ie, only 1 + 2, only a, or only b. That's kind of awkward, so if the buffer is small, show the entire parse tree. * lisp/treesit.el (treesit--explorer-refresh): See above.
-rw-r--r--lisp/treesit.el14
1 files changed, 9 insertions, 5 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el
index e53d5d53bd0..7a604121c4e 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -2415,11 +2415,15 @@ in the region."
2415 (window-start) (window-end) treesit--explorer-language)) 2415 (window-start) (window-end) treesit--explorer-language))
2416 ;; Only highlight the current top-level construct. 2416 ;; Only highlight the current top-level construct.
2417 ;; Highlighting the whole buffer is slow and unnecessary. 2417 ;; Highlighting the whole buffer is slow and unnecessary.
2418 (top-level (treesit-node-first-child-for-pos 2418 ;; But if the buffer is small (ie, used in playground
2419 root (if (eolp) 2419 ;; style), just highlight the whole buffer.
2420 (max (point-min) (1- (point))) 2420 (top-level (if (< (buffer-size) 4000)
2421 (point)) 2421 root
2422 t)) 2422 (treesit-node-first-child-for-pos
2423 root (if (eolp)
2424 (max (point-min) (1- (point)))
2425 (point))
2426 t)))
2423 ;; Only highlight node when region is active, if we 2427 ;; Only highlight node when region is active, if we
2424 ;; highlight node at point the syntax tree is too jumpy. 2428 ;; highlight node at point the syntax tree is too jumpy.
2425 (nodes-hl 2429 (nodes-hl