Skip to main content
The 2024 Developer Survey results are live! See the results
57 votes

How can I get a ruler at column 80?

Are there any better alternatives? Emacs 27 (officially released 2020-08-11) added support for a fill-column indicator natively by way of the buffer-local minor mode[1] display-fill-column-indicator-...
Basil's user avatar
  • 12.5k
9 votes
Accepted

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

I don't really have org-mode 9.1.1 installed. In org-mode 9.0.5 the following works: (require 'org-habit nil t) (defun org-add-my-extra-fonts () "Add alert and overdue fonts." (add-to-list 'org-...
Tobias's user avatar
  • 33.4k
9 votes
Accepted

Apply ANSI color escape sequences for Org Babel results

If I understand you question correctly you wish to interpret ansi color codes in the results of org babel code blocks. I achieved this by adding a hook to org-babel-after-execute-hook: (defun ek/babel-...
Erki der Loony's user avatar
6 votes
Accepted

What code is font locking quoted strings in my custom mode buffer?

This highlighting is syntactic font-lock highlighting. It occurs when variable font-lock-keywords-only is nil. This variable is normally set automatically by Font Lock mode based on the KEYWORDS-...
Drew's user avatar
  • 78.1k
5 votes

Adding new commands to the syntax highlighting of a language mode

You can do this using the function font-lock-add-keywords. It takes two arguments, the first is the major mode to extend. Alternatively, you can pass nil which mean the current buffer, which is useful ...
Lindydancer's user avatar
  • 6,180
5 votes
Accepted

Python mode - custom syntax highlighting

If you have a look into the python library (M-x find-library RET python RET) you see that the python-font-lock-keywords are constructed by the rx macro: (defvar python-font-lock-keywords ;; ...
Tobias's user avatar
  • 33.4k
5 votes
Accepted

How to syntax highlight text which is not already highlighted?

Yes, you can tell font-lock to apply some syntax highlighting only if the matched text is not already highlighted by font-lock. To do this, you use keep for OVERRIDE in the match expression: (...
Drew's user avatar
  • 78.1k
5 votes
Accepted

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

I've found a solution using the emacs package mmm-mode. Most of the information I got was from this article. What this package does, is allow multiple major modes in the same buffer. You basically ...
andykais's user avatar
  • 166
5 votes
Accepted

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

Following Drew's suggestion in the comments, here's a simple solution that can also be adapted to more specific needs: (defun boring-font-lock () "Activate font lock only for strings and ...
Augusto's user avatar
  • 436
4 votes
Accepted

Add text property, when global-font-lock mode is on

When font-lock-mode is in use, you can use the font-lock-face property instead of face. (add-text-properties 1 8 '(font-lock-face (:foreground "red")))
JeanPierre's user avatar
  • 7,475
4 votes
Accepted

Display another symbol than asterisks in org headings

compose-region does not solve your problem. Use the text property display instead and put the string you like atop the header leader. You can let you guide by org-bullets-mode for that. If you want ...
Tobias's user avatar
  • 33.4k
4 votes
Accepted

Why are code blocks and code literals displaying with large face in markdown

This can be fixed by calling M-x customize-group RET markdown-faces while in Markdown mode. It opens a menu of various font face settings. Under Markdown Code Face, uncheck/delete everything and then ...
Adam Michael Wood's user avatar
4 votes
Accepted

Replacing a string with symbols using font-lock?

Here's a code snippet that will make all occurrences of " / " appear as " รท " in the current buffer: (add-to-list 'font-lock-extra-managed-props 'display) (font-lock-add-keywords nil '((" \\(/\\) " ...
jpi's user avatar
  • 116
4 votes
Accepted

Hi-lock code syntax

It refers to the regexp group that should be highlighted. 0 means the entire regexp. 1 means the first group etc. A group is specified using \( and \). For example: "\\(Humpty\\)\\(Dumpty\\)" (1 'hi-...
Lindydancer's user avatar
  • 6,180
4 votes
Accepted

show binary value in different colors

I wrote the following a while ago, it provides a minor mode highlight-c-bits that highlights exactly your pattern. It only highlights the 1:s, but it should be trivial to extend to highlighting both 0:...
Lindydancer's user avatar
  • 6,180
3 votes
Accepted

Why do some faces not work with font lock mode expressions?

Variable dired-directory does not have face dired-directory as its value. Instead, it has a directory as its value (as you can see by C-h v dired-directory). In general, faces are not associated ...
Drew's user avatar
  • 78.1k
3 votes
Accepted

How to font lock the second token on a line of tokens

The following regex will do what you want for your examples: ^[ \t]*[^ \t\n]+[ \t]+\\([[:alpha:]][^ \t\n]*\\) It matches the start of line ^. Then possible leading whitespaces, everything but ...
theldoria's user avatar
  • 1,845
3 votes
Accepted

Override c++-mode font lock

Font-lock use two phases: The syntactic phase. In this phase, Emacs determines things like strings and comments. The keyword phase, i.e. the normal font-lock rules. If you want to make Emacs ignore ...
Lindydancer's user avatar
  • 6,180
3 votes
Accepted

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

You need to tell font-lock to fontify the text you entered. Font-lock generally behaves lazily. It has already font-locked the text shown in the window, and you need to tell it to do so again, to pick ...
Drew's user avatar
  • 78.1k
3 votes

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

The function designed specifically for that purpose is font-lock-ensure. So just call (font-lock-ensure) or (font-lock-ensure START END) before your call to buffer-substring.
Stefan's user avatar
  • 26.5k
3 votes
Accepted

font-lock for \left and \big in auctex

The error message is quite descriptive. You are missing the containing customization group in defface. The following code is working with GNU Emacs 25.1.50.2 (i686-pc-linux-gnu, GTK+ Version 3.10.8) ...
Tobias's user avatar
  • 33.4k
3 votes
Accepted

Why can't I fontify an indirect buffer?

You should be able to go to the base buffer (the one that you derived the indirect buffer from) and toggle font-lock-mode there (probably twice), to turn font-locking back on (in both the base and the ...
Drew's user avatar
  • 78.1k
3 votes

Determine the face(s) that would be applied to a character inserted at point, after font-lock does its thing?

I don't think "inserting x and seeing the resulting font-lock highlighting" is a good approach in general. You'll likely be better off calling asking directly the code that performs this font-lock ...
Stefan's user avatar
  • 26.5k
3 votes
Accepted

how can I unit test my font-face rules?

There is indeed an existing test framework: https://github.com/Lindydancer/faceup Make sure to check out the author's other packages, many of them are related to the intricacies of font-lock.
wasamasa's user avatar
  • 22.2k
3 votes

Profiling simulated interactive editing

You can use the package font-lock-profiler. For each font-lock rule, it measures execution time and the number of times the rule matched. The package supports measuring time for highlighting a buffer ...
Lindydancer's user avatar
  • 6,180
3 votes

Why in dired+ mode some text is strikethrough?

They are displayed in the diredp-omit-file-name face defined in the very same file: (defface diredp-omit-file-name (if (assq :inherit custom-face-attributes) ; Emacs 22+ '((((background dark))...
choroba's user avatar
  • 2,085
3 votes
Accepted

How to highlight digit groups of 3 in numerals?

You can simulate the \ze construct using repeated matching. See also (info "(elisp) Search-based Fontification"). (defun my-matcher (limit) (when (re-search-forward "\\([0-9]\\{1,3\\}\\)\\...
politza's user avatar
  • 3,346
3 votes
Accepted

AUCTeX: only use monospace for rendering macros?

You can make the face used for math and the so-called sedate face used for macro names inherit from fixed-pitch, and activate variable-pitch-mode in the LaTeX mode hook: (set-face-attribute 'font-...
Omar's user avatar
  • 4,842

Only top scored, non community-wiki answers of a minimum length are eligible