ap / vim-css-color

Preview colours in source code while editing
http://www.vim.org/scripts/script.php?script_id=5056
MIT License
1.79k stars 80 forks source link

Support for unitless hsl values in Sass #140

Open arusahni opened 4 years ago

arusahni commented 4 years ago

First off, thanks for the plugin! It's one of the few that I never really have to worry about breaking on me.

Unfortunately, I've hit a (fun?) edge case that I think could at least be better handled. Sass allows for unitless hsla() or hsl(), e.g.:

div {
    color: hsla(149,28,76,1);
}

When css-color encounters the unitless invocation, an error message is raised:

Error detected while processing function <SNR>145_parse_screen[4]..<SNR>145_create_syn_match:
line   20:
E605: Exception not caught: css_color: create_syn_match invoked on bad match data

In an ideal world, this plugin would be able to treat the unitless variant the same as the version with units. However, the unitless variant is not valid CSS, so that may pose a challenge. At the very least, would it be possible to suppress the error? Having the entire UI block until I dismiss a message can be cumbersome.

ap commented 3 years ago

Glad you enjoy it 🙂 And I deeply appreciate getting this particular praise – not making users jump through hoops for mere convenience on my part without real benefit to them is one of the values I hold highly, which seems to be eroding everywhere else. (Also sorry I took so long to get back to you!)

It definitely shouldn’t raise this error and it should indeed support the unitless version if possible. I’ll take a look.

Aster89 commented 3 years ago

Hi, I've hit the same "bug" and it is very annoying when one is picking colors from some online source, for instance.

To give an example, I have a lot of variables holding colors defined in HEX, which is a bit inconventient when one wants to change just hue, or just the lightness, ... So I'm converting them to HLS using this online converter, which however gives me the value swithout the % signs on lightness and saturation, so when I paste e.e. hsl(224,13,34) in Vim, I get a first error; then when I add % to either 13 or 34 I get another error because I've have corrected only one of them.

adamhotep commented 1 year ago

Dang, I was looking for this when I put in the format-vetting in my fork. I don't know anything about SASS/SCSS, and wasn't able to find it in the docs from a quick glance. I'll have to revisit this.