[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Difficulties with `purecopy' discarding text properties from strings
From: |
Alan Mackenzie |
Subject: |
Re: Difficulties with `purecopy' discarding text properties from strings |
Date: |
Fri, 19 May 2017 19:54:58 +0000 |
User-agent: |
Mutt/1.5.24 (2015-08-30) |
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).