From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.help Subject: Re: A problem in using font-lock-add-keywords Date: Tue, 05 Mar 2013 08:58:56 +0400 Message-ID: <87d2veigrz.fsf@yandex.ru> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1362459559 10318 80.91.229.3 (5 Mar 2013 04:59:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 5 Mar 2013 04:59:19 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: source liu Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 05 05:59:39 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UCjyU-000467-Rp for geh-help-gnu-emacs@m.gmane.org; Tue, 05 Mar 2013 05:59:38 +0100 Original-Received: from localhost ([::1]:52959 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCjy9-0003Sd-DC for geh-help-gnu-emacs@m.gmane.org; Mon, 04 Mar 2013 23:59:17 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:41606) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCjxv-0003SS-BB for help-gnu-emacs@gnu.org; Mon, 04 Mar 2013 23:59:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UCjxq-0002NM-Nw for help-gnu-emacs@gnu.org; Mon, 04 Mar 2013 23:59:03 -0500 Original-Received: from mail-la0-x22d.google.com ([2a00:1450:4010:c03::22d]:45357) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCjxq-0002Mv-FD for help-gnu-emacs@gnu.org; Mon, 04 Mar 2013 23:58:58 -0500 Original-Received: by mail-la0-f45.google.com with SMTP id er20so5809294lab.32 for ; Mon, 04 Mar 2013 20:58:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=W3IxI1RE86PnC4h66/SD9FYHymp5tqpKdr5wPML797Q=; b=wpXxdKBIIERpE0PxZlkEY2CfkEAtsy2LZJqFzPMU2olsDMCceWpcRbYZ6LlT545Z7y PbpEC5CtWdg+gG5n0d7ks0Dw48F0X0ByQ2cAuETzPaKfaDcGkLTgLrZoATE+oQpo5skK cEINqticbDIlLHZtzngp1Dv32FacS5vS/87Szy4Q90Z65UgefAZ9QzG/vy0hfCQANU+K ri/Ords4BZQU+vQbrP/4R4FHCpHNXTdBc0ktvu1DNi7j8zVv4CK2iNQupJ7ZgKZOFd8J aflbztH3rQQW3DCKpRjaJ6nDRggVPeSmQ4YieFm7zQQ+JBhGJ/dVIltjVupBDqhdoEud YtqQ== X-Received: by 10.152.111.67 with SMTP id ig3mr20117382lab.41.1362459536636; Mon, 04 Mar 2013 20:58:56 -0800 (PST) Original-Received: from SOL ([178.252.98.87]) by mx.google.com with ESMTPS id b13sm8030401lbd.10.2013.03.04.20.58.55 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 04 Mar 2013 20:58:55 -0800 (PST) In-Reply-To: (source liu's message of "Tue, 5 Mar 2013 10:54:20 +0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (windows-nt) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::22d X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:89357 Archived-At: source liu 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.