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

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

Re: font-lock-add-keywords


From: Arjan Bos
Subject: Re: font-lock-add-keywords
Date: Fri, 06 Aug 2004 00:35:55 +0200
User-agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7) Gecko/20040616

Randy Haddox wrote:

I am using code in .emacs to find and color code various keywords.  I
haven't had any luck handling the "if" keyword when it doesn't starting
in column 1 (ie, has leading whitespace).  Most of the time the "if"
will start at the beginning.

(defface test-keyword6-face
  '((t (:foreground "gold")))
  "Keyword face.")
(font-lock-add-keywords 'latex-mode
  '(("^if\\|then\\|else\\|endif" . 'test-keyword6-face))
)


Any help would be much appreciated.


So `if' can have zero or more whitespaces in front of it. And perhaps there might even be a tab character in front of it too. So you might want to consider matching

"^[ \t]*if\\|then\\|else\\|endif"

"^" will match the beginning of a line (as you know)
"[ \t]" will match a whitespace or a tab character
"*" will match zero or more of the thing before it.
So "[ \t]*" will match zero or more of either whitespace or tab and
"^[ \t]*if" will match `if' starting on a line with zero or more whitespace and / or tab characters in front of it.

HTH,

Arjan


--
--
If you really want to contact me, then replace the "I see you" text by its three letter accronym, hetnet.

Fabricate Diem PVNC, Motto of the Night Watch -- Terry Pratchett


reply via email to

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