Snippet does not work for .md or .rmd


#1

Hi there,

I encountered a problem using snippets. I could create my own snippets and brought them to work for several file types. So, the problem should not be the way I create snippets since just changing the first line from e.g. text.mdor .source.gfm to .source.r makes the snippet work.

So, I need to know what to put into the first line when I want the snippet to work for .rmd files and .md files. According to what I found this should be .text.md or .source.gfm. However, neither of these works. I guess there is some other problem. Maybe a package that prevents it from working?

Can you please help me to solve this issue.

Thank you!

Here the code, which makes the snippet work for whatever I put in the first line. I tested it also for e.g. .source.r and it works.

'.source.pweave.md, .source.gfm, text.md':
  'python_chunk':
    'prefix': 'p`'
    'body': """
    ```{python$2}
    $1
    ```
    """

  'r_chunk':
    'prefix': 'r`'
    'body': """
    ```{r$2}
    $1
    ```
    """

EDIT:
I just saw that the package language-gfm is disabled. I can activate it but whenever I restart Atom it gets disabled automatically. This is weird. But maybe this is related…

EDIT 2:
No, I think the language-gfm package is automatically disabled correctly because I have language-markdown installed…

Edit 3:
It was caused by the language-markdown package. When I uninstall this and restart Atom, then it works again but then the syntax highlighting for code junks is gone…


#2

Nice edits. You’ve gotten yourself partway to the solution. Let me bridge the rest of the gap. The “scope name” you see frequently in Atom is structured as a series of CSS classes, because Atom is basically a web page. When you have a grammar active that says its scopeName is, for instance, text.md, the atom-text-editor element in the DOM will have those classes applied and all of the style rules and propagating events will know what language is turned on in the active editor.

Snippets are one of the features that looks at the scope of the active DOM element to see if they should apply. So when you press tab from inside an R (source.r, represented in the DOM as <atom-text-editor class="source r" />) file, it successfully matches any snippets under .source.r. You can look up the scope name under the package settings view in Atom, or by looking at the code of the package (here’s language-markdown's grammar file).

So you can reinstall language-markdown and change your snippets to .text.md since that matches.


#3

Thanks @DamnedScholar. Indeed, I could reinstall it and it now works all fine!