emacs-devel
[Top][All Lists]
Advanced

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

Re: Reading text properties from a yanked text


From: Eli Zaretskii
Subject: Re: Reading text properties from a yanked text
Date: Sun, 27 Nov 2022 08:14:19 +0200

> From: "Nicolas P. Rougier (inria)" <nicolas.rougier@inria.fr>
> Date: Sat, 26 Nov 2022 22:35:13 +0100
> 
> I'm trying to read the properties of a yanked string and I do not 
> understand why I get a nil result:
> 
> 1. I evaluate the line below to get a bold "Hello" and I copy the 
> result in the kill ring.
> 
> (insert (propertize "Hello" 'face 'bold))
> 
> 2. If I try to get the properties of the yanked text, I get 
> nil. However, the text is displayed bold and a (text-properties-at 
> (point)) returns '(face bold) when point is on the H letter.
> 
> (text-properties-at 0 "Hello") 
> 
> 3. This version works as expected (but this is not what I need):
> (text-properties-at 0 (propertize "Hello" 'face 'bold))
> 
> Why do I get a nil result in case 2 (using Emacs 28.2) even though 
> the text is displayed bold?

Because "Hello" is just a string, with no properties.  The "Hello" that you
propertized and inserted is long gone by the time you evaluate case 2.  The
mere fact that both strings have the same text "Hello" doesn't mean they are
the same string object.  And text properties in Emacs are properties of
specific objects.

Try this instead:

  (let ((str (propertize "Hello" 'face 'bold)))
    (insert str)
    (text-properties-at 0 str))

This makes sure the same string that gets inserted is passed to
text-properties-at, and produces the results you expect.



reply via email to

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