Questions tagged [font-lock]

Font Lock mode is a minor mode, always local to a particular buffer, which assigns faces to the text in the buffer.

Font Lock mode is a minor mode, always local to a particular buffer, which assigns faces to the text in the buffer.


Each buffer's major mode tells Font Lock mode which text to fontify; for instance, programming language modes fontify syntactically relevant constructs like comments, strings, and function names.

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

Type M-xglobal-font-lock-mode to toggle Font Lock mode in all buffers. To impose this setting for future Emacs sessions, customize the variable global-font-lock-mode (see Easy Customization), or add the following line to your init file:

(global-font-lock-mode 0)

317 questions
8
votes
4 answers

How can I highlight duplicate lines?

Here's what I have: (defun my-show-duplicate-lines () (interactive) (highlight-lines-matching-regexp (concat "^" (regexp-quote (substring-no-properties (thing-at-point 'line) 0 -1)) "$") …
Sean Allred
  • 6,921
  • 18
  • 86
6
votes
1 answer

How to font-lock only strings and comments (syntactic font-locking)?

I generally want font-locking only for comments and strings. This would seem easy to do: customize the relevant font lock faces to make them identical to default. That unfortunately is not satisfactory, because many other places which actually…
Augusto
  • 436
  • 3
  • 8
6
votes
1 answer

Function matcher with font-lock-keywords anchored highlighter

I can highlight text like the following: constant:'variable,variable' with code like this which uses the anchored matcher form: (font-lock-add-keywords nil '(("\\(constant\\):'" (1 font-lock-constant-face t) ("\\(variable\\)[,']" nil nil (1…
6
votes
1 answer

Syntax highlighting for comments in text mode

From time to time I open a script or config file for which there is no major mode defined. When I invoke comment-region within that buffer, Emacs will prompt me for the comment syntax, and save it as the buffer-local variable comment-start. Can I…
nispio
  • 8,225
  • 2
  • 36
  • 74
5
votes
2 answers

How can I get a font-locked string just as substring it from a buffer under specified major mode?

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…
Saddle Point
  • 486
  • 8
  • 24
4
votes
1 answer

How can I apply faces interactively under `font-lock-mode`?

font-lock-mode sets font lock for the entire buffer -- normally to provide syntax highlighting. Sometimes though, when I'm preparing a tutorial, I want to call attention out to certain lines. It would be great if I could underline them (M-o u with…
Sean Allred
  • 6,921
  • 18
  • 86
3
votes
1 answer

How to add more fontify rules

I'm following the instruction at http://www.emacswiki.org/emacs/AllOut#toc3 to have the allout mode fontify its headers (enclosed below). It works but the existing major mode's fontifying effort would be gone. Is it possible to have them both?…
xpt
  • 467
  • 1
  • 4
  • 17
3
votes
1 answer

How to syntax highlight text which is not already highlighted?

I'd like to highlight function calls in C code, eg: (font-lock-add-keywords 'c-mode `((,(concat "\\([_a-zA-Z][_a-zA-Z0-9]*\\)" ; Object identifier "\\s *" ; Optional white space "(") …
ideasman42
  • 8,786
  • 1
  • 32
  • 114
3
votes
2 answers

Emacs keeps highlighting the word 'fix' in every context - how do I turn it off?

In pretty much every mode, whenever the word 'fix' occurs, whether its in a comment or not, it gets highlighted in a very visible way. I'm not sure what's causing this, and would like to turn it off. How do I do that?
Koz Ross
  • 425
  • 3
  • 13
3
votes
0 answers

Is it possible to have conditional font locks?

For example, I want to use font-lock-add-keywords highlight some keywords in source code. But the font lock system would also highlight the same words (anywhere) in the comments/docs/strings part of the source file. Since there are functions that…
Saddle Point
  • 486
  • 8
  • 24
3
votes
4 answers

How can I improve ansi-color rendering performance?

Previously I posted this question to Stack Overflow regarding rendering ansi-colors. The tip worked but performance very bad; when I open a 15 MB log file, emacs just locks up. I decided to try installing tty-format.el. This had the same result…
3
votes
1 answer

How would you customize a subsection of keywords in a major mode in Emacs?

Is it possible to customize some, not all, of keywords in a major mode? (Pardon my vocabulary, since this is still new to me.) For example, let's say these are keywords: function, new, throw, return. And I want to override the look of throw and new,…
dgo.a
  • 205
  • 1
  • 8
2
votes
5 answers

How to use font-lock to highlight end-of-line comments?

I am trying to add a comment feature to json-mode. A comment starts with a hash sign and ends at the end of the line. However, if the hash sign is inside a string it should not count as the start of the comment. For example: I am using Emacs 24.4,…
Håkon Hægland
  • 3,648
  • 1
  • 22
  • 51
2
votes
1 answer

Additional keyword fontification

How do I add fontification of additional keywords ? This does not work: (add-hook 'c++-mode-hook (lambda () (font-lock-add-keywords nil '(("^\\(trn\\|def\\|mem\\)\\>" . 'font-lock-keyword-face))))) I am using a variant of the C++…
2
votes
2 answers

How to change color of "font-lock-add-keywords"?

I found this piece of code to change org-mode list elements from dashes (-) to circles (•): (font-lock-add-keywords 'org-mode '(("^ *\\([-]\\) " (0 (prog1 () (compose-region (match-beginning 1)…
Daniel
  • 3,653
  • 18
  • 42
1
2 3