1

I have a plugin using the add_regions command to draw underlines for certain regions.

I also have a custom tmLanguage and tmTheme, so I can control font style/foreground color etc. for scopes I have set.

Now, I'm trying to get my underlines to be a specific color (and not the default white-ish ST3 color)... I know this is possible because the spellcheck in ST3 has a red squiggly underline.

I've poked at changing the scope/settings/keys etc. in my tmTheme and my plugin's add_regions command, but nothing seems to stick.

Any direction would be very helpful!

Jimmy Huch
  • 4,400
  • 7
  • 29
  • 34
  • 1
    using a different scope works for me to change the color of the underline - select some text and type this in the console to see the effect `view.add_regions('test', [view.sel()[0]], 'entity.name.tag', '', sublime.DRAW_STIPPLED_UNDERLINE | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE)` and then change `entity.name.tag` to `comment` or `string` etc. – Keith Hall Jan 20 '17 at 07:24
  • @KeithHall Interesting... I tested it and it seems to work. So I have to use an entirely different scope to source the color... I'll test it some more and report back :) – Jimmy Huch Jan 20 '17 at 07:33
  • @KeithHall - Working like a charm!!! Thank you! Feel free to write an answer and I'll accept (or I can write the answer, if you don't care for the karma). – Jimmy Huch Jan 20 '17 at 07:41
  • feel free to write the answer yourself - you would benefit more from the rep more than me I think :) – Keith Hall Jan 20 '17 at 07:49
  • @KeithHall - done! – Jimmy Huch Jan 20 '17 at 09:02

1 Answers1

1

You can simply set up a dummy scope in your tmTheme file with the foreground setting valued to the color you want your underline to be. Then pass in that scope name to the add_regions function call.

Example for yellow underline...

In the tmTheme file:

...
<dict>
  <key>name</key>
  <string>Yellow Underline</string>
  <key>scope</key>
  <string>underline.yellow.text</string>
  <key>settings</key>
  <dict>
    <key>foreground</key>
    <string>#FFFF00</string>
  </dict>
</dict>
...

In your plugin:

# ...
# set regions variable above
view.add_regions('key', regions, 'underline.yellow.text', '', sublime.DRAW_STIPPLED_UNDERLINE | sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE)
# ...

Ta-da! You should have yellow underlines now :)

Jimmy Huch
  • 4,400
  • 7
  • 29
  • 34