Search code examples
regexemacselispfont-lock

Regexp to highlight differently 1 asterisk, versus 2 asterisks, versus 3 astericks


I'm looking for a regexp to highlight differently one asterisk (e.g., red), and two asterisks (e.g., blue), and three asterisks (yellow). I have a working example of three (3) all together. Defining just one, however, would affect everything unless there is a regexp exclusion.

* -- red

** -- blue

*** -- yellow

(defvar lawlist-yellow-jacket-face (make-face 'lawlist-yellow-jacket-face))
(set-face-attribute 'lawlist-yellow-jacket-face nil
  :background "black" :foreground "yellow" :underline "red" :bold t)

(add-hook 'text-mode-hook (lambda ()
  (font-lock-add-keywords nil (list
    (list (concat "lawlist\\|\\*\\*\\*")
      '(0 lawlist-yellow-jacket-face t))
     ))
  ))

Solution

  • If I understand correctly what you are asking, this does it:

    (add-hook 'text-mode-hook
              (lambda ()
                (font-lock-add-keywords
                 nil
                 '(("lawlist\\|\\*\\*\\*"
                    (0 lawlist-yellow-jacket-face))
                    ("lawlist\\|\\*\\*"
                    (0 'link keep))
                   ("lawlist\\|\\*"
                    (0 'warning keep))))))