diff options
author | Yuan Fu <casouri@gmail.com> | 2023-01-08 20:30:07 -0800 |
---|---|---|
committer | Yuan Fu <casouri@gmail.com> | 2023-01-08 21:22:28 -0800 |
commit | 1f8ad353d9fbf8fb7706e91dda336dfd650b57cc (patch) | |
tree | b8f7293d9b72cbbf5b938a12b4dac2ec3fe134fa /lisp | |
parent | ef87c75566018b546e56f64f66f665ebfd8da305 (diff) | |
download | emacs-1f8ad353d9fbf8fb7706e91dda336dfd650b57cc.tar.gz emacs-1f8ad353d9fbf8fb7706e91dda336dfd650b57cc.tar.bz2 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.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/treesit.el | 14 |
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." (window-start) (window-end) treesit--explorer-language)) ;; Only highlight the current top-level construct. ;; Highlighting the whole buffer is slow and unnecessary. - (top-level (treesit-node-first-child-for-pos - root (if (eolp) - (max (point-min) (1- (point))) - (point)) - t)) + ;; But if the buffer is small (ie, used in playground + ;; style), just highlight the whole buffer. + (top-level (if (< (buffer-size) 4000) + root + (treesit-node-first-child-for-pos + root (if (eolp) + (max (point-min) (1- (point))) + (point)) + t))) ;; Only highlight node when region is active, if we ;; highlight node at point the syntax tree is too jumpy. (nodes-hl |