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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 61735 in the body.
You can then email your comments to 61735 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#61735; Package emacs. (Thu, 23 Feb 2023 16:34:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to dalanicolai <dalanicolai <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 23 Feb 2023 16:34:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: dalanicolai <dalanicolai <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.50;
 String object in margin not associated correctly with buffer text
Date: Thu, 23 Feb 2023 17:32:50 +0100
[Message part 1 (text/plain, inline)]
The section 'Displaying in the Margins
<https://www.gnu.org/software/emacs/manual/html_node/elisp/Display-Margins.html>'
of the elisp manual mentions
that 'To display something in the margin in association with certain
buffer text ... put a before-string property on the text and put the
margin display specification on the contents of the before-string'.

So this is what I am trying to achieve using the following code

```
(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.

To me, this looks like a bug. And otherwise, if I am doing something
wrong, then of course this report can be seen as a 'help/support
request'. Thanks!

In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.34, cairo version 1.17.6) of 2022-09-10 built on fedora
Repository revision: 4cf9c92e27d20da9453f9abe89d84bee5d776329
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12014000
System Description: Fedora Linux 37 (Workstation Edition)

Configured using:
 'configure --with-modules --with-cairo --with-native-compilation
 --with-json'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LIBSELINUX LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG
SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS X11 XDBE XIM
XINPUT2 XPM GTK3 ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  blink-cursor-mode: t
  buffer-read-only: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util text-property-search time-date mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs
comp comp-cstr warnings icons subr-x rx cl-seq cl-macs gv cl-extra
help-mode bytecomp byte-compile cconv cl-lib sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils rmc iso-transl tooltip eldoc
paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode
mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
faces cus-face macroexp files window text-properties overlay sha1 md5
base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify
dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit xinput2 x multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 77301 10328)
 (symbols 48 7112 0)
 (strings 32 19407 1642)
 (string-bytes 1 593504)
 (vectors 16 15411)
 (vector-slots 8 317149 17892)
 (floats 8 28 58)
 (intervals 56 372 3)
 (buffers 1000 13))
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61735; Package emacs. (Thu, 23 Feb 2023 17:46:02 GMT) Full text and rfc822 format available.

Message #8 received at 61735 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: dalanicolai <dalanicolai <at> gmail.com>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 61735 <at> debbugs.gnu.org
Subject: Re: bug#61735: 29.0.50;
 String object in margin not associated correctly with buffer text
Date: Thu, 23 Feb 2023 19:45:29 +0200
> 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?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61735; Package emacs. (Thu, 23 Feb 2023 18:06:02 GMT) Full text and rfc822 format available.

Message #11 received at 61735 <at> debbugs.gnu.org (full text, mbox):

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: Re: 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)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61735; Package emacs. (Thu, 23 Feb 2023 18:37:02 GMT) Full text and rfc822 format available.

Message #14 received at 61735 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: dalanicolai <dalanicolai <at> gmail.com>
Cc: 61735 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#61735: 29.0.50; String object in margin not associated
 correctly with buffer text
Date: Thu, 23 Feb 2023 13:36:44 -0500
> Indeed, I assumed that I was creating new strings because (eq " " " ")
> is nil.

Your test can return nil even if new strings aren't created at runtime
(e.g. because each source code string gets its own runtime string).

It may be nil in your test, but it may also return t (I think if you
byte-compile your test it will return t).

>> >         (let ((s " "))

Here you have a single " " string in your source code.  And no it's not
recreated each time, it will be the same one reused everytime (and
modified by `put-text-property`).

You can use `propertize` instead.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61735; Package emacs. (Thu, 23 Feb 2023 19:58:02 GMT) Full text and rfc822 format available.

Message #17 received at 61735 <at> debbugs.gnu.org (full text, mbox):

From: dalanicolai <dalanicolai <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 61735 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#61735: 29.0.50; String object in margin not associated
 correctly with buffer text
Date: Thu, 23 Feb 2023 20:57:20 +0100
[Message part 1 (text/plain, inline)]
Thanks for that explanation. Indeed, I found it hard to find a thorough
explanation anywhere. Also, thanks for reminding me about propertize.


On Thu, 23 Feb 2023 at 19:36, Stefan Monnier <monnier <at> iro.umontreal.ca>
wrote:

> > Indeed, I assumed that I was creating new strings because (eq " " " ")
> > is nil.
>
> Your test can return nil even if new strings aren't created at runtime
> (e.g. because each source code string gets its own runtime string).
>
> It may be nil in your test, but it may also return t (I think if you
> byte-compile your test it will return t).
>
> >> >         (let ((s " "))
>
> Here you have a single " " string in your source code.  And no it's not
> recreated each time, it will be the same one reused everytime (and
> modified by `put-text-property`).
>
> You can use `propertize` instead.
>
>
>         Stefan
>
>
[Message part 2 (text/html, inline)]

Reply sent to Stefan Kangas <stefankangas <at> gmail.com>:
You have taken responsibility. (Tue, 12 Sep 2023 01:07:01 GMT) Full text and rfc822 format available.

Notification sent to dalanicolai <dalanicolai <at> gmail.com>:
bug acknowledged by developer. (Tue, 12 Sep 2023 01:07:01 GMT) Full text and rfc822 format available.

Message #22 received at 61735-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: dalanicolai <dalanicolai <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 61735-done <at> debbugs.gnu.org,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#61735: 29.0.50; String object in margin not associated
 correctly with buffer text
Date: Mon, 11 Sep 2023 18:06:10 -0700
dalanicolai <dalanicolai <at> gmail.com> writes:

> Thanks for that explanation. Indeed, I found it hard to find a thorough
> explanation anywhere. Also, thanks for reminding me about propertize.

I think the conclusion here is that this was not a bug, so I'm closing
this now.

If this conclusion is incorrect, please reply to this email (use "Reply
to all" in your email client) and we can reopen the bug report.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 10 Oct 2023 11:24:09 GMT) Full text and rfc822 format available.

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

Previous Next


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