1

So I'm currently working on a Sublime Text plugin [my firt] that displays pips in the gutter that match colors in lines of css. Similar to what JetBrains does:

Inline color preview in JetBrains editors

I have a bit of a problem though. As far as I can tell when adding a region I can only give the region a scope which the template then themes. Now I could write out a template file that defines every hex code as a scope and a theme to match but that sounds ghastly. Is there a better way to do this? Is it possible to color a region separately from the theme? I'm very new to ST plugins so if there's a crucial piece of the docs I've missed let me know :)

Here's a very stripped down version of my plugin to show how I'm achieving this currently:

import sublime, sublime_plugin

class FooCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        regions = [s for s in self.view.sel()]
        for region in regions:
            lines = self.view.split_by_newlines(region)
            for index, line in enumerate(lines):
                self.view.add_regions("csspip-{0}".format(index), [line], "csspip", "dot",
                                      sublime.HIDDEN | sublime.PERSISTENT)

Make a selection and run view.run_command('foo') from the console to see what it does currently [not much].

4

1 回答 1

1

所以事实证明有人已经做了我想做的事,而我正在寻找错误的东西。它被称为天沟颜色。

他们实际上是在调用 imagemagick 来为 sublime 看到的每种颜色创建一个自定义图标文件。这听起来很疯狂,但[显然]是唯一的方法。我不会引用代码,因为上下文是必需的,但是如果您得到以下行,您可以计算出他们为使其工作所做的工作:

https://github.com/ggordan/GutterColor/blob/master/line.py#L88

于 2014-06-05T06:20:56.343 回答