Suppose I have a python-mode
user buffer with content import os
, I can use (buffer-substring (point-min) (point-max))
to get a colorized string
#("import os" 0 6
(fontified t face font-lock-keyword-face)
6 9
(fontified t))
But now I want to generate this using emacs lisp code like
(setq string
(with-temp-buffer
(python-mode)
(font-lock-mode 1)
(insert "import os")
(buffer-substring (point-min) (point-max))))
but got result
#("import os" 0 9 (fontified nil))
So my question is how can I generate the same string just as I substring it from a truly existed user buffer?
Thanks in advance.