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
102
votes
9answers
37k 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
595 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 ...
14
votes
1answer
2k 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, ...
14
votes
2answers
767 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 $...
14
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 ...
13
votes
3answers
1k 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, ...
12
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-...
12
votes
1answer
515 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 ...
11
votes
1answer
1k 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
656 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. ...
10
votes
0answers
200 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 ...
9
votes
2answers
2k 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 ...
9
votes
1answer
407 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
2k 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
2k 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
357 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
412 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 ...
7
votes
1answer
615 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 ...
7
votes
1answer
93 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. ...
7
votes
1answer
171 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
1k 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
398 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
529 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
1k 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 ...
6
votes
1answer
182 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]*), ...
6
votes
1answer
1k 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
3answers
2k 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 ...
6
votes
1answer
343 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
2answers
191 views

ANSI / xterm font-locking

I have a buffer with terminal escape codes in it and I want them to be colored: I was able to do this with (ansi-color-apply-on-region (point-min) (point-max)): However, my file is really big and ...
6
votes
0answers
108 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
659 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#...
5
votes
2answers
742 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. ...
5
votes
2answers
2k 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
1answer
2k views

How to make my own org-mode text emphasis work again?

This might be interersting: For quite some time I used the code block below in my custom.el to make my own emphasis definitions. This worked up to org 9, I think. Then all of a sudden when I needed it ...
5
votes
2answers
207 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
1answer
97 views

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 ...
5
votes
2answers
76 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
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
1k 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
1answer
202 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
660 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
87 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
111 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
145 views

AUCTeX: only use monospace for rendering macros?

I've been using the fontify features of AUCTeX, as well as magic-latex-buffer, to display my TeX code in a more readable way. But I'm wondering if I can crank this up to 11: is there a way to render ...
4
votes
1answer
266 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
756 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
2answers
196 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)))...
4
votes
1answer
292 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
61 views

How to highlight digit groups of 3 in numerals?

I find it very useful to visually distinguish every 3 digit group of numbers in source code so that I can read it. For example something if I see 1000000 it is fairly easy to see that this is 1M ...

1
2 3 4 5 6