I have spend a bit of time over the week end working with the jedit edit mode file for R code. That is the file that guides jedit on how to syntax highlight R code. The previous one I was using was based on the idea "let's put all the names of all the functions in standard R packages as keywords", although "it works", it is not a very good idea since it makes the edit mode huge and consequently must have some effect on jedit's performance when painting R code
The new mode file can be found on the biocep-editor project on r-forge
Here are some of the choices I have made
- function calls are highlighted with type FUNCTION. A function call is a name followed by a round bracket
- Core language constructs are highlighted with type KEYWORD1: (for, function, if, else, ifelse, in, repeat, return, switch, while, break, next) I have also added these to that list: (expression, quote, parse, deparse, substitute, get, getAnywhere, assign, exists, expression, bquote, typeof, mode, eval, evalq, with).
- Debugging related functions are highlighted with type KEYWORD2: browser, debug, trace, traceback, recover, undebug, isdebugged, bp, mtrace
- Error handling functions are highlighted using KEYWORD3: try, tryCatch, withRestarts, withCallingHandlers, stop, stopifnot, geterrmessage, warning, signalCondition, simpleCondition, simpleError, simpleWarning, simpleMessage, conditionCall, conditionMessage, computeRestarts, findRestart, invokeRestart, invokeRestartInteractively, isRestart, restartDescription, restartFormals, .signalSimpleWarning, .handleSimpleError
- Object Oriented related functions (S3 and S4) are using type KEYWORD4: class, inherits, setClass, representation, structure, methods, setIs, slot, new, setMethod, validObject, setValidity, getValidity, initialize, setOldClass, callNextMethod, NextMethod, UseMethod, getS3method
- Constants are using type LITERAL2: NULL, Inf, NULL, NA, NaN, T, TRUE, F, FALSE, pi, NA_character_, NA_complex_, NA_integer_, NA_real_
- Apply functions are using LITERAL4: lapply, sapply, by, mapply, tapply, apply, replicate, aggregate. I have also added some functions from the packages reshape and plyr to that list
- Support for R4X by delegating to the R4X mode (mainly XML) between strings "'##((xml" and "'##xml))"
- Support for Roxygen comment, inspired from the way javadoc comments are treated in the java mode