4

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))
3
  • 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
    Commented Aug 6, 2018 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
    Commented Aug 8, 2018 at 13:35
  • @Tobias No I think it's more about literals between two otherwise adjacent %-sequences.
    – cYrus
    Commented Aug 8, 2018 at 13:49

1 Answer 1

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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