0

I am using the following code to insert colored text into an Emacs buffer.

(insert 
 (propertize "green" 
 'font-lock-face 
  '(:strike-through t 
    :foreground "green" 
    :background "blue")))

How can I have Emacs save these text properties so that when I reopen the buffer they are available?

Edit: I am attempting to do this with a .el file and would like to save any text properties not just font properties. It would be nice if there was a way to do this for any type of file.

Smashgen
  • 131
  • 2
  • 3
    Just save it as [enriched text format](https://www.gnu.org/software/emacs/manual/html_node/emacs/Enriched-Text.html). The easiest way is to give it the file extension `.etf`. [This question is (almost?) a duplicate](https://emacs.stackexchange.com/questions/43871/theres-a-way-to-use-emacs-like-ms-word-to-make-text-permanently-colored-styli/43875#43875). – Tobias Jul 01 '19 at 15:07
  • I just noticed that `:strike-through` is not supported by `enriched-mode`. – Tobias Jul 01 '19 at 15:13
  • Okay you have `font-lock-mode` running. Does that mean that the buffer contains primarily program code? – Tobias Jul 01 '19 at 15:28
  • Yes, I am attempting to do this with a .el file. – Smashgen Jul 01 '19 at 15:41
  • With Emacs lisp files you are lucky. Emacs itself knows how to handle enriched encoding and you can switch on `M-x enriched-mode` for Emacs lisp files. Other programming environments would be totally confused by the stuff Emacs saves for the enriched encoding. – Tobias Jul 01 '19 at 16:06
  • Depending on exactly what kind of "text properties" you intend to put and on which parts of the code, there might be several alternative options, so please clarify (clarify also if this request is very specifically for Elisp files or should also work in other programming language modes). – Stefan Jul 01 '19 at 16:59
  • I added a way to save user-defined highlights in program text at https://emacs.stackexchange.com/questions/43871/theres-a-way-to-use-emacs-like-ms-word-to-make-text-permanently-colored-styli/51352#51352. Maybe that would fit in better here. – Tobias Jul 02 '19 at 11:43

0 Answers0