Sublime Forum

[CSS, theme] use real colors to highlight colors props

#3

Yeah like this idea, would be great if someone wrote a plugin to do this.

0 Likes

#4

In general, a plugin that does this would not be difficult…

but here is the catch: the current api does not allow to specify a color for highlight, the color must be assigned to a scope that is already defined in a theme file. (at least as far as I understand)

If the api gets updated with support to feed in a color for highlight, then this would be pretty easy.

0 Likes

#5

awesome idea! would be simple, but it does seem like this will require a patch to core. I’d sign the petition.

0 Likes

#6

Great Idea and I also think that the Plugin API needs to be updated to achieve this. Its not powerful enough as far as I can see.
In general, coloring text with the help of plugins should be possible.

0 Likes

#7

So, i found out that even without proper API i can implement this feature.
Everyone who is interested, you are welcome to test and report bugs.

What works:

  • On-the-fly colorizing
  • Colorizing/uncolorizing using ST commands
0 Likes

#8

It crashes when used with RGBA:

Traceback (most recent call last): File ".\sublime_plugin.py", line 127, in on_load callback.on_load(v) File ".\css-colors.py", line 268, in on_load File ".\css-colors.py", line 231, in colorize_css File ".\css-colors.py", line 200, in generate_color_theme File ".\css-colors.py", line 199, in <genexpr> File ".\css-colors.py", line 182, in template File ".\css-colors.py", line 38, in hex File ".\css-colors.py", line 72, in _rgb_to_hex File ".\css-colors.py", line 72, in <genexpr> ValueError: invalid literal for int() with base 10: '0.8'

Also gives the this error when a file with colorization is edited:

Error loading colour scheme Packages/C:\Users\tre\AppData\Roaming\Sublime Text 2\Color Scheme - Default\Colorized-Monokai.tmTheme: Error parsing plist xml: Falied to open file In file "Packages/C:\Users\tre\AppData\Roaming\Sublime Text 2\Color Scheme - Default\Colorized-Monokai.tmTheme"

0 Likes

#9
  1. You can only specify strings with scopes as stated earlier.

  2. I edit my tmTheme file all the time, so it doesn’t crash when you edit it…it crashes when you edit it wrong. I would have to see what you added or changed to tell you why it is crashing, but it is a syntax error for sure.

The only way you can accomplish what you want in the current framework is to define all permutations between #000000 and #FFFFFF with individual scopes and then define colors for each of those scopes in a tmTheme file…that is way to many to be practical, which is why I say the API needs to be modified to allow for on the fly color definitions if you wanted to do what you are trying. I would make the request to jps and wait and see.

0 Likes

#10

I’m not talking about the theme file, but a css file. And it’s not a syntax error, I get the error whenever I write down a color.

0 Likes

#11

[quote]Error loading colour scheme
Packages/C:\Users\tre\AppData\Roaming\Sublime Text 2\Color Scheme - Default\Colorized-Monokai.tmTheme: Error parsing plist xml:
Falied to open file In file
“Packages/C:\Users\tre\AppData\Roaming\Sublime Text 2\Color Scheme - Default\Colorized-Monokai.tmTheme”[/quote]

Isn’t this what you posted as your error? This is a plist parsing error, meaning the the xml structure of the plist is corrupt. Maybe I don’t know what you are doing, but the error is telling me the plist is corrupt.

0 Likes

#12

Thanks for your feedback.

Fixed, thanks.

Strange, seems if fails to find your color-scheme because of bad path:
“**Packages/**C:\Users\tre\AppData\Roaming\Sublime Text 2\Color Scheme - Default\Colorized-Monokai.tmTheme”

Can you go to C:\Users\tre\AppData\Roaming\Sublime Text 2 and check if there is Packages folder.

0 Likes

#13

I apologize, I didn’t see the post where you mentioned you figured out how to do it. I will download and give it a try. I am intrigued at how you did it.

0 Likes

#14

Actually i did it, like you wrote few posts before. So nothing innovative :smile:
And it is still quite buggy. So more testers is good.

0 Likes

#15

Clever. Dynamic theme file changing. It is a shame API doesn’t make this easier on you, but it looks like it didn’t slow you down too much. Very cool, hadn’t considered this approach.

0 Likes

#16

[quote=“ask”]
Strange, seems if fails to find your color-scheme because of bad path:
“**Packages/**C:\Users\tre\AppData\Roaming\Sublime Text 2\Color Scheme - Default\Colorized-Monokai.tmTheme”

Can you go to C:\Users\tre\AppData\Roaming\Sublime Text 2 and check if there is Packages folder.[/quote]

After some more testing, I’ve found out that it only occurs when having an extra ‘Default.sublime-theme’ in the packages/user directory.

0 Likes

#17

At the very beginning of writing this plugin, i did’t pay attention to add_regions command, so i generated syntax file too (:

I’m trying to generate theme file only if it’s really necessary.

0 Likes

#18

Hm, yeah. Now it assumes that your color scheme is located in Color Scheme - Default folder.
Will fix it in near future.
Thanks

0 Likes

#19

Yeah, add_regions is the way to go. I use that any time I need to highlight anything in a plugin.

So, do you actually switch out the theme file for just the CSS view or for all views? I have only skimmed the code. It would be nice if ST2 allowed access to the structure in memory so you didn’t have to save a modified physical copy, but sadly I don’t think that is available either.

0 Likes

#20

Hmm. Only get grey scale colors here. I may take a deeper look into it later.

0 Likes

#21

I’m generating theme file only:

  1. in css file
  2. new colors are in file, otherwise just re-do add_regions

Hope is future ST releases, we will have richer API.

Ugdate from github. I made some fixes. Hope they will help.

0 Likes

#22

I hope so, too. I have to do some ugly things in Hex Viewer because the API can’t quite do what I need.

Much Better. It is recognizing color names now, and seems to be handling hex fine, for the most part. Sometimes I get weird issues where half the hex will be one color and the other half will be another; it seems to sometimes split the six char hex into two three char hex. RGB on the other hand doesn’t seem to be working to well, but I am sure it is just a matter of time before you get all of that working smoothly, I really think you got the hard part done. Really good progress. Keep it up.

I was just playing around with colors.

I actually suspect it is highlighting hex correctly but not always clearing old highlighting correctly. I believe in the picture above, it highlighted ff0 correctly, and then highlighted ff0000 correctly but they both still exist creating the weird looking split. I haven’t traced the issue in the code, but I would double check the clearing algorithm and possibly look for overlaps.

0 Likes