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 display-fill-column-indicator-...
Basil's user avatar
  • 12.4k
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.2k
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

Echo Area font face?

Sure you can, (see this SO question) although it seems a bit heavy-handed. (defun nadvice/message-color (old-fun &optional str &rest args) (if (not str) (funcall old-fun) (funcall ...
PythonNut's user avatar
  • 10.4k
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
  • 77.7k
5 votes
Accepted

Colorizing `functions/variables' within comments in `c-mode'

This seems to work for me: (require 'cc-mode) (setq yashi-font-lock-doc-comments (let ((symbol "[a-zA-Z0-9_-]+")) `((,(concat "`" symbol "'") 0 ,c-doc-markup-face-name prepend nil)) ...
Yasushi Shoji's user avatar
5 votes
Accepted

Line highlighting canceling out syntax highlighting

Basically, the hl-line face is defining a :foreground property, which is overriding the other foreground colors in your theme. misterioso defines hl-line in terms of highlight using inheritance, and ...
PythonNut's user avatar
  • 10.4k
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,160
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.2k
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
  • 77.7k
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

Part II -- Colorizing `functions/variables' within comments in `c-mode'

You are using the wrong tool. The c-doc system is used to highlight doxygen-style comments, which is why it changes the face from font-lock-comment-face to font-lock-doc-face. Another drawback is ...
Lindydancer's user avatar
  • 6,160
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.2k
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,160
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,160
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,160
3 votes
Accepted

How to prevent font-lock from being lazy?

[ Indeed, your rules are "single line", so it's not among the problems described in (elisp)Font Lock Multiline. It really doesn't have anything to do with "laziness". ] The problem is quite simple: ...
Stefan's user avatar
  • 26.4k
3 votes
Accepted

setting comment face in major mode on multi-line word-delimited comments

Rather than handle it in font-lock highlighing rules, you want to handle it at the level of syntax tables. Now syntax-tables can't directly handle such start/end markers, so you'll have to use the ...
Stefan's user avatar
  • 26.4k
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

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
  • 77.7k
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
  • 77.7k
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.4k
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.2k

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