SublimeText / WordHighlight

Highlight all copies of the currently selected word.
MIT License
180 stars 24 forks source link

Make it easier to set the highlight background color without having to change theme #67

Closed uglycoyote closed 8 years ago

uglycoyote commented 8 years ago

I really wanted WordHighlight to use a bright background color so that it would be easy to see the matches. I followed the instructions on how to set the color_scope_name settings property, and added the required XML to my theme. It took a good half hour or so to get this working. The stumbling blocks were

It would be much much simpler if WordHighlight would allow you to just simply specify a background highlight color in the user preferences.

adzenith commented 8 years ago

Unfortunately this is a limitation in Sublime Text. You can only specify colors in the theme.

uglycoyote commented 8 years ago

I see! that is very unfortunate. I'm not sure how they expect every theme author to know about every color scope defined in every plugin. Do you know if it is possible to reload the theme while sublime text is running? If I change my wordhighlight background colour and then choose a different theme and then go back to the same theme, it's still using the old colour so I guess that's not triggering a reload of the theme, which I find odd.

adzenith commented 8 years ago

Theoretically Sublime Text reloads the theme every time you save it, but I've found ST's file-reloading to be iffy. A long time ago I wrote a plugin that automatically edited the theme file, which @FichteFoll reworked and has been maintaining since (thanks!). Potentially something like this could be done to add colors to the theme and use them for WordHighlight. I don't suppose you'd want to take a stab at it? :)

uglycoyote commented 8 years ago

one could write something to auto-edit the theme XML but if Sublime's theme-reloading doesn't work that seems like it would be an unfulfilling project. I just noticed that some of my other plugins seem to have copies of my theme, e.g. I am using the Color Highlighter and the SublimeLinter plugins,

Theme I am using:

C:\Users\admin\AppData\Roaming\Sublime Text 3\Packages\Theme - Flatland\Flatland Monokai.tmTheme

Plugin-specific copies:

C:\Users\admin\AppData\Roaming\Sublime Text 3\Packages\User\Color Highlighter\themes\Flatland Monokai (SL).tmTheme C:\Users\admin\AppData\Roaming\Sublime Text 3\Packages\User\SublimeLinter\Flatland Monokai (SL).tmTheme

And interestingly, the wordhighlight scope from the main theme file has found its way in to these other copies. It seems that these plugins copy your main theme and then append on plugin-specific theme scopes at the end. Given this it's not really clear which one of these themes sublime is actually loading in the end. Perhaps this partiallly explains my editors reluctance to respond to me changing the main tmTheme file though. Probably it's part of these other plugins initialization procedure to rebuild its plugin-specific theme file.

FichteFoll commented 8 years ago

Both Color Highlighter and SublimeLinter potentially create copies of a color scheme file, correct. However, SL modifies the scheme only once (when you change the preference globally and then overrides the setting with the edited scheme) while ColorHighlighter periodically generates new schemes and sets them on a per-view basis. As such, Color Highlighter will modify the already-modified SL version (the one with (SL) in the file name).

InactivePanes (what @adzenith linked earlier) falls more in the category of Color Highlighter, but only regenerates a color scheme when it is seen for the first time since the last ST restart (because it doesn't consider the color scheme changing in the meantime iirc). As a result, Color Highlighter and InactivePanes are most likely incompatible and can run into race conditions where they override the other's color scheme changes.

A while ago I considered writing a library that would unify color scheme changes "on-the-fly" in order to create a single point of access to the underlying color scheme mechanic of Sublime Text. It would be a rather complex because of the different needs of the color-scheme-modifying plugins, but definitely managable. You could have used that, if it existed, but ... well, I never started working on it.

uglycoyote commented 8 years ago

Thanks for the discussion.

It was a real eye opener into the crazy things that people are doing to try to change text colors in Sublime. I had no idea!

I guess I will close this issue. I submitted a pull request for a small documentation change which might help another user in my similar situation save time by understanding what's going on with color themes a bit better.

FichteFoll commented 8 years ago

Note that you opened the pull request to your own fork, not this repo.

Also note that when using SL you must either edit the SL-modified version (in User package) or additionally re-set the original color scheme preference after you modified it in order to make SL make "it's thing" again on the newer version. I don't think it periodically regenerates.

uglycoyote commented 8 years ago

Ah thanks. I am a GitHub newbie. I had already committed the changes to my branch, so it makes no sense that the UI allowed me to make a pull request on my own branch. Anyhow, I believe I made a pull request on the main branch now.