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.

Filter by
Sorted by
Tagged with
86
votes
8answers
27k views

How can I get a ruler at column 80?

As a programmer, I want to see a ruler at a specific column (usually 80), both so I see when I cross that column, but also to see how close I am getting to it so I can reformat my code early. The ...
17
votes
2answers
539 views

How can I use the SE flavor of Markdown in emacs?

I would like to use the SE flavor of markdown in my emacs. The default Markdown mode has some features (backticks and indentation mark code, # makes a header and > also changes the font) but I ...
13
votes
1answer
1k views

Make org-mode markup symbols invisible?

In Emacs, one can use asterisks * to achieve bold font, for example, *bold*. My question is can I make the asterisks invisible? i.e. bold instead of *bold*. Same question for strike through, italics, ...
13
votes
2answers
592 views

Highlighting shell variables within quotes

In vim, the following document will cause the $PWD on lines 2 and 3 to be colored in two different ways: #/bin/sh echo "Current Directory: $PWD" echo 'Current Directory: $PWD' The first instance of $...
13
votes
1answer
2k views

Optimizing font lock performance

I want to perform a variant of anchored font lock matching. I have function definitions that start with a list of names, and I want those names to be highlighted inside the function body. I have ...
12
votes
3answers
953 views

Fontify a region of a buffer with another major mode

I have a buffer that shows documentation for Ansible modules. This buffer has its own major mode which provides all the standard stuff. Notably, it fontifies the buffer to highlight inline markup, ...
11
votes
1answer
2k views

How do I specify a custom face with font-lock-defaults?

If I define font lock keywords using existing faces, I can highlight the string 'foo'. (defconst my-mode-font-lock-keywords (list (cons "foo" 'font-lock-type-face))) (define-derived-mode my-...
11
votes
1answer
935 views

Color declared variables

I'm looking for a simple way to make emacs remember of declared variable in a single function in C/C++. By "simple", I mean without any external package, just with some elisp lines in configuration ...
10
votes
1answer
1k views

How to customize syntax highlight for just a given mode

I would like to change the syntax highlighting in my lua-mode.el without affecting other major modes. Just as an example, I would like "key words" like if, then, else to be in bold and blue typeface ...
10
votes
2answers
474 views

How to add complex syntax highlighting in a minor mode?

I'd like to highlight code with various faces in a minor mode. Here's a screenshot that's close to what I want: One thing that I'm missing is having the comment chars # in font-lock-comment-face. ...
9
votes
1answer
335 views

Make consistent syntax highlighting of LaTeX source blocks

Org manual's solution for syntax highlighting of org-babel code blocks is to turn on native fontification with (setq org-src-fontify-natively t) works well for LaTeX code enclosed in blocks with #+...
8
votes
4answers
1k views

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 (...
7
votes
1answer
1k views

How to highlight specific keywords inside strings/quotes?

I have another syntax highlighting for SQL keywords inside strings (inside quotes) in VIM. It looks like this: Then in Emacs with PHP-mode, everything between quotes (') will be considered as a ...
7
votes
1answer
303 views

Use font-lock mode on only part of buffer

I am trying to add a comment feature to Pod documentation for Perl scripts, and I would like to highligh Pod comments with a special face. A simple prototype Perl script could be: #! /usr/bin/env ...
7
votes
1answer
1k views

How to implement the piping operator %>% in ESS mode?

Recently, R witnessed the smart introduction of the piping operator %>% or then operator in code which I use quite frequently nowadays. I wonder if this has already been implemented in the newest ...
7
votes
1answer
155 views

Modify org-mode's definition of comment lines?

Q: how do I change org-mode's definition of a commented line? According to the manual, org-mode comments work as follows: Lines starting with zero or more whitespace characters followed by one '#' ...
6
votes
2answers
970 views

Change the way CC-mode font-lock the C++11 `auto` syntax

With C++11, the keyword auto attained a new syntax and semantics. However, it seems that CC-mode has not been aware of this. For example, if I write auto var = exp, I get var in green, in which ...
6
votes
1answer
270 views

Echo Area font face?

Is there any way to set a custom face for the echo area (and, by extension, the Isearch input text)? So far my searching hasn't turned up anything, except that it seems like there isn't a way to ...
6
votes
1answer
347 views

Auto-complete looks funny around bold fonts

When I use font-lock faces that are bold, it messes up my auto-complete overlays so that they look like this: One obvious solution to the problem would be to stop using bold fonts. But since I am ...
6
votes
1answer
542 views

Line highlighting canceling out syntax highlighting

I use hl-line-mode and I really like the built-in misterioso theme. However, the way that lines are highlighted with this theme cancels out syntax highlighting or any other properties of the ...
6
votes
1answer
437 views

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-...
6
votes
1answer
293 views

Why does inserting a newline break highlighting with syntax-propertize-function?

I'm trying to write a major-mode that highlights triple-quoted strings. Here's a minimal reproducible example: (defconst demo-triple-quoted-string-regex (rx "\"\"\"" ;; After the delimiter, ...
6
votes
1answer
79 views

How to highlight text based on regions--not regular expresions

When font-lock-mode is enabled I cannot get custom faces to stick with add-text-properties or set-text-properties. I've looked through libraries like hi-lock.el, but they all seem to be regexp based. ...
6
votes
1answer
541 views

How to highlight graphql template literals (gql) in js(x) files?

Inside of a jsx file, I want to use a gql template literal to define GraphQL queries. Could I in emacs make that section of the jsx file highlight graphql syntax, instead of just showing it as a ...
6
votes
0answers
101 views

Code blocks in font-lock comments

I'm developing a major mode for a language that has doc comments. They look like this: (** Foos three bars. Better call this as [foo 1 b c]. Though of course [foo a b 1] works as well. **) ...
5
votes
2answers
1k views

Can I add highlighting in a minor mode?

I'm trying to understand minor modes with the goal of adding a minor mode for Jinja2 syntax highlighting (from jinja2-mode) to stuff like YAML. I'm running into problems though. When following a ...
5
votes
2answers
124 views

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-...
5
votes
2answers
69 views

Let-bind a variable while font-locking

I am writing a font-lock rule that calls a function to decide what face to apply to a symbol. Here's a simplified version: ("\\(?1:\\s_+\\)" (1 (the-function 1))) The problem is that this function ...
5
votes
2answers
162 views

How do I handle multiple string delimeters in a major mode?

I'm trying to write a major mode for a language that supports normal strings and triple-quoted strings ("foo" and """foo"""). (defconst my-string-mode-syntax-table (let ((table (make-syntax-table)))...
5
votes
3answers
1k views

How do I debug an “Invalid face reference: quote” message?

After using Emacs for some time, the message Invalid face reference: quote starts popping up in my message buffer. I'm not sure what causes it to start appearing. debug-on-message doesn't do anything ...
5
votes
1answer
894 views

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 ...
5
votes
1answer
170 views

How can I fontify a symbol by regexp match group (as in a naming convention)?

I want to add better support for expl3 to AUCTeX. I have regular expressions that properly group according to the naming conventions for: functions (\\(?:__)?[a-z]+_)([a-z_]+)(:[nNpTFwcVvxof]*), ...
5
votes
1answer
1k views

“Error running timer `font-latex-jit-lock-force-redisplay'” in LaTeX mode

Since an upgrade to GNU Emacs 24.4.1, I Error running timer `font-latex-jit-lock-force-redisplay': (wrong-number-of-arguments (2 . 2) 3) [N times] where N in my observations ranges from single ...
5
votes
1answer
816 views

Easiest way to render an overline in org mode?

Org mode has support for showing unicode in place of latex commands through org-pretty-entities. Org mode also has support for underlining through font locks that are activated through the _ character....
5
votes
0answers
153 views

Apply ANSI color escape sequences for Org Babel results

Feature There is a nice built-in Emacs feature to colorize strings with ANSI color escape sequences. So evaluating the following Elisp code, will insert the "Test text" at the point with proper ...
5
votes
1answer
151 views

Syntax highlighting is breaking in long bibtex files (spacemacs bibtex layer)

So I have a long papers.bib bibtex file that I edit with emacs (spacemacs bibtex layer), but the syntax highlighting only ever goes about halfway down. Here it is at about line 790: Other times this ...
5
votes
0answers
490 views

Ways to make Emacs feel snappy as Vim? [closed]

When I switched to Emacs from Vim, I really loved the extensibility of Emacs. But compared with Vim, Emacs still feels somewhat sluggish. Especially when I moved my pointer/cursor around, and typing ...
5
votes
0answers
69 views

How to investigate “color bleeding”?

I frequently have color-bleed issues in emacs, most often with AUCTeX: all of a sudden and for no apparent reason, the line I'm writing will be fontified as math. First things first: no, I do not ...
5
votes
0answers
82 views

How to replace a character display only for the `italic` face?

I am using a font that does not include italic characters. However, it does include characters like mathematical italic small a, which I would like to use instead. I can set up a display-table that ...
5
votes
0answers
100 views

Fontify result of source block in org-mode [duplicate]

Let's say I have a source block containing a shell command that outputs some C code. For instance #+BEGIN_SRC sh :results verbatim :exports both echo 'const char* str = "foo";' #+END_SRC #+RESULTS: :...
4
votes
2answers
561 views

Three-characters comment syntax

Emacs supports syntax flags for 1- and 2-characters comment delimiters. Can it be made to recognize and properly highlight 3-characters delimiters? For example: In Emacs Lisp: ;;; Headings In C#...
4
votes
2answers
611 views

Color-code a new generic character combination

I'm new to Emacs and Org-mode, this is a very basic question. Unfortunately the keywords are too common for me to find the answer. I would like to create a custom pattern to colour my writing input. ...
4
votes
1answer
205 views

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 ...
4
votes
2answers
696 views

CC-Mode - Javadoc Comment Colors in C/C++

I've been fiddling around a bit with CC-mode lately and figured that since I prefer to comment my functions/classes with javadoc-like syntax, I'd like to use the built-in comment highlighting provided ...
4
votes
1answer
257 views

Add more symbols to haskell `haskell-font-lock-symbols-alist`

I'm trying to add more symbols to haskell-mode's haskell-font-lock. The documentation for haskell-font-lock-symbols-alist says: Alist mapping Haskell symbols to chars. Each element has the form (...
4
votes
1answer
281 views

Highlight HTML entities in Web mode

I often edit articles in web-mode (using PHP). Is there some way of fontifying HTML entities (like –, é, and so on)? I'd like them to be a lighter color so that they're easier to ...
4
votes
1answer
149 views

Is there a way to disable multi-line string literals in c++-mode?

Suppose I have a short string in C++ and I accidentally delete the double quote that ends it. What Emacs does is highlight the rest of the code as a single very long string, which messes up all the ...
4
votes
1answer
112 views

Can I apply a face to an optional group?

When I try to execute the following, font-lock fails abruptly after it matches the first group. A little bit of debugging with the neat tool font-lock-studio and I realized that font-lock is upset ...
4
votes
0answers
309 views

“Invalid face reference: linum” even load linum after make frame

I want to have line number at buffer, but when I use Emacs server, the Message buffer display the following error: Invalid face reference: font-lock-comment-delimiter-face [2 times] Invalid face ...
4
votes
1answer
120 views

Certain symbols resulting in really tall line (and cursor)

This one is honestly a bit of a mystery for me. The strange behavior is caused by the lambda symbol: the line goes to normal height if I remove the lambda. How can I get Emacs to display such ...