From cffc4278eb7cbcceaaaaccfd2217b224c0ad6818 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Tue, 13 Jan 2026 09:26:20 -0500 Subject: [PATCH] (forward-sexp-function): Give it a default value * lisp/emacs-lisp/lisp.el (forward-sexp-function): Give it a default value. (forward-sexp): Simplify a bit. (up-list-default-function): Fix for `forward-sexp-default-function`. --- lisp/emacs-lisp/lisp.el | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index 4d4efba76b0..797f40ca1ba 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -50,7 +50,7 @@ This affects `insert-parentheses' and `insert-pair'." (goto-char (or (scan-sexps (point) arg) (buffer-end arg))) (if (< arg 0) (backward-prefix-chars))) -(defvar forward-sexp-function nil +(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 @@ -79,9 +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) - (forward-sexp-default-function arg)))) + (funcall (or forward-sexp-function + #'forward-sexp-default-function) + arg))) (defun backward-sexp (&optional arg interactive) "Move backward across one balanced expression (sexp). @@ -289,7 +289,9 @@ On error, location of point is unspecified." (scan-error (point-max))) (forward-comment 1) (point))))))) - (if (null forward-sexp-function) + ;; FIXME: Comparing functions is a code smell. + (if (memq forward-sexp-function + '(nil forward-sexp-default-function)) (goto-char (or (scan-lists (point) inc 1) (buffer-end arg))) (condition-case err