Take a look at this example:

(format (concat "%s" (propertize "%s" 'face 'error)) "foo" "bar")
"foobar"

(format (concat "%s " (propertize "%s" 'face 'error)) "foo" "bar")
#("foo bar" 4 7 (face error))

And the documentation of format explicitly states:

Text properties, if any, are copied from the format-string to the produced text.

Why is that?

I know I can work around this with:

(format "%s%s" "foo" (propertize "bar" 'face 'error))
#("foobar" 3 6 (face error))

Or even:

(concat "foo" (propertize "bar" 'face 'error))
#("foobar" 3 6 (face error))

But my original use case is a bit more complex than this.


Edit

A probably more general example is the following:

(format (concat (propertize "%s" 'face 'bold)
                "" ; any non-empty string works
                (propertize "%s" 'face 'error))
        "foo" "bar")
#("foobar" 0 6 (face bold))
  • Looks like a bug, or an enhancement request. Wait a bit, to see what others say, then consider filing a bug report: M-x report-emacs-bug. – Drew Aug 6 at 18:03
  • Observation: Text properties are copied only when there is a literal character in the format string, e.g., (format (propertize "\s%s" 'face 'error) "foo") gives #(" foo" 0 4 (face error)). – Tobias Aug 8 at 13:35
  • @Tobias No I think it's more about literals between two otherwise adjacent %-sequences. – cYrus Aug 8 at 13:49
up vote 2 down vote accepted

So it was a bug which has now been fixed in this commit.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.