I am creating a plugin for ST3 and need the list of all defined scopes. I know that hitting ctrl+alt+shift+p
shows the current scope in the status bar but I can't do it for every file extension.
Edit:
In addition to simple .tmLanguage
files I am extracting the .sublime-package
files and reading .tmLanguage
files from inside. This added some entries like source.php
to the list. But source.python
is still missing !
Actually, the python code is: ( this is for Python 3.3 )
import sublime, sublime_plugin, os, subprocess, glob, tempfile, plistlib
from zipfile import ZipFile
def scopes_inside(d):
result = []
for k in d.keys():
if k == 'scopeName':
result = result + [ s.strip() for s in d[k].split(',') ]
elif isinstance(d[k], dict):
result = result + scopes_inside(d[k])
return result
scopes = set()
for x in os.walk(sublime.packages_path() + '/..'):
for f in glob.glob(os.path.join(x[0], '*.tmLanguage')):
for s in scopes_inside(plistlib.readPlist(f)):
scopes.add(s.strip())
for x in os.walk(sublime.packages_path() + '/..'):
for f in glob.glob(os.path.join(x[0], '*.sublime-package')):
input_zip = ZipFile(f)
for name in input_zip.namelist():
if name.endswith('.tmLanguage'):
for s in self.get_scopes_from(plistlib.readPlistFromBytes(input_zip.read(name))):
scopes.add(s.strip())
scopes = list(scopes)
And it gives this list now:
"font",
"license",
"source.c++",
"source.cmake",
"source.coffee",
"source.css",
"source.d",
"source.disasm",
"source.dockerfile",
"source.gdb.session",
"source.gdbregs",
"source.git",
"source.gradle",
"source.groovy",
"source.gruntfile.coffee",
"source.gruntfile.js",
"source.gulpfile.coffee",
"source.gulpfile.js",
"source.ini",
"source.ini.editorconfig",
"source.jade",
"source.jl",
"source.js",
"source.json",
"source.json.bower",
"source.json.npm",
"source.jsx",
"source.less",
"source.php",
"source.procfile",
"source.puppet",
"source.pyjade",
"source.qml",
"source.rust",
"source.sass",
"source.scss",
"source.shell",
"source.stylus",
"source.swift",
"source.yaml",
"source.zen.5a454e6772616d6d6172",
"text.html.basic",
"text.html.mustache",
"text.html.ruby",
"text.html.twig",
"text.slim",
"text.todo"
But I can't find some languages like python
in this list. I guess other are stored within some binary files somewhere within the installation folder. If that's true so how the parse thoses files ?