Subject: 29.1.50; treesit-query-capture in an interactive function has no effect?

From: 赵 纪阳 <[email-masked]>
Date: Sat, 5 Aug 2023 13:43:31 +0000

--text follows this line--

I have a test function as following:

(defun treesit-context-test-query ()
  (interactive)
  (treesit-query-capture (treesit-buffer-root-node) '((if_statement consequence: (_) @context.end) @context)))

I expected this function would return all =if statement= in a java buffer.

But if I invoke it from M-x, it doesn't print anything in *Message* buffer.

If I call it from M-:(aka. eval-expression), it does print something.

Is there a bug here? If not, how should I use it correctly? Thanks.

How to reproduce:

0. install java tree-sitter parser

1. emacs -Q

2. open a java file

3. enable java-ts-mode

4. call the function interactively from M-x

In GNU Emacs 29.1.50 (build 1, x86_64-pc-linux-gnu, X toolkit, Xaw3d
 scroll bars) of 2023-08-04 built on tux
Repository revision: 8cbd4a02a2b9823a6aa7e722af6e3d204f881aed
Repository branch: makepkg
Windowing system distributor 'The X.Org Foundation', version 11.0.12101008
System Description: Manjaro Linux

Configured using:
 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games
 --with-modules --without-libotf --without-m17n-flt --without-gconf
 --with-native-compilation=no --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=2 -Wformat -Werror=format-security
 -fstack-clash-protection -fcf-protection'
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'

Configured features:
ACL DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON LCMS2
LIBSYSTEMD LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP
SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XAW3D XDBE
XFT XIM XINPUT2 XPM LUCID ZLIB

Important settings:
  value of $LC_MONETARY: zh_CN.UTF-8
  value of $LC_NUMERIC: zh_CN.UTF-8
  value of $LC_TIME: zh_CN.UTF-8
  value of $LANG: zh_CN.UTF-8
  value of $XMODIFIERS: @im=fcitx
  locale-coding-system: utf-8-unix

Major mode: Java

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util text-property-search time-date subr-x mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
java-ts-mode c-ts-common treesit cl-seq vc-git diff-mode easy-mmode
vc-dispatcher cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles
cc-align cc-engine cc-vars cc-defs cl-loaddefs cl-lib china-util 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 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 make-network-process
emacs)

Memory information:
((conses 16 70348 9640)
 (symbols 48 7693 0)
 (strings 32 23042 2533)
 (string-bytes 1 809783)
 (vectors 16 14358)
 (vector-slots 8 248208 8162)
 (floats 8 28 23)
 (intervals 56 1870 0)
 (buffers 984 14))