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

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

Re: Problem when optimizing font-lock-keywords


From: Nikolaj Schumacher
Subject: Re: Problem when optimizing font-lock-keywords
Date: Tue, 21 Oct 2008 23:26:10 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (darwin)

Nordlöw <per.nordlow@gmail.com> wrote:

> I am trying to optimize my extra calls to font-lock-add-keywords() by
> concatenating the MATCHERs like follows:
>
> (defun pnw-fancy/sh-mode-font-locking ()
>   "Fancy Shell Script Syntax Highlighting."
>   (font-lock-add-keywords
>    nil
>    (list
>     (cons (concat  "\\((\\|)\\)" "?"
>                   "\\(\\[\\|]\\|{\\|}\\)" "?"
>                   "\\(,\\|;\\)")
>           '((1 'font-lock-parens-face keep)
>             (2 'font-lock-braces-face keep)
>             (3 'font-lock-separator-face keep)))
>     )
>    t))
> (add-hook 'sh-mode-hook 'pnw-fancy/sh-mode-font-locking t)
>
> I believe this idea is used in emacs-lisp-mode() but I can't make it
> work --- I get the error:
> Error during redisplay: (error No match 1 in highlight (1 (quote font-
> lock-parens-face) keep)) [5 times]
>
> What have I missed?

I think all groups must be matched successfully or accessing them will
throw an error.  That isn't the case if the ? operator wasn't successful.

So instead of

"\\(  (\\|)  \\)?"

do:

"\\(  \\(:? (\\|) \\)? \\)"

(spaces added for readability)

regards,
Nikolaj Schumacher




reply via email to

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