获取 Sublime Text 3 上的所有范围名称

2024-04-21

我正在创建一个插件ST3 http://www.sublimetext.com/并需要所有定义范围的列表。我知道打ctrl+alt+shift+p在状态栏中显示当前范围,但我无法对每个文件扩展名执行此操作。

Edit:

除了简单的.tmLanguage我正在提取的文件.sublime-package文件和阅读.tmLanguage来自内部的文件。这添加了一些条目,例如source.php到列表中。但source.python仍然失踪!

实际上,Python代码是:(这是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)

现在它给出了这个列表:

"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"

但我找不到像这样的语言python在此列表中。我猜其他的存储在安装文件夹中某处的一些二进制文件中。如果这是真的那么如何解析这些文件?


我刚刚发现剩余的软件包存储在安装目录中。因此,给出所有范围名称的最终代码是:

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)

根据安装的软件包,此代码可能会给出不同的结果(某些软件包添加新的语法/范围名称)。就我而言,结果是:

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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

获取 Sublime Text 3 上的所有范围名称 的相关文章

  • 中断 Select 以添加另一个要在 Python 中监视的套接字

    我正在 Windows XP 应用程序中使用 TCP 实现点对点 IPC 我正在使用select and socketPython 2 6 6 中的模块 我有三个 TCP 线程 一个读取线程通常会阻塞select 一个通常等待事件的写入线程
  • 使用 python requests 模块时出现 HTTP 503 错误

    我正在尝试发出 HTTP 请求 但当前可以从 Firefox 浏览器访问的网站响应 503 错误 代码本身非常简单 在网上搜索一番后我添加了user Agent请求参数 但也没有帮助 有人能解释一下如何消除这个 503 错误吗 顺便说一句
  • 与区域指示符字符类匹配的 python 正则表达式

    我在 Mac 上使用 python 2 7 10 表情符号中的标志由一对表示区域指示符号 https en wikipedia org wiki Regional Indicator Symbol 我想编写一个 python 正则表达式来在
  • Python 中的哈希映射

    我想用Python实现HashMap 我想请求用户输入 根据他的输入 我从 HashMap 中检索一些信息 如果用户输入HashMap的某个键 我想检索相应的值 如何在 Python 中实现此功能 HashMap
  • 用枢轴点拟合曲线 Python

    我有下面的图 我想用 2 条线来拟合它 使用 python 我设法适应上半部分 def func x a b x np array x return a x b popt pcov curve fit func up x up y 我想用另
  • 需要在python中找到print或printf的源代码[关闭]

    很难说出这里问的是什么 这个问题是含糊的 模糊的 不完整的 过于宽泛的或修辞性的 无法以目前的形式得到合理的回答 如需帮助澄清此问题以便重新打开 访问帮助中心 help reopen questions 我正在做一些我不能完全谈论的事情 我
  • 在Python中连接反斜杠

    我是 python 新手 所以如果这听起来很简单 请原谅我 我想加入一些变量来生成一条路径 像这样 AAAABBBBCCCC 2 2014 04 2014 04 01 csv Id TypeOfMachine year month year
  • “隐藏”内置类对象、函数、代码等的名称和性质[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我很好奇模块中存在的类builtins无法直接访问的 例如 type lambda 0 name function of module
  • 如何使用 pybrain 黑盒优化训练神经网络来处理监督数据集?

    我玩了一下 pybrain 了解如何生成具有自定义架构的神经网络 并使用反向传播算法将它们训练为监督数据集 然而 我对优化算法以及任务 学习代理和环境的概念感到困惑 例如 我将如何实现一个神经网络 例如 1 以使用 pybrain 遗传算法
  • Cython 和类的构造函数

    我对 Cython 使用默认构造函数有疑问 我的 C 类 Node 如下 Node h class Node public Node std cerr lt lt calling no arg constructor lt lt std e
  • Python3 在 DirectX 游戏中移动鼠标

    我正在尝试构建一个在 DirectX 游戏中执行一些操作的脚本 除了移动鼠标之外 我一切都正常 是否有任何可用的模块可以移动鼠标 适用于 Windows python 3 Thanks I used pynput https pypi or
  • 不同编程语言中的浮点数学

    我知道浮点数学充其量可能是丑陋的 但我想知道是否有人可以解释以下怪癖 在大多数编程语言中 我测试了 0 4 到 0 2 的加法会产生轻微的错误 而 0 4 0 1 0 1 则不会产生错误 两者计算不平等的原因是什么 在各自的编程语言中可以采
  • 仅第一个加载的 Django 站点有效

    我最近向 stackoverflow 提交了一个问题 标题为使用mod wsgi在apache上多次请求后Django无限加载 https stackoverflow com questions 71705909 django infini
  • 使用特定颜色和抖动在箱形图上绘制数据点

    我有一个plotly graph objects Box图 我显示了箱形 图中的所有点 我需要根据数据的属性为标记着色 如下所示 我还想抖动这些点 下面未显示 Using Box我可以绘制点并抖动它们 但我不认为我可以给它们着色 fig a
  • 如何在 Windows 命令行中使用参数运行 Python 脚本

    这是我的蟒蛇hello py script def hello a b print hello and that s your sum sum a b print sum import sys if name main hello sys
  • Pandas 将多行列数据帧转换为单行多列数据帧

    我的数据框如下 code df Car measurements Before After amb temp 30 268212 26 627491 engine temp 41 812730 39 254255 engine eff 15
  • python import inside函数隐藏现有变量

    我在我正在处理的多子模块项目中遇到了一个奇怪的 UnboundLocalError 分配之前引用的局部变量 问题 并将其精简为这个片段 使用标准库中的日志记录模块 import logging def foo logging info fo
  • 如何应用一个函数 n 次? [关闭]

    Closed 这个问题需要细节或清晰度 help closed questions 目前不接受答案 假设我有一个函数 它接受一个参数并返回相同类型的结果 def increment x return x 1 如何制作高阶函数repeat可以
  • 在 JavaScript 函数的 Django 模板中转义字符串参数

    我有一个 JavaScript 函数 它返回一组对象 return Func id name 例如 我在传递包含引号的字符串时遇到问题 Dr Seuss ABC BOOk 是无效语法 I tried name safe 但无济于事 有什么解
  • 使用随机放置的 NaN 创建示例 numpy 数组

    出于测试目的 我想创建一个M by Nnumpy 数组与c随机放置的 NaN import numpy as np M 10 N 5 c 15 A np random randn M N A mask np nan 我在创建时遇到问题mas

随机推荐

  • Android 相当于 iPhone 的“添加到主屏幕”吗?

    我正在开发一个移动网络应用程序 目前我有一段 jQuery 代码 用于检查应用程序是否全屏运行 if window navigator standalone content before div class notice To enjoy
  • XSD 架构和 JAXB 类中的多态性

    我有一个像这样的xml
  • 如何防止 SVN 缓存单个存储库的凭据?

    我正在使用 Collabnet SVN 客户端版本 1 5 和 1 6 我的本地计算机运行的是 Windows Vista x64 我知道 确实非常悲伤 我想每次尝试在选定的存储库上执行任何颠覆操作时都强制进行身份验证 我如何将属性或设置设
  • 用于将 格式的 unicode 字符转换为其 ASCII 等效项的脚本

    我正在对 Linux 区域设置文件进行一些更改 usr share i18n locales 如 pt BR 更改日期 时间 数字等的默认格式 但是由于 unicode 字符在
  • 使用 Angular FormArray 计算值

    我正在尝试根据 FormArray 中的特定值计算总计或其他值 我发现订阅时valueChanges并尝试将整个数组传递给类似的东西reduce 新值 不存在于父 FormGroup 中 StackBlitz 上的原始示例 https st
  • 如何确定 C 中数组的大小?

    如何确定 C 中数组的大小 即数组可以容纳多少个元素 执行摘要 int a 17 size t n sizeof a sizeof a 0 完整答案 要确定数组的大小 以字节为单位 您可以使用sizeof操作员 int a 17 size
  • @ControllerAdvice 未触发

    我正在开发 Spring MVC Webflow 应用程序 版本 3 2 并尝试进行异常处理 我可以将自定义异常消息输出到日志文件和 error jsp 我遇到的问题是异常处理程序没有被解雇 我创建了以下类并对其进行了注释 Controll
  • 如何以编程方式从设置中设置默认启动器?

    我想将我的启动器设置为默认启动器 我的代码对很多人来说都可以正常工作 但在乐视设备上却无法正常工作 因为它提供了从默认应用程序设置中设置默认启动器的功能 运行此代码时 它会在默认启动器上移动 但仅在乐视设备中不显示启动器选择器弹出窗口 如何
  • libgdx 中帧缓冲区的结果不明确

    我得到以下奇怪的结果帧缓冲区 http libgdx badlogicgames com nightlies docs api com badlogic gdx graphics glutils FrameBuffer htmllibgdx
  • 二进制到十进制转换 C 代码 - 满足特定测试用例的问题

    C程序将输入的二进制数转换为十进制数 该代码对于输入 10001000 101100 工作正常 输出分别为 136 和 44 但对于以下情况则失败 My code include
  • Cloud Firestore - 动态查询

    我有一个Collection在 Cloud Firestore 中有一定数量的项目 我们称之为Collection X 这个项目数量会不断变化 在任何给定时间 我想听一下此中的项目数Collection并创建几个whereEqualto 调
  • 在 python 中创建接口和可交换实现

    是否可以在 python 中创建一个类接口以及该接口的各种实现 示例 我想创建一个用于 pop3 访问的类 以及所有方法等 如果我使用商业组件 我想将其包装以遵守合同 将来 如果我想使用另一个组件或编写自己的代码 我希望能够交换组件而不是让
  • Jarsigner:找不到证书链

    我已将证书导入到私有证书中 keystore file keytool list Enter keystore password Keystore type JKS Keystore provider SUN Your keystore c
  • 无法安排 azure webjob

    我无法将计划的 WebJob 发布到 Azure 应用服务 我正在使用 Visual Studio 2017 使用此设置一切正常 架构 http schemastore org schemas json webjob publish set
  • 如何设置 Silverlight 4 OOB 应用程序的最小宽度和高度?

    有没有办法为我的 Silverlight 4 浏览器外应用程序设置最小宽度和高度 没有内置设置来控制窗口的最小宽度和高度 因此您需要使用代码来处理它 首先 您的 OOB 应用程序需要具有更高的信任度 然后您需要附加一个处理程序SizeCha
  • 如何在Prolog中编写cmp_list/3函数?

    Write a predicate cmp list 3 the first 2 arguments are 2 lists and the last one is Comparison which means ge lt le or gt
  • 为什么 [CSS 功能] 在 [浏览器] 中不起作用,但在其他浏览器中起作用?

    我尝试使用transition在 Firefox 15 上 它不起作用 即使它可以在其他版本的 Firefox 以及 Chrome 和 Safari 等其他浏览器上运行 当我使用 Firefox 的检查器查看属性时transition被删除
  • 如何禁用 Silverlight DataGrid 验证页脚?

    我面临以下问题 我正在使用验证摘要弹出窗口来在页面上显示错误 并且我有一个可编辑的 DataGrid 所以有2个问题 1 如果 DataGrid 单元格中出现验证错误 则 DataGrid 验证会重复验证错误 例如 DataGrid 包含
  • 使用Rvest登录网站抓取时出现403错误

    我试图在需要登录的网站上抓取页面 但不断收到 403 错误 我已经修改了我网站的这两篇文章中的代码 使用rvest或httr登录网页上的非标准表单 https stackoverflow com questions 28418770 usi
  • 获取 Sublime Text 3 上的所有范围名称

    我正在创建一个插件ST3 http www sublimetext com 并需要所有定义范围的列表 我知道打ctrl alt shift p在状态栏中显示当前范围 但我无法对每个文件扩展名执行此操作 Edit 除了简单的 tmLangua