Sublime Forum

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

#1

I’m thinking in particular for using Sweave (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]This is some LaTeX I’m writing about something interesting. Below is a plot of something even more interesting

<<>>=
plot(something, interesting)
@

Notice that:

\begin{enumerate}
\item This is actually;
\item rather mundane
\end{enumerate}
[/code]

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?

Thanks,
-steve

0 Likes

#2

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:

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 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.

  1. Less ugly solution :wink:

Modify SWeave.tmbundle like this:

[code]- text.tex.latex.sweave

  • source.r text.tex.latex.sweave[/code]

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.

0 Likes