bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#54156: [External] : bug#54156: 28.0.91; set-face-attribute with a ni


From: Drew Adams
Subject: bug#54156: [External] : bug#54156: 28.0.91; set-face-attribute with a nil FRAME doesn't change the default
Date: Sat, 26 Feb 2022 16:17:19 +0000

> > > So we need a special trick to override defface with 'unspecified',
> > > and that trick is this call:
> > >   (set-face-attribute 'region t :background 'unspecified)
> > > This is handled specially in internal-set-lisp-face-attribute
> > > to do what Damien wants.
> >
> > So perhaps set-face-attribute should do that automatically when
> > handed a nil value?
> 
> The fact that we handle nil as 'unspecified' in the case of the color
> is for compatibility with Emacs 20.  In Emacs 21 and later, a color
> cannot be nil.  This is well-documented: a color must be a string or
> 'unspecified'.  I don't think we want to resurrect that old convention
> of nil; it's just that Damien and others will have to get used to not
> using nil for a color.

What Eli says here makes sense to me.  We could also
perhaps explicitly (more visibly) recommend that you
always use an explicit `unspecified' rather than nil.
___

It does not make sense to me to change the longstanding
behavior, to make `set-face-attibute' do something
different (and backward-incompatible).  As Eli said:
"This is basic in how faces are handled in Emacs; we
cannot easily change that without breaking gobs of code."
___

I'm not sure I understand this from Eli, however:

  The correct way to do what Damien wants (AFAIU) is this:

   (set-face-attribute 'region nil :background 'unspecified)
   (set-face-attribute 'region t :background 'unspecified)

  That is, one must explicitly call set-face-attribute
  with FRAME = t (as well as nil), and pass 'unspecified'
               ^^^^^^^^^^^^^^^^^^
  (NOT nil!) as the value.  Maybe we should document that,
  although it is a obscure and unusual thing to do.

My impression is that it's enough to do this:

(set-face-attribute 'region nil :background 'unspecified)

I'm probably not testing/checking this correctly,
but it seems to me that both the selected frame
and new (future) frames are affected by using
nil for the frame (and `unspecified' for the
face attribute value).

In any case, yes, whatever the correct message
is for users, please do consider adding it to
the doc.  You might consider this an unusual
thing to do (why so?), but misunderstanding this
is a gotcha that we should help users avoid.

Eli, you say "This is well-documented: a color
must be a string or 'unspecified'."  Still, it
wouldn't hurt to add something to that effect in
the doc of `set-face-attribute' - and say what
the effect is of using nil (for the face color)
- it's tolerated (no error) but it doesn't have
the effect of `unspecified'.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]