From: Dmitry Gutov <dgutov@yandex.ru>
To: source liu <sourceonly@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: A problem in using font-lock-add-keywords
Date: Tue, 05 Mar 2013 08:58:56 +0400 [thread overview]
Message-ID: <87d2veigrz.fsf@yandex.ru> (raw)
In-Reply-To: <CAAzVxgMcJ4o6+-Z4uVCJM-ChSr2uAAZqn8-Z2g_yU7c0XCfTZg@mail.gmail.com> (source liu's message of "Tue, 5 Mar 2013 10:54:20 +0800")
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.
next prev parent reply other threads:[~2013-03-05 4:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-05 2:54 A problem in using font-lock-add-keywords source liu
2013-03-05 4:58 ` Dmitry Gutov [this message]
2013-03-05 7:34 ` source liu
2013-03-05 8:50 ` Dmitry Gutov
[not found] ` <CAAzVxgMu3EnA1_FMG9oLshCxhPV03=qkVNoWKhygUJKa8C6DwA@mail.gmail.com>
2013-03-05 10:14 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87d2veigrz.fsf@yandex.ru \
--to=dgutov@yandex.ru \
--cc=help-gnu-emacs@gnu.org \
--cc=sourceonly@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.