Plurrrr

Fri 12 Apr 2019

Emacs highlight-regexp

After some playing with font-lock in Emacs I was wondering how to highlight the entire line when it just has a % character on it in Markdown mode. Entire line as in all other columns, with a background color.

So I asked this question at the Emacs StackExchange and very soon got a helpful answer by Tobias which with some additional Googling led to the following solution:

(defface markdown-item-face
  '((t (:background "#364e7a")))
  "Used to highlight %")

(add-hook 'markdown-mode-hook
    (lambda()
        (highlight-regexp
         "^%\n"
         'markdown-item-face)))

Now my blog posts in Emacs are separated by blue bars:

Emacs with highlight-regexp in Markdown mode showing blue bars
Emacs with highlight-regexp in Markdown mode showing blue bars.