Subject: 31.0.50; C-g fails to exit loop

From: Mike Kupfer <[email-masked]>
Date: Fri, 27 Jun 2025 14:36:06 -0700

Recipe from 'emacs -Q':

1. Save the test-data attachment to a file.

2. Evaluate the following defun:

(defun do-test ()
  (while (re-search-forward "bug#[[:digit:]]+:" nil t)
    (search-backward "(\"bug")
    (let (end (start (point)))
      (forward-sexp)
      (setq end (point))
      (query-replace-regexp "\\(\"bug#[[:digit:]]+:\\).*\"" "\\1\""
			    nil start end))))

3. Visit the test data file.  With point at the start of the buffer, run
the do-test function, and press space a couple times.  Now press C-g.

Expected behavior:

  The do-test function stops executing, and point is left at the same
  position where you pressed C-g.  (This is the behavior I see with
  Emacs 30 and with a build derived from Emacs master 648453c04d9.)

Observed behavior:

  point progresses through the remaining sexps, without giving you any
  query-replace prompt.  When do-test has finished, point is now after
  '"bug#78900:"'.

The git hash reported below by 'report-emacs-bug' includes a few Lisp
changes that I believe are unrelated to the issue, and which are
unchanged from the Emacs master build that works as expected.  The
corresponding git hash from master (for the buggy build) is a002ca79ee7.

In GNU Emacs 31.0.50 (build 11, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.16.0, Xaw scroll bars) of 2025-06-26 built on bach
Repository revision: 272a10db724bf17aa4af0e958d3b41c996d22c4a
Repository branch: master-mdk
Windowing system distributor 'The X.Org Foundation', version 11.0.12101007
System Description: Debian GNU/Linux 12 (bookworm)

Configured using:
 'configure --prefix=/usr/new --enable-checking'

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG
LIBSELINUX LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG SECCOMP SOUND
THREADS TIFF TOOLKIT_SCROLL_BARS WEBP X11 XDBE XIM XPM LUCID ZLIB

Important settings:
  value of $LC_TIME: C
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Shell

Minor modes in effect:
  server-mode: t
  shell-dirtrack-mode: t
  delete-selection-mode: t
  display-time-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  minibuffer-regexp-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 mh-identity mh-tool-bar mh-letter mh-show goto-addr thingatpt
gnus-cite mh-mime mh-acros mh-xface mh-utils emacsbug lisp-mnt files-x
mdk-mail gnus-mh gnus-msg mh-comp mh-scan mh-gnus gnus-dup nnmh
gnus-score score-mode gnus-art mm-uu mml2015 mm-view mml-smime smime
gnutls dig gnus-sum shr pixel-fill kinsoku url-file svg dom gnus-group
gnus-undo gnus-start gnus-dbus dbus xml gnus-cloud nnimap nnmail
browse-url xdg url url-proxy url-privacy url-expand url-methods
url-history url-cookie generate-lisp-file url-domsuf url-util url-parse
auth-source cl-seq eieio eieio-core cl-macs json map byte-opt gv
bytecomp byte-compile url-vars mail-source utf7 nnoo parse-time iso8601
gnus-spec gnus-int gnus-range gnus-win gnus nnheader range wid-edit mh-e
mh-buffers mh-loaddefs message sendmail 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 mm-decode mm-bodies
mm-encode mail-parse rfc2231 rfc2047 rfc2045 mm-util ietf-drums
mail-prsvr mailabbrev mail-utils gmm-utils mailheader server warnings
timeclock noutline outline icons cc-mode cc-fonts cc-guess cc-menus
cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs advice shell
pcomplete comint subr-x ansi-osc ansi-color ring xcscope delsel time vc
cl-loaddefs cl-lib vc-dispatcher mdk-hacks 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 dynamic-setting system-font-setting font-render-setting cairo
x-toolkit x multi-tty move-toolbar make-network-process tty-child-frames
emacs)

Memory information:
((conses 16 179700 20237) (symbols 48 18865 0) (strings 32 55102 2372)
 (string-bytes 1 1569839) (vectors 16 32210)
 (vector-slots 8 312579 6626) (floats 8 225 15) (intervals 56 310 0)
 (buffers 984 13))