Home Download Buy Blog Forum Support

Registering new syntax(es)/document types with SublimeREPL?

Registering new syntax(es)/document types with SublimeREPL?

Postby lianos on Mon Oct 15, 2012 9:00 pm

I'm thinking in particular for using Sweave (http://www.statistik.lmu.de/~leisch/Sweave/) and knitr (http://yihui.name/knitr/) with SublimeText.

Using Sweave, for example, one can write essentially write LaTeX documents that have chunks of R code embedded in them that are evaluated and embedded back into the document. Knitr essentially does the same.

Assuming we have valid language syntaxes for both (there is a SWeave syntax), how can we enable sending code chunks to an R session running in sublimeREPL? This is helpful so that one could debug the R code written in the document.

An example SWeave section might look like:

Code: Select all
This is some LaTeX I'm writing about something interesting. Below is a plot of something even more interesting

plot(something, interesting)

Notice that:

  \item This is actually;
  \item rather mundane

R code lives between the "<<>>=" and "@" blocks. Currently when I highlight the code and select:

`Tools > SumblieREPL > Eval in REPL > Selection`

nothing is sent to the R REPL I have fired up.

Is there a way to get this to work?

Posts: 1
Joined: Mon Oct 15, 2012 8:48 pm

Re: Registering new syntax(es)/document types with SublimeREPL?

Postby wuub on Tue Oct 16, 2012 9:21 pm

That depends on what level of "ugly" you're willing to accept.

SublimeREPL uses the following code to find out in what language a file is written in:

Code: Select all
view.scope_name(0).split(" ")[0].split(".")[1]

(you can run it yourself in ST2's Python console [open with Ctrl+`])

Optput of the above is used to find first REPL with matching external_id. If there is no such repl, the command just does nothing.

1) Ugly solution
For this SWeave bundle https://github.com/textmate/sweave.tmbundle it outputs "tex", so... copy config/R/ into config/SWeave and change content accordingly

* "file": in Defalt.sublime-commands,
* "external_id": to "tex" in "Main.sublime-menu
* repl names in both

This should "work" only for SWeave files, it's less than stellar tbh.

2) Less ugly solution ;)

Modify SWeave.tmbundle like this:

Code: Select all
- <string>text.tex.latex.sweave</string>
+ <string>source.r text.tex.latex.sweave</string>

to trick SublimeREPL into thinking that SWeave files are actually R source files. AFAICT additional source.r scope shouldn't affect your code highlight but please verify that your linter works if you use one in Sublime.
SublimeREPL via Package Control Twitter: @wuub
Posts: 161
Joined: Wed Aug 10, 2011 8:16 am
Location: Poland

Return to Technical Support

Who is online

Users browsing this forum: No registered users and 15 guests