[Top][All Lists]

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

regexp/font-lock question

From: Joe Corneli
Subject: regexp/font-lock question
Date: Tue, 18 May 2004 22:04:08 -0500

I'm running into something reminiscent of a problem I was having a
while ago, which Jesper Harder put down to replace-match leaving
the point after the replacement text (see below).  But this time
the problem comes up in font lock, not text replacement.

Specifically, I thout it would be nice to fontify gnugo-board-mode,
so I defined the following set of font-lock keywords:

(defconst gnugo-font-lock-keywords
  (list '("X" . font-lock-builtin-face)
        '("[^N][ ()]\\(O\\)" 1 font-lock-type-face))
  "Highlighting expressions for todl mode.")

The [^N] in the second pattern is present to escape the O in "N O"
that appears at the top and the bottom of the board.

Things are working just fine until a pattern like "O O", "(O) O", or
"O (O)" appears on the board, in which case the second O is not
fontified properly.

So my question is: what matcher should I be using to get these
additionaly strings to fontify properly?

multiple alternatives regexp question, Joe Corneli, 2004/01/06

> Unfortunately, when I search and replace like so:
> (let ((case-fold-search nil))
> (while (re-search-forward "\\([[:lower:]]\\|[[:digit:]]\\|A\\)\\([A-Z]\\)"
>                           nil t)
>   (replace-match (concat (match-string 1) " " (match-string 2)))))
> on something like
> ProofOfPropertiesOfTraceOfAMatrix
> I get back
> Proof Of Properties Of Trace Of AMatrix
>                                  ^
> Why is the `A' not being treated the way I want the first time
> around?

Re: multiple alternatives regexp question, Jesper Harder, 2004/01/06

> It doesn't work because `replace-match' leaves point after the
> replacement text.  You could use something like this instead:
>    (replace-match "\\1 " t nil nil 1)

reply via email to

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