[ESS] Customizing syntax highlighting

Sven Hartenstein lists at svenhartenstein.de
Sat Jul 31 09:06:26 CEST 2010


Hi Steve, S. McKay Curtis, and others,

thank you for posting this, I like this improved syntax highlighting a
lot!

Developers, how about making it the default in ESS?

Sven


------- start of forwarded message -------
From: Steve Lianoglou <mailinglist.honeypot at gmail.com>
Sender: ess-help-bounces at stat.math.ethz.ch
To: "S. McKay Curtis" <smcurtis at stat.washington.edu>
Cc: ESS-help at stat.math.ethz.ch
Subject: Re: [ESS] Customizing syntax highlighting
Date: Fri, 23 Jul 2010 12:33:27 -0400

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

______________________________________________
ESS-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help
------- end of forwarded message -------



More information about the ESS-help mailing list