简体   繁体   中英

emacs major-mode define font-lock for line preceding regexp

I'm working on making a custom emacs major-mode, but I'm completely unfamiliar with lisp - so I'm struggling. I'm trying to add a font lock such that a line of repeating ' = ' or ' - ' is highlighted, along with the line above it (so that I can use these as headings), ie

This is a Colored Heading
=========================

this is a differently-colored sub-heading
-----------------------------------------

I've tried to set this up with:

(font-lock-add-keywords nil '(("\\(.*\n=\{3,\}\\)"
                             1 font-lock-warning-face prepend)))

but it isn't working. I thought this meant:

' .* ' any characters
' \\n ' followed by a newline
' =\\{3,\\} ' followed by 3 or more '=' characters

Where am I going wrong?

"\\{" and "\\}" are treated as an escape sequence, which they're not. You need to use "\\\\{" and "\\\\}" instead:

(font-lock-add-keywords nil '(("\\(.*\n=\\{3,\\}\\)"
                             1 font-lock-warning-face prepend)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM