Subject: bug#76676: 30.1.50; C-M-b in c-ts-mode moves too far

From: Eli Zaretskii <[email-masked]>
Date: Sun, 02 Mar 2025 10:53:52 +0200

To reproduce:

  emacs -Q
  C-x C-f src/xdisp.c
  C-u 20722 M-g g

If xdisp.c is from the master branch, that should place you on the
closing brace at the end of the following fragment (else modify the
line number accordingly or just move point to that brace):

  /* Try to scroll by specified few lines.  */
  if ((0 < scroll_conservatively
       /* FIXME: the option is supposed to affect minibuffers, but we
	  test MINI_WINDOW_P, which can also catch uses of
	  mini-windows for displaying the echo area.  Do we need to
	  distinguish these two use cases?  */
       || (scroll_minibuffer_conservatively && MINI_WINDOW_P (w))
       || 0 < emacs_scroll_step
       || temp_scroll_step
       || NUMBERP (BVAR (current_buffer, scroll_up_aggressively))
       || NUMBERP (BVAR (current_buffer, scroll_down_aggressively)))
      && CHARPOS (startp) >= BEGV
      && CHARPOS (startp) <= ZV)
    {
      /* The function returns -1 if new fonts were loaded, 1 if
	 successful, 0 if not successful.  */
      int ss = try_scrolling (window, just_this_one_p,
			      ((scroll_minibuffer_conservatively
			        && MINI_WINDOW_P (w))
			       ? SCROLL_LIMIT + 1
			       : scroll_conservatively),
			      emacs_scroll_step,
			      temp_scroll_step, last_line_misfit);
      switch (ss)
	{
	case SCROLLING_SUCCESS:
	  goto done;

	case SCROLLING_NEED_LARGER_MATRICES:
	  goto need_larger_matrices;

	case SCROLLING_FAILED:
	  break;

	default:
	  emacs_abort ();
	}
    }

Now type C-M-b.  The expected result is that point moves to the
corresponding opening brace, as shown below:

  /* Try to scroll by specified few lines.  */
  if ((0 < scroll_conservatively
       /* FIXME: the option is supposed to affect minibuffers, but we
	  test MINI_WINDOW_P, which can also catch uses of
	  mini-windows for displaying the echo area.  Do we need to
	  distinguish these two use cases?  */
       || (scroll_minibuffer_conservatively && MINI_WINDOW_P (w))
       || 0 < emacs_scroll_step
       || temp_scroll_step
       || NUMBERP (BVAR (current_buffer, scroll_up_aggressively))
       || NUMBERP (BVAR (current_buffer, scroll_down_aggressively)))
      && CHARPOS (startp) >= BEGV
      && CHARPOS (startp) <= ZV)
    { <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
      /* The function returns -1 if new fonts were loaded, 1 if
	 successful, 0 if not successful.  */

But in fact, point moves to the first character of 'if' before that:

  if ((0 < scroll_conservatively

Let me know if I can supply more information.

In GNU Emacs 30.1.50 (build 9, i686-pc-mingw32) of 2025-03-01 built on
 ELIZ-PC
Repository revision: 3998dea566aee807922e6edf8d1b20f3da89b4fc
Repository branch: emacs-30
Windowing system distributor 'Microsoft Corp.', version 10.0.26100
System Description: Microsoft Windows 10 Enterprise (v10.0.2009.26100.3194)

Configured using:
 'configure -C --prefix=/d/usr --with-wide-int
 --enable-checking=yes,glyphs --without-native-compilation 'CFLAGS=-O0
 -gdwarf-4 -g3''

Configured features:
ACL GIF GMP GNUTLS HARFBUZZ JPEG LCMS2 LIBXML2 MODULES NOTIFY W32NOTIFY
PDUMPER PNG RSVG SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS
TREE_SITTER WEBP XPM ZLIB

Important settings:
  value of $LANG: ENU
  locale-coding-system: cp1252

Major mode: C/*

Minor modes in effect:
  bug-reference-prog-mode: t
  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
  minibuffer-regexp-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 cl-seq
c++-ts-mode c-ts-mode c-ts-common treesit vc-git diff-mode track-changes
easy-mmode vc vc-dispatcher bug-reference byte-opt gv bytecomp
byte-compile thingatpt cc-mode cc-fonts cc-guess cc-menus cc-cmds
cc-styles cc-align cc-engine cc-vars cc-defs cl-loaddefs cl-lib rmc
iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode mwheel touch-screen dos-w32 ls-lisp
disp-table term/w32-win w32-win w32-vars term/common-win 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 w32notify w32 lcms2 multi-tty
move-toolbar make-network-process emacs)

Memory information:
((conses 16 92841 16422) (symbols 48 10144 0) (strings 16 28304 2881)
 (string-bytes 1 808502) (vectors 16 15855)
 (vector-slots 8 166559 10406) (floats 8 29 64) (intervals 40 3862 76)
 (buffers 896 11))