Sublime text: Adding symbols to a new language def

2019-04-09 18:33发布

问题:

I have written syntax highlighting for a slightly unfamiliar language (Cadence SKILL) in sublime text 2.

Its working like a charm, however I miss the feature of CTRL + R , which locates all the symbols (functions) in the present file in an easily accessible way.

Can anyone please suggest how to tell Sublime Text where to look for a pattern of function (procedure) declaration?

Thanks!

回答1:

Take a look at Default/Symbol List.tmPreferences. You can create this preference file and specify scopes to include in the symbol list. You may also want to look at Java/Symbol List <some specifier>.tmPreferences for examples of a language specific symbol list. Alternatively, you can ensure the things that you want to include have the scope entity.name.function or entity.name.type.

edit

You will need to look at your color scheme file. These files are Plist, so you may want to use something like PlistJsonConverter to make it a little more readable (though this is more of a personal preference). In this file, you will see a number of dictionary entries. One of the keys to these entries is scope. When a matching scope is found as defined by your language definition. You will also see a "settings" key that defines details about color, font style, etc. Since you want different colors, you will need to apply different scopes. You will need to define a custom Symbol List preference file so everything gets included properly. The following is from the Java package.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Symbol List: Classes</string>
    <key>scope</key>
    <string>source.java meta.class meta.class.identifier</string>
    <key>settings</key>
    <dict>
        <key>showInSymbolList</key>
        <integer>1</integer>
    </dict>
    <key>uuid</key>
    <string>22E489AE-989E-4A76-9C18-89944CF5013D</string>
</dict>
</plist>

You will define whatever scopes are being applied to the entries you want to appear in the list.



回答2:

I too made one myself for Cadence Skill. You can try it out here

https://github.com/noisyass2/SublimeCadenceSkill