Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: font-lock explanation

I'm using Emacs since a long time and I've customized it quite a lot. I've even written simple ELisp functions and now I'm starting to use macros more and more. I'm not anywhere near a knowledgable Emacs user but I'm not either a complete beginner.

I'm using nxhtml, mumamo, dired, ido, custom keybindings and so many things I added throughout the years that I don't remember all of them ; )

But there's something I really never understood: what is the "font-lock" mode and why should I care?

For example, I've read that nxhtml and nxml, if I recall correctly, do not use font-locking. Maybe I didn't understand that part well but in either way: what does it change for me, as a user?

Or take for example this description about WhiteSpace:

Note that when WhiteSpace is turned on, WhiteSpace saves the font-lock state, that is, if font-lock is on or off. And WhiteSpace restores the font-lock state when it is turned off. So, if WhiteSpace is turned on and font-lock is off, WhiteSpace also turns on the font-lock to highlight blanks, but the font-lock will be turned off when WhiteSpace is turned off. Thus, turn on font-lock before WhiteSpace is on, if you want that font-lock continues on after WhiteSpace is turned off.

OK, fine. I understand that. But what does it change if font-lock continues after or not?

Basically I just don't "get it", no matter how much I read about the subject.

Any example/explanation as to what "font-lock" is under Emacs and why it concerns me would be most welcome!

like image 231
Cedric Martin Avatar asked Mar 19 '12 17:03

Cedric Martin


People also ask

What is emacs font Lock?

Font Lock mode is a minor mode, always local to a particular buffer, which highlights (or “fontifies”) the buffer contents according to the syntax of the text you are editing.

How to turn off font Lock?

Font Lock mode is enabled by default in major modes that support it. To toggle it in the current buffer, type M-x font-lock-mode . A positive numeric argument unconditionally enables Font Lock mode, and a negative or zero argument disables it.


1 Answers

font-lock-mode == colorful syntax highligthing. global-font-lock-mode enables font-locking for each and every mode in Emacs. Older Emacs version required you to enable it manually, newer version (23+ I think) enable this by default. I can't imagine that many people would want to turn off this feature, since it makes some type of content (like source code) immensely more readable. Every mode that uses font-lock relies on a certain set of faces - a combination of font properties like size, bold, underline, italic and color. The basic faces that most modes use are:

font-lock-builtin-face
font-lock-comment-face
font-lock-comment-delimiter-face
font-lock-constant-face
font-lock-doc-face
font-lock-doc-string-face
font-lock-function-name-face
font-lock-keyword-face
font-lock-negation-char-face
font-lock-preprocessor-face
font-lock-string-face
font-lock-type-face
font-lock-variable-name-face
font-lock-warning-face

You can easily override their values if you'd like them (or use a different color-theme). Some modes happen to define additional faces as well.

like image 182
Bozhidar Batsov Avatar answered Oct 05 '22 08:10

Bozhidar Batsov