GNU bug report logs - #79857
hideshow: Unbalanced parentheses

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Juri Linkov <juri@HIDDEN>; Done: Juri Linkov <juri@HIDDEN>; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
bug marked as fixed in version 31.0.50, send any further explanations to 79857 <at> debbugs.gnu.org and Juri Linkov <juri@HIDDEN> Request was from Juri Linkov <juri@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 79857 <at> debbugs.gnu.org:


Received: (at 79857) by debbugs.gnu.org; 19 Nov 2025 07:22:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Nov 19 02:22:47 2025
Received: from localhost ([127.0.0.1]:34973 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1vLcWc-0007Oh-Gz
	for submit <at> debbugs.gnu.org; Wed, 19 Nov 2025 02:22:47 -0500
Received: from mout-p-102.mailbox.org ([80.241.56.152]:35452)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>)
 id 1vLcWV-0007Nt-HM; Wed, 19 Nov 2025 02:22:39 -0500
Received: from smtp102.mailbox.org (smtp102.mailbox.org
 [IPv6:2001:67c:2050:b231:465::102])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
 (No client certificate requested)
 by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4dBCc71GXjz9v7B;
 Wed, 19 Nov 2025 08:22:31 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linkov.net; s=MBO0001; 
 t=1763536951;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 in-reply-to:in-reply-to:references:references;
 bh=99uGChb9ODQEcYiK3fo8AuZ+TkTzD3UpzKWtpLy1SJM=;
 b=VWZwOoe9BJha5U3q9uzTTqvgovcVA7IRb3bGI7sLT5JuJogHl3UnKK6irVa4GfjSl4iUAT
 pQIaBIlxGxy4oG2+tt6HonZ8igjkwqo3QUKrjkofKtytzagtdSqi5Z8eQJCr0l0ePGLCNk
 Gr1J59UQ3Y+DaJJd2HN5j3YQp9MVpqqjdS9cylAmvV6l1Cjj/6YAXH/79anXpzh5Q1WoKb
 umH2YGcQkoNP5Fc1x0lWgLY4SVUuZUlgB92I2VVfY39+y886xg0Qh8fyOHOTwnbpXQdmVM
 l0JIuzjeTC5WeC5bKR16htBmVsONinNBYqh2ghGA5pGII4nrtScMUJ5MWrBGww==
Authentication-Results: outgoing_mbo_mout; dkim=none;
 spf=pass (outgoing_mbo_mout: domain of juri@HIDDEN designates
 2001:67c:2050:b231:465::102 as permitted sender)
 smtp.mailfrom=juri@HIDDEN
From: Juri Linkov <juri@HIDDEN>
To: Elijah Gabe =?iso-8859-1?Q?P=E9rez?= <eg642616@HIDDEN>
Subject: Re: bug#79857: hideshow: Unbalanced parentheses
In-Reply-To: <878qg3rwzk.fsf@HIDDEN>
Organization: LINKOV.NET
References: <87ikf7z32k.fsf@HIDDEN> <878qg3rwzk.fsf@HIDDEN>
Date: Wed, 19 Nov 2025 09:20:27 +0200
Message-ID: <87jyzmtrno.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Rspamd-Queue-Id: 4dBCc71GXjz9v7B
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 79857
Cc: 79857 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

close 79857 31.0.50
thanks

> I fixed it and an bug that made `hs-hide-level-recursive` infloop.

Thanks for the patch, I pushed it with 'condition-case'
instead of 'condition-case-unless-debug'.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#79857; Package emacs. Full text available.

Message received at 79857 <at> debbugs.gnu.org:


Received: (at 79857) by debbugs.gnu.org; 18 Nov 2025 19:20:57 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Nov 18 14:20:56 2025
Received: from localhost ([127.0.0.1]:59404 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1vLRG4-0005fo-K9
	for submit <at> debbugs.gnu.org; Tue, 18 Nov 2025 14:20:56 -0500
Received: from mout-p-103.mailbox.org ([2001:67c:2050:0:465::103]:47398)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1vLRG1-0005fO-GJ
 for 79857 <at> debbugs.gnu.org; Tue, 18 Nov 2025 14:20:54 -0500
Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
 (No client certificate requested)
 by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4d9vbG5Fkyz9tF7;
 Tue, 18 Nov 2025 20:20:42 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linkov.net; s=MBO0001; 
 t=1763493642;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 in-reply-to:in-reply-to:references:references;
 bh=u44HLFwPKRuT4TE1y8MK1ROuh02Fg0LvYvmA2Oj/g2o=;
 b=xw++wjIjVfTNZHExhjlHRgQVIYcJ5L+KtiPr4ye6kOuY6YagYT4AkMqod/kqBTbXPZuo/J
 ZIWWxwG3LQP0jilimUbXku7gEC1hwNrF5fAtWjLcdmNofLQKWGmznIki9TTO2w2ta4g+g7
 KJL++52MFuezHuOmTl5uI8ImaskedP4PD/gpYG8se15I+mIt1a8je91zFyB82dCqZsK0fB
 8qN3gt+TUai+I9sJELJSultOHEbdgkb+hBIwi20cDjK3d1jGKSXWLSdy/MAeKa8qI/Xcfa
 t6Wbw9pzjjEOp0NPZEdB/yvJRFJm3ROS311mrp9XvqSsQf4u4UcaXZKNpy5k5A==
From: Juri Linkov <juri@HIDDEN>
To: Elijah Gabe =?iso-8859-1?Q?P=E9rez?= <eg642616@HIDDEN>
Subject: Re: bug#79857: hideshow: Unbalanced parentheses
In-Reply-To: <878qg3rwzk.fsf@HIDDEN>
Organization: LINKOV.NET
References: <87ikf7z32k.fsf@HIDDEN> <878qg3rwzk.fsf@HIDDEN>
Date: Tue, 18 Nov 2025 21:16:57 +0200
Message-ID: <87pl9fw3py.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 79857
Cc: 79857 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

> +            (condition-case-unless-debug _

I always run Emacs with with debug-on-error,
so this condition-case-unless-debug still fails,
but condition-case fixed this problem.

I wonder why Emacs source has so many occurrences of
condition-case-unless-debug?  There are so many problems with it.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#79857; Package emacs. Full text available.

Message received at 79857 <at> debbugs.gnu.org:


Received: (at 79857) by debbugs.gnu.org; 18 Nov 2025 18:56:11 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Nov 18 13:56:11 2025
Received: from localhost ([127.0.0.1]:59316 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1vLQs6-0004AB-IY
	for submit <at> debbugs.gnu.org; Tue, 18 Nov 2025 13:56:11 -0500
Received: from mail-yw1-x1143.google.com ([2607:f8b0:4864:20::1143]:45162)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <eg642616@HIDDEN>)
 id 1vLQs3-00049t-Bk
 for 79857 <at> debbugs.gnu.org; Tue, 18 Nov 2025 13:56:08 -0500
Received: by mail-yw1-x1143.google.com with SMTP id
 00721157ae682-78677ff31c2so50504377b3.2
 for <79857 <at> debbugs.gnu.org>; Tue, 18 Nov 2025 10:56:07 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1763492161; x=1764096961; darn=debbugs.gnu.org;
 h=mime-version:user-agent:message-id:date:references:in-reply-to
 :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to;
 bh=XJoA00HjbtnI+SxFPVgVQgGADRVSxJGrwekq3hjEMYA=;
 b=CGCjPrD9Rv+WCCBggvaF/X2/GcQuR6boInKmrxQ8fr3fo+jCB9LhgsIAFQwHq/RIWX
 9l85eJieobIvyZE1Bjt5Jkna1wOhLD9u5IfazHzboxP6qB7J9dzvWeW6ua+gKDaKFf7p
 ZTP61GvaLAMqrV/RGE3LHAJkWW57VYrAeOdX2AzUw2WsmPX84BvJ0AeFW13Ya0MQg0ca
 4JPJqXUUcJB48hIuOyXSG5ySgeZuNH2VWf63GhZ9TNnEqd5wqmfRWmxJvzq3pYhRISHU
 IcRP4JF9mbHK0ZK8SAW3hXemTs6787fbzSjhEjK4MRwX8ZBYsPn9/kJwBt045sPoFqhl
 RfBw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1763492161; x=1764096961;
 h=mime-version:user-agent:message-id:date:references:in-reply-to
 :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject
 :date:message-id:reply-to;
 bh=XJoA00HjbtnI+SxFPVgVQgGADRVSxJGrwekq3hjEMYA=;
 b=JEzdtzaBsHmfJhbE3xTWnGh9t4RPoLsjZc3yJb0ZLRz7dbhDiZil2D3meP/JS8uz6f
 pb6RDd99Wf5UT9xFHZhPuI3iiPLECzxxleSEEcMED/Ig6hotNL8saPzhVhfwWzXqYfhJ
 VlJd1O47re8T1llYqswKaMjQ7E1MwyZDjZRsSnTv1rx5HjHGJHojKcIUDdeShtXCh2M2
 0ZhZV3jIqWRexU5wOpCzD+w3VtorETUkzFUaWRH6Mqq2+9rHM7LulRhH6ptw288NjLkN
 WnC+2/suXnYySde0y1AO6HJ+gHcniw/iUZ2ftLrxvz5Mi1ypbN/V7NDRqhyyqXf4+j6N
 M/Nw==
X-Gm-Message-State: AOJu0YwkfGpZ/gIYZ0IFlJEMDmNa351IJeNlXRMoezrQo+7cwGrflaLt
 8cf56TJshKx4lzWdKYGfF1pTNOKJ1xFQ+J+jU9y1KmpQD8bxosU0xwtmefSDDIUj
X-Gm-Gg: ASbGncvRhKZVsq06HNam4LvRVLzh9j6R1tflwwttc01eZf/x5cPjlwPbLIfkgbxeE/H
 mTSJOheH31eSM646xl+O3dw8ppaVQP3BYTJlpVKQCwpmEAWyfzS9gCrEahcXl8qp4FCsh8fTyLR
 8zZ5ri+n+C/LCl8tkq9Hz9PenCd396YsPVlJAQnjAWZGulHlqNw8GsUXLrAkTZNkTo8BLckqLfA
 0ZrCbYC+ZzjHc09ehgYdBL9QYR4vvaPzLK5jQGfTKejKXrB4css4Y6jsDREb4huBWa0xgef+w1j
 2MjxoDmFt4g+ekIPYdn6ur72brhThnQEjVXWFjjtUMnIkyn3UJU1pA0vjk8OoPcH56/9RgpRIOJ
 PndC3XlJ+wsub61Pv67SajenV6jIkuO4jDLr1oV5nMxI1uyb9votX0Za3imUa7Mr3b0heTNjWFx
 fUPbg8rllMp9jMew==
X-Google-Smtp-Source: AGHT+IFpfjrjOiSz+J4XVEssOZp5+HxP37xdH/EN6YC7D7FClGVKwD/XfJjlR7RFVtIty37pRQB1Yg==
X-Received: by 2002:a05:690c:23ca:b0:786:5212:4a7b with SMTP id
 00721157ae682-78a6cbddd8fmr494807b3.58.1763492161318; 
 Tue, 18 Nov 2025 10:56:01 -0800 (PST)
Received: from fedora ([189.215.165.71]) by smtp.gmail.com with ESMTPSA id
 00721157ae682-7882214b57fsm54933787b3.40.2025.11.18.10.56.00
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 18 Nov 2025 10:56:00 -0800 (PST)
From: =?utf-8?Q?Elijah_Gabe_P=C3=A9rez?= <eg642616@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
Subject: Re: bug#79857: hideshow: Unbalanced parentheses
In-Reply-To: <87ikf7z32k.fsf@HIDDEN>
References: <87ikf7z32k.fsf@HIDDEN>
Date: Tue, 18 Nov 2025 12:55:59 -0600
Message-ID: <878qg3rwzk.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: 0.3 (/)
X-Debbugs-Envelope-To: 79857
Cc: 79857 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.7 (/)

--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Juri Linkov <juri@HIDDEN> writes:

> Some strange error occurs during font-lock in hs-minor-mode.
> Reproducible test case:
>
> 0. emacs -Q
> 1. Eval:
>
> (progn
>   (setq backtrace-on-redisplay-error t)
>   (setq hs-show-indicators t)
>   (add-hook 'find-file-hook 'hs-minor-mode)
>   (find-file (expand-file-name "lisp/frame.el" installation-directory))
>   (search-forward "set-window-fringes")
>   (reposition-window))
>
> This shows:
>
> =E2=9B=94 Warning (error): Error in a redisplay Lisp hook.  See buffer *R=
edisplay-trace*
>
> And the buffer *Redisplay-trace* contains:
>
> Error: scan-error ("Unbalanced parentheses" 48293 48793)
>   scan-sexps(48293 1)
>   forward-sexp-default-function(1)
>   forward-sexp(1)
>   hs-forward-sexp((48293 48294 #<buffer frame.el>) 1)
>   hs-block-positions()
>   hs-hideable-region-p()
>   hs-get-first-block()
>   hs--add-indicators(48005 48793)
>   jit-lock--run-functions(48005 48793)
>   jit-lock-fontify-now(48005 48793)
>   jit-lock-function(48005)
>   repos-count-screen-lines(1 48793)
>   reposition-window()

Yes, I forgot that forward-sexp can fail.

I fixed it and an bug that made `hs-hide-level-recursive` infloop.


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=0001-hideshow-Fix-regressions.-Bug-79857.patch

From 39323cec7d979aad09e517a30e3deb7b25e40109 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?El=C3=ADas=20Gabriel=20P=C3=A9rez?= <eg642616@HIDDEN>
Date: Tue, 18 Nov 2025 11:02:24 -0600
Subject: [PATCH] hideshow: Fix regressions.  (Bug#79857)

* lisp/progmodes/hideshow.el (hs-block-positions): Exit the
function if 'hs-forward-sexp' fails.
(hs-hide-level-recursive): Fix infloop.
* test/lisp/progmodes/hideshow-tests.el (hideshow-hide-level-1):
(hideshow-hide-level-2): Update tests.
---
 lisp/progmodes/hideshow.el            | 66 +++++++++++++++------------
 test/lisp/progmodes/hideshow-tests.el |  8 ++++
 2 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/lisp/progmodes/hideshow.el b/lisp/progmodes/hideshow.el
index 62bbbe40164..a738f51bdaa 100644
--- a/lisp/progmodes/hideshow.el
+++ b/lisp/progmodes/hideshow.el
@@ -794,34 +794,39 @@ hs-block-positions
 This returns a list with the current code block beginning and end
 positions.  This does nothing if there is not a code block at current
 point."
-  (save-match-data
-    (save-excursion
-      (when (funcall hs-looking-at-block-start-predicate)
-        (let ((mdata (match-data t))
-              (header-end (match-end 0))
-              block-beg block-end)
-          ;; `block-start' is the point at the end of the block
-          ;; beginning, which may need to be adjusted
-          (save-excursion
-            (when hs-adjust-block-beginning-function
-              (goto-char (funcall hs-adjust-block-beginning-function header-end)))
-            (setq block-beg (line-end-position)))
-          ;; `block-end' is the point at the end of the block
-          (hs-forward-sexp mdata 1)
-          (setq block-end
-                (cond ((and (stringp hs-block-end-regexp)
-                            (looking-back hs-block-end-regexp nil))
-                       (match-beginning 0))
-                      ((functionp hs-block-end-regexp)
-                       (funcall hs-block-end-regexp)
-                       (match-beginning 0))
-                      (t (point))))
-          ;; adjust block end (if needed)
-          (when hs-adjust-block-end-function
+  ;; `catch' is used here if the search fails due unbalanced parentheses
+  ;; or any other unknown error caused in `hs-forward-sexp'.
+  (catch 'hs-sexp-error
+    (save-match-data
+      (save-excursion
+        (when (funcall hs-looking-at-block-start-predicate)
+          (let ((mdata (match-data t))
+                (header-end (match-end 0))
+                block-beg block-end)
+            ;; `block-start' is the point at the end of the block
+            ;; beginning, which may need to be adjusted
+            (save-excursion
+              (when hs-adjust-block-beginning-function
+                (goto-char (funcall hs-adjust-block-beginning-function header-end)))
+              (setq block-beg (line-end-position)))
+            ;; `block-end' is the point at the end of the block
+            (condition-case-unless-debug _
+                (hs-forward-sexp mdata 1)
+              (scan-error (throw 'hs-sexp-error nil)))
             (setq block-end
-                  (or (funcall hs-adjust-block-end-function block-beg)
-                      block-end)))
-          (list block-beg block-end))))))
+                  (cond ((and (stringp hs-block-end-regexp)
+                              (looking-back hs-block-end-regexp nil))
+                         (match-beginning 0))
+                        ((functionp hs-block-end-regexp)
+                         (funcall hs-block-end-regexp)
+                         (match-beginning 0))
+                        (t (point))))
+            ;; adjust block end (if needed)
+            (when hs-adjust-block-end-function
+              (setq block-end
+                    (or (funcall hs-adjust-block-end-function block-beg)
+                        block-end)))
+            (list block-beg block-end)))))))
 
 (defun hs--make-indicators-overlays (beg)
   "Helper function to make the indicators overlays."
@@ -1177,8 +1182,11 @@ hs-hide-level-recursive
 	    (not (nth 8 (syntax-ppss)))) ; not inside comments or strings
       (if (> arg 1)
 	  (hs-hide-level-recursive (1- arg) minp maxp)
-	(goto-char (match-beginning hs-block-start-mdata-select))
-	(hs-hide-block-at-point t))))
+        ;; `hs-hide-block-at-point' already moves the cursor, but if it
+        ;; fails, return to the previous position where we were.
+	(unless (and (goto-char (match-beginning hs-block-start-mdata-select))
+	             (hs-hide-block-at-point t))
+            (goto-char (match-end hs-block-start-mdata-select))))))
   (goto-char maxp))
 
 (defmacro hs-life-goes-on (&rest body)
diff --git a/test/lisp/progmodes/hideshow-tests.el b/test/lisp/progmodes/hideshow-tests.el
index a6b3ecfbd3d..9cf60c1ec84 100644
--- a/test/lisp/progmodes/hideshow-tests.el
+++ b/test/lisp/progmodes/hideshow-tests.el
@@ -254,6 +254,8 @@ hideshow-hide-level-1
    Comments
 */
 
+\"String\"
+
 int
 main(int argc, char **argv)
 {
@@ -270,6 +272,8 @@ hideshow-hide-level-1
    Comments
 */
 
+\"String\"
+
 int
 main(int argc, char **argv)
 {}
@@ -284,6 +288,8 @@ hideshow-hide-level-2
    Comments
 */
 
+\"String\"
+
 int
 main(int argc, char **argv)
 {
@@ -300,6 +306,8 @@ hideshow-hide-level-2
    Comments
 */
 
+\"String\"
+
 int
 main(int argc, char **argv)
 {
-- 
2.51.1


--=-=-=
Content-Type: text/plain


-- 
- E.G via Gnus and Org.

--=-=-=--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#79857; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 18 Nov 2025 17:06:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Nov 18 12:06:32 2025
Received: from localhost ([127.0.0.1]:58876 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1vLP9z-0003DN-QE
	for submit <at> debbugs.gnu.org; Tue, 18 Nov 2025 12:06:32 -0500
Received: from lists.gnu.org ([2001:470:142::17]:50350)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <juri@HIDDEN>) id 1vLP9y-0003Cv-1l
 for submit <at> debbugs.gnu.org; Tue, 18 Nov 2025 12:06:30 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <juri@HIDDEN>) id 1vLP9k-0004hj-BT
 for bug-gnu-emacs@HIDDEN; Tue, 18 Nov 2025 12:06:16 -0500
Received: from mout-p-201.mailbox.org ([80.241.56.171])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256)
 (Exim 4.90_1) (envelope-from <juri@HIDDEN>) id 1vLP9g-0005O9-0d
 for bug-gnu-emacs@HIDDEN; Tue, 18 Nov 2025 12:06:13 -0500
Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
 (No client certificate requested)
 by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4d9rbk6gjyz9v6B
 for <bug-gnu-emacs@HIDDEN>; Tue, 18 Nov 2025 18:05:54 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linkov.net; s=MBO0001; 
 t=1763485555;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding;
 bh=AGq85lrlCn+V8fTYB3p+JMJm68idU2+QKYFyJOcYFaA=;
 b=X0B5GhDppFVh/pWhHBTOHo8k0xnpn49KyEvGGUDYYQ1kXAR+walcmnnADT9gJ5mJb5Is7N
 C6yZjynz8mtNCniwo/BB3oLRo0KXuCKJrg7rHv0n2U8QVdhXXehS6YOD4hwZzHEkZAsaix
 oQVw/HCxit1rTfzcfTXF3/RNDqBxQCWy8928ynN4xreCAYMaTHUEIl58VNz+n9Iav170bd
 smhK29YP5syox8HNPxoYRF7TGD0BysUAVqG1kFVE3QBruDSMamoBTfCyAQ/MiLAuJRLdB+
 q+mq54DS7XYHOO3Yka1axvc08LZYJDrTcxd90uQsVpbgAt/SEYUouRAMYVLphQ==
From: Juri Linkov <juri@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: hideshow: Unbalanced parentheses
Organization: LINKOV.NET
X-Debbugs-Cc: Elijah Gabe =?iso-8859-1?Q?P=E9rez?= <eg642616@HIDDEN>
Date: Tue, 18 Nov 2025 19:05:43 +0200
Message-ID: <87ikf7z32k.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Received-SPF: pass client-ip=80.241.56.171; envelope-from=juri@HIDDEN;
 helo=mout-p-201.mailbox.org
X-Spam_score_int: -27
X-Spam_score: -2.8
X-Spam_bar: --
X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001,
 RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 1.0 (+)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

Some strange error occurs during font-lock in hs-minor-mode.
Reproducible test case:

0. emacs -Q
1. Eval:

(progn
  (setq backtrace-on-redisplay-error t)
  (setq hs-show-indicators t)
  (add-hook 'find-file-hook 'hs-minor-mode)
  (find-file (expand-file-name "lisp/frame.el" installation-directory))
  (search-forward "set-window-fringes")
  (reposition-window))

This shows:

⛔ Warning (error): Error in a redisplay Lisp hook.  See buffer *Redisplay-trace*

And the buffer *Redisplay-trace* contains:

Error: scan-error ("Unbalanced parentheses" 48293 48793)
  scan-sexps(48293 1)
  forward-sexp-default-function(1)
  forward-sexp(1)
  hs-forward-sexp((48293 48294 #<buffer frame.el>) 1)
  hs-block-positions()
  hs-hideable-region-p()
  hs-get-first-block()
  hs--add-indicators(48005 48793)
  jit-lock--run-functions(48005 48793)
  jit-lock-fontify-now(48005 48793)
  jit-lock-function(48005)
  repos-count-screen-lines(1 48793)
  reposition-window()




Acknowledgement sent to Juri Linkov <juri@HIDDEN>:
New bug report received and forwarded. Copy sent to eg642616@HIDDEN, bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to eg642616@HIDDEN, bug-gnu-emacs@HIDDEN:
bug#79857; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Wed, 19 Nov 2025 07:30:03 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.