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: Nicolas P. Rougier (inria)
Subject: Re: Reading text properties from a yanked text
Date: Sun, 27 Nov 2022 07:16:45 +0100
User-agent: mu4e 1.8.11; emacs 28.2


Eli Zaretskii [2022-11-27 at 08:14] wrote:
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.

Thanks for the explanation. I think I get it (but it is still is a bit confusing to me).

For example this returns (face bold):

(with-temp-buffer
 (insert (propertize "Hello" 'face 'bold))
 (kill-region (point-min) (point-max))
 (yank)
 (text-properties-at 0
       (buffer-substring (point-min) (point-max))))

While this returns nil:

(with-temp-buffer
 (insert (propertize "Hello" 'face 'bold))
 (kill-region (point-min) (point-max))
 (insert (format "(text-properties-at 0 \"%s\")"
                 (current-kill 0)))
 (eval-buffer))


Nicolas

--
Nicolas P. Rougier —— www.labri.fr/perso/nrougier
Institute of Neurodegenerative Diseases, Bordeaux



reply via email to

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