Search code examples
emacselispemacs-faces

set text properties


I want to copy a text from one buffer to another with text properties. So I have

(with-current-buffer from-buffer
  (setq text-to-copy (buffer-substring beg end)))

How can I insert the text-to-copy to another buffer with all text properties? I'm interested especially in 'face' properties.

The function buffer-substring returns a list, for example ("substring" 42 51 (face font-lock-keyword-face) 52 59 (face font-lock-function-name-face))

If I pass this list to (insert text-to-copy) it seems that it ignores text properties


Solution

  • If font-lock-mode is turned on in the target buffer of insertion, the face property will be reset once the fontification kicks in. I think you'll need to either turn off font-lock-mode, or munge the text properties to replace 'face' with 'font-lock-face' before insertion.