Sublime Forum

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

#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

#23

Thanks for testing.
Yeah, i didā€™n clear old regions well.
Iā€™m currently working on improving re-colorization.
Then test, test, and test once more _)
ps: i would be grateful for any suggestions how to improve my code, because iā€™m not actually a programmer.

0 Likes

#24

Thanks for this plugin, it works great.

0 Likes

#25

You are welcome. Hope soon i can fix most noticeable bugs.
If you have any suggestions about this plugin, iā€™m ready to listen.

0 Likes

#26

I found out your issue with RGB. You should only refer to your colors in hex throughout. Donā€™t save colors in theme as RGB, or color name; just hex. This is invalid in the theme file 255,255,0. The commas cause it to fail. RGB will not get colored. Be consistant. Since you are already converting everything to hex, let that be the way you save them all, and reference them all since it will work without issue in the theme file. Remove all of the other referencing. I have always found that simplicity makes my life easier in coding. The less things I have to keep track of, the better. I would even go as far to make sure to convert 3 char hex to 6 char hex (#3f3 -> #33ff33)

For example just changing these two functions below to only reference the color.hex portion allowed RGB, color names, and hex to work.

[code]def template(color):
ā€œā€ā€œTemplate dict to use in color theme plist generatingā€""
el = {
ā€˜nameā€™: escape(color.hex),
ā€˜scopeā€™: color.hex,
ā€˜settingsā€™: {
ā€˜backgroundā€™: color.hex,
ā€˜foregroundā€™: color.opposite
}
}
return el

def colorize_regions(view, regions, colors):
ā€œā€"Colorize given regions through ST API.

Arguments:
regions: [sublime.Region], regions to colorize
colors: , colors to colorize `regions`
"""

regions_colors = zip(regions, colors)
for r, c  in regions_colors:
    view.add_regions(str(r), [r], c.hex)[/code]

I havenā€™t dug into how you are trying to manage re-colorization, but that is going to have to be looked into. I think at one time in testing, I had a rgb color highlighted in three overlapping colors.

**Edit: **I think I will make a pull request of the few things I have changed. I fix the RGB issue, I fixed the handling of your 3 sign hex. I might not get to it today, but I will let you know.

0 Likes

#27

I think I fixed the re-colorization issue as well. The key is to use very predictable names for region highlighting, so you can quickly clear them all before re-colorizing.

I issued a pull request with all of my current fixes.

0 Likes

#28

At first, thanks for advices. I really appreciate it.
Second, thanks you for digging into my code, I know how painful sometimes it can be.
I looked through your changes, the idea of naming regions is quite good.
And of course dozen of stupid bugs.
Merged.

0 Likes