Get all scope names on Sublime Text 3

浪尽此生 提交于 2019-12-05 03:42:37

I just found the remaining packages wich are stored within the installation directory. So the final code which gives all scope names is:

import sublime, sublime_plugin, os, subprocess, glob, tempfile, plistlib
from zipfile import ZipFile

# This function gives array of scope names from the plist dictionary passed as argument
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

# Using set to have unique values
scopes = set()
# Parsing all .tmLanguage files from the Packages directory
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())
# Parsing all .tmLanguage files inside .sublime-package files from the Installed Packages directory
for x in os.walk(sublime.installed_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())
# Parsing all .tmLanguage files inside .sublime-package files from the Installation directory
for x in os.walk(os.path.dirname(sublime.executable_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)

This code may give different results depending on Packages installed (some packages add new syntax/scope names). In my case, the result was :

font
license
source.actionscript.2
source.applescript
source.asp
source.c
source.c++
source.camlp4.ocaml
source.clojure
source.cmake
source.coffee
source.cs
source.css
source.d
source.diff
source.disasm
source.dockerfile
source.dosbatch
source.dot
source.erlang
source.gdb.session
source.gdbregs
source.git
source.go
source.gradle
source.groovy
source.gruntfile.coffee
source.gruntfile.js
source.gulpfile.coffee
source.gulpfile.js
source.haskell
source.ini
source.ini.editorconfig
source.jade
source.java
source.java-props
source.jl
source.js
source.js.rails
source.json
source.json.bower
source.json.npm
source.jsx
source.less
source.lisp
source.lua
source.makefile
source.matlab
source.nant-build
source.objc
source.objc++
source.ocaml
source.ocamllex
source.ocamlyacc
source.pascal
source.perl
source.php
source.procfile
source.puppet
source.pyjade
source.python
source.qml
source.r
source.r-console
source.regexp
source.regexp.python
source.ruby
source.ruby.rails
source.rust
source.sass
source.scala
source.scss
source.shell
source.sql
source.sql.ruby
source.stylus
source.swift
source.tcl
source.yaml
source.zen.5a454e6772616d6d6172
text.bibtex
text.haml
text.html.asp
text.html.basic
text.html.erlang.yaws
text.html.javadoc
text.html.jsp
text.html.markdown
text.html.markdown.multimarkdown
text.html.mustache
text.html.ruby
text.html.tcl
text.html.textile
text.html.twig
text.log.latex
text.plain
text.restructuredtext
text.slim
text.tex
text.tex.latex
text.tex.latex.beamer
text.tex.latex.haskell
text.tex.latex.memoir
text.tex.latex.rd
text.tex.math
text.todo
text.xml
text.xml.xsl
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!