Re: bug#35005: 27.0.50; Fontification unexpectedly works with anonymous faces

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: bug#35005: 27.0.50; Fontification unexpectedly works with anonymous faces

Lars Ingebrigtsen
Eli Zaretskii <[hidden email]> writes:

>> The Elisp info material states in "39.12 Faces":
>>
>>       Many parts of Emacs require named faces, and do not accept
>>    anonymous faces. These include the functions documented in Attribute
>>    Functions, and the variable ‘font-lock-keywords’ (see Search-based
>>    Fontification). Unless otherwise stated, we will use the term “face”
>>    to refer only to named faces.
>>
>> However, when I start Emacs with "emacs -Q", and then evaluate in
>> the *scratch* buffer the form:
>>
>>     (progn
>>       (font-lock-add-keywords nil '(("hello" 0 '(:background "green")) t))
>>       (insert "hello"))
>>
>> then I see that "hello" is inserted and highlighted in green, apparently
>> due to search-based fontification where an anonymous face is specified!
>>
>> I am currently working on an application where this functionality (i.e.,
>> anonymous faces that can be specified for fontification) would be
>> extremely useful. Could you please consider supporting this feature,
>> and - if this already works as intended - officially document it?
>
> I suggest to ask on emacs-devel whether the documentation is correct
> or not.  It's possible that there are some subtle use cases where
> anonymous faces won't work in this situation.  The real experts on
> this matter don't read the bug list.

I'm not sure whether this was ever brought up on emacs-devel?  I
wondered about that restriction myself -- I could see why it might be an
issue (some parts of the font locking machinery checking for whether an
element is a list and interpreting is as something other than a face),
but it would be nice if this worked with anonymous faces.

Does anybody know what the manual is referring to here, or whether it's
an outdated restriction that has gone away?

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no

Reply | Threaded
Open this post in threaded view
|

Re: bug#35005: 27.0.50; Fontification unexpectedly works with anonymous faces

Stefan Monnier
> I'm not sure whether this was ever brought up on emacs-devel?  I
> wondered about that restriction myself -- I could see why it might be an
> issue (some parts of the font locking machinery checking for whether an
> element is a list and interpreting is as something other than a face),
> but it would be nice if this worked with anonymous faces.
>
> Does anybody know what the manual is referring to here, or whether it's
> an outdated restriction that has gone away?

AFAIK anonymous faces work fine in font-lock.  They can be a bit more
delicate to us because many places that accept faces also accept lists
(either of faces or of other things) but in general there's no real
restriction that I know of.

So I think the "do not accept" part is not true (any more?), but it's
still the case that you're generally better off using named faces
when possible.


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: bug#35005: 27.0.50; Fontification unexpectedly works with anonymous faces

Markus Triska-4
In reply to this post by Lars Ingebrigtsen
Dear Lars,

Lars Ingebrigtsen <[hidden email]> writes:

> I'm not sure whether this was ever brought up on emacs-devel?

It was, but I have not received any answer so far:

  https://lists.gnu.org/archive/html/emacs-devel/2019-03/msg01092.html

Thank you for looking into this!

All the best,
Markus


Reply | Threaded
Open this post in threaded view
|

Re: bug#35005: 27.0.50; Fontification unexpectedly works with anonymous faces

Lars Ingebrigtsen
In reply to this post by Stefan Monnier
Stefan Monnier <[hidden email]> writes:

> AFAIK anonymous faces work fine in font-lock.  They can be a bit more
> delicate to us because many places that accept faces also accept lists
> (either of faces or of other things) but in general there's no real
> restriction that I know of.
>
> So I think the "do not accept" part is not true (any more?), but it's
> still the case that you're generally better off using named faces
> when possible.

OK, I'll adjust the text in the manual.  Names faces are preferable, but
generating faces on the fly is sometimes necessary.

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no

Reply | Threaded
Open this post in threaded view
|

Re: bug#35005: 27.0.50; Fontification unexpectedly works with anonymous faces

Markus Triska-4
Lars Ingebrigtsen <[hidden email]> writes:

> OK, I'll adjust the text in the manual.  Names faces are preferable, but
> generating faces on the fly is sometimes necessary.

In my opinion, this issue is not resolved, please consider reopening it.

With the change that is now installed, the documentation reads:

   Many parts of Emacs require named faces, but some do not accept
   anonymous faces (e.g., the functions documented in @ref{Attribute
   Functions})

Where "require named faces" and "do not accept anonymous faces" amounts
to the same thing, so the wording seems not to be the intended one.

So in fact, the documentation now stresses further that named faces are
required, whereas the point of this issue is to document that anonymous
faces can be used for fontification. This still cannot be deduced from
the current manual. If that works, could you please document it?

Thank you and all the best,
Markus

Reply | Threaded
Open this post in threaded view
|

Re: bug#35005: 27.0.50; Fontification unexpectedly works with anonymous faces

Lars Ingebrigtsen
Markus Triska <[hidden email]> writes:

> With the change that is now installed, the documentation reads:
>
>    Many parts of Emacs require named faces, but some do not accept
>    anonymous faces (e.g., the functions documented in @ref{Attribute
>    Functions})
>
> Where "require named faces" and "do not accept anonymous faces" amounts
> to the same thing, so the wording seems not to be the intended one.

Yeah, that's a very awkward of putting it, so I've now tweaked it some.

> So in fact, the documentation now stresses further that named faces are
> required, whereas the point of this issue is to document that anonymous
> faces can be used for fontification. This still cannot be deduced from
> the current manual. If that works, could you please document it?

It just mentions one example where named faces are required, and I think
the reader will take from that that Emacs will document when you can't
use anonymous faces.  Since font locking doesn't say anything about
that, then the natural interpretation is that font locking doesn't
require named faces.

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no

Reply | Threaded
Open this post in threaded view
|

Re: bug#35005: 27.0.50; Fontification unexpectedly works with anonymous faces

Markus Triska-4
Lars Ingebrigtsen <[hidden email]> writes:

> It just mentions one example where named faces are required, and I think
> the reader will take from that that Emacs will document when you can't
> use anonymous faces.  Since font locking doesn't say anything about
> that, then the natural interpretation is that font locking doesn't
> require named faces.

Please consider specifically the documentation of the function
font-lock-add-keywords that I used in the example. Its documentation
points to that of font-lock-keywords, which contains the description:

   FACENAME is an expression whose value is the face name to use.
   Instead of a face, FACENAME can evaluate to a property list of
   the form (face FACE PROP1 VAL1 PROP2 VAL2 ...)  in which case all
   the listed text-properties will be set rather than just FACE.

This currently states that a face name is expected.

Since the Elisp documentation also states: "Unless otherwise stated, we
will use the term “face” to refer only to named faces.", the notion of
"face" in the description above also does not include anonymous faces.

Would it work to mention that "face FACE" can also be omitted, i.e.,
that an anonymous face can also be specified here?

Thank you and all the best,
Markus

Reply | Threaded
Open this post in threaded view
|

Re: bug#35005: 27.0.50; Fontification unexpectedly works with anonymous faces

Stefan Monnier
>    FACENAME is an expression whose value is the face name to use.
>    Instead of a face, FACENAME can evaluate to a property list of
>    the form (face FACE PROP1 VAL1 PROP2 VAL2 ...)  in which case all
>    the listed text-properties will be set rather than just FACE.
>
> This currently states that a face name is expected.
>
> Since the Elisp documentation also states: "Unless otherwise stated, we
> will use the term “face” to refer only to named faces.", the notion of
> "face" in the description above also does not include anonymous faces.
>
> Would it work to mention that "face FACE" can also be omitted, i.e.,
> that an anonymous face can also be specified here?

No, the `face FACE` *cannot* be omitted: the `face' symbol in the car is
tested to distinguish this case.  Note also that the `PROP1 VAL1 ...`
are *not* face properties, they are *text* properties.

The above docstring should probably replace "face name" by "face" but
other than that it looks about right.


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: bug#35005: 27.0.50; Fontification unexpectedly works with anonymous faces

Lars Ingebrigtsen
Stefan Monnier <[hidden email]> writes:

> The above docstring should probably replace "face name" by "face" but
> other than that it looks about right.

OK; updated.

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no

Reply | Threaded
Open this post in threaded view
|

Re: bug#35005: 27.0.50; Fontification unexpectedly works with anonymous faces

Markus Triska-4
Lars Ingebrigtsen <[hidden email]> writes:

>> The above docstring should probably replace "face name" by "face" but
>> other than that it looks about right.
>
> OK; updated.

Initially, I also thought this would solve it. However, as I mentioned,
the Emacs documentation states:

   "Unless otherwise stated, we will use the term “face” to refer only
   to named faces."

Therefore, the description now still does not make clear that anonymous
faces can be used here. I filed this issue to document this feature, and
I would appreciate if a phrasing to that effect could be added.

Thank you and all the best,
Markus


Reply | Threaded
Open this post in threaded view
|

Re: bug#35005: 27.0.50; Fontification unexpectedly works with anonymous faces

Stefan Monnier
> Therefore, the description now still does not make clear that anonymous
> faces can be used here.

Maybe we should simply better document the general rules about where
anonymous faces can usually be used and where they usually can't be used
(AFAICT they can be used where they affect the redisplay (e.g. in the
`face` and `font-lock-face` properties) but they can't be passed to face
manipulation functions like `set-face-attributes` and `describe-face`).
Their usage in font-lock is a natural consequence of those general
rules and doesn't merit extra discussion in the font-lock-keywords
doc which is already complex enough IMO.


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: bug#35005: 27.0.50; Fontification unexpectedly works with anonymous faces

Markus Triska-4
Stefan Monnier <[hidden email]> writes:

> Maybe we should simply better document the general rules about where
> anonymous faces can usually be used and where they usually can't be
> used

Yes, I would greatly appreciate this, and it would also solve this
concrete issue.

Thank you and all the best,
Markus

Reply | Threaded
Open this post in threaded view
|

RE: bug#35005: 27.0.50; Fontification unexpectedly works with anonymous faces

Drew Adams
In reply to this post by Markus Triska-4
Sorry to interrupt, but is there a good
reason y'all are sending this to both
the bug list and emacs-devel?  If not,
please consider sending it to only the
bug list.  Thx.