Sublime Forum

How to determine the magic string in <source> etc

#1

There are a few magic strings in Sublime.

Snippet for HTML:

<snippet> <content><![CDATA[ <label for="${1:Id}">${2:Label text}</lablel> <input type="${3:text}" id="$1" value="${4:something}" /> ]]></content> <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <tabTrigger>labelinput</tabTrigger> <!-- Optional: Set a scope to limit where the snippet will trigger --> <scope>text.html</scope> </snippet>

Snippet for C#:

<snippet> <content><![CDATA[ Console.WriteLine("${1:Hello World!}"); ]]></content> <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <tabTrigger>cw</tabTrigger> <!-- Optional: Set a scope to limit where the snippet will trigger --> <scope>source.cs</scope> <description>Console.WriteLine("{1}");</description> </snippet>

When saving language specific settings I need to know the magic string (with casing) in order to name the file correctly (as per my SO question http://stackoverflow.com/questions/32549556/set-word-wrap-for-plain-text-only)

[code]Plain Text.sublime-settings <== Bad

Plain text.sublime-settings <== Good[/code]

  1. Are these defined somewhere?
  2. What is the practical difference between source.* and text.*?

Thanks all

Dave

0 Likes

#2
  1. It’s just the Syntax name. Since ST ignores the name of the file, only the syntax definition’s filename matters. It’s the same as in the status bar and in the command palette and in the syntax menu.
  2. text and source are mostly differentiated for auto-completion. ST by default won’t auto-prompt the completion popup for text scopes, which “text.plain” and “text.html” fall under. There might be more, but this is the most notable.
0 Likes

#3

C# is displayed as C# in the status bar, the package file is C#.sublime-package but the magic string for it is source.cs. For most it’s probably the same, do you know where the definitive definition for it lives?

0 Likes

#4

Now you’re mixing syntax name and base scope. The base scope is definied in the syntax definition at the root level.

The easiest way to find the base scope is to open any view with the syntax you want (can be emtpy) and press ctrl+alt+shift+p. This will display the scope name of the current caret position in the status bar.

0 Likes