A better jedit edit mode for R
By romain francois on Monday, March 16 2009, 08:35 - Permalink
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
Comments
Hi Francois,
I appreciate your efforts, since I was the one who complained about R-jedit not being as fast as I was used to.
However, the new syntax file, while faster, may not change the overall picture.
I opened a small text file (no highlight at all), and pressing down arrow to the botton of the screen makes it really slow to paint the new lines (scroll). Happens with mouse wheel too. It might be some silly setting (i.e. highlighting cursor row or something).
Is this the case for you too?
Thanks
Hi Jose,
I though you might comment here.
There is hardly any painting done when you are using text files, see the edit mode for text (nothing there to slow things up):
<MODE>
<RULES>
<TERMINATE AT_CHAR="0" />
</RULES>
</MODE>
So if it is slow with text files, you are not going to get it faster with any other mode, what about moving one page at a time instead of one line at a time, is that better ?
Romain
yes,
one-page scroll is fine I guess. Line by line is only slow when reaching the end of page, and jedit has to scroll.
I'll have to hunt down the responsible. But since I'm very comfortable with vim, it really doesn't pay off for me to spend that much time debugging Jedit...
The other thing is that you could allocate more memory to the JVM running jedit
java -Xmx1024m jedit.jar
and see if it is better. Otherwise, jedit has all sort of user mailing lists and request trackers, ...
Small bug in the mode file: If I have a variable name that starts with a KEYWORD1 and then a special character (i.e. do_analysis() )", it will interpret "do" as a language construct.
Not sure if that's easily fixable...