GNU bug report logs - #77336
[PATCH] Fix mouse highlighting for compact mode lines

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: Pengji Zhang <me@HIDDEN>; Keywords: patch; dated Fri, 28 Mar 2025 10:56:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

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


Received: (at 77336) by debbugs.gnu.org; 31 Mar 2025 13:03:31 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Mar 31 09:03:31 2025
Received: from localhost ([127.0.0.1]:40281 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tzEnb-0001Ah-7U
	for submit <at> debbugs.gnu.org; Mon, 31 Mar 2025 09:03:31 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:49480)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tzEnX-00019M-OK
 for 77336 <at> debbugs.gnu.org; Mon, 31 Mar 2025 09:03:28 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tzEnS-0001ec-0u; Mon, 31 Mar 2025 09:03:22 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=p9c0prGt5Ub84hX6TaOjR4hnWQA+O1IczJ3Q2zayGuo=; b=P9ga4MEy18WH
 9Xl4eVGimVI64auHlkP8PUoA0NJTx1G8S4TemHha/Oefq3VL/xso7UofWJj3lMFiPkMZxl/KYRwdf
 K6avJKJCsf0HGXgQZSWv1qOOIGSd3+F7V1WUiRFi6MhYfG8OQPEbVUxghn3YHuvWxVGTUQmUbvn4V
 81NAbg4HcU+Xr0rUKBa30IQIX3cvG+4UpvTWxoGLcqsmsDOPcdwQnbp7zlmTtPvceQ/NgxG7N8qBH
 WqsBzecW9rgBG/oi29n77/V0AJpWtUc4xA5tJ5oOnFqVc2iysr219M4srhEKwyjWSZzBJgxhjnFTB
 VmQ4roa49U/n8yj9RQVSuA==;
Date: Mon, 31 Mar 2025 16:03:18 +0300
Message-Id: <86cydx4ajt.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Pengji Zhang <me@HIDDEN>
In-Reply-To: <87ldslho4n.fsf@HIDDEN> (message from Pengji Zhang on Mon,
 31 Mar 2025 11:31:36 +0800)
Subject: Re: bug#77336: [PATCH] Fix mouse highlighting for compact mode lines
References: <87iknt4e71.fsf@HIDDEN> <86tt7c8a6a.fsf@HIDDEN>
 <871pueagjo.fsf@HIDDEN> <86zfh24tim.fsf@HIDDEN>
 <87ldslho4n.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 77336
Cc: 77336 <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: -3.3 (---)

> From: Pengji Zhang <me@HIDDEN>
> Cc: 77336 <at> debbugs.gnu.org
> Date: Mon, 31 Mar 2025 11:31:36 +0800
> 
> Eli Zaretskii <eliz@HIDDEN> writes:
> 
> >> Is casting the 'Lisp_Object' to a number acceptable here?
> >
> > No, because Lisp_Object could be a struct (if Emacs was configured with
> > "--enable-check-lisp-object-type").
> 
> Sorry I did not make it clear. I meant 'make_fixnum(XLI(elt))'. I
> suppose 'XLI' will handle that case correctly?

I'd prefer not to do that unless there's no other reasonable solution.

> I am actually concerned that there could be a collision between two
> different 'elt's, e.g., a symbol and a string, because 'make_fixnum'
> alters the tag of 'elt'. I think it might be fine because 'elt' should
> always be a 'Lisp_String' when this is called.

Sorry, I don't understand: what do you mean by "alters the tag of
'elt'", and how could make_fixnum affect 'elt'?

> > A global variable is what I had in mind.  I don't see why it would be
> > less clean.
> 
> It is just that maintaining a global state is not as tasteful to me. If
> 'make_fixnum(XLI(elt))' is not good here, I am happy to go this way.

Yes, a global variable is cleaner than using XLI for this purpose.




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

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


Received: (at 77336) by debbugs.gnu.org; 31 Mar 2025 03:31:58 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Mar 30 23:31:57 2025
Received: from localhost ([127.0.0.1]:38917 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tz5sR-0005rd-8m
	for submit <at> debbugs.gnu.org; Sun, 30 Mar 2025 23:31:57 -0400
Received: from fout-a4-smtp.messagingengine.com ([103.168.172.147]:35171)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <me@HIDDEN>) id 1tz5sI-0005pV-KS
 for 77336 <at> debbugs.gnu.org; Sun, 30 Mar 2025 23:31:52 -0400
Received: from phl-compute-05.internal (phl-compute-05.phl.internal
 [10.202.2.45])
 by mailfout.phl.internal (Postfix) with ESMTP id D93CB1383820;
 Sun, 30 Mar 2025 23:31:40 -0400 (EDT)
Received: from phl-mailfrontend-02 ([10.202.2.163])
 by phl-compute-05.internal (MEProxy); Sun, 30 Mar 2025 23:31:40 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengjiz.com; h=
 cc:cc:content-type:content-type:date:date:from:from:in-reply-to
 :in-reply-to:message-id:mime-version:references:reply-to:subject
 :subject:to:to; s=fm3; t=1743391900; x=1743478300; bh=/Pk3rpBKdI
 WKQZ4T3OaVYG0OuzLyy8SFX4+a6c/bQPI=; b=3xSCIG04BNWSj/2gdyoO5btQ61
 X5B/SWDb4JSpCEv7D46mBq/BKFYwEqjEklsZjXZ4jXKA42q8nETQRZizRVZmAhNO
 oXbdTTlYlkKMsToLhRL+D3yK0lBJlpg6JcJpTmxt1gt1YZoAPjLwm6tN7QApMeRE
 UewKS8wFw+3wDg4Qmcz+rIyHcRlURdQkkUZmALI0MIRXZhqeFnLHeYhVrsmN0csm
 42exMM4BhjhEy4k1lsb14Hy7GJDGzfYmu4/lqafANvET/dO39O5xgF/fJlhJq6pu
 1vmSrXEjj1Zb081yAXWmZLqjka6X4RQZS7cTNUtJR3+x6u7/kBiRe8yU+tWw==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
 messagingengine.com; h=cc:cc:content-type:content-type:date:date
 :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to
 :message-id:mime-version:references:reply-to:subject:subject:to
 :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=
 1743391900; x=1743478300; bh=/Pk3rpBKdIWKQZ4T3OaVYG0OuzLyy8SFX4+
 a6c/bQPI=; b=UN9aDycR/LEMj+E0GCSQ1K41/0uuntyKlkDGn9Th4tx28284x7E
 iVL7dNT/eA6qM3KJXTsi0ByqdOWsZRzoySMfDiq50fqkEX+5UWv8EftPmIwzCSre
 AWSTKAV6nSICMqH/yTPwAQxS66yXdbQ/wdc5fC9bUFV/NDMuRPcj08f4M6f6eRUo
 JJ/iroNEkUwAG7lnDUtX1ScpScqONleNXhXZFGIuDLtwawTUrVGqabpqJrxvV+UQ
 3jjl1WvCy8StsfmXtCNycYraaOtKhVGxITpzLgyFNO9Ib1Iw/fMvfwmho9AmKtbf
 WUaR/WUFNpQ1IMrkSFOhKMI1X/vcs+RcmrQ==
X-ME-Sender: <xms:nAzqZ0xhLhC3LIun5mDUyAoovsgKG_K8_mISDCQ0i65dXHAaWdnBWw>
 <xme:nAzqZ4TRL3Hl3opAoYlgRG3ae5-k-cn5uAAXmK89EE7ud8db7VZFxmTTruReiIfy_
 Yc5oQyRsAM4vsH4a44>
X-ME-Received: <xmr:nAzqZ2Ulqby-7Z6J5F8K8uHgfN5xikKs64ezw3lsA2u7xjXmxjguu7vPWgQ>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddujeekkeehucetufdoteggodetrf
 dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv
 pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih
 gvnhhtshculddquddttddmnecujfgurhephffvvefujghffffkgggtsehttdertddttddt
 necuhfhrohhmpefrvghnghhjihcukghhrghnghcuoehmvgesphgvnhhgjhhiiidrtghomh
 eqnecuggftrfgrthhtvghrnhepgeefieeivddukeeitdegudeftdevtdeuteeifffhvdeh
 ffetgfeijeeileelheegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg
 hilhhfrhhomhepmhgvsehpvghnghhjihiirdgtohhmpdhnsggprhgtphhtthhopedvpdhm
 ohguvgepshhmthhpohhuthdprhgtphhtthhopegvlhhiiiesghhnuhdrohhrghdprhgtph
 htthhopeejjeeffeeiseguvggssghughhsrdhgnhhurdhorhhg
X-ME-Proxy: <xmx:nAzqZygWnZ92B5SsK4j7s9K2S0CKUcslCSY8UCA8rXTi5UFHriFarQ>
 <xmx:nAzqZ2Aj7nD54TKuU-OMRXeb7xGGTmF2Kwjcw8KL1RdDk8KaZmHVPg>
 <xmx:nAzqZzLsk2aj24v805RURHCMSX-FZBuoBY55DOdmZc5GeZlSrF1oXQ>
 <xmx:nAzqZ9AO5h-g46649js6_Mlh9zn2hHGOdJd_wYrcUnaZPgg_pgkZLg>
 <xmx:nAzqZ5M8VvC7HGEOyCK5qCOayNqPPhbnbzS-lNrlTz-9IWgPsVGV_-8F>
Feedback-ID: i16614472:Fastmail
Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun,
 30 Mar 2025 23:31:39 -0400 (EDT)
From: Pengji Zhang <me@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#77336: [PATCH] Fix mouse highlighting for compact mode lines
In-Reply-To: <86zfh24tim.fsf@HIDDEN>
References: <87iknt4e71.fsf@HIDDEN> <86tt7c8a6a.fsf@HIDDEN>
 <871pueagjo.fsf@HIDDEN> <86zfh24tim.fsf@HIDDEN>
Date: Mon, 31 Mar 2025 11:31:36 +0800
Message-ID: <87ldslho4n.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 77336
Cc: 77336 <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 (-)

Eli Zaretskii <eliz@HIDDEN> writes:

>> From: Pengji Zhang <me@HIDDEN>
>> Cc: 77336 <at> debbugs.gnu.org
>> Date: Sun, 30 Mar 2025 19:44:59 +0800
>> 
>> > Thanks, but why do we need to make the value of this mode-line-element
>> > property be the element itself?  Why not give it some simple value,
>> > like the ordinal number of the element (which should be incremented
>> > whenever we process another element)?  So we could call this property
>> > mode-line-elt-number and assign the elements values 1, 2, 3, etc.
>> 
>> Is casting the 'Lisp_Object' to a number acceptable here?
>
> No, because Lisp_Object could be a struct (if Emacs was configured with
> "--enable-check-lisp-object-type").

Sorry I did not make it clear. I meant 'make_fixnum(XLI(elt))'. I
suppose 'XLI' will handle that case correctly?

I am actually concerned that there could be a collision between two
different 'elt's, e.g., a symbol and a string, because 'make_fixnum'
alters the tag of 'elt'. I think it might be fine because 'elt' should
always be a 'Lisp_String' when this is called.

> What I had in mind was to have a static global int variable named, say
> elt_no, initialized to zero when display_mode_line is called, and then
> give each segment of the mode line a value like this:
>
>    AUTO_LIST2 (src, Qmode_line_element, make_fixnum (elt_no++));
>    n += store_mode_line_string (NULL, elt, true, 0, prec, src);   
>
>> I tried an incremental counter but gave up. Because
>> 'display_mode_element' could be called recursively, we may have to
>> change its signature or introduce a new global variable. That feels a
>> bit less clean to me.
>
> A global variable is what I had in mind.  I don't see why it would be
> less clean.

It is just that maintaining a global state is not as tasteful to me. If
'make_fixnum(XLI(elt))' is not good here, I am happy to go this way.

>> > I'm concerned that having the elements themselves be values will
>> > prevent them from being GC'd, which might increase the memory
>> > pressure.  By contrast, fixnums are immediate values that don't need
>> > to be GC'ed, and the element itself will not have any references after
>> > the mode line is processed.
>> 
>> I thought all objects would be GC'd. Since fixnums are not, I guess now
>> we do not need to remove the text property before displaying the string?
>> Please let me know what you think and I will update the patch if needed.
>
> If you remove the text property because of GC, then indeed you don't
> need to do that anymore with fixnums.

Thanks. I will update the patch accordingly.




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

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


Received: (at 77336) by debbugs.gnu.org; 30 Mar 2025 12:01:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Mar 30 08:01:32 2025
Received: from localhost ([127.0.0.1]:35068 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tyrM4-0004FO-E7
	for submit <at> debbugs.gnu.org; Sun, 30 Mar 2025 08:01:32 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:58906)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tyrM2-0004FA-3o
 for 77336 <at> debbugs.gnu.org; Sun, 30 Mar 2025 08:01:30 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tyrLw-0005GH-OF; Sun, 30 Mar 2025 08:01:24 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=dxUSwEV7o39KPiWlQ8fTpuzNcmMgcNXZF0FWtskDarI=; b=QqTkBV+H73cG
 NsDbqjLGetVcqz8crv3VKMXQrYxNZZCeEiSbVqjTlq1c9x3n4c6sqSyJ2fffMStoJKt8JsZk7fpdj
 VIYvbh86N65uTyqed1C0XUVPMm+3EMuXYJI0wzo3tFoeDPTJ0z6fNLuRURKwxtHisJdt8ajYuqqg8
 q/9ESduXg0ZZ7ncBL3ehJVMXtg1RSr7ICbnwheTMiPfSHpROQcivGFGyH1qzFcddvd+eqNEsD1yYo
 HMaT2RhEubFlqwgYZ10nISuruFT797aN39+BBwYbr0ggrOMn2NYoZJAzp1sdHQWLw8sZxJxgjAgZH
 QpkGr+nuR14aA/ZuG3SjgQ==;
Date: Sun, 30 Mar 2025 15:01:21 +0300
Message-Id: <86zfh24tim.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Pengji Zhang <me@HIDDEN>
In-Reply-To: <871pueagjo.fsf@HIDDEN> (message from Pengji Zhang on Sun,
 30 Mar 2025 19:44:59 +0800)
Subject: Re: bug#77336: [PATCH] Fix mouse highlighting for compact mode lines
References: <87iknt4e71.fsf@HIDDEN> <86tt7c8a6a.fsf@HIDDEN>
 <871pueagjo.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 77336
Cc: 77336 <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: -3.3 (---)

> From: Pengji Zhang <me@HIDDEN>
> Cc: 77336 <at> debbugs.gnu.org
> Date: Sun, 30 Mar 2025 19:44:59 +0800
> 
> > Thanks, but why do we need to make the value of this mode-line-element
> > property be the element itself?  Why not give it some simple value,
> > like the ordinal number of the element (which should be incremented
> > whenever we process another element)?  So we could call this property
> > mode-line-elt-number and assign the elements values 1, 2, 3, etc.
> 
> Is casting the 'Lisp_Object' to a number acceptable here?

No, because Lisp_Object could be a struct (if Emacs was configured with
"--enable-check-lisp-object-type").

What I had in mind was to have a static global int variable named, say
elt_no, initialized to zero when display_mode_line is called, and then
give each segment of the mode line a value like this:

   AUTO_LIST2 (src, Qmode_line_element, make_fixnum (elt_no++));
   n += store_mode_line_string (NULL, elt, true, 0, prec, src);   

> I tried an incremental counter but gave up. Because
> 'display_mode_element' could be called recursively, we may have to
> change its signature or introduce a new global variable. That feels a
> bit less clean to me.

A global variable is what I had in mind.  I don't see why it would be
less clean.

> > I'm concerned that having the elements themselves be values will
> > prevent them from being GC'd, which might increase the memory
> > pressure.  By contrast, fixnums are immediate values that don't need
> > to be GC'ed, and the element itself will not have any references after
> > the mode line is processed.
> 
> I thought all objects would be GC'd. Since fixnums are not, I guess now
> we do not need to remove the text property before displaying the string?
> Please let me know what you think and I will update the patch if needed.

If you remove the text property because of GC, then indeed you don't
need to do that anymore with fixnums.




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

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


Received: (at 77336) by debbugs.gnu.org; 30 Mar 2025 11:45:12 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Mar 30 07:45:12 2025
Received: from localhost ([127.0.0.1]:34985 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tyr6F-0003RQ-Uy
	for submit <at> debbugs.gnu.org; Sun, 30 Mar 2025 07:45:12 -0400
Received: from fhigh-b1-smtp.messagingengine.com ([202.12.124.152]:43195)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <me@HIDDEN>) id 1tyr6D-0003Lr-7B
 for 77336 <at> debbugs.gnu.org; Sun, 30 Mar 2025 07:45:09 -0400
Received: from phl-compute-01.internal (phl-compute-01.phl.internal
 [10.202.2.41])
 by mailfhigh.stl.internal (Postfix) with ESMTP id C68012540127;
 Sun, 30 Mar 2025 07:45:03 -0400 (EDT)
Received: from phl-mailfrontend-02 ([10.202.2.163])
 by phl-compute-01.internal (MEProxy); Sun, 30 Mar 2025 07:45:03 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengjiz.com; h=
 cc:cc:content-type:content-type:date:date:from:from:in-reply-to
 :in-reply-to:message-id:mime-version:references:reply-to:subject
 :subject:to:to; s=fm3; t=1743335103; x=1743421503; bh=BrnF/ZgX97
 saqR2wtYBvJFAyL0VQ77wFhrZZKHIczSI=; b=0YD+CeUbJuEKOTzIF64CUEzjdx
 FXGrg1HjUKm3/EIXI2vEUmagDlC71PXFMAmX+E5rnRLvmz5eO8AsTfrRTJ1isWck
 gd0n8N7sM/WQiP6IDil2FXAEDvvZzFoXj7ZBeCAtLrp7sM0UO7pmZ88DiaSXQziC
 zhsgAPRTkM716iR8QyHAYXfr9bkoNao7CtmmeJfbHg6BZwE1PmC3Sst4yFy8Ret8
 d0S0Lva5QNHXt6vCaK9lKSgIb0+kxlVcgscoIO4UttNSnuKJwOUqup0wZWnaE/4m
 qTjKayf9HBJ08fP8hSTOyDkqg6bcliUuAruKwGi9iEk0C8Fth9HuzYbWSUmA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
 messagingengine.com; h=cc:cc:content-type:content-type:date:date
 :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to
 :message-id:mime-version:references:reply-to:subject:subject:to
 :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=
 1743335103; x=1743421503; bh=BrnF/ZgX97saqR2wtYBvJFAyL0VQ77wFhrZ
 ZKHIczSI=; b=vOscRsDsN1vsa9AuiOSPRB2pTmvglyEbrW+vl1dv8VCrJxRsYOe
 Koko5x3o7qtHB9DiQsBMckjVoGGd4biRCZPUqVJCz8hNB6nBnYXv0V5ZFTgxPI1D
 UM1QvRTp+dvMErRRsmc31+OBFUQCDqk+154dsXpf+d9+gZzVwkjmYnh+MuuItsdG
 mBAf/2AgP7TuWEUaa2LoxwWgLdsmT/XYt2kDMa8AhXghMLUdNi4s6EMfLL8ySwGH
 Wyn8PeTbpmya5xS1q0VPKA4cFkn+PGPSoksNe6AhmfEUD7xs+8xaSQpO6swMcGe1
 EY/QVk6xp6XAp6ttlC6C6jobGbo2DYXN7WQ==
X-ME-Sender: <xms:vy7pZ64pOZZ6MHEay57E5H4JCfdEcpr0lfAxcjsLzzhAU2BVmSmPrQ>
 <xme:vy7pZz4vJ-oJmz_qrJ3RGinQ27rMN-AlbZzh2lVH60_8sbGj7tdY9sftUDMiotPHI
 R7YeXAxVYz6Sj86waI>
X-ME-Received: <xmr:vy7pZ5cpqS87r5IAiTbEzzwobs_abg_GkBOudyK0yz-zpbjwD56mbMQtyDs>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddujeeileeiucetufdoteggodetrf
 dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv
 pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih
 gvnhhtshculddquddttddmnecujfgurhephffvvefujghffffkgggtsehmtderredttddt
 necuhfhrohhmpefrvghnghhjihcukghhrghnghcuoehmvgesphgvnhhgjhhiiidrtghomh
 eqnecuggftrfgrthhtvghrnhepieffgfeiueelgfejjeeivdelheffffeuieeihffhffev
 jeeuhfegvdfhkefgleeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg
 hilhhfrhhomhepmhgvsehpvghnghhjihiirdgtohhmpdhnsggprhgtphhtthhopedvpdhm
 ohguvgepshhmthhpohhuthdprhgtphhtthhopegvlhhiiiesghhnuhdrohhrghdprhgtph
 htthhopeejjeeffeeiseguvggssghughhsrdhgnhhurdhorhhg
X-ME-Proxy: <xmx:vy7pZ3LLe9SbByNA3UqBrsIUD6IaxBfcCVyUfDswQbL2vOpVrsMOGQ>
 <xmx:vy7pZ-LP2VbUSvyHbmtCE8wIOSdOeexgWmcTHUq1HAPF8hiNRP3D7A>
 <xmx:vy7pZ4wrwcyheZhqzipVWKNCZMnDMFl3D4knnGwbdDYus0HQYxqyFQ>
 <xmx:vy7pZyLkDLvecz-6gt_9o9XuazBXcQaP11alNFuGHv1bVWleCm2AgQ>
 <xmx:vy7pZ1U3pqA1sd20tx4LRbJcFqC9GAHkZ3eIfo7f8OzAHG0ndznFkx_w>
Feedback-ID: i16614472:Fastmail
Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun,
 30 Mar 2025 07:45:02 -0400 (EDT)
From: Pengji Zhang <me@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#77336: [PATCH] Fix mouse highlighting for compact mode lines
In-Reply-To: <86tt7c8a6a.fsf@HIDDEN>
References: <87iknt4e71.fsf@HIDDEN> <86tt7c8a6a.fsf@HIDDEN>
Date: Sun, 30 Mar 2025 19:44:59 +0800
Message-ID: <871pueagjo.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 77336
Cc: 77336 <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 (-)

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

Eli Zaretskii <eliz@HIDDEN> writes:

> Thanks, but why do we need to make the value of this mode-line-element
> property be the element itself?  Why not give it some simple value,
> like the ordinal number of the element (which should be incremented
> whenever we process another element)?  So we could call this property
> mode-line-elt-number and assign the elements values 1, 2, 3, etc.

Is casting the 'Lisp_Object' to a number acceptable here? Please have a
look at the updated patch.

I tried an incremental counter but gave up. Because
'display_mode_element' could be called recursively, we may have to
change its signature or introduce a new global variable. That feels a
bit less clean to me.

> I'm concerned that having the elements themselves be values will
> prevent them from being GC'd, which might increase the memory
> pressure.  By contrast, fixnums are immediate values that don't need
> to be GC'ed, and the element itself will not have any references after
> the mode line is processed.

I thought all objects would be GC'd. Since fixnums are not, I guess now
we do not need to remove the text property before displaying the string?
Please let me know what you think and I will update the patch if needed.


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0001-Fix-mouse-highlighting-for-compact-mode-lines.patch

From 73bc97111ace409a5de27930d0dadcd18490fa5e Mon Sep 17 00:00:00 2001
From: Pengji Zhang <me@HIDDEN>
Date: Sun, 30 Mar 2025 19:24:10 +0800
Subject: [PATCH] Fix mouse highlighting for compact mode lines (bug#77336)

When 'mode-line-compact' is non-nil, the mode line string is
displayed as a whole.  That confuses the computation of ranges
of mouse highlighting on the mode line because all the glyphs
have the same Lisp object source.  As such, in this commit we
instead split the mode line string by sources, and display those
elements one by one, so the boundaries of each element could be
correctly detected for the purpose of mouse highlighting.

* src/xdisp.c (display_mode_line): Display mode line elements
one by one when 'mode-line-compact' is non-nil.
(display_mode_element): Record source of the stored string via a
text property.
(syms_of_xdisp): New symbol for the text property.
---
 src/xdisp.c | 132 ++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 93 insertions(+), 39 deletions(-)

diff --git a/src/xdisp.c b/src/xdisp.c
index 2c676c09827..d712e3d02ae 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -27754,57 +27754,102 @@ display_mode_line (struct window *w, enum face_id face_id, Lisp_Object format)
 	{
 	  /* The window is wide enough; just display the mode line we
 	     just computed. */
-	  display_string (NULL, mode_string, Qnil,
-			  0, 0, &it, 0, 0, 0,
-			  STRING_MULTIBYTE (mode_string));
+	  Lisp_Object start = make_fixnum (0), end;
+	  Lisp_Object elt;
+	  AUTO_LIST2 (props, Qmode_line_element, Qnil);
+
+	  /* Display the mode line string one element by one element.
+	     This is to make the ranges of mouse highlighting
+	     correct. */
+	  do
+	    {
+	      end = Fnext_single_property_change (start, Qmode_line_element,
+						  mode_string, Qnil);
+	      elt = Fsubstring (mode_string, start, end);
+	      Fremove_text_properties (make_fixnum (0),
+				       make_fixnum (SCHARS (elt)),
+				       props, elt);
+	      display_string (NULL, elt, Qnil, 0, 0, &it, 0, 0, 0,
+			      STRING_MULTIBYTE (elt));
+	      start = end;
+	    }
+	  while (!NILP (end));
 	}
       else
 	{
 	  /* Compress the mode line. */
-	  ptrdiff_t i = 0, i_byte = 0, start = 0;
+	  ptrdiff_t i = 0, i_byte = 0;
 	  int prev = 0;
+	  Lisp_Object start = make_fixnum (0), end;
+	  Lisp_Object elt = empty_unibyte_string;
+	  AUTO_LIST2 (props, Qmode_line_element, Qnil);
 
-	  while (i < SCHARS (mode_string))
+	  /* Display the mode line string one element by one element.
+	     This is to make the ranges of mouse highlighting
+	     correct. */
+	  do
 	    {
-	      int c = fetch_string_char_advance (mode_string, &i, &i_byte);
-	      if (c == ' ' && prev == ' ')
+	      end = Fnext_single_property_change (start,
+						  Qmode_line_element,
+						  mode_string,
+						  make_fixnum (SCHARS (mode_string)));
+	      while (i < XFIXNUM (end))
 		{
-		  Lisp_Object prev_pos = make_fixnum (i - 1);
-
-		  /* SPC characters with 'display' properties are not
-                     really "empty", since they have non-trivial visual
-                     effects on the mode line.  */
-		  if (NILP (Fget_text_property (prev_pos, Qdisplay,
-						mode_string)))
+		  int c = fetch_string_char_advance (mode_string, &i, &i_byte);
+		  if (c == ' ' && prev == ' ')
 		    {
-		      display_string (NULL,
-				      Fsubstring (mode_string,
-						  make_fixnum (start),
-						  prev_pos),
-				      Qnil, 0, 0, &it, 0, 0, 0,
-				      STRING_MULTIBYTE (mode_string));
-		      /* Skip past the rest of the space characters. */
-		      while (c == ' ' && i < SCHARS (mode_string)
-			     && NILP (Fget_text_property (make_fixnum (i),
-							  Qdisplay,
-							  mode_string)))
+		      Lisp_Object prev_pos = make_fixnum (i - 1);
+		      Lisp_Object display = Fget_text_property (prev_pos,
+								Qdisplay,
+								mode_string);
+
+		      /* SPC characters with 'display' properties are not
+			 really "empty", since they have non-trivial visual
+			 effects on the mode line.  */
+		      if (NILP (display))
 			{
-			  c = fetch_string_char_advance (mode_string,
-							 &i, &i_byte);
+			  elt = concat2 (elt, Fsubstring (mode_string,
+							  start,
+							  prev_pos));
+
+			  /* Skip past the rest of the space characters. */
+			  Lisp_Object display = Fget_text_property (make_fixnum (i),
+								    Qdisplay,
+								    mode_string);
+			  while (c == ' ' && i < XFIXNUM (end)
+				 && NILP (display))
+			    {
+			      c = fetch_string_char_advance (mode_string,
+							     &i, &i_byte);
+			      display = Fget_text_property (make_fixnum (i),
+							    Qdisplay,
+							    mode_string);
+			    }
+
+			  /* Skip the final space no matter how the loop
+			     above ends. */
+			  if (c == ' ' && NILP (display))
+			    start = end;
+			  else
+			    start = make_fixnum (i - 1);
 			}
-		      start = i - 1;
 		    }
+		  prev = c;
 		}
-	      prev = c;
-	    }
 
-	  /* Display the final bit. */
-	  if (start < i)
-	    display_string (NULL,
-			    Fsubstring (mode_string, make_fixnum (start),
-					make_fixnum (i)),
-			    Qnil, 0, 0, &it, 0, 0, 0,
-			    STRING_MULTIBYTE (mode_string));
+	      /* Append the final bit. */
+	      if (XFIXNUM (start) < XFIXNUM (end))
+		elt = concat2 (elt, Fsubstring (mode_string, start, end));
+
+	      Fremove_text_properties (make_fixnum (0),
+				       make_fixnum (SCHARS (elt)),
+				       props, elt);
+	      display_string (NULL, elt, Qnil, 0, 0, &it, 0, 0, 0,
+			      STRING_MULTIBYTE (elt));
+	      elt = empty_unibyte_string;
+	      start = end;
+	    }
+	  while (XFIXNUM (end) < SCHARS (mode_string));
 	}
     }
   pop_kboard ();
@@ -28023,7 +28068,10 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
 		n += store_mode_line_noprop (SSDATA (elt), -1, prec);
 		break;
 	      case MODE_LINE_STRING:
-		n += store_mode_line_string (NULL, elt, true, 0, prec, Qnil);
+		{
+		  AUTO_LIST2 (src, Qmode_line_element, make_fixnum (XLI (elt)));
+		  n += store_mode_line_string (NULL, elt, true, 0, prec, src);
+		}
 		break;
 	      case MODE_LINE_DISPLAY:
 		n += display_string (NULL, elt, Qnil, 0, 0, it,
@@ -28076,8 +28124,9 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
 		      Lisp_Object mode_string
 			= Fsubstring (elt, make_fixnum (charpos),
 				      make_fixnum (endpos));
+		      AUTO_LIST2 (src, Qmode_line_element, make_fixnum (XLI (elt)));
 		      n += store_mode_line_string (NULL, mode_string, false,
-						   0, 0, Qnil);
+						   0, 0, src);
 		    }
 		    break;
 		  case MODE_LINE_DISPLAY:
@@ -28157,6 +28206,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
 			{
 			  Lisp_Object tem = build_string (spec);
 			  props = Ftext_properties_at (make_fixnum (charpos), elt);
+			  props = plist_put (props, Qmode_line_element, make_fixnum (XLI (elt)));
 			  /* Should only keep face property in props */
 			  n += store_mode_line_string (NULL, tem, false,
 						       field, prec, props);
@@ -28372,6 +28422,9 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
 	  n += store_mode_line_noprop ("", field_width - n, 0);
 	  break;
 	case MODE_LINE_STRING:
+	  /* NOTE: Padding implicitly has 'mode-line-element' property
+	     to be nil.  Normally padding spaces are between two real
+	     elements, so this should be good. */
 	  n += store_mode_line_string ("", Qnil, false, field_width - n, 0,
 				       Qnil);
 	  break;
@@ -37666,6 +37719,7 @@ syms_of_xdisp (void)
   DEFSYM (Qfontification_functions, "fontification-functions");
   DEFSYM (Qlong_line_optimizations_in_fontification_functions,
 	  "long-line-optimizations-in-fontification-functions");
+  DEFSYM (Qmode_line_element, "mode-line-element");
 
   /* Name of the symbol which disables Lisp evaluation in 'display'
      properties.  This is used by enriched.el.  */
-- 
2.49.0


--=-=-=--




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

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


Received: (at 77336) by debbugs.gnu.org; 29 Mar 2025 09:21:12 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 29 05:21:12 2025
Received: from localhost ([127.0.0.1]:56805 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tySNM-0004Td-4W
	for submit <at> debbugs.gnu.org; Sat, 29 Mar 2025 05:21:12 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:43876)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1tySNJ-0004TN-Oc
 for 77336 <at> debbugs.gnu.org; Sat, 29 Mar 2025 05:21:11 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1tySNE-00067e-34; Sat, 29 Mar 2025 05:21:04 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=wADLitfz/LRX1mpUQks+Hoa9LcI7se6Oqhy636K2AZc=; b=DKssuHcAK2LG
 4OAU6mNhelz5R8AYZ1YkZ3B+Uts1o6LZbPPLY3d/wCYvOCau4rZhcTIl7tzZ2Zif3DRiY+7qMz5br
 hl0cRC/vDERerzEJW7pL+dCc0de7oXrdckfUd/pr63wBEW4sAD5I1fJsdwJB1ZTp8djbyQUqbvgL/
 d6qANlyk95PLTNquLsruwm3MxNLajLYFEG9k2hwf9BgK4jKDLwh9h15/6lnWaxGilz5N1B7W0i0A2
 Pd4t3HmYR8vneFDOuOyARfNV3o9QiNwOsfeBKx9Ip5tZp/dUTr7Y85huhE1p6l5EE8Kdtkqgsp81G
 ObJ3QLScDkjJHHCO0sa18w==;
Date: Sat, 29 Mar 2025 12:21:01 +0300
Message-Id: <86tt7c8a6a.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Pengji Zhang <me@HIDDEN>
In-Reply-To: <87iknt4e71.fsf@HIDDEN> (message from Pengji Zhang on Fri,
 28 Mar 2025 18:55:30 +0800)
Subject: Re: bug#77336: [PATCH] Fix mouse highlighting for compact mode lines
References: <87iknt4e71.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 77336
Cc: 77336 <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: -3.3 (---)

> From: Pengji Zhang <me@HIDDEN>
> Date: Fri, 28 Mar 2025 18:55:30 +0800
> 
> @@ -28014,7 +28059,10 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
>  		n += store_mode_line_noprop (SSDATA (elt), -1, prec);
>  		break;
>  	      case MODE_LINE_STRING:
> -		n += store_mode_line_string (NULL, elt, true, 0, prec, Qnil);
> +		{
> +		  AUTO_LIST2 (src, Qmode_line_element, elt);
> +		  n += store_mode_line_string (NULL, elt, true, 0, prec, src);
> +		}
>  		break;
>  	      case MODE_LINE_DISPLAY:
>  		n += display_string (NULL, elt, Qnil, 0, 0, it,
> @@ -28067,8 +28115,9 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
>  		      Lisp_Object mode_string
>  			= Fsubstring (elt, make_fixnum (charpos),
>  				      make_fixnum (endpos));
> +		      AUTO_LIST2 (src, Qmode_line_element, elt);
>  		      n += store_mode_line_string (NULL, mode_string, false,
> -						   0, 0, Qnil);
> +						   0, 0, src);
>  		    }
>  		    break;
>  		  case MODE_LINE_DISPLAY:
> @@ -28148,6 +28197,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
>  			{
>  			  Lisp_Object tem = build_string (spec);
>  			  props = Ftext_properties_at (make_fixnum (charpos), elt);
> +			  props = plist_put (props, Qmode_line_element, elt);
>  			  /* Should only keep face property in props */
>  			  n += store_mode_line_string (NULL, tem, false,
>  						       field, prec, props);

Thanks, but why do we need to make the value of this mode-line-element
property be the element itself?  Why not give it some simple value,
like the ordinal number of the element (which should be incremented
whenever we process another element)?  So we could call this property
mode-line-elt-number and assign the elements values 1, 2, 3, etc.

I'm concerned that having the elements themselves be values will
prevent them from being GC'd, which might increase the memory
pressure.  By contrast, fixnums are immediate values that don't need
to be GC'ed, and the element itself will not have any references after
the mode line is processed.




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

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


Received: (at submit) by debbugs.gnu.org; 28 Mar 2025 10:55:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 28 06:55:47 2025
Received: from localhost ([127.0.0.1]:53034 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ty7NK-0003dF-PX
	for submit <at> debbugs.gnu.org; Fri, 28 Mar 2025 06:55:47 -0400
Received: from lists.gnu.org ([2001:470:142::17]:41976)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <me@HIDDEN>) id 1ty7NH-0003cy-Q7
 for submit <at> debbugs.gnu.org; Fri, 28 Mar 2025 06:55:44 -0400
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 <me@HIDDEN>) id 1ty7NB-0002H8-MX
 for bug-gnu-emacs@HIDDEN; Fri, 28 Mar 2025 06:55:38 -0400
Received: from fout-b3-smtp.messagingengine.com ([202.12.124.146])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <me@HIDDEN>) id 1ty7N9-00050T-Bp
 for bug-gnu-emacs@HIDDEN; Fri, 28 Mar 2025 06:55:37 -0400
Received: from phl-compute-12.internal (phl-compute-12.phl.internal
 [10.202.2.52])
 by mailfout.stl.internal (Postfix) with ESMTP id 363451140187
 for <bug-gnu-emacs@HIDDEN>; Fri, 28 Mar 2025 06:55:34 -0400 (EDT)
Received: from phl-mailfrontend-02 ([10.202.2.163])
 by phl-compute-12.internal (MEProxy); Fri, 28 Mar 2025 06:55:34 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengjiz.com; h=
 cc:content-type:content-type:date:date:from:from:in-reply-to
 :message-id:mime-version:reply-to:subject:subject:to:to; s=fm3;
 t=1743159334; x=1743245734; bh=/ljTKLeSgYPVIOoCxqU/BdblvY3HyS9m
 T+4JTeIHnC0=; b=o9NLzeUoKIhKNK8hN4eJU4wjBNopZOB0k+BDCrY9lM5Y7689
 7pQeR5JrNLyyZiKlNEm57CFXyYN/i5fz22rNuy+YD9Utfs6B48nKrclE1yHAvQdX
 7hLNjUcKWoLhq4VTJm5sIk5V1kBTdCRe9LoVxCsk1b4DOIP4e0NmsBPlYNVAAzrN
 ql9F2ZiSDKZt4gX910i832eAi98giBHTILNST30KWPE/K50ukEUC//qtvYm0Cyaf
 3uc48YFo0NxQofCplEJyEobUCKCQbiLv1Cf7D4liuPNFxAh9XOoEovnztjtxxW4O
 X1N2nGKMGhBi4Zk0elb8aPLk2m3G2YQvg0IKuQ==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
 messagingengine.com; h=cc:content-type:content-type:date:date
 :feedback-id:feedback-id:from:from:in-reply-to:message-id
 :mime-version:reply-to:subject:subject:to:to:x-me-proxy
 :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1743159334; x=
 1743245734; bh=/ljTKLeSgYPVIOoCxqU/BdblvY3HyS9mT+4JTeIHnC0=; b=f
 UrUdgLGpYYWJmXIkMrBMal+3p1Xl8q1NgDqEO9hKJVOZVSPjYghdyWPpEW/AYorA
 QA84ESGPfmtRaiPp6Hm/rsE5dF2IdyVyef9+Ulz7wbwGc4h6/6QmcxDEMgMvFFZf
 sV6jeHeDKSqqDxQcb7o5HFpWABcqhkM/tZ3GXE+sm07srJvy02/Ntl28FVelTg+/
 nocsj5MrmV9F6jZevJot3vI30NwMbDINd7kujUoZtH76P1tyAlg9/w7y7Np2x5CI
 y8NNmndycnn1CgPXRTAQ1vnkHf7hx5jXYDVnApVT6SrG/HpCKA7c753yYFNEOyt8
 WixVk0/ci9REIkNVkBZJg==
X-ME-Sender: <xms:JYDmZ06kUeLVx5k0fI-XmZWRkcHvTTYLoLZ68gRNG3GXnEe8PeZL-A>
 <xme:JYDmZ14lPxojvJ59Pm4z9gjNXb4zkWsxRcK0YdWrz9tBOuMFmUmucl4Qb-UswIddU
 wP3tYZKneslvmVcXow>
X-ME-Received: <xmr:JYDmZze1fdbdv0gbG6CBr7008zMYwWfiL0W4ECdNIiN85riesVpQiELtoKQ>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddujeduuddtucetufdoteggodetrf
 dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv
 pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvf
 fufffkgggtsehmtderredttddtnecuhfhrohhmpefrvghnghhjihcukghhrghnghcuoehm
 vgesphgvnhhgjhhiiidrtghomheqnecuggftrfgrthhtvghrnhepfffgiefhgfduleelvd
 eiiedtvdefieegkedtkefftdeljefgheelvdffjeegteegnecuvehluhhsthgvrhfuihii
 vgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhgvsehpvghnghhjihiirdgtohhmpd
 hnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegsuhhg
 qdhgnhhuqdgvmhgrtghssehgnhhurdhorhhg
X-ME-Proxy: <xmx:JYDmZ5L-7ElHrAzXeltZn4F3dlwfE17noKhlVQ8gD52NSEQvyiunEA>
 <xmx:JYDmZ4JUe-2B2bQM0tAjLaVr1TDINR9OxQMdGhvKp3PXBqPrvCvg0g>
 <xmx:JYDmZ6xjLhAv__3jo5Mqzmb57JKwt4qNK25gPADX3HgcQQ_jS9CA0g>
 <xmx:JYDmZ8KJeg5uYbaUmKZCI0klunEuo04MY-qlcOQCQ2H-TDllZsmmiA>
 <xmx:JoDmZyiKGk74gPjk2H45HqHuYh8s5wAJfkKIKjoZyBpDMloSiVZq7kLm>
Feedback-ID: i16614472:Fastmail
Received: by mail.messagingengine.com (Postfix) with ESMTPA for
 <bug-gnu-emacs@HIDDEN>; Fri, 28 Mar 2025 06:55:32 -0400 (EDT)
From: Pengji Zhang <me@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: [PATCH] Fix mouse highlighting for compact mode lines
Date: Fri, 28 Mar 2025 18:55:30 +0800
Message-ID: <87iknt4e71.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Received-SPF: pass client-ip=202.12.124.146; envelope-from=me@HIDDEN;
 helo=fout-b3-smtp.messagingengine.com
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_RPBL_BLOCKED=0.001,
 RCVD_IN_VALIDITY_SAFE_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: 0.7 (/)
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.3 (/)

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

Hello,

I found that with 'mode-line-compact' being non-nil, mouse highlighting
would not work properly. To reproduce:

  - emacs -Q
  - (setq mode-line-compact t) or (setq mode-line-compact 'long)
  - Hover mouse cursor over the major mode part on the mode line

Now the minor mode lighters are also highlighted. That is presumably
because when 'mode-line-compact' is non-nil, the whole mode line string
is displayed at once. So the glyphs produced all have the same 'object'
field. That confuses the computation of boundaries for mouse
highlighting.

In this patch we instead split the mode line string into elements and
display them one by one.

Thanks!


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline;
 filename=0001-Fix-mouse-highlighting-for-compact-mode-lines.patch

From 5c7538aceb7e80ea44be7d74890d36e88d36169c Mon Sep 17 00:00:00 2001
From: Pengji Zhang <me@HIDDEN>
Date: Sun, 23 Mar 2025 20:19:09 +0800
Subject: [PATCH] Fix mouse highlighting for compact mode lines

When 'mode-line-compact' is non-nil, the mode line string is
displayed as a whole.  That confuses the computation of ranges
of mouse highlighting on the mode line because all the glyphs
have the same Lisp object source.  As such, in this commit we
instead split the mode line string by sources, and display those
elements one by one, so the boundaries of each element could be
correctly detected for the purpose of mouse highlighting.

* src/xdisp.c (display_mode_line): Display mode line elements
one by one when 'mode-line-compact' is non-nil.
(display_mode_element): Record source of the stored string via a
text property.
(syms_of_xdisp): New symbol for the text property.
---
 src/xdisp.c | 132 ++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 93 insertions(+), 39 deletions(-)

diff --git a/src/xdisp.c b/src/xdisp.c
index f2b158f00e3..193f9767c6f 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -27745,57 +27745,102 @@ display_mode_line (struct window *w, enum face_id face_id, Lisp_Object format)
 	{
 	  /* The window is wide enough; just display the mode line we
 	     just computed. */
-	  display_string (NULL, mode_string, Qnil,
-			  0, 0, &it, 0, 0, 0,
-			  STRING_MULTIBYTE (mode_string));
+	  Lisp_Object start = make_fixnum (0), end;
+	  Lisp_Object elt;
+	  AUTO_LIST2 (props, Qmode_line_element, Qnil);
+
+	  /* Display the mode line string one element by one element.
+	     This is to make the ranges of mouse highlighting
+	     correct. */
+	  do
+	    {
+	      end = Fnext_single_property_change (start, Qmode_line_element,
+						  mode_string, Qnil);
+	      elt = Fsubstring (mode_string, start, end);
+	      Fremove_text_properties (make_fixnum (0),
+				       make_fixnum (SCHARS (elt)),
+				       props, elt);
+	      display_string (NULL, elt, Qnil, 0, 0, &it, 0, 0, 0,
+			      STRING_MULTIBYTE (elt));
+	      start = end;
+	    }
+	  while (!NILP (end));
 	}
       else
 	{
 	  /* Compress the mode line. */
-	  ptrdiff_t i = 0, i_byte = 0, start = 0;
+	  ptrdiff_t i = 0, i_byte = 0;
 	  int prev = 0;
+	  Lisp_Object start = make_fixnum (0), end;
+	  Lisp_Object elt = empty_unibyte_string;
+	  AUTO_LIST2 (props, Qmode_line_element, Qnil);
 
-	  while (i < SCHARS (mode_string))
+	  /* Display the mode line string one element by one element.
+	     This is to make the ranges of mouse highlighting
+	     correct. */
+	  do
 	    {
-	      int c = fetch_string_char_advance (mode_string, &i, &i_byte);
-	      if (c == ' ' && prev == ' ')
+	      end = Fnext_single_property_change (start,
+						  Qmode_line_element,
+						  mode_string,
+						  make_fixnum (SCHARS (mode_string)));
+	      while (i < XFIXNUM (end))
 		{
-		  Lisp_Object prev_pos = make_fixnum (i - 1);
-
-		  /* SPC characters with 'display' properties are not
-                     really "empty", since they have non-trivial visual
-                     effects on the mode line.  */
-		  if (NILP (Fget_text_property (prev_pos, Qdisplay,
-						mode_string)))
+		  int c = fetch_string_char_advance (mode_string, &i, &i_byte);
+		  if (c == ' ' && prev == ' ')
 		    {
-		      display_string (NULL,
-				      Fsubstring (mode_string,
-						  make_fixnum (start),
-						  prev_pos),
-				      Qnil, 0, 0, &it, 0, 0, 0,
-				      STRING_MULTIBYTE (mode_string));
-		      /* Skip past the rest of the space characters. */
-		      while (c == ' ' && i < SCHARS (mode_string)
-			     && NILP (Fget_text_property (make_fixnum (i),
-							  Qdisplay,
-							  mode_string)))
+		      Lisp_Object prev_pos = make_fixnum (i - 1);
+		      Lisp_Object display = Fget_text_property (prev_pos,
+								Qdisplay,
+								mode_string);
+
+		      /* SPC characters with 'display' properties are not
+			 really "empty", since they have non-trivial visual
+			 effects on the mode line.  */
+		      if (NILP (display))
 			{
-			  c = fetch_string_char_advance (mode_string,
-							 &i, &i_byte);
+			  elt = concat2 (elt, Fsubstring (mode_string,
+							  start,
+							  prev_pos));
+
+			  /* Skip past the rest of the space characters. */
+			  Lisp_Object display = Fget_text_property (make_fixnum (i),
+								    Qdisplay,
+								    mode_string);
+			  while (c == ' ' && i < XFIXNUM (end)
+				 && NILP (display))
+			    {
+			      c = fetch_string_char_advance (mode_string,
+							     &i, &i_byte);
+			      display = Fget_text_property (make_fixnum (i),
+							    Qdisplay,
+							    mode_string);
+			    }
+
+			  /* Skip the final space no matter how the loop
+			     above ends. */
+			  if (c == ' ' && NILP (display))
+			    start = end;
+			  else
+			    start = make_fixnum (i - 1);
 			}
-		      start = i - 1;
 		    }
+		  prev = c;
 		}
-	      prev = c;
-	    }
 
-	  /* Display the final bit. */
-	  if (start < i)
-	    display_string (NULL,
-			    Fsubstring (mode_string, make_fixnum (start),
-					make_fixnum (i)),
-			    Qnil, 0, 0, &it, 0, 0, 0,
-			    STRING_MULTIBYTE (mode_string));
+	      /* Append the final bit. */
+	      if (XFIXNUM (start) < XFIXNUM (end))
+		elt = concat2 (elt, Fsubstring (mode_string, start, end));
+
+	      Fremove_text_properties (make_fixnum (0),
+				       make_fixnum (SCHARS (elt)),
+				       props, elt);
+	      display_string (NULL, elt, Qnil, 0, 0, &it, 0, 0, 0,
+			      STRING_MULTIBYTE (elt));
+	      elt = empty_unibyte_string;
+	      start = end;
+	    }
+	  while (XFIXNUM (end) < SCHARS (mode_string));
 	}
     }
   pop_kboard ();
@@ -28014,7 +28059,10 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
 		n += store_mode_line_noprop (SSDATA (elt), -1, prec);
 		break;
 	      case MODE_LINE_STRING:
-		n += store_mode_line_string (NULL, elt, true, 0, prec, Qnil);
+		{
+		  AUTO_LIST2 (src, Qmode_line_element, elt);
+		  n += store_mode_line_string (NULL, elt, true, 0, prec, src);
+		}
 		break;
 	      case MODE_LINE_DISPLAY:
 		n += display_string (NULL, elt, Qnil, 0, 0, it,
@@ -28067,8 +28115,9 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
 		      Lisp_Object mode_string
 			= Fsubstring (elt, make_fixnum (charpos),
 				      make_fixnum (endpos));
+		      AUTO_LIST2 (src, Qmode_line_element, elt);
 		      n += store_mode_line_string (NULL, mode_string, false,
-						   0, 0, Qnil);
+						   0, 0, src);
 		    }
 		    break;
 		  case MODE_LINE_DISPLAY:
@@ -28148,6 +28197,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
 			{
 			  Lisp_Object tem = build_string (spec);
 			  props = Ftext_properties_at (make_fixnum (charpos), elt);
+			  props = plist_put (props, Qmode_line_element, elt);
 			  /* Should only keep face property in props */
 			  n += store_mode_line_string (NULL, tem, false,
 						       field, prec, props);
@@ -28363,6 +28413,9 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
 	  n += store_mode_line_noprop ("", field_width - n, 0);
 	  break;
 	case MODE_LINE_STRING:
+	  /* NOTE: Padding implicitly has 'mode-line-element' property
+	     to be nil.  Normally padding spaces are between two real
+	     elements, so this should be good. */
 	  n += store_mode_line_string ("", Qnil, false, field_width - n, 0,
 				       Qnil);
 	  break;
@@ -37657,6 +37710,7 @@ syms_of_xdisp (void)
   DEFSYM (Qfontification_functions, "fontification-functions");
   DEFSYM (Qlong_line_optimizations_in_fontification_functions,
 	  "long-line-optimizations-in-fontification-functions");
+  DEFSYM (Qmode_line_element, "mode-line-element");
 
   /* Name of the symbol which disables Lisp evaluation in 'display'
      properties.  This is used by enriched.el.  */
-- 
2.49.0


--=-=-=--




Acknowledgement sent to Pengji Zhang <me@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#77336; 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: Mon, 31 Mar 2025 13:15:03 UTC

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