[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A problem in using font-lock-add-keywords
From: |
Dmitry Gutov |
Subject: |
Re: A problem in using font-lock-add-keywords |
Date: |
Tue, 05 Mar 2013 08:58:56 +0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (windows-nt) |
source liu <sourceonly@gmail.com> writes:
> 1. about font-lock-add-keywords
> I'm new to elisp, and i want to add some keywords to a mode( say,
> c-mode), a list is below,
> (defvar my-list '("FIXME" "AND" "OR"))
>
>
> and I find some hint in emacs help C-h f "font-lock-add-keywords"
>
> ========= reference from the buff of help ===========
> (add-hook 'c-mode-hook
> (lambda ()
> (font-lock-add-keywords nil
> '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
> ("\\<\\(and\\|or\\|not\\)\\>" .
> font-lock-keyword-face)))))
> ==========================================
>
> i've tested it, it works, but when i change the expression of
> "\\<(FIXME\\):" by (regexp-opt mylist t), it can't work. does
> someone give me some hint where my problem is?
The problem is likely with quoting. You need to expand the `regexp-opt'
call:
(font-lock-add-keywords nil
`((,(regexp-opt mylist t) 1 font-lock-warning-face prepend)
("\\<\\(and\\|or\\|not\\)\\>" . font-lock-keyword-face))
By the way, as long as you want to highlight the whole match, you can
use the group number 0 and no grouping.