Given e.g. (with-temp-buffer (clojure-mode) (insert ":hello") (buffer-string)), I'd expected the result to be propertized, however it isn't.

How to get a propertized string out of a temporary buffer?

1 Answer 1


You're mistaken. with-temp-buffer does not remove text properties.

  (insert (propertize ":hello" 'face 'error))

=> #(":hello" 0 6 (face error))

I think you're expecting the call to clojure-mode to cause the subsequent non-propertized text to instantaneously acquire text properties as it is inserted into the buffer, which is not the case. (It may seem instant when you are entering text interactively, but that's just because humans are very slow.)

Assuming you want to force font-lock-mode to process the buffer before obtaining the buffer string, use font-lock-ensure:

  (insert ":hello")

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.