all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: dalanicolai <dalanicolai@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 61735@debbugs.gnu.org, Stefan Monnier <monnier@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	[thread overview]
Message-ID: <CACJP=3=+SEf1fCrCW_2QrZ6JpY+3L4khYhyu8bwOzysogtrBQg@mail.gmail.com> (raw)
In-Reply-To: <83h6vcp96u.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2161 bytes --]

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@gnu.org> wrote:

> > From: dalanicolai <dalanicolai@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?
>

[-- Attachment #2: Type: text/html, Size: 3078 bytes --]

  reply	other threads:[~2023-02-23 18:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-23 16:32 bug#61735: 29.0.50; String object in margin not associated correctly with buffer text dalanicolai
2023-02-23 17:45 ` Eli Zaretskii
2023-02-23 18:05   ` dalanicolai [this message]
2023-02-23 18:36     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-23 19:57       ` dalanicolai
2023-09-12  1:06         ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACJP=3=+SEf1fCrCW_2QrZ6JpY+3L4khYhyu8bwOzysogtrBQg@mail.gmail.com' \
    --to=dalanicolai@gmail.com \
    --cc=61735@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.