Subject: 31.0.50; up-list works incorrectly on emacs-30 if forward-sexp-function is set to treesit-forward-sexp

From: Roman Rudakov <[email-masked]>
Date: Thu, 06 Mar 2025 17:50:51 +0100

The bug is reproducible for clojure-ts-mode. If "sexp" thing is 
defined for tree-sitter mode, forward-sexp-function is set to 
treesit-forward-sexp 
(https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/treesit.el?h=emacs-30#n3147)

This setting triggers condition in the up-list function 
(https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/emacs-lisp/lisp.el?h=emacs-30#n258)

If point is outside of a top-level sexp, up-list function calls 
forward-list until point position reaches the bottom of the buffer.

Expected behavior: point stays at the end of sexp and message "At the 
top level" is shown in the echo area.

On master branch this issue can be fixed by setting up-list-function 
to treesit-up-list, but on emacs-30 up-list-function doesn't exist.

Would it be possible to fix the issue in the next bugfix release (if 
it's planned)?

More details: 
https://github.com/clojure-emacs/clojure-ts-mode/issues/62

Thank you.

In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, Xaw3d
 scroll bars) of 2025-02-25 built on rudakov-xps
Repository revision: 4101df53cc4d0bb5a913ce374206845d49336a15
Repository branch: makepkg
Windowing system distributor 'The X.Org Foundation', version 
11.0.12101016
System Description: Arch Linux

Configured using:
 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games
 --with-modules --without-m17n-flt --disable-gc-mark-trace
 --without-gconf --with-native-compilation=yes
 --with-native-compilation=aot --with-xinput2 --with-x-toolkit=lucid
 --with-xft --with-xaw3d --without-cairo --with-sound=no
 --with-tree-sitter --without-gpm --without-compress-install
 '--program-transform-name=s/\([ec]tags\)/\1.emacs/'
 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions
 -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security
 -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer
 -mno-omit-leaf-frame-pointer -flto=auto' 'LDFLAGS=-Wl,-O1
 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now
 -Wl,-z,pack-relative-relocs -flto=auto''
Configured features:
ACL DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG LCMS2
LIBOTF LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER 
PNG
RSVG SECCOMP SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP
X11 XAW3D XDBE XFT XIM XINERAMA XINPUT2 XPM XRANDR LUCID ZLIB
Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  server-mode: t
  idle-highlight-mode: t
  subword-mode: t
  yas-minor-mode: t
  hl-todo-mode: t
  flymake-mode: t
  pdf-occur-global-minor-mode: t
  mu4e-column-faces-mode: t
  mu4e-modeline-mode: t
  auto-insert-mode: t
  electric-pair-mode: t
  org-roam-db-autosync-mode: t
  outline-minor-mode: t
  minions-mode: t
  repeat-mode: t
  save-place-mode: t
  minibuffer-electric-default-mode: t
  savehist-mode: t
  recentf-mode: t
  global-auto-revert-mode: t
  global-hl-line-mode: t
  apheleia-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tab-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  window-divider-mode: t
  minibuffer-regexp-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  hs-minor-mode: t

Load-path shadows:
/home/rrudakov/.config/emacs/elpa/ef-themes-1.9.0/theme-loaddefs hides 
/home/rrudakov/.config/emacs/elpa/modus-themes-4.6.0/theme-loaddefs
/home/rrudakov/.config/emacs/elpa/magit-4.3.1/magit-autorevert hides 
/home/rrudakov/.config/emacs/elpa/magit-section-4.3.1/magit-autorevert
/home/rrudakov/.config/emacs/elpa/transient-0.8.5/transient hides 
/usr/share/emacs/31.0.50/lisp/transient
/home/rrudakov/.config/emacs/elpa/ef-themes-1.9.0/theme-loaddefs hides 
/usr/share/emacs/31.0.50/lisp/theme-loaddefs
/home/rrudakov/.config/emacs/elpa/python-0.29/python hides 
/usr/share/emacs/31.0.50/lisp/progmodes/python

Features:
(shadow face-remap emacsbug apheleia apheleia-rcs apheleia-dp
apheleia-formatters apheleia-utils apheleia-log
apheleia-formatter-context vc-git diff-mode track-changes sort 
gnus-cite
mm-archive mail-extr textsec uni-scripts idna-mapping ucs-normalize
uni-confusable textsec-check flymake-kondor clojure-ts-mode 
clj-refactor
hydra lv inflections mc-hide-unmatched-lines-mode mc-mark-more 
sgml-mode
mc-cycle-cursors multiple-cursors-core rect paredit cider cider-debug
cider-browse-ns cider-mode cider-xref-backend cider-find 
cider-inspector
cider-completion cider-profile cider-eval cider-jar arc-mode
archive-mode cider-repl-history pulse cider-repl cider-resolve
cider-test cider-overlays cider-stacktrace cider-doc cider-browse-spec
cider-clojuredocs cider-eldoc cider-docstring cider-client 
cider-common
xref cider-completion-context cider-connection cider-popup
sesman-browser nrepl-client cider-util sesman queue nrepl-dict spinner
parseedn parseclj-parser parseclj-lex parseclj-alist clojure-mode 
align
ef-maris-dark-theme server idle-highlight-mode cap-words superword
subword hideshow yasnippet ef-themes cus-start hl-todo checkdoc 
lisp-mnt
flymake org-git ghub-graphql treepy gsexp ghub url-http url-gw nsm
url-auth google-translate-smooth-ui google-translate-core-ui facemenu
color popup google-translate-core google-translate-backend
use-package-ensure pdf-occur tablist tablist-filter 
semantic/wisent/comp
semantic/wisent semantic/wisent/wisent semantic/util-modes 
semantic/util
semantic semantic/tag semantic/lex semantic/fw mode-local cedet
pdf-isearch let-alist pdf-misc imenu pdf-tools pdf-view jka-compr
pdf-cache pdf-info tq pdf-util pdf-macs image-mode exif ob-restclient
restclient mu4e-column-faces mu4e-icalendar gnus-icalendar icalendar
mu4e mu4e-org mu4e-notification notifications mu4e-main smtpmail
mu4e-view mu4e-mime-parts mu4e-headers mu4e-thread mu4e-actions
mu4e-compose mu4e-draft gnus-msg mu4e-search mu4e-lists mu4e-bookmarks
mu4e-mark mu4e-message flow-fill mule-util mu4e-contacts mu4e-update
mu4e-folders mu4e-context mu4e-query-items mu4e-server mu4e-modeline
mu4e-vars mu4e-helpers mu4e-config mu4e-window bookmark ido
mu4e-obsolete yaml-ts-mode dockerfile-ts-mode rust-ts-mode c-ts-common
vlf-setup vlf vlf-base vlf-tune autoinsert rg vc vc-dispatcher
rg-info-hack rg-menu transient edmacro kmacro rg-ibuffer rg-result
wgrep-rg wgrep rg-history rg-header ibuf-ext ibuffer ibuffer-loaddefs
grep compile elec-pair emacsql-sqlite-builtin sqlite org-roam-migrate
org-roam-log org-roam-mode org-roam-capture org-roam-id org-roam-node
crm org-roam-db org-roam-utils org-roam-compat org-roam org-capture
emacsql-sqlite emacsql emacsql-compiler magit-section cursor-sensor
llama comp comp-cstr dash async ob-async ob-plantuml ob-ditaa 
ob-clojure
ob-haskell ob-sqlite ob-shell ob-sql ob-python python project 
org-clock
appt diary-lib diary-loaddefs org-duration flyspell ispell oc-basic
bibtex disp-table ol-info ol-gnus nnselect gnus-art mm-uu mml2015
mm-view mml-smime smime gnutls dig gnus-sum shr-tag-pre-highlight
language-detection shr pixel-fill kinsoku url-file svg dom gnus-group
gnus-undo gnus-start gnus-dbus dbus comp-run comp-common xml 
gnus-cloud
nnimap nnmail mail-source utf7 nnoo gnus-spec gnus-int gnus-range
message sendmail yank-media puny dired dired-loaddefs rfc822 mml 
mml-sec
epa derived epg rfc6068 epg-config mm-decode mm-bodies mm-encode
mail-parse rfc2231 rfc2047 rfc2045 ietf-drums mailabbrev gmm-utils
mailheader gnus-win gnus nnheader gnus-util text-property-search
mail-utils range mm-util mail-prsvr ox-gfm ox-md ox-odt rng-loc 
rng-uri
rng-parse rng-match rng-dt rng-util rng-pttrn nxml-parse nxml-ns
nxml-enc xmltok nxml-util ox-latex ox-icalendar ox-html table ox-ascii
ox-publish ox org-attach org-agenda org-element org-persist org-id
org-element-ast inline avl-tree generator org-refile org ob ob-tangle
ob-ref ob-lob ob-table ob-exp org-macro org-src sh-script smie treesit
executable ob-comint org-pcomplete org-list org-footnote org-faces
org-entities noutline outline org-version ob-emacs-lisp ob-core 
ob-eval
org-cycle org-table org-keys oc org-loaddefs thingatpt find-func
cal-menu calendar cal-loaddefs ol org-fold org-fold-core org-compat
org-macs exec-path-from-shell minions compat warnings repeat 
hippie-exp
advice saveplace minibuf-eldef savehist tramp-cache time-stamp 
tramp-sh
tramp trampver tramp-integration files-x tramp-message tramp-compat
shell pcomplete comint ansi-osc ring parse-time iso8601 time-date
format-spec ansi-color tramp-loaddefs recentf tree-widget cl-extra
help-mode autorevert filenotify use-package-core hl-line finder-inf
add-node-modules-path-autoloads alert-autoloads apheleia-autoloads
easy-mmode auctex-autoloads tex-site clj-refactor-autoloads
cider-autoloads clojure-mode-autoloads clojure-ts-mode-autoloads
csv-mode-autoloads debbugs-autoloads dired-git-info-autoloads
dired-subtree-autoloads dired-hacks-utils-autoloads
dtrt-indent-autoloads edit-indirect-autoloads ef-themes-autoloads
elfeed-autoloads emacs-everywhere-autoloads emmet-mode-autoloads
exec-path-from-shell-autoloads expand-region-autoloads
flymake-kondor-autoloads flyspell-correct-autoloads ghub-autoloads
git-link-autoloads gitignore-templates-autoloads gntp-autoloads
google-c-style-autoloads google-translate-autoloads
groovy-mode-autoloads haskell-mode-autoloads hl-todo-autoloads
hydra-autoloads idle-highlight-mode-autoloads inflections-autoloads
log4e-autoloads logview-autoloads datetime-autoloads extmap-autoloads
lua-mode-autoloads lv-autoloads magit-autoloads pcase
markdown-mode-autoloads minions-autoloads modus-themes-autoloads
mu4e-column-faces-autoloads multiple-cursors-autoloads
nginx-mode-autoloads nov-autoloads esxml-autoloads kv-autoloads
ob-async-autoloads async-autoloads ob-restclient-autoloads
org-roam-autoloads magit-section-autoloads llama-autoloads
emacsql-autoloads org-tree-slide-autoloads ox-jira-autoloads
ox-slack-autoloads ox-gfm-autoloads paredit-autoloads 
parseedn-autoloads
parseclj-autoloads password-store-otp-autoloads 
password-store-autoloads
pdf-tools-autoloads pip-requirements-autoloads pkgbuild-mode-autoloads
plantuml-mode-autoloads dash-autoloads popup-autoloads 
python-autoloads
pyvenv-autoloads queue-autoloads rainbow-mode-autoloads
restclient-autoloads rg-autoloads s-autoloads sesman-autoloads
shr-tag-pre-highlight-autoloads language-detection-autoloads
sly-autoloads spinner-autoloads sql-indent-autoloads
ssh-config-mode-autoloads rx tablist-autoloads telega-autoloads
transient-autoloads treepy-autoloads vimrc-mode-autoloads
visual-fill-column-autoloads vlf-autoloads web-mode-autoloads
wgrep-autoloads info with-editor-autoloads yasnippet-autoloads package
browse-url xdg url url-proxy url-privacy url-expand url-methods
url-history url-cookie generate-lisp-file url-domsuf url-util mailcap
url-handlers url-parse auth-source cl-seq eieio eieio-core cl-macs
password-cache json subr-x map byte-opt gv bytecomp byte-compile
url-vars cus-edit pp cus-load icons wid-edit cl-loaddefs cl-lib rmc
iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
term/common-win x-dnd touch-screen tool-bar dnd fontset image 
regexp-opt
fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode
register page tab-bar menu-bar rfn-eshadow isearch easymenu timer 
select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet 
lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj 
charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray 
oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable 
backquote
threads dbusbind inotify lcms2 dynamic-setting system-font-setting
font-render-setting x-toolkit xinput2 x multi-tty move-toolbar
make-network-process tty-child-frames native-compile emacs)

Memory information:
((conses 16 1155128 248284) (symbols 48 57181 190)
 (strings 32 321579 17220) (string-bytes 1 9488197)
 (vectors 16 303372) (vector-slots 8 2828876 159177)
 (floats 8 91517 989) (intervals 56 10957 4947) (buffers 992 33))

-- 
Best regards, Roman