bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#17507: Documentation for `add-text-property' and relatives


From: Eli Barzilay
Subject: bug#17507: Documentation for `add-text-property' and relatives
Date: Sat, 17 Aug 2019 02:49:54 +0300

To clarify what I said, it sounds like a string is a tuple of the
actual string *and* its properties, so it's always #("xyz" ...) where
the quotes denote the raw string contents, except that when there's no
properties, then you see just the "xyz" part -- but that's *not* a raw
string, it just doesn't show the (empty) properties.

Yet another way to show this is the fact that if you evaluate
#("xyz"), the result is *displayed* as "xyz".

Maybe adding some note to that effect (perhaps rephrased, to point at
the fact that all strings have properties, there are no raw strings)
would have resolved my original confusion.

On Fri, Aug 16, 2019 at 11:46 AM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Eli Barzilay <eli@barzilay.org>
> > Date: Fri, 16 Aug 2019 04:35:35 +0300
> > Cc: Lars Ingebrigtsen <larsi@gnus.org>, 17507@debbugs.gnu.org
> >
> > In lisps you can mutate properties of an object, but you cannot change
> > the pointer itself.  I think that another way to clarify it would be
> > to say that "foo" is actually shorthand for #("foo") but the #() is
> > omitted for brevity.  But at this point this is subjective enough to
> > be ignorable...
>
> Sorry for prolonging this discussion, but I still don't think I
> understand the difficulty.
>
> Allow me to step back a notch and look at this from a higher-level
> perspective.
>
> In Emacs, text properties are stored separately from the text itself.
> In particular, text properties of a string are not part of the string
> text, they live in a separate structure, and a string only maintains a
> reference to that structure.  When Emacs needs to display the string,
> it consults that structure and renders the string characters
> accordingly.  When the Lisp interpreter needs to print the string, it
> prints the properties as well, to make them visible.
>
> It sounds like your mental model of a string was that it included the
> properties, and therefore you were surprised that add-text-property
> etc. appeared to modify the string by side effect.  Is that what
> surprised you?  If so, would saying that these functions modify the
> properties of a string without mutating the string itself resolve the
> difficulty?



-- 
                   ((x=>x(x))(x=>x(x)))                  Eli Barzilay:
                   http://barzilay.org/                  Maze is Life!





reply via email to

[Prev in Thread] Current Thread [Next in Thread]