Anaconda Package Sublime 中的 Linting 定制

弗罗塔尔

我正在为 Sublime 3 使用 Anaconda 包,它运行良好。我唯一的问题是 linting 以相同的颜色(白色)突出显示所有类型的错误、警告和 PEP8 建议。我想改变它,所以错误是红色的,警告是黄色的等等......但我不知道该怎么做。我发现这个资源基本上告诉我向我当前的主题添加一些 XML 代码以更改 linting 颜色,但我尝试这样做,但它什么也没做。

首先,我相信现在主题使用 json 而不是 XML,文件名类型为“.sublime-color-scheme”或“.sublime-theme”。因此,我找到了一个确实有“.tmtheme”文件的自定义主题,并粘贴了此处给出的 XML 代码,但 linting 仍然是完全白色的。

然后我尝试将此 XML 代码转换为 json,并将其粘贴到“.sublime-color-scheme”文件中,但又一次,linting 是白色的。准确地说,我把它粘贴在"rules" :[]条目中,因为这似乎符合格式。

任何有更多经验的人都可以告诉我我做错了什么,或者指出另一种改变掉毛颜色的方法?我知道像 SublimeLinter 这样的包,但我宁愿坚持使用 Anaconda 包的内置 linter,因为它在着色旁边工作得很好。

奥达特

正如您所指出的,Sublime Text 中有两种不同类型的配色方案:

  1. tmTheme格式,这是一个XML plist文件。此格式仍受支持,但此时被视为旧文件格式。

  2. sublime-color-scheme格式,这是一个JSON文件。此格式可以执行该格式可以执行的所有tmTheme操作,并且具有tmTheme文件无法执行的额外功能

注意:尽管名称如此,但tmTheme文件是配色方案,而不是主题。不幸的是,格式被命名了,但在 Sublime Text 中,aTheme是一个完全不同的东西,它使应用程序看起来像一个整体。

这种区别在这里并不是特别重要,但它会使您在搜索信息时不知道,因为有时您最终会找到似乎并不适用于任何事物的信息。

很难准确说出您可能做错了什么,因为您没有包含您尝试添加到文件中的内容。通常,我希望您在其中添加的任何内容都可以正常工作或导致某种错误(弹出窗口或 Sublime 控制台),除非包本身存在任何配置问题。

作为补充说明,我不使用这个包(或一般的 linters),因此出于测试目的,我测试的 Anaconda 设置是库存,除了以下两个设置:

    // The default is "basic", but that seemed too generic for testing
    "anaconda_gutter_theme": "bright",

    // I don't use linters, but I happened to have pylint already installed
    // so this was the path of least resistance.
    "use_pylint": true,

您将如何将额外规则添加到您的配色方案首先取决于您的配色方案所在的位置。特别是,如果您创建了自己的自定义配色方案并存储在您的User包中,则步骤与使用其他人提供的配色方案(Sublime Text 或您安装的某个包)时的步骤不同。

由于大多数人倾向于使用他们从其他地方获得的预先存在的配色方案,我们将首先介绍这一点。

您链接的页面上给出的颜色规则采用tmThemeXML 格式,如下所示:

<!-- Anaconda -->
<dict>
  <key>name</key>
  <string>anaconda Error Outline</string>
  <key>scope</key>
  <string>anaconda.outline.illegal</string>
  <key>settings</key>
  <dict>
      <key>background</key>
      <string>#FF4A52</string>
      <key>foreground</key>
      <string>#FFFFFF</string>
  </dict>
</dict>
<dict>
  <key>name</key>
  <string>anaconda Error Underline</string>
  <key>scope</key>
  <string>anaconda.underline.illegal</string>
  <key>settings</key>
  <dict>
      <key>background</key>
      <string>#FF0000</string>
  </dict>
</dict>
<dict>
  <key>name</key>
  <string>anaconda Warning Outline</string>
  <key>scope</key>
  <string>anaconda.outline.warning</string>
  <key>settings</key>
  <dict>
      <key>background</key>
      <string>#DF9400</string>
      <key>foreground</key>
      <string>#FFFFFF</string>
  </dict>
</dict>
<dict>
  <key>name</key>
  <string>anaconda Warning Underline</string>
  <key>scope</key>
  <string>anaconda.underline.warning</string>
  <key>settings</key>
  <dict>
      <key>background</key>
      <string>#FF0000</string>
  </dict>
</dict>
<dict>
  <key>name</key>
  <string>anaconda Violation Outline</string>
  <key>scope</key>
  <string>anaconda.outline.violation</string>
  <key>settings</key>
  <dict>
      <key>background</key>
      <string>#ffffff33</string>
      <key>foreground</key>
      <string>#FFFFFF</string>
  </dict>
</dict>
<dict>
  <key>name</key>
  <string>anaconda Violation Underline</string>
  <key>scope</key>
  <string>anaconda.underline.violation</string>
  <key>settings</key>
  <dict>
      <key>background</key>
      <string>#FF0000</string>
  </dict>
</dict>

要添加这些规则,我们需要先将它们转换为sublime-color-schemeJSON 格式,即使您的配色方案是tmThemecolor scheme用于调整配色方案的方法是在User包含附加内容的包中创建一个文件,并且该文件始终采用该sublime-color-scheme格式。

这些规则到 a 的新 JSON 格式的转换sublime-color-scheme如下所示:

{
    "name": "anaconda Error Outline",
    "scope": "anaconda.outline.illegal",
    "foreground": "#FFFFFF",
    "background": "#FF4A52"
},
{
    "name": "anaconda Error Underline",
    "scope": "anaconda.underline.illegal",
    "background": "#FF0000"
},
{
    "name": "anaconda Warning Outline",
    "scope": "anaconda.outline.warning",
    "foreground": "#FFFFFF",
    "background": "#DF9400"
},
{
    "name": "anaconda Warning Underline",
    "scope": "anaconda.underline.warning",
    "background": "#FF0000"
},
{
    "name": "anaconda Violation Outline",
    "scope": "anaconda.outline.violation",
    "foreground": "#FFFFFF",
    "background": "#ffffff33"
},
{
    "name": "anaconda Violation Underline",
    "scope": "anaconda.underline.violation",
    "background": "#FF0000"
},

根据您的实际配色方案,此处的颜色可能合适也可能不合适,因此您必须使用它们以使它们看起来如您所愿。这还需要知道什么归类为illegalvs warningvsviolation以及您如何设置 Anaconda 的 linting 样式。您的规则可能需要foregroundbackground或者both取决于您如何设置。

有了这些内容,我们就可以开始了。为了进行调整,您需要知道您的配色方案的名称是什么。您可以通过使用Preferences > Settings和查看color_scheme设置来获得它(如果您使用的是特定于语法的设置,则打开该类型的文件并使用Preferences > Settings - syntax specific并从那里获取配色方案)。

我们在这里感兴趣的部分是文件名;我们不关心它可能说它存在于哪个包中,只关心文件本身的名称。我们也不关心文件的扩展名是什么,因为我们将假设扩展名是sublime-color-scheme无论如何。

例如,设置如下,配色方案的名称就是Cobalt我们所关心的。

    "color_scheme": "Packages/Color Scheme - Legacy/Cobalt.tmTheme",

有了这个配色方案,上面的配置和一些示例代码,我在缓冲区中看到的结果是这样的:

未经调整的钴样品

为了实施新规则,我们需要sublime-color-schemeUser以我们的配色方案命名包中创建一个文件所以在这种情况下就是Cobalt.sublime-color-scheme. 如果您不确定您的User包裹在哪里,您可以使用Preferences > Browse Packages它来查找它。

您创建的文件的内容应如下所示(根据需要粘贴上面的内容;为简洁起见,我不会在此处再次包含它):

{
    "rules": [
        // Paste the JSON rules above here
    ]
}

保存文件后,它将立即生效。结果是这样的:

钴的新规则

假设您使用的是自己在User包中创建的配色方案,这将不起作用,您需要将规则直接添加到User包中的配色方案文件中如果您的包中已经有这样的“补丁”文件User(例如,如果您为其他东西添加了额外的颜色规则),情况也会如此。

如果您的自定义配色方案是sublime-color-scheme格式,那么您可以rules像上面一样将这些规则添加到配色方案部分中,以使它们生效。

If your color scheme is in tmTheme format, then instead you'd need to copy the XML version of the settings into your color scheme. Here how you'd do that is not entirely as straight forward as with the sublime-color-scheme formatted file due to the XML nature of the file.

In this case you'd instead need to note that each rule is a <dict></dict> tag with specific keys, then examine the color scheme to see where it has similar color rules and inject yours into the correct location.

Generally speaking if you get it wrong the color scheme will be ignored (everything will turn black and white) and you'll get an error dialog to tell you that something has gone wrong.

有关配色方案如何工作、如何应用颜色等的更多信息,可以在这个关于 Sublime Text 配色方案的视频系列中找到(免责声明,我是相关视频的作者)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章