From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: dalanicolai Newsgroups: gmane.emacs.bugs Subject: bug#61735: 29.0.50; String object in margin not associated correctly with buffer text Date: Thu, 23 Feb 2023 19:05:11 +0100 Message-ID: References: <83h6vcp96u.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000413cff05f561db54" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1167"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 61735@debbugs.gnu.org, Stefan Monnier To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Feb 23 19:06:18 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pVFyz-000AWK-I5 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 23 Feb 2023 19:06:17 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVFyn-0007fd-EI; Thu, 23 Feb 2023 13:06:05 -0500 Original-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 ) id 1pVFyl-0007fL-7V for bug-gnu-emacs@gnu.org; Thu, 23 Feb 2023 13:06:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVFyk-0004JH-VF for bug-gnu-emacs@gnu.org; Thu, 23 Feb 2023 13:06:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pVFyk-0006xg-FI for bug-gnu-emacs@gnu.org; Thu, 23 Feb 2023 13:06:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: dalanicolai Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 23 Feb 2023 18:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61735 X-GNU-PR-Package: emacs Original-Received: via spool by 61735-submit@debbugs.gnu.org id=B61735.167717553026717 (code B ref 61735); Thu, 23 Feb 2023 18:06:02 +0000 Original-Received: (at 61735) by debbugs.gnu.org; 23 Feb 2023 18:05:30 +0000 Original-Received: from localhost ([127.0.0.1]:35245 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pVFyE-0006wq-03 for submit@debbugs.gnu.org; Thu, 23 Feb 2023 13:05:30 -0500 Original-Received: from mail-wr1-f50.google.com ([209.85.221.50]:41690) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pVFyC-0006wZ-PF for 61735@debbugs.gnu.org; Thu, 23 Feb 2023 13:05:29 -0500 Original-Received: by mail-wr1-f50.google.com with SMTP id bt28so4720029wrb.8 for <61735@debbugs.gnu.org>; Thu, 23 Feb 2023 10:05:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=1bwTT+U3sqVoVpqAZOKIWTBEol2wdNlf7zNN8IchQqk=; b=PnofIJU8QHnxobQ6j0PVZoatcCg7Z3QaNQQVFyKdx9I9awwjZzsWa5X/fSxMXTdWLT ndB7onvPgoWIaqntxBkJoBHVl5RfzjhVGkqm8pqLTApaUjTVZegQmN0E0n/vCUBYG/3O rqnybgZmN6zCVkWGzCRdLlwmC67BxNrL4esVaD8PYkJWXeh1wNUkFEBKXnkERlCXovlY 6hiqBvSYXK5fw+wxTnQLpXRbpNbqhnzfcbDNvR5NAnWU7jmhDNfeqcEZm3hH+ED3FoVD rBC1aaLEFL0n3WcU/6IJ9d2xP1I6pvULDgHcxpi5ITHMDIVgwYGzCOig16rWaPSdKyA6 OSGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1bwTT+U3sqVoVpqAZOKIWTBEol2wdNlf7zNN8IchQqk=; b=nzUu4a0tX9p+P5AtV2f1VauFdHOnSh+Na+ZEWWjE87jiwm9McjJjECtc2X8TMdCl+L 74wfvzCHCYHIwUMj1rnf9pEzsWw2e/BsMyvjJEt2Czhom0ZOIYCEM71+QnASP6CLwvBH Tg6SdDeFAKnvjqvFvc+OPRfym8Ba/ZVohTYShT5Xllmi22tPIWScKInc2IwIyRp8l+c1 YpPEkUOL6s2ZL3DM21JF+x/p2hFC/M0gn/Iot6hMt8eJNDxof/CXI35pQRR4djKzZs1/ b8PHDI2uu7DXt2FFvuBbSvc2chKKIs8KtECgYwGBBD/FjF/KhUlWTkb4zcEfeZEKmqpl SGzw== X-Gm-Message-State: AO0yUKWr49KVEhkYNQbfj3xLHJWLIECaLX+bO/2KK9vaLMNlcg2QMbuy RD6+xWkN9kF4s9gkW+Cvge8ZMznnICIL2trh6rQ= X-Google-Smtp-Source: AK7set/L6UIiugK/YcS/CWyEAjqxhMEiCJCZh8UqqdHvEkOara87kDqTBUs2xNtUf/Giy/QVavNBU0nM8LphWfc6RWw= X-Received: by 2002:a5d:6410:0:b0:2c5:8377:3eaf with SMTP id z16-20020a5d6410000000b002c583773eafmr590707wru.2.1677175522670; Thu, 23 Feb 2023 10:05:22 -0800 (PST) In-Reply-To: <83h6vcp96u.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:256504 Archived-At: --000000000000413cff05f561db54 Content-Type: text/plain; charset="UTF-8" Aha, it appears that I do not really understand how storing strings in memory works. Indeed, I assumed that I was creating new strings because (eq " " " ") is nil. I guess I have to read up on it (again). Obviously... thanks again for your quick helpful response! On Thu, 23 Feb 2023 at 18:45, Eli Zaretskii wrote: > > From: dalanicolai > > Date: Thu, 23 Feb 2023 17:32:50 +0100 > > > > (defun baleen-render (data) > > (pop-to-buffer (get-buffer-create "*baleen*")) > > (set-window-margins nil 5) > > (dolist (page data) > > (dolist (match (cdr page)) > > (let ((o (make-overlay (point) > > (progn (insert match) > > (point))))) > > (let ((s " ")) > > (put-text-property 0 1 > > 'display `((margin left-margin) ,(format " > %d" (car page))) > > s) > > (overlay-put o 'before-string s))) > > (insert "\n")))) > > > > (baleen-render '((1 "test1" "test2") (2 "test3"))) > > ``` > > > > Here, for every 'match' in a 'page' I am creating a new string 's' > > to which I add the margin display property to 'associate' it > > with some buffer text by using it as the value for its before-string > > property. > > However, although each 's' should get a different display property value > > via (format " %d" (car page)), all margin entries end up showing the > > same value of 2 (while the first two lines should show page number 1). > > > > To reproduce the error, simply evaluate the code above. Using edebug on > > 'baleen-render' it can be seen that the code seems correct, i.e. (car > > page) correctly returns the correct page number. > > > > It seems that although I am creating a different string object on each > > iteration, somehow the object put in the marging seems to be always the > > same. > > Is it really true that you create a different string object every > time? Add a copy-sequence call there, like this: > > (let ((s (copy-sequence " "))) > > and the code does what you expect. > > Stefan, am I missing something here? > --000000000000413cff05f561db54 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Aha, it appears that I do not really understand how s= toring strings in memory works.
Indeed, I assumed that I was crea= ting new strings because (eq " " " ") is nil.
I guess I have to read up on it (again).

Obviousl= y... thanks again for your quick helpful response!

On Thu, 23 Feb = 2023 at 18:45, Eli Zaretskii <eliz@gnu.o= rg> wrote:
dalanicolai@gmail.com>
> Date: Thu, 23 Feb 2023 17:32:50 +0100
>
> (defun baleen-render (data)
>=C2=A0 =C2=A0(pop-to-buffer (get-buffer-create "*baleen*")) >=C2=A0 =C2=A0(set-window-margins nil 5)
>=C2=A0 =C2=A0(dolist (page data)
>=C2=A0 =C2=A0 =C2=A0(dolist (match (cdr page))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(let ((o (make-overlay (point)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (progn (insert match)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(point))))) >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let ((s " "))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(put-text-property 0 1
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 'display `((margin left-margin) ,(fo= rmat " %d" (car page)))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 s)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(overlay-put o 'before-str= ing s)))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(insert "\n"))))
>
> (baleen-render '((1 "test1" "test2") (2 "= test3")))
> ```
>
> Here, for every 'match' in a 'page' I am creating a ne= w string 's'
> to which I add the margin display property to 'associate' it > with some buffer text by using it as the value for its before-string > property.
> However, although each 's' should get a different display prop= erty value
> via (format " %d" (car page)), all margin entries end up sho= wing the
> same value of 2 (while the first two lines should show page number 1).=
>
> To reproduce the error, simply evaluate the code above. Using edebug o= n
> 'baleen-render' it can be seen that the code seems correct, i.= e. (car
> page) correctly returns the correct page number.
>
> It seems that although I am creating a different string object on each=
> iteration, somehow the object put in the marging seems to be always th= e
> same.

Is it really true that you create a different string object every
time?=C2=A0 Add a copy-sequence call there, like this:

=C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ((s (copy-sequence " ")))

and the code does what you expect.

Stefan, am I missing something here?
--000000000000413cff05f561db54--