[Top][All Lists]

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

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

From: Lars Ingebrigtsen
Subject: bug#17507: Documentation for `add-text-property' and relatives
Date: Wed, 14 Aug 2019 16:57:44 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Eli Barzilay <address@hidden> writes:

> What I was surprised to find out is that
>     (let ((s "foo")) (put-text-property 0 3 'foo 'bar s) s)
> works.  It's probably obvious for elisp hackers, but coming from
> most other lisps/schemes, I kind of assumed that the #("foo" ...)
> thing is made of the "foo" string in some vector-like container that
> holds the properties.  Given that unconscious assumption, I assumed
> that it wouldn't work, and that I'll need some uglier hack like
>     (let ((s (propertize "foo" 'foo nil)))
>       (put-text-property 0 3 'foo 'bar s) s)
> so that `s' points to an object that can be mutated inside.
> So I think that it would be a good idea to add a comment in the docs
> (of all of these functions) that notes that when given a string, they
> mutate it, and it works even if the input is property-less.  Or just
> make it easier with showing a example as the above.
> (Hopefully the above makes sense -- I wonder how many lispers who are
> not native e-lispers have that assumption...)

(I'm going through old bug reports that have unfortunately gotten no
responses yet.)

Hm...  I think the doc string is pretty clear here:

If the optional fifth argument OBJECT is a buffer (or nil, which means
the current buffer), START and END are buffer positions (integers or
markers).  If OBJECT is a string, START and END are 0-based indices into it.

I understand that if you come from a C background (or something like
that) your assumption may be that a string is just a bunch of bytes with
a null at the end, so you can't add any properties to it -- but that's
not the case in most languages, where a string is an object with lots of
different qualities in addition to the text itself.

So I don't think this is something that's desirable to explain in this
specific context, and I'm closing this bug report.

(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no

reply via email to

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