help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: font-locking regexps ?


From: Kevin Rodgers
Subject: Re: font-locking regexps ?
Date: Mon, 26 Sep 2005 15:33:25 -0600
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

Mads Jensen wrote:
> I am trying to write some code for coloring some regexps, but cannot
> really make it work. Since regexps seem to be working a little bit
> differently (| = \\| in emacs lisp and so on), I'd like some help. I am
> trying to get some items in a list colored:
>
> <code>
>         (codes-inducks
>     (eval-when-compile
>       (list
>        '("[YZ]. [0-9]{2}-[0-9]{2}-[0-9]"
>          "I .{9}"
>          "F .{8}"
>          "[DH] [0-9-]{6}"
>          "D 20[0-9-]{6}"
>          "W .{10}")))))
> </code>

The syntax of regular expressions is explained in the Regexps node of
the Emacs manual.  The syntax of strings is explained in the Syntax for
Strings node of the Emacs Lisp manual, but the Regexps node of the Emacs
manual mentions the key aspect (that each backslash of the regexp needs
to be doubled in the string):

|    Here is a complicated regexp, stored in `sentence-end' and used by
| Emacs to recognize the end of a sentence together with any whitespace
| that follows.  We show its Lisp syntax to distinguish the spaces from
| the tab characters.  In Lisp syntax, the string constant begins and
| ends with a double-quote.  `\"' stands for a double-quote as part of
| the regexp, `\\' for a backslash as part of the regexp, `\t' for a tab,
| and `\n' for a newline.
|
|      "[.?!][]\"')]*\\($\\| $\\|\t\\|  \\)[ \t\n]*"

So I suspect your code should be:

        (codes-inducks
            '("[YZ]. [0-9]\\{2\\}-[0-9]\\{2\\}-[0-9]"
              "I .\\{9\\}"
              "F .\\{8\\}"
              "[DH] [0-9-]\\{6\\}"
              "D 20[0-9-]\\{6\\}"
              "W .\\{10\\}"))

> and I'm using these code for coloring it:
>
> <code>
>     (setq inducks-keywords
>      (list (cons keywords-inducks 'inducks-keyword-face)
>                 (cons codes-inducks 'inducks-code-face)))
> </code>
>
> But it's not working.
>
> Please just point me to a major mode, that uses this. Someone refered me
> to sql.el in an earlier thread, which helped me get some of the
> font-lock part to work in a mode, I'm working on.

M-x grep font-lock lisp/progmodes/*.el

--
Kevin Rodgers





reply via email to

[Prev in Thread] Current Thread [Next in Thread]