GNU bug report logs -
#68993
treesitter support for forward-sexp-default-function
Previous Next
Reported by: Juri Linkov <juri <at> linkov.net>
Date: Thu, 8 Feb 2024 17:42:01 UTC
Severity: normal
Fixed in version 30.0.50
Done: Juri Linkov <juri <at> linkov.net>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
> My suggestion would be for both treesit-forward-sentence and -sexp to
> use “text” for their heuristic. If someone wants more customized
> behavior, they can always write a custom forward-sentence/sexp function.
Thanks for the suggestion. So here is the patch that implements this:
[treesit-forward-sexp-text.patch (text/x-diff, inline)]
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 1443162f79c..62d797513fc 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -2145,7 +2145,10 @@ treesit-forward-sexp
(interactive "^p")
(let ((arg (or arg 1))
(pred (or treesit-sexp-type-regexp 'sexp)))
- (or (if (> arg 0)
+ (or (when (treesit-node-match-p (treesit-node-at (point)) 'text t)
+ (funcall #'forward-sexp-default-function arg)
+ t)
+ (if (> arg 0)
(treesit-end-of-thing pred (abs arg) 'restricted)
(treesit-beginning-of-thing pred (abs arg) 'restricted))
;; If we couldn't move, we should signal an error and report
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index c57b1357f63..4c0f720b1a0 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -45,7 +45,12 @@ parens-require-spaces
:type 'boolean
:group 'lisp)
-(defvar forward-sexp-function nil
+(defun forward-sexp-default-function (&optional arg)
+ "Default function for `forward-sexp-function'."
+ (goto-char (or (scan-sexps (point) arg) (buffer-end arg)))
+ (if (< arg 0) (backward-prefix-chars)))
+
+(defvar forward-sexp-function #'forward-sexp-default-function
;; FIXME:
;; - for some uses, we may want a "sexp-only" version, which only
;; jumps over a well-formed sexp, rather than some dwimish thing
@@ -74,10 +79,9 @@ forward-sexp
"No next sexp"
"No previous sexp"))))
(or arg (setq arg 1))
- (if forward-sexp-function
- (funcall forward-sexp-function arg)
- (goto-char (or (scan-sexps (point) arg) (buffer-end arg)))
- (if (< arg 0) (backward-prefix-chars)))))
+ (funcall (or forward-sexp-function
+ #'forward-sexp-default-function)
+ arg)))
(defun backward-sexp (&optional arg interactive)
"Move backward across one balanced expression (sexp).
This bug report was last modified 1 year and 91 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.