From 568c1741352a4932508fbbd474b9fd9ebe90ddfb Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Sun, 14 Apr 2024 19:18:31 +0300 Subject: 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. --- lisp/emacs-lisp/lisp.el | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'lisp/emacs-lisp/lisp.el') 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). -- cgit v1.2.3