[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 9dbbf93a4a0: Improve treesit-forward-sexp behavior for leaf nodes
From: |
Yuan Fu |
Subject: |
master 9dbbf93a4a0: Improve treesit-forward-sexp behavior for leaf nodes (bug#68899) |
Date: |
Sun, 4 Feb 2024 19:49:36 -0500 (EST) |
branch: master
commit 9dbbf93a4a08f71cf5f2278ec2a22a722fe0e0f7
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Improve treesit-forward-sexp behavior for leaf nodes (bug#68899)
treesit-forward-sexp uses treesit--navigate-thing with 'restricted'
tactic. In this tactic we don't move over the parent thing. However,
this makes forward-sexp useless for symbols when point is in the
symbol rather than at the beginning of it: in that case, the symbol is
considered parent and treesit-forward-sexp won't move to the end of
it.
To solve that, we allow to move across the parent even in 'restricted'
mode if the parent is a leaf thing.
Here, "leaf thing" is defined as "doesn't have any child 'thing'
inside it".
* lisp/treesit.el (treesit--navigate-thing): Move over parent in
'restricted' tactic if the parent is a leaf thing.
---
lisp/treesit.el | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/lisp/treesit.el b/lisp/treesit.el
index fab2ddd88e6..93b6b56534d 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -2662,9 +2662,17 @@ function is called recursively."
(setq parent (treesit-node-top-level parent thing t)
prev nil
next nil))
- ;; If TACTIC is `restricted', the implementation is very simple.
+ ;; If TACTIC is `restricted', the implementation is simple.
+ ;; In principle we don't go to parent's beg/end for
+ ;; `restricted' tactic, but if the parent is a "leaf thing"
+ ;; (doesn't have any child "thing" inside it), then we can
+ ;; move to the beg/end of it (bug#68899).
(if (eq tactic 'restricted)
- (setq pos (funcall advance (if (> arg 0) next prev)))
+ (setq pos (funcall
+ advance
+ (cond ((and (null next) (null prev)) parent)
+ ((> arg 0) next)
+ (t prev))))
;; For `nested', it's a bit more work:
;; Move...
(if (> arg 0)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 9dbbf93a4a0: Improve treesit-forward-sexp behavior for leaf nodes (bug#68899),
Yuan Fu <=