From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Reading text properties from a yanked text Date: Sun, 27 Nov 2022 08:14:19 +0200 Message-ID: <83lenwrkjo.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11837"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: "Nicolas P. Rougier (inria)" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Nov 27 07:14:25 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ozAvo-0002sd-8O for ged-emacs-devel@m.gmane-mx.org; Sun, 27 Nov 2022 07:14:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozAvK-0002MJ-6B; Sun, 27 Nov 2022 01:13:54 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ozAvI-0002MA-P0 for emacs-devel@gnu.org; Sun, 27 Nov 2022 01:13:52 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ozAvI-0005B5-Da; Sun, 27 Nov 2022 01:13:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=ky2C2ItnzDcLf9QYn1z+g4XKOXloyb7nZz14NoSseJc=; b=U/8exkynYfED ErgO/lw2UEjbtoZT1m45xMLYy88gVi3XtBOOgMy77YYkLb9gy9orqszLIFVL3nyxnxfkMzs+LxkIh tiD7VsqU5Y0xKzgXUkrXYPda0qVXOMkaa07dX6Ud1hcVFWLV6V/SVajjmRZI5G9x0/Zuu/1BA1J61 BTwxhb8kmGspWeJMN4mAczsymUw4Vri8U+O4BcYzE1zrCrY4QkfRias/Cy5Rit1TtwoC8P8AbVeHA 2f/7DRZEvfIHOZktLkqcYmj83NXYGq0qHAOaxrGIDIWOmVXA3P4t60uTV3N3PHstu8rSxV+slbNAM Tjc0akYdGsFXPeCRU0OVXw==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ozAvH-0006A6-J8; Sun, 27 Nov 2022 01:13:51 -0500 In-Reply-To: (nicolas.rougier@inria.fr) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:300611 Archived-At: > From: "Nicolas P. Rougier (inria)" > 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.