unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Adam Porter <adam@alphapapa.net>
To: Eli Zaretskii <eliz@gnu.org>, Visuwesh <visuweshm@gmail.com>
Cc: luangruo@yahoo.com, 55623@debbugs.gnu.org
Subject: bug#55623: 29.0.50; Mention that (face-foreground 'default) can return "unspecified-fg"
Date: Fri, 27 May 2022 00:44:38 -0500	[thread overview]
Message-ID: <4a17447f-c07f-b522-67a5-c81136dd4f4e@alphapapa.net> (raw)
In-Reply-To: <83pmk1pl8h.fsf@gnu.org>

On 5/25/22 12:37, Eli Zaretskii wrote:
>> From: Visuwesh <visuweshm@gmail.com>
>> Cc: luangruo@yahoo.com,  adam@alphapapa.net,  55623@debbugs.gnu.org
>> Date: Wed, 25 May 2022 22:52:00 +0530
>>
>> How about the following instead then?
>>
>>      The 'default' face is always fully specified except in special cases
>>      of TTY frames where :foreground and :background attributes may be
>>      the strings "unspecified-bg" and "unspecified-bg" respectively to
>>      mean to use the TTY's color for the foreground and background.
> 
> This is inaccurate and thus misleading.  These special color names are
> just like any other color names, they are "special" only when Emacs
> needs to actually use them on the screen.  For any other purposes,
> they are just color names.  Thus, the default face is "fully
> specified" even when these colors are used.  Also, these colors can be
> used by other faces, not just by 'default'.

The code in question calls color-gradient on a face's foreground color, 
using the default face as the fallback: 
https://github.com/alphapapa/ement.el/blob/fd96491e82a5335058b72aaff7665f0a2c3d4495/ement-room-list.el#L201

   (color-gradient
    (color-name-to-rgb (face-foreground 'ement-room-list-very-recent
                                        nil 'default))
    (color-name-to-rgb (face-foreground 'ement-room-list-recent
                                        nil 'default))
    6)

When running on a TTY, face-foreground returns "unspecified-fg", which 
causes color-name-to-rgb to return nil, which causes color-gradient to 
signal an error.

> Technically, these colors just tell Emacs not to emit a color-changing
> command when it writes text to the screen, or emit a command that
> tells the terminal driver "reset to your default color".  But this is
> an implementation detail, and we cannot talk about it in the manual
> without explaining a lot of details about the inner workings of color
> support on TTY frames.

Since the docstring says that the default face is always fully 
specified, I thought that meant that the default face's foreground would 
always have a defined, usable color name.  Since "unspecified-fg" is not 
in the manual, and apparently isn't usable by, e.g. color-name-to-rgb 
(even on a graphical frame; and by "usable", I mean that it returns an 
expected, useful color name), it seemed like an oversight in the manual 
to not mention that string somewhere.

Theoretically, if "unspecified-fg" were documented somewhere, I could 
have known that my code needs to account for it.  I don't necessarily 
need to know about the inner workings of color support on a TTY--only 
that...

   (face-foreground 'default)

...may return "unspecified-fg" rather than a specific color name, and 
that, therefore...

   (color-name-to-rgb (face-foreground 'default))

...may return nil rather than a color name.

I think a sentence or two in the appropriate place could clear this up 
and prevent users like me from running into this problem.  e.g.

   Note that, on non-graphical frames, the default face's foreground and
   background colors may be unspecified; in this case, those color names
   may be the special values "unspecified-fg" and "unspecified-bg",
   respectively.  While these are in some senses legitimate color names
   in Emacs, not all functions that expect color names as arguments may
   handle these values as expected, so it may be necessary to check for
   these special color names before calling such functions with them.





  reply	other threads:[~2022-05-27  5:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-25  5:39 bug#55623: 29.0.50; Mention that (face-foreground 'default) can return "unspecified-fg" Visuwesh
2022-05-25  7:17 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-05-25  7:53   ` Visuwesh
2022-05-25 13:18     ` Eli Zaretskii
2022-05-25 14:57       ` Visuwesh
2022-05-25 17:07         ` Eli Zaretskii
2022-05-25 17:22           ` Visuwesh
2022-05-25 17:37             ` Eli Zaretskii
2022-05-27  5:44               ` Adam Porter [this message]
2022-05-27  6:34                 ` Eli Zaretskii
2022-05-27  7:27                   ` Adam Porter
2022-06-28 21:37                   ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4a17447f-c07f-b522-67a5-c81136dd4f4e@alphapapa.net \
    --to=adam@alphapapa.net \
    --cc=55623@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=luangruo@yahoo.com \
    --cc=visuweshm@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).