[ESS] Customizing syntax highlighting
Steve Lianoglou
mailinglist.honeypot at gmail.com
Fri Jul 23 18:33:27 CEST 2010
Hi S,
Thanks for sharing this ... I made a small tweak to your regex for
argument matching:
On Thu, Jul 22, 2010 at 3:40 PM, S. McKay Curtis
<smcurtis at stat.washington.edu> wrote:
> Here's code that I added to my .emacs file to beef up the default syntax
> highlighting. It doesn't do exactly what you requested, but perhaps you can
> make it work after playing around with it (I'd be interested to see what you
> come up with...):
>
> (add-hook 'ess-mode-hook
> '(lambda()
> (font-lock-add-keywords nil
> '(("\\<\\(if\\|for\\|function\\|return\\)\\>[\n[:blank:]]*(" 1
> font-lock-keyword-face) ; must go first to override highlighting below
> ("\\<\\([.A-Za-z][._A-Za-z0-9]*\\)[\n[:blank:]]*(" 1
> font-lock-function-name-face) ; highlight function names
> ("[(,][\n[:blank:]]*\\([.A-Za-z][._A-Za-z0-9]*\\)[\n[:blank:]]*=" 1
> font-lock-reference-face) ;highlight argument names
> ))
> ))
Your last regex would, imho, erroneously highlight parts of `if`
clauses, and not highlight the first argument in an argument list that
continued to the next line. For example, in this function:
test <- function(one=1, two=2,
three=3, four=4, ...) {
if (a == 3) {
}
}
`three` is not highlighted, but `a` is.
To try and fix this behavior, I changed your last regex to be:
("\\([(,]\\|[\n[:blank:]]*\\)\\([.A-Za-z][._A-Za-z0-9]*\\)[\n[:blank:]]*=[^=]"
2
font-lock-reference-face) ;highlight argument names
Which I think works a bit better, no?
Thought I'd share,
-steve
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
More information about the ESS-help
mailing list