(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?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
with-temp-buffer does not remove text properties.
(with-temp-buffer (insert (propertize ":hello" 'face 'error)) (buffer-string)) => #(":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
(with-temp-buffer (clojure-mode) (insert ":hello") (font-lock-ensure) (buffer-string))