* Problem when optimizing font-lock-keywords
@ 2008-10-21 14:06 Nordlöw
2008-10-21 21:26 ` Nikolaj Schumacher
0 siblings, 1 reply; 2+ messages in thread
From: Nordlöw @ 2008-10-21 14:06 UTC (permalink / raw
To: help-gnu-emacs
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?
Many thanks in advance,
Nordlöw
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Problem when optimizing font-lock-keywords
2008-10-21 14:06 Problem when optimizing font-lock-keywords Nordlöw
@ 2008-10-21 21:26 ` Nikolaj Schumacher
0 siblings, 0 replies; 2+ messages in thread
From: Nikolaj Schumacher @ 2008-10-21 21:26 UTC (permalink / raw
To: Nordlöw; +Cc: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-10-21 21:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-21 14:06 Problem when optimizing font-lock-keywords Nordlöw
2008-10-21 21:26 ` Nikolaj Schumacher
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.