Question

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].

Was it helpful?

Solution

So it turns out someone has already done what I was trying to do, and I was searching for the wrong things. It's called Gutter Color.

They're actually calling imagemagick to create a custom icon file for every color sublime sees. Which sounds insane, but is the only way to do it [apparently]. I wont quote the code because context is required, but if you got the following line you can work out what they did to make it work:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top