After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 728614 - [PATCH] Fix Sweave R-block delimiter
[PATCH] Fix Sweave R-block delimiter
Status: RESOLVED FIXED
Product: gtksourceview
Classification: Platform
Component: Syntax files
git master
Other Linux
: Normal trivial
: ---
Assigned To: GTK Sourceview maintainers
GTK Sourceview maintainers
Depends on:
Blocks:
 
 
Reported: 2014-04-20 15:36 UTC by matmoser
Modified: 2014-04-20 19:47 UTC
See Also:
GNOME target: ---
GNOME version: 3.11/3.12


Attachments
Patch to make sure that @ is the end of block delimiter (529 bytes, patch)
2014-04-20 15:36 UTC, matmoser
reviewed Details | Review
Temporary fix for R S4 slots (@) (839 bytes, patch)
2014-04-20 19:27 UTC, matmoser
committed Details | Review
Testfile for sweave.lang (846 bytes, patch)
2014-04-20 19:27 UTC, matmoser
committed Details | Review

Description matmoser 2014-04-20 15:36:28 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
Comment 1 Sébastien Wilmet 2014-04-20 17:58:09 UTC
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 2 Sébastien Wilmet 2014-04-20 18:00:58 UTC
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.
Comment 3 matmoser 2014-04-20 19:27:07 UTC
Created attachment 274770 [details] [review]
Temporary fix for R S4 slots (@)
Comment 4 matmoser 2014-04-20 19:27:39 UTC
Created attachment 274771 [details] [review]
Testfile for sweave.lang
Comment 5 Sébastien Wilmet 2014-04-20 19:46:02 UTC
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.
Comment 6 Sébastien Wilmet 2014-04-20 19:47:45 UTC
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.