Note that there are some explanatory texts on larger screens.

plurals
  1. POApply different scopes to the same character in a Sublime Text syntax definition file
    text
    copied!<p>I'm trying to create a new <code>.tmLanguage</code> file for Sublime Text 2 that defines special fenced code blocks for <a href="http://yihui.name/knitr/" rel="nofollow noreferrer">knitr</a> and Markdown. These blocks take this form:</p> <pre><code>```{r example_chunk, echo=true} x &lt;- rnorm(100) y &lt;- rnorm(100) plot(y ~ x, pch=20) ``` </code></pre> <p>There are two sections: (1) the parameters (<code>{r ...}</code>) and (2) the actual embedded code (between the closing <code>}</code> and the ``` at the end). There are four scopes that need to be applied to delineate the two sections:</p> <ul> <li><code>punctuation.definition.parameters.begin.knitr</code></li> <li><code>punctuation.definition.parameters.end.knitr</code></li> <li><code>punctuation.section.embedded.begin.knitr</code></li> <li><code>punctuation.section.embedded.end.knitr</code></li> </ul> <p>Using regular expressions to peg these scopes to parts of code is easy enough (partial code available <a href="https://gist.github.com/6302774" rel="nofollow noreferrer">here</a>). However, two of these scopes need to be applied to the same single character: the final <code>}</code> in the parameters section, which ends the parameters and signifies the beginning of the fenced/embedded code.</p> <p><img src="https://i.stack.imgur.com/k3z8C.png" alt="enter image description here"></p> <p>However, it appears to be impossible to assign two scopes to the same character in a .tmLanguage file. It's not possible to end the parameters section and begin the embedded section. The first scope defined takes precedence, thus breaking the syntax highlighting.</p> <p>Is there a way to use a <code>.tmLanguage</code> syntax definition to apply two different scopes to the same character in Sublime Text? If not, is there some way I can peg <code>punctuation.definition.parameters.end.knitr</code> and <code>punctuation.section.embedded.begin.knitr</code> to two different somethings instead of the single <code>{</code>? (Keeping in mind that I can't add additional characters to the code block.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload