From: Nikolaj Schumacher <me@nschum.de>
To: Nordlöw <per.nordlow@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Problem when optimizing font-lock-keywords
Date: Tue, 21 Oct 2008 23:26:10 +0200 [thread overview]
Message-ID: <m2iqrlhc7h.fsf@nschum.de> (raw)
In-Reply-To: <86864f7e-d948-4d9c-b554-589cb1f9b660@y21g2000hsf.googlegroups.com> ("Nordlöw"'s message of "Tue\, 21 Oct 2008 07\:06\:13 -0700 \(PDT\)")
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
prev parent reply other threads:[~2008-10-21 21:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-21 14:06 Problem when optimizing font-lock-keywords Nordlöw
2008-10-21 21:26 ` Nikolaj Schumacher [this message]
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2iqrlhc7h.fsf@nschum.de \
--to=me@nschum.de \
--cc=help-gnu-emacs@gnu.org \
--cc=per.nordlow@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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).