GNU bug report logs - #29456
[PATCH] Add command for cycling between CSS color formats

Previous Next

Package: emacs;

Reported by: Simen Heggestøyl <simenheg <at> gmail.com>

Date: Sun, 26 Nov 2017 15:23:01 UTC

Severity: wishlist

Tags: patch

Done: Simen Heggestøyl <simenheg <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 29456 in the body.
You can then email your comments to 29456 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#29456; Package emacs. (Sun, 26 Nov 2017 15:23:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Simen Heggestøyl <simenheg <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 26 Nov 2017 15:23:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Simen Heggestøyl <simenheg <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Cc: Tom Tromey <tom <at> tromey.com>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: [PATCH] Add command for cycling between CSS color formats
Date: Sun, 26 Nov 2017 16:21:51 +0100
[Message part 1 (text/plain, inline)]
The attached patch adds a new command 'css-cycle-color-format' to CSS
mode, for cycling between color formats (e.g. "black" => "#000000" =>
"rgb(0, 0, 0)" => "black"), bound to 'C-c C-f'.

I'll install the patch after a while unless there are any comments.

-- Simen
[Message part 2 (text/html, inline)]
[0001-Add-command-for-cycling-between-CSS-color-formats.patch (text/x-patch, attachment)]

Message #6 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tom Tromey <tom <at> tromey.com>
To: Simen Heggestøyl <simenheg <at> gmail.com>
Cc: bug-gnu-emacs <at> gnu.org, Tom Tromey <tom <at> tromey.com>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: [PATCH] Add command for cycling between CSS color formats
Date: Sun, 26 Nov 2017 10:53:30 -0700
>>>>> "Simen" == Simen Heggestøyl <simenheg <at> gmail.com> writes:

Simen> I'll install the patch after a while unless there are any comments.

Nice feature!

It seems to me that none of the functions handle alpha components.
css-color-4 added optional alpha to hex colors (and made rgb and rgba
synonyms), and there's been rgba for a while...

Tom




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29456; Package emacs. (Mon, 27 Nov 2017 17:09:01 GMT) Full text and rfc822 format available.

Message #9 received at 29456 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Simen Heggestøyl <simenheg <at> gmail.com>
Cc: 29456 <at> debbugs.gnu.org, tom <at> tromey.com, monnier <at> iro.umontreal.ca
Subject: Re: bug#29456: [PATCH] Add command for cycling between CSS color
 formats
Date: Mon, 27 Nov 2017 19:07:56 +0200
> Date: Sun, 26 Nov 2017 16:21:51 +0100
> From: Simen Heggestøyl <simenheg <at> gmail.com>
> Cc: Tom Tromey <tom <at> tromey.com>, Stefan Monnier <monnier <at> iro.umontreal.ca>
> 
> The attached patch adds a new command 'css-cycle-color-format' to CSS
> mode, for cycling between color formats (e.g. "black" => "#000000" =>
> "rgb(0, 0, 0)" => "black"), bound to 'C-c C-f'.

Thanks.

These functions are confusingly similar to, but subtly different from,
the similar functions in color.el, and in general the whole system of
color conversions used by Emacs for its display needs.  Here's a
tell-tale example:

    (css--web-color-to-4-dpc "#fff")
      => "#ffffffffffff"
but
    (apply 'color-rgb-to-hex (color-name-to-rgb "#fff"))
      => "#f0f0f0f0f0f0"

The latter follows the X color definitions, so why does css-mode.el
need a different interpretation of the hex-RGB notation?

My fear is that someone will mix css-mode functions with those from
elsewhere in Emacs, and will bump into confusing and contradicting
results.  Is it possible to avoid that?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29456; Package emacs. (Mon, 27 Nov 2017 17:42:01 GMT) Full text and rfc822 format available.

Message #12 received at 29456 <at> debbugs.gnu.org (full text, mbox):

From: Tom Tromey <tom <at> tromey.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 29456 <at> debbugs.gnu.org, tom <at> tromey.com,
 Simen Heggestøyl <simenheg <at> gmail.com>,
 monnier <at> iro.umontreal.ca
Subject: Re: bug#29456: [PATCH] Add command for cycling between CSS color
 formats
Date: Mon, 27 Nov 2017 10:41:29 -0700
>>>>> "Eli" == Eli Zaretskii <eliz <at> gnu.org> writes:

Eli> The latter follows the X color definitions, so why does css-mode.el
Eli> need a different interpretation of the hex-RGB notation?

CSS color names came from X a long time ago, but their mapping to rgb is
now part of the CSS specification.  And, apparently there were multiple
versions of this file coming from X.  The Emacs one would be ok provided
the lists are identical and will always remain so.  Otherwise, css-mode
needs its own list.

Eli> My fear is that someone will mix css-mode functions with those from
Eli> elsewhere in Emacs, and will bump into confusing and contradicting
Eli> results.  Is it possible to avoid that?

Using "css-" in the name seems sufficient to me.  Maybe a comment
explaining this would help as well.

Tom




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29456; Package emacs. (Mon, 27 Nov 2017 18:12:01 GMT) Full text and rfc822 format available.

Message #15 received at 29456 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Tom Tromey <tom <at> tromey.com>
Cc: 29456 <at> debbugs.gnu.org, simenheg <at> gmail.com, monnier <at> iro.umontreal.ca
Subject: Re: bug#29456: [PATCH] Add command for cycling between CSS color
 formats
Date: Mon, 27 Nov 2017 20:11:21 +0200
> From: Tom Tromey <tom <at> tromey.com>
> Cc: Simen Heggestøyl <simenheg <at> gmail.com>,
>   29456 <at> debbugs.gnu.org,  tom <at> tromey.com,  monnier <at> iro.umontreal.ca
> Date: Mon, 27 Nov 2017 10:41:29 -0700
> 
> >>>>> "Eli" == Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> Eli> The latter follows the X color definitions, so why does css-mode.el
> Eli> need a different interpretation of the hex-RGB notation?
> 
> CSS color names came from X a long time ago, but their mapping to rgb is
> now part of the CSS specification.  And, apparently there were multiple
> versions of this file coming from X.  The Emacs one would be ok provided
> the lists are identical and will always remain so.  Otherwise, css-mode
> needs its own list.

Sorry, I don't understand: what list are you talking about?

> Eli> My fear is that someone will mix css-mode functions with those from
> Eli> elsewhere in Emacs, and will bump into confusing and contradicting
> Eli> results.  Is it possible to avoid that?
> 
> Using "css-" in the name seems sufficient to me.  Maybe a comment
> explaining this would help as well.

A comment will help, but I'm actually wondering why does css-mode need
to use 12-bit or 16-bit per component RGB notation?  Why not use only
8-bit, as in #RRGGBB?  The problems only happen in converting 8-bit
RGB notations to higher number of bits.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29456; Package emacs. (Mon, 27 Nov 2017 18:36:01 GMT) Full text and rfc822 format available.

Message #18 received at 29456 <at> debbugs.gnu.org (full text, mbox):

From: Tom Tromey <tom <at> tromey.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 29456 <at> debbugs.gnu.org, Tom Tromey <tom <at> tromey.com>, simenheg <at> gmail.com,
 monnier <at> iro.umontreal.ca
Subject: Re: bug#29456: [PATCH] Add command for cycling between CSS color
 formats
Date: Mon, 27 Nov 2017 11:35:04 -0700
>>>>> "Eli" == Eli Zaretskii <eliz <at> gnu.org> writes:

Eli> Sorry, I don't understand: what list are you talking about?

Sorry, I misunderstood.

CSS also specifies hex and rgb syntax itself.

Eli> A comment will help, but I'm actually wondering why does css-mode need
Eli> to use 12-bit or 16-bit per component RGB notation?  Why not use only
Eli> 8-bit, as in #RRGGBB?  The problems only happen in converting 8-bit
Eli> RGB notations to higher number of bits.

#RGB is specified by CSS, it is equivalent to #RRGGBB, and is often
seen.  With css-color-4, #RGBA is also allowed.

Basically css-mode needs to understand the peculiarities of CSS syntax,
which differs somewhat from other systems AFAIK.

Tom




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29456; Package emacs. (Mon, 27 Nov 2017 18:44:01 GMT) Full text and rfc822 format available.

Message #21 received at 29456 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Tom Tromey <tom <at> tromey.com>
Cc: 29456 <at> debbugs.gnu.org, simenheg <at> gmail.com, monnier <at> iro.umontreal.ca
Subject: Re: bug#29456: [PATCH] Add command for cycling between CSS color
 formats
Date: Mon, 27 Nov 2017 20:43:06 +0200
> From: Tom Tromey <tom <at> tromey.com>
> Cc: Tom Tromey <tom <at> tromey.com>,  simenheg <at> gmail.com,  29456 <at> debbugs.gnu.org,  monnier <at> iro.umontreal.ca
> Date: Mon, 27 Nov 2017 11:35:04 -0700
> 
> Eli> A comment will help, but I'm actually wondering why does css-mode need
> Eli> to use 12-bit or 16-bit per component RGB notation?  Why not use only
> Eli> 8-bit, as in #RRGGBB?  The problems only happen in converting 8-bit
> Eli> RGB notations to higher number of bits.
> 
> #RGB is specified by CSS, it is equivalent to #RRGGBB, and is often
> seen.  With css-color-4, #RGBA is also allowed.
> 
> Basically css-mode needs to understand the peculiarities of CSS syntax,
> which differs somewhat from other systems AFAIK.

Then I think there should be a prominent remark in the doc strings of
css-mode not to mix these functions with those from color.el, due to
this incompatibility.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29456; Package emacs. (Tue, 28 Nov 2017 18:34:02 GMT) Full text and rfc822 format available.

Message #24 received at 29456 <at> debbugs.gnu.org (full text, mbox):

From: Simen Heggestøyl <simenheg <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 29456 <at> debbugs.gnu.org, tom <at> tromey.com, monnier <at> iro.umontreal.ca
Subject: Re: bug#29456: [PATCH] Add command for cycling between CSS color
 formats
Date: Tue, 28 Nov 2017 19:33:30 +0100
Tom Tromey <tom <at> tromey.com> writes:
> Nice feature!

Glad you like it!

> It seems to me that none of the functions handle alpha components.
> css-color-4 added optional alpha to hex colors (and made rgb and rgba
> synonyms), and there's been rgba for a while...

Right, it makes sense to support that too. I haven't used alpha formats
other than rgba(...) myself. Would it be useful for rgba(255, 0, 0, 0.5)
to turn into #ff000088, for instance?

Eli Zaretskii <eliz <at> gnu.org> writes:
> Then I think there should be a prominent remark in the doc strings of
> css-mode not to mix these functions with those from color.el, due to
> this incompatibility.

That sounds like a good idea.

I'll address the comments from both of you in an update to the patch,
though it might be a while until I have the time to update it.

Thanks for your comments so far.

-- Simen




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29456; Package emacs. (Tue, 28 Nov 2017 20:58:02 GMT) Full text and rfc822 format available.

Message #27 received at 29456 <at> debbugs.gnu.org (full text, mbox):

From: Simen Heggestøyl <simenheg <at> gmail.com>
To: Simen Heggestøyl <simenheg <at> gmail.com>
Cc: eliz <at> gnu.org, 29456 <at> debbugs.gnu.org, tom <at> tromey.com,
 monnier <at> iro.umontreal.ca
Subject: Re: bug#29456: [PATCH] Add command for cycling between CSS color
 formats
Date: Tue, 28 Nov 2017 21:57:30 +0100
Simen Heggestøyl <simenheg <at> gmail.com> writes:
> Right, it makes sense to support that too. I haven't used alpha formats
> other than rgba(...) myself. Would it be useful for rgba(255, 0, 0, 0.5)
> to turn into #ff000088, for instance?
               ^^^^^^^^^ #ff000080, sorry.

-- Simen




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29456; Package emacs. (Sun, 10 Dec 2017 12:47:01 GMT) Full text and rfc822 format available.

Message #30 received at 29456 <at> debbugs.gnu.org (full text, mbox):

From: Simen Heggestøyl <simenheg <at> gmail.com>
To: Simen Heggestøyl <simenheg <at> gmail.com>
Cc: eliz <at> gnu.org, 29456 <at> debbugs.gnu.org, tom <at> tromey.com,
 monnier <at> iro.umontreal.ca
Subject: Re: bug#29456: [PATCH] Add command for cycling between CSS color
 formats
Date: Sun, 10 Dec 2017 13:46:14 +0100
[Message part 1 (text/plain, inline)]
I've updated the patch to support switching between #RGBA/#RRGGBBAA and
rgba() too, fixing a bug in `css--hex-color' along the way for handling
the #RGBA case. If you agree, I think that fix should go into the
emacs-26 branch as well.

I also prefixed the function names with `css--' to more strongly
indicate that they're intended for internal usage, and mentioned in the
docstrings their incompatibility with color.el.

-- Simen
[Message part 2 (text/html, inline)]
[0001-Add-command-for-cycling-between-CSS-color-formats.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#29456; Package emacs. (Sun, 10 Dec 2017 18:11:02 GMT) Full text and rfc822 format available.

Message #33 received at 29456 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Simen Heggestøyl <simenheg <at> gmail.com>
Cc: 29456 <at> debbugs.gnu.org, tom <at> tromey.com, monnier <at> iro.umontreal.ca
Subject: Re: bug#29456: [PATCH] Add command for cycling between CSS color
 formats
Date: Sun, 10 Dec 2017 20:09:32 +0200
> Date: Sun, 10 Dec 2017 13:46:14 +0100
> From: Simen Heggestøyl <simenheg <at> gmail.com>
> Cc: eliz <at> gnu.org, 29456 <at> debbugs.gnu.org, tom <at> tromey.com,
> 	monnier <at> iro.umontreal.ca
> 
> I've updated the patch to support switching between #RGBA/#RRGGBBAA and
> rgba() too, fixing a bug in `css--hex-color' along the way for handling
> the #RGBA case. If you agree, I think that fix should go into the
> emacs-26 branch as well.

It's OK to put the css--hex-color bugfix on emacs-26, but then please
remove it from the changeset you push to master, so that it could be
merged from emacs-26.

Thanks.




Reply sent to Simen Heggestøyl <simenheg <at> gmail.com>:
You have taken responsibility. (Sun, 17 Dec 2017 09:33:02 GMT) Full text and rfc822 format available.

Notification sent to Simen Heggestøyl <simenheg <at> gmail.com>:
bug acknowledged by developer. (Sun, 17 Dec 2017 09:33:03 GMT) Full text and rfc822 format available.

Message #38 received at 29456-done <at> debbugs.gnu.org (full text, mbox):

From: Simen Heggestøyl <simenheg <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: tom <at> tromey.com, 29456-done <at> debbugs.gnu.org, monnier <at> iro.umontreal.ca
Subject: Re: bug#29456: [PATCH] Add command for cycling between CSS color
 formats
Date: Sun, 17 Dec 2017 10:32:01 +0100
[Message part 1 (text/plain, inline)]
Good, thanks. I've installed the two patches.

-- Simen

On Sun, Dec 10, 2017 at 7:09 PM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> It's OK to put the css--hex-color bugfix on emacs-26, but then please
> remove it from the changeset you push to master, so that it could be
> merged from emacs-26.
> 
> Thanks.
[Message part 2 (text/html, inline)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 14 Jan 2018 12:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 219 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.