GNOME Bugzilla – Bug 728614
[PATCH] Fix Sweave R-block delimiter
Last modified: 2014-04-20 19:47:45 UTC
Created attachment 274763 [details] [review] Patch to make sure that @ is the end of block delimiter A Sweave R block ends with an '@'. This character can also be used in R to access lists (such as 'map@data') but is currently matched as end of block. The patch avoids matching [[:alnum:]]@[[:alnum:]] so that we still allow R code to appear on the same line as the ending @ (or latex code/comments after it), such as: <<test>>= map@data <- 1 @ % a comment
The bug occurs because the R syntax highlighting doesn't have a context that match "map@data", so the @ matches the end of "R-block". It seems that R doesn't highlight variables. If I write: map <- 12 map@data <- 12 "map" and "map@data" are not highlighted. Maybe a better fix is to match variables in R. As an intermediate solution, you can include a context in "R-block" in sweave.lang to match things like "map@data", to keep the <end>@</end>. The new context would have a lower priority than the R context, but a higher priority than the <end>. By doing this, [[:alnum:]]@[[:alnum:]] is matched explicitly instead of taking its negation (which is more complicated). Btw, if you have time it would be nice to have an example of a Sweave document in tests/testfiles.sh, to test the various features of the sweave.lang.
Comment on attachment 274763 [details] [review] Patch to make sure that @ is the end of block delimiter Also it's easier for us if you generate patches with the "git format-patch" command, so we have a commit message and the author.
Created attachment 274770 [details] [review] Temporary fix for R S4 slots (@)
Created attachment 274771 [details] [review] Testfile for sweave.lang
Review of attachment 274770 [details] [review]: Pushed. ::: data/language-specs/sweave.lang @@ +52,3 @@ <context ref="r:r"/> + <context id="R-slot" class="no-spell-check"> + <match>[[:alnum:]]@[[:alnum:]]</match> I've fixed the indentation here with two spaces.
I think the current fix is good enough. So I close this bug. But if you want to work on the R.lang for highlighting variables, feel free to provide a patch.