GNU bug report logs - #61735
29.0.50; String object in margin not associated correctly with buffer text

Previous Next

Package: emacs;

Reported by: dalanicolai <dalanicolai <at> gmail.com>

Date: Thu, 23 Feb 2023 16:34:02 UTC

Severity: normal

Found in version 29.0.50

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: dalanicolai <dalanicolai <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 61735 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
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 part 1 (text/plain, inline)]
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 <eliz <at> gnu.org> wrote:

> > From: dalanicolai <dalanicolai <at> gmail.com>
> > 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?
>
[Message part 2 (text/html, inline)]

This bug report was last modified 1 year and 257 days ago.

Previous Next


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