Search code examples
sublimetext2sublimetext3sublime-text-plugin

Sublime Text Plugin - Add a scope(or colour) to a region


I am trying to create a plugin for SublimeText that will check a file path and highlights it in the editor if it is invalid. While I think I have the correct way of checking if the filepath exists or not, I have no idea how to go about setting a scope(or other text highlight ie, turn it red) for that region. for example

* file * ./././thisisaninvalidfilepath * rest_of_file *

Cheers in advance, Chris


Solution

  • You have to call view.add_region. See the method documentation here: https://www.sublimetext.com/docs/3/api_reference.html#sublime.View

    The bad part is that you can't use any color, just pre-defined scopes. The plugin mentioned above, ColorHighlighter, works by duplicating your current scheme and adding the needed colors (corresponding to the hexadecimal strings) into a "fake" scheme, then loading this fake scheme.

    This is a basic flaw in Sublime's API, IMO.