all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#61735: 29.0.50; String object in margin not associated correctly with buffer text
@ 2023-02-23 16:32 dalanicolai
  2023-02-23 17:45 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: dalanicolai @ 2023-02-23 16:32 UTC (permalink / raw)
  To: 61735

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

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))

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#61735: 29.0.50; String object in margin not associated correctly with buffer text
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2023-02-23 17:45 UTC (permalink / raw)
  To: dalanicolai, Stefan Monnier; +Cc: 61735

> 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?





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#61735: 29.0.50; String object in margin not associated correctly with buffer text
  2023-02-23 17:45 ` Eli Zaretskii
@ 2023-02-23 18:05   ` dalanicolai
  2023-02-23 18:36     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 6+ messages in thread
From: dalanicolai @ 2023-02-23 18:05 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 61735, Stefan Monnier

[-- 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 --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#61735: 29.0.50; String object in margin not associated correctly with buffer text
  2023-02-23 18:05   ` dalanicolai
@ 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
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-02-23 18:36 UTC (permalink / raw)
  To: dalanicolai; +Cc: 61735, Eli Zaretskii

> 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






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#61735: 29.0.50; String object in margin not associated correctly with buffer text
  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
  0 siblings, 1 reply; 6+ messages in thread
From: dalanicolai @ 2023-02-23 19:57 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 61735, Eli Zaretskii

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

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@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
>
>

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#61735: 29.0.50; String object in margin not associated correctly with buffer text
  2023-02-23 19:57       ` dalanicolai
@ 2023-09-12  1:06         ` Stefan Kangas
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Kangas @ 2023-09-12  1:06 UTC (permalink / raw)
  To: dalanicolai; +Cc: Eli Zaretskii, 61735-done, Stefan Monnier

dalanicolai <dalanicolai@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.





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-09-12  1:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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.