reddit / emacs

Is there a quick tutorial on faces, 5 min max?

vfclists · 2022-06-11 22:55
I need to highlight some text that I programmatically update in an org document in a different colour. Lets say I want to output '2022-06-11' in the text in a different colour. What do I have to suffix or prefix it with to get it to print differently. In orgmode docs, the `TITLE`, `AUTHOR`, and `DATE` properties are a different colour. How is that done?
itistheblurstoftimes · 2022-06-12 00:37
I think you'll have to accept that it'll take more than 5 minutes to understand it. [https://www.gnu.org/software/emacs/manual/html\_node/elisp/Faces.html](https://www.gnu.org/software/emacs/manual/html_node/elisp/Faces.html)
JDRiverRun · 2022-06-12 02:30
A mode called font-lock controls the faces in most buffers; `C-h v font-lock-keywords`. You can inspect any face or other property with `C-u C-x =` on the char of interest.
dpoggio · 2022-06-12 06:00
If adding some highlight, I would use [Highlight](https://www.emacswiki.org/emacs/HighlightLibrary)
E3D3redit · 2022-06-12 17:59
I can't offer you a 5 min tutorial on faces, only 2 functions to save and load files with faces. Due to in the file inserted color codes it is not practical for everything but I was happy to use it to store [keywiz](https://github.com/deestan/emacs/blob/master/emacs-goodies-el/keywiz.el) scores with all it faces. You can also, for example, use \``highlight-regexp`' to add different faces to a buffer, and then save it, incl. faces, to a file with next function: (defun e3/save-buffer-incl-faces (file) "Save buffer with faces to file" (interactive "FFile to save to: ") (let ((blabla (prin1-to-string (buffer-string)))) (with-temp-file file (insert blabla)))) Next function loads a file that is saved with above function: (defun e3/load-file-with-faces (file) "Open buffer from file with faces" (interactive "FFace-file to read: ") (find-file file) (let ((blabla (buffer-substring (point-min)(point-max)))) (erase-buffer) (insert (read blabla)))) `list-faces-display` gives a preview of available faces, while `describe-face` describes a face, by default the face at point.