summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/lisp.el
diff options
context:
space:
mode:
authorJuri Linkov <juri@linkov.net>2024-04-14 19:18:31 +0300
committerJuri Linkov <juri@linkov.net>2024-04-14 19:22:01 +0300
commit568c1741352a4932508fbbd474b9fd9ebe90ddfb (patch)
treeee663e9acb86a02a742f83214ddc9a6b3524380a /lisp/emacs-lisp/lisp.el
parentcd113d8c45ccf3bfa8b687c06a5d03618adf7a2c (diff)
downloademacs-568c1741352a4932508fbbd474b9fd9ebe90ddfb.tar.gz
emacs-568c1741352a4932508fbbd474b9fd9ebe90ddfb.tar.bz2
emacs-568c1741352a4932508fbbd474b9fd9ebe90ddfb.zip
Add 'forward-sexp-default-function' to be used by 'treesit-forward-sexp'
* lisp/emacs-lisp/lisp.el (forward-sexp-default-function): New function with body from 'forward-sexp' (bug#68993). (forward-sexp-function): Change the default value from nil to 'forward-sexp-default-function'. (forward-sexp): Use either 'forward-sexp-function' or 'forward-sexp-default-function'. * lisp/treesit.el (treesit-forward-sexp): In nodes of type 'text' fall back to 'forward-sexp-default-function'. Improve docstring. * doc/lispref/positions.texi (List Motion): Fix pxref.
Diffstat (limited to 'lisp/emacs-lisp/lisp.el')
-rw-r--r--lisp/emacs-lisp/lisp.el14
1 files changed, 9 insertions, 5 deletions
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index c57b1357f63..bd0b38db7ea 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -45,7 +45,12 @@ This affects `insert-parentheses' and `insert-pair'."
: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 @@ report errors as appropriate for this kind of usage."
"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).