From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Difficulties with `purecopy' discarding text properties from strings Date: Fri, 19 May 2017 19:54:58 +0000 Message-ID: <20170519195458.GB5330@acm.fritz.box> References: <20170519185508.GA5330@acm.fritz.box> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1495223995 9137 195.159.176.226 (19 May 2017 19:59:55 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 19 May 2017 19:59:55 +0000 (UTC) User-Agent: Mutt/1.5.24 (2015-08-30) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri May 19 21:59:50 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dBo3w-0002Bd-UW for ged-emacs-devel@m.gmane.org; Fri, 19 May 2017 21:59:49 +0200 Original-Received: from localhost ([::1]:60101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBo40-0005l9-PB for ged-emacs-devel@m.gmane.org; Fri, 19 May 2017 15:59:52 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34880) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBo0F-0003Es-NW for emacs-devel@gnu.org; Fri, 19 May 2017 15:56:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBo0C-0002QQ-Mf for emacs-devel@gnu.org; Fri, 19 May 2017 15:55:59 -0400 Original-Received: from ocolin.muc.de ([193.149.48.4]:11911 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1dBo0B-0002Pp-Ro for emacs-devel@gnu.org; Fri, 19 May 2017 15:55:56 -0400 Original-Received: (qmail 75172 invoked by uid 3782); 19 May 2017 19:55:54 -0000 Original-Received: from acm.muc.de (p548C713C.dip0.t-ipconnect.de [84.140.113.60]) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 19 May 2017 21:55:53 +0200 Original-Received: (qmail 7492 invoked by uid 1000); 19 May 2017 19:54:58 -0000 Content-Disposition: inline In-Reply-To: X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 193.149.48.4 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:215001 Archived-At: Hello, Stefan. On Fri, May 19, 2017 at 15:22:50 -0400, Stefan Monnier wrote: > > Presumably there are good reasons for discarding text properties when > > purecopying strings. > I don't think so. > > Or, maybe, there was just no particular reason to amend the workings > > of `purecopy' when text properties came into existence. > I think that's what happens. Yes, that's probably what happened. > But wait a minute: > > I naively constructed such a defcustom, with text properties on the > > value option strings. > How exactly did you do that? Using #("..." ...) > or using (propertize "..." ...)? By using propertize: (defun mode-line-%-propertize (str) "Add standard mode-line properties to STR, a string. These enable certain mouse operations when the mouse pointer is hovering over the display of STR in the mode line." (propertize str 'local-map mode-line-column-line-number-mode-map 'mouse-face 'mode-line-highlight ;; XXX needs better description 'help-echo "Size indication mode\n\ mouse-1: Display Line and Column Mode Menu")) (defcustom mode-line-percent-position `(,(mode-line-%-propertize "%p")) "Type of \"percentage offset\" of window through buffer to display This option specifies the type of offset displayed in `mode-line-position', a component of the default `mode-line-format'." :type `(radio (const :tag "nil: No offset is displayed" nil) (const :tag "\"%o\": Proportion of \"travel\" of the window through the buffer" (,(mode-line-%-propertize "%o"))) (const :tag "\"%p\": Offset of top of window through buffer" (,(mode-line-%-propertize "%p"))) (const :tag "\"%P\": Offset of bottom of window through buffer" (,(mode-line-%-propertize "%P"))) (const :tag "\"%q\": Offsets of both top and bottom of window" (,(mode-line-%-propertize "%q")))) :version "26.1" :group 'mode-line) (put 'mode-line-percent-position 'risky-local-variable t) > > After some debugging, I discover that defcustom strips those text > > properties off the strings. It does this by using `purecopy' on these > > strings (in the function `custom-declare-variable'). > But AFAICT custom-declare-variable only applies purecopy to its > `default` argument which is supposed to be an expression (which > evaluates to the intended value) rather than a value. So if you use the > (propertize "..." ...) form, the properties should not be stripped. > Or am I missing something? purecopy is applied to the entire type: argument. > Stefan -- Alan Mackenzie (Nuremberg, Germany).