unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Overriding inherited face attributes
@ 2018-11-27 20:18 Boris Buliga
  2018-11-27 21:33 ` Stephen Berman
  0 siblings, 1 reply; 17+ messages in thread
From: Boris Buliga @ 2018-11-27 20:18 UTC (permalink / raw)
  To: help-gnu-emacs

Hi everyone,

Sorry if this question was answered somewhere before. I searched and didn't
find any working solution, so here I am.

Problem. Override a face attribute that is defined in an inherited face.

For example, open up a new buffer in the fundamental mode and evaulate the
following experssion:

(insert (propertize "hello" 'face '(:foreground "red" :inherit (:foreground
"orange"))))

I expect the word 'hello' to be red, but instead, it is orange.

So two questions:

1. Am I right to expect the text to be red?
2. How to achieve this?

Thanks in advance!

-- 
Cheers,
Boris


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Overriding inherited face attributes
  2018-11-27 20:18 Overriding inherited face attributes Boris Buliga
@ 2018-11-27 21:33 ` Stephen Berman
  2018-11-28  6:19   ` Eli Zaretskii
  2018-11-28  7:39   ` Boris Buliga
  0 siblings, 2 replies; 17+ messages in thread
From: Stephen Berman @ 2018-11-27 21:33 UTC (permalink / raw)
  To: Boris Buliga; +Cc: help-gnu-emacs

On Tue, 27 Nov 2018 22:18:45 +0200 Boris Buliga <boris@d12frosted.io> wrote:

> Hi everyone,
>
> Sorry if this question was answered somewhere before. I searched and didn't
> find any working solution, so here I am.
>
> Problem. Override a face attribute that is defined in an inherited face.
>
> For example, open up a new buffer in the fundamental mode and evaulate the
> following experssion:
>
> (insert (propertize "hello" 'face '(:foreground "red" :inherit (:foreground
> "orange"))))
>
> I expect the word 'hello' to be red, but instead, it is orange.
>
> So two questions:
>
> 1. Am I right to expect the text to be red?
> 2. How to achieve this?

I don't know the answer to your first questions, but the answer to the
second question appears to be: switch the order.  At least, when I
evaluate the following in fundamental mode, 'hello' is red:

(insert (propertize "hello" 'face '(:inherit (:foreground "orange")
:foreground "red")))

In (info "(elisp) Special Properties") it says this: "The value of the
[`face'] property can be... A list of faces... Faces occurring earlier
in the list have higher priority."  And in (info "(elisp) Face
Attributes") it says: "Attributes from inherited faces are merged into
the face like an underlying face would be, with higher priority than
underlying faces."  Whether this implies the above observed behavior is
not clear to me.

Steve Berman



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Overriding inherited face attributes
  2018-11-27 21:33 ` Stephen Berman
@ 2018-11-28  6:19   ` Eli Zaretskii
  2018-11-28 12:24     ` Stephen Berman
  2018-11-28  7:39   ` Boris Buliga
  1 sibling, 1 reply; 17+ messages in thread
From: Eli Zaretskii @ 2018-11-28  6:19 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Stephen Berman <stephen.berman@gmx.net>
> Date: Tue, 27 Nov 2018 22:33:23 +0100
> Cc: help-gnu-emacs@gnu.org
> 
> In (info "(elisp) Special Properties") it says this: "The value of the
> [`face'] property can be... A list of faces... Faces occurring earlier
> in the list have higher priority."  And in (info "(elisp) Face
> Attributes") it says: "Attributes from inherited faces are merged into
> the face like an underlying face would be, with higher priority than
> underlying faces."  Whether this implies the above observed behavior is
> not clear to me.

Is it really not clear?  What part(s) make(s) the above text not
clear about the order in which the face attributes are applied?



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Overriding inherited face attributes
  2018-11-27 21:33 ` Stephen Berman
  2018-11-28  6:19   ` Eli Zaretskii
@ 2018-11-28  7:39   ` Boris Buliga
  2018-11-28  7:51     ` Eli Zaretskii
  1 sibling, 1 reply; 17+ messages in thread
From: Boris Buliga @ 2018-11-28  7:39 UTC (permalink / raw)
  To: stephen.berman; +Cc: help-gnu-emacs

Stephen,

Thank you for the answer. Indeed, adding this property to the end resolves
my
problem.

--------------------------------------------------------------------------------

Stephen and Eli,

Regarding documentation.

1. We have a part saying that 'faces occurring earlier in the list have
higher
priority'. This is super clear and easy to check. For example,

  > (setq my-test-string (propertize "hello" 'face '(:inherit (:foreground
"orange"))))
  #("hello" 0 5 (face (:inherit (:foreground "orange"))))
  > (add-face-text-property 0 5 '(:foreground "red") nil my-test-string)
  nil
  > my-test-string
  #("hello" 0 5 (face ((:foreground "red") (:inherit ...))))

Inserting this string results in the red 'hello'.

If you try you do append the property to the end, you'll get an orange
'hello'.

So far so good. Then I tried to do the same with propertize and I've got
quite
different result.

  > (propertize "hello" 'face '(:foreground "red" :inherit (:foreground
"orange")))
  #("hello" 0 5 (face (:foreground "red" :inherit (:foreground "orange"))))
  ;; results in an orange text

  > (propertize "hello" 'face '((:foreground "red") (:inherit (:foreground
"orange"))))
  #("hello" 0 5 (face ((:foreground "red") (:inherit ...))))
  ;; results in a red text

To me, it's still confusing. Why in the first example I have an orange text
and
in the second one - red?

2. And there is a part saying something I don't quite understand about
inheritance.

> Attributes from inherited faces are merged into the face like an
underlying
> face would be, with higher priority than underlying faces.

This one looks good to me. If I understand this correctly - inherited face
attributes behave as usual face attributes. Am I right?

On Tue, 27 Nov 2018 at 23:33, Stephen Berman <stephen.berman@gmx.net> wrote:

> On Tue, 27 Nov 2018 22:18:45 +0200 Boris Buliga <boris@d12frosted.io>
> wrote:
>
> > Hi everyone,
> >
> > Sorry if this question was answered somewhere before. I searched and
> didn't
> > find any working solution, so here I am.
> >
> > Problem. Override a face attribute that is defined in an inherited face.
> >
> > For example, open up a new buffer in the fundamental mode and evaulate
> the
> > following experssion:
> >
> > (insert (propertize "hello" 'face '(:foreground "red" :inherit
> (:foreground
> > "orange"))))
> >
> > I expect the word 'hello' to be red, but instead, it is orange.
> >
> > So two questions:
> >
> > 1. Am I right to expect the text to be red?
> > 2. How to achieve this?
>
> I don't know the answer to your first questions, but the answer to the
> second question appears to be: switch the order.  At least, when I
> evaluate the following in fundamental mode, 'hello' is red:
>
> (insert (propertize "hello" 'face '(:inherit (:foreground "orange")
> :foreground "red")))
>
> In (info "(elisp) Special Properties") it says this: "The value of the
> [`face'] property can be... A list of faces... Faces occurring earlier
> in the list have higher priority."  And in (info "(elisp) Face
> Attributes") it says: "Attributes from inherited faces are merged into
> the face like an underlying face would be, with higher priority than
> underlying faces."  Whether this implies the above observed behavior is
> not clear to me.
>
> Steve Berman
>


-- 
Cheers,
Boris


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Overriding inherited face attributes
  2018-11-28  7:39   ` Boris Buliga
@ 2018-11-28  7:51     ` Eli Zaretskii
  2018-11-28  8:42       ` Boris Buliga
  0 siblings, 1 reply; 17+ messages in thread
From: Eli Zaretskii @ 2018-11-28  7:51 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Boris Buliga <boris@d12frosted.io>
> Date: Wed, 28 Nov 2018 09:39:29 +0200
> Cc: help-gnu-emacs@gnu.org
> 
>   > (propertize "hello" 'face '(:foreground "red" :inherit (:foreground
> "orange")))
>   #("hello" 0 5 (face (:foreground "red" :inherit (:foreground "orange"))))
>   ;; results in an orange text
> 
>   > (propertize "hello" 'face '((:foreground "red") (:inherit (:foreground
> "orange"))))
>   #("hello" 0 5 (face ((:foreground "red") (:inherit ...))))
>   ;; results in a red text
> 
> To me, it's still confusing. Why in the first example I have an orange text
> and
> in the second one - red?

Isn't the second example simply wrong syntax-wise?  Why did you use an
extra level of parentheses?

> 2. And there is a part saying something I don't quite understand about
> inheritance.
> 
> > Attributes from inherited faces are merged into the face like an
> underlying
> > face would be, with higher priority than underlying faces.
> 
> This one looks good to me. If I understand this correctly - inherited face
> attributes behave as usual face attributes.

They behave the same as attributes of the underlying face, but they
override the underlying face where both specify the same attributes.



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Overriding inherited face attributes
  2018-11-28  7:51     ` Eli Zaretskii
@ 2018-11-28  8:42       ` Boris Buliga
  0 siblings, 0 replies; 17+ messages in thread
From: Boris Buliga @ 2018-11-28  8:42 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

Eli,

> Isn't the second example simply wrong syntax-wise?  Why did you use an
> extra level of parentheses?

No, it's totally valid. Built Emacs from the master a month ago.

I did it to replicate the exact result of add-face-text-property example.

On Wed, 28 Nov 2018 at 09:51, Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Boris Buliga <boris@d12frosted.io>
> > Date: Wed, 28 Nov 2018 09:39:29 +0200
> > Cc: help-gnu-emacs@gnu.org
> >
> >   > (propertize "hello" 'face '(:foreground "red" :inherit (:foreground
> > "orange")))
> >   #("hello" 0 5 (face (:foreground "red" :inherit (:foreground
> "orange"))))
> >   ;; results in an orange text
> >
> >   > (propertize "hello" 'face '((:foreground "red") (:inherit
> (:foreground
> > "orange"))))
> >   #("hello" 0 5 (face ((:foreground "red") (:inherit ...))))
> >   ;; results in a red text
> >
> > To me, it's still confusing. Why in the first example I have an orange
> text
> > and
> > in the second one - red?
>
> Isn't the second example simply wrong syntax-wise?  Why did you use an
> extra level of parentheses?
>
> > 2. And there is a part saying something I don't quite understand about
> > inheritance.
> >
> > > Attributes from inherited faces are merged into the face like an
> > underlying
> > > face would be, with higher priority than underlying faces.
> >
> > This one looks good to me. If I understand this correctly - inherited
> face
> > attributes behave as usual face attributes.
>
> They behave the same as attributes of the underlying face, but they
> override the underlying face where both specify the same attributes.
>
>

-- 
Cheers,
Boris


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Overriding inherited face attributes
  2018-11-28  6:19   ` Eli Zaretskii
@ 2018-11-28 12:24     ` Stephen Berman
  2018-11-28 13:06       ` Eli Zaretskii
  0 siblings, 1 reply; 17+ messages in thread
From: Stephen Berman @ 2018-11-28 12:24 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

On Wed, 28 Nov 2018 08:19:20 +0200 Eli Zaretskii <eliz@gnu.org> wrote:

>> From: Stephen Berman <stephen.berman@gmx.net>
>> Date: Tue, 27 Nov 2018 22:33:23 +0100
>> Cc: help-gnu-emacs@gnu.org
>> 
>> In (info "(elisp) Special Properties") it says this: "The value of the
>> [`face'] property can be... A list of faces... Faces occurring earlier
>> in the list have higher priority."  And in (info "(elisp) Face
>> Attributes") it says: "Attributes from inherited faces are merged into
>> the face like an underlying face would be, with higher priority than
>> underlying faces."  Whether this implies the above observed behavior is
>> not clear to me.
>
> Is it really not clear?  What part(s) make(s) the above text not
> clear about the order in which the face attributes are applied?

The text itself is clear in the abstract, and when I apply it to the
example Boris gave, it seems to explain the observed result.  That is,
given this form:

(insert (propertize "hello" 'face '(:foreground "red" :inherit
(:foreground "orange"))))

and given that "Faces occurring earlier in the list have higher
priority", I would expect the displayed face to be red, as Boris did.
But it's different with the `inherit' property: "Attributes from
inherited faces are merged into the face like an underlying face would
be, with higher priority than underlying faces".  So that explains why
the face is displayed as orange.  But then I observed that merely
switching the order:

(insert (propertize "hello" 'face '(:inherit (:foreground "orange")
:foreground "red")))

makes the face display as red, and this seems to conflict with the above
documentation.  Maybe I'm misunderstanding the doc, but in any case,
because of the difference from switching the order of the properties,
it's not clear to me.

(The same seems to go for form Boris gave in his followup, which you
suggested is syntactically incorrect, but does evaluate without error
and displays a red face; as Boris noted, that syntax is the same as the
result of applying add-face-text-property.)

Steve Berman



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Overriding inherited face attributes
  2018-11-28 12:24     ` Stephen Berman
@ 2018-11-28 13:06       ` Eli Zaretskii
  2018-11-28 13:13         ` Stephen Berman
  0 siblings, 1 reply; 17+ messages in thread
From: Eli Zaretskii @ 2018-11-28 13:06 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Stephen Berman <stephen.berman@gmx.net>
> Cc: help-gnu-emacs@gnu.org
> Date: Wed, 28 Nov 2018 13:24:51 +0100
> 
> But then I observed that merely switching the order:
> 
> (insert (propertize "hello" 'face '(:inherit (:foreground "orange")
> :foreground "red")))
> 
> makes the face display as red, and this seems to conflict with the above
> documentation.

It doesn't, because ':foreground "red"' is not the "underlying face".



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Overriding inherited face attributes
  2018-11-28 13:06       ` Eli Zaretskii
@ 2018-11-28 13:13         ` Stephen Berman
  2018-11-28 16:18           ` Eli Zaretskii
  0 siblings, 1 reply; 17+ messages in thread
From: Stephen Berman @ 2018-11-28 13:13 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

On Wed, 28 Nov 2018 15:06:17 +0200 Eli Zaretskii <eliz@gnu.org> wrote:

>> From: Stephen Berman <stephen.berman@gmx.net>
>> Cc: help-gnu-emacs@gnu.org
>> Date: Wed, 28 Nov 2018 13:24:51 +0100
>> 
>> But then I observed that merely switching the order:
>> 
>> (insert (propertize "hello" 'face '(:inherit (:foreground "orange")
>> :foreground "red")))
>> 
>> makes the face display as red, and this seems to conflict with the above
>> documentation.
>
> It doesn't, because ':foreground "red"' is not the "underlying face".

That occurred to me, but then I have to conclude I really don't
understand the doc, according to my reading of which the `inherit'
property should have higher priority by virtue of being earlier in the
list.

Steve Berman



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Overriding inherited face attributes
  2018-11-28 13:13         ` Stephen Berman
@ 2018-11-28 16:18           ` Eli Zaretskii
  2018-11-28 20:01             ` Stephen Berman
  0 siblings, 1 reply; 17+ messages in thread
From: Eli Zaretskii @ 2018-11-28 16:18 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Stephen Berman <stephen.berman@gmx.net>
> Cc: help-gnu-emacs@gnu.org
> Date: Wed, 28 Nov 2018 14:13:39 +0100
> 
> >> (insert (propertize "hello" 'face '(:inherit (:foreground "orange")
> >> :foreground "red")))
> >> 
> >> makes the face display as red, and this seems to conflict with the above
> >> documentation.
> >
> > It doesn't, because ':foreground "red"' is not the "underlying face".
> 
> That occurred to me, but then I have to conclude I really don't
> understand the doc, according to my reading of which the `inherit'
> property should have higher priority by virtue of being earlier in the
> list.

If someone has concrete proposals for how to make the documentation of
these aspects better, I'm open to suggestions.



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Overriding inherited face attributes
  2018-11-28 16:18           ` Eli Zaretskii
@ 2018-11-28 20:01             ` Stephen Berman
  2018-11-28 20:35               ` Eli Zaretskii
  0 siblings, 1 reply; 17+ messages in thread
From: Stephen Berman @ 2018-11-28 20:01 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

On Wed, 28 Nov 2018 18:18:25 +0200 Eli Zaretskii <eliz@gnu.org> wrote:

>> From: Stephen Berman <stephen.berman@gmx.net>
>> Cc: help-gnu-emacs@gnu.org
>> Date: Wed, 28 Nov 2018 14:13:39 +0100
>> 
>> >> (insert (propertize "hello" 'face '(:inherit (:foreground "orange")
>> >> :foreground "red")))
>> >> 
>> >> makes the face display as red, and this seems to conflict with the above
>> >> documentation.
>> >
>> > It doesn't, because ':foreground "red"' is not the "underlying face".
>> 
>> That occurred to me, but then I have to conclude I really don't
>> understand the doc, according to my reading of which the `inherit'
>> property should have higher priority by virtue of being earlier in the
>> list.
>
> If someone has concrete proposals for how to make the documentation of
> these aspects better, I'm open to suggestions.

It would be helpful to know from precisely which part of the
documentation it follows that evaluating this:

(insert (propertize "hello" 'face '(:foreground "red" :inherit
(:foreground "orange"))))

displays "hello" in orange while evaluating this:

(insert (propertize "hello" 'face '(:inherit (:foreground "orange")
:foreground "red")))

displays "hello" in red.  I don't see how it follows from the passage in
the Lisp manual I cited ("Faces occurring earlier in the list have
higher priority") unless "occurring earlier in the list" and "higher
priority" have non-standard meanings, which should then also be defined
in the documentation.  And from what you wrote above, the higher
priority of the `inherit' property is irrelevant in these examples,
since as you said "':foreground "red"' is not the "underlying face".  So
can you point out the passage(s) in the manual from which the above
observed differences follow?  Maybe once I see that I'll be satisfied
with the existing documentation, or else could try to suggest
improvements.

Steve Berman



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Overriding inherited face attributes
  2018-11-28 20:01             ` Stephen Berman
@ 2018-11-28 20:35               ` Eli Zaretskii
  2018-11-28 21:34                 ` Stephen Berman
  2018-11-28 21:44                 ` Boris Buliga
  0 siblings, 2 replies; 17+ messages in thread
From: Eli Zaretskii @ 2018-11-28 20:35 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Stephen Berman <stephen.berman@gmx.net>
> Cc: help-gnu-emacs@gnu.org
> Date: Wed, 28 Nov 2018 21:01:36 +0100
> 
> It would be helpful to know from precisely which part of the
> documentation it follows that evaluating this:
> 
> (insert (propertize "hello" 'face '(:foreground "red" :inherit
> (:foreground "orange"))))
> 
> displays "hello" in orange while evaluating this:
> 
> (insert (propertize "hello" 'face '(:inherit (:foreground "orange")
> :foreground "red")))
> 
> displays "hello" in red.

So this is only about what propertize does?  And only when some of the
later properties override earlier ones?

> I don't see how it follows from the passage in the Lisp manual I
> cited ("Faces occurring earlier in the list have higher priority")

It doesn't, because what you cited is not related to propertize, it's
related to how we process faces that come from several different
sources that affect the same piece of text.



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Overriding inherited face attributes
  2018-11-28 20:35               ` Eli Zaretskii
@ 2018-11-28 21:34                 ` Stephen Berman
  2018-11-29  7:14                   ` Eli Zaretskii
  2018-11-28 21:44                 ` Boris Buliga
  1 sibling, 1 reply; 17+ messages in thread
From: Stephen Berman @ 2018-11-28 21:34 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

On Wed, 28 Nov 2018 22:35:55 +0200 Eli Zaretskii <eliz@gnu.org> wrote:

>> From: Stephen Berman <stephen.berman@gmx.net>
>> Cc: help-gnu-emacs@gnu.org
>> Date: Wed, 28 Nov 2018 21:01:36 +0100
>> 
>> It would be helpful to know from precisely which part of the
>> documentation it follows that evaluating this:
>> 
>> (insert (propertize "hello" 'face '(:foreground "red" :inherit
>> (:foreground "orange"))))
>> 
>> displays "hello" in orange while evaluating this:
>> 
>> (insert (propertize "hello" 'face '(:inherit (:foreground "orange")
>> :foreground "red")))
>> 
>> displays "hello" in red.
>
> So this is only about what propertize does?  And only when some of the
> later properties override earlier ones?

Well, it's at least about what propertize does, since that was the OP's
example (the first form above), which lead to my observation of the
difference with the second form.  The documentation of propertize in
Lisp manual does not explain this difference, so I tried looking for
what I thought could be related, but in my ignorance of how face
properties work cited apparently irrelevant passages of the manual,
which seems to have sidetracked the question.  Sorry about that.

Steve Berman



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Overriding inherited face attributes
  2018-11-28 20:35               ` Eli Zaretskii
  2018-11-28 21:34                 ` Stephen Berman
@ 2018-11-28 21:44                 ` Boris Buliga
  2018-11-29  7:08                   ` Eli Zaretskii
  1 sibling, 1 reply; 17+ messages in thread
From: Boris Buliga @ 2018-11-28 21:44 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

Hi,

I don't see how it's specific to propetize. I can attach face differently,
for
example, by using add-text-properties or add-face-text-property:

  > (setq my-test-string "hello")
  "hello"
  > (add-text-properties 0 5 '(face (:inherit (:foreground "orange")))
my-test-string)
  nil
  > my-test-string
  #("hello" 0 5 (face (:inherit (:foreground "orange"))))
  ;; insert it and you'll get orange text

  > (setq my-test-string "hello")
  "hello"
  > (add-text-properties 0 5 '(face (:foreground "red" :inherit
(:foreground "orange"))) my-test-string)
  nil
  > my-test-string
  #("hello" 0 5 (face (:foreground "red" :inherit (:foreground "orange"))))
  ;; insert it and you'll get orange text

  > (setq my-test-string "hello")
  "hello"
  > (add-text-properties 0 5 '(face (:inherit (:foreground "orange")
:foreground "red" )) my-test-string)
  nil
  > my-test-string
  #("hello" 0 5 (face (:inherit (:foreground "orange") :foreground "red")))
  ;; insert it and you'll get red text

  > (setq my-test-string "hello")
  "hello"
  > (add-text-properties 0 5 '(face ((:foreground "red") (:inherit
(:foreground "orange")))) my-test-string)
  nil
  > my-test-string
  #("hello" 0 5 (face ((:foreground "red") (:inherit ...))))
  ;; insert it and you'll get red text

  > (setq my-test-string "hello")
  "hello"
  > (add-text-properties 0 5 '(face ((:inherit (:foreground "orange"))
(:foreground "red"))) my-test-string)
  nil
  > my-test-string
  #("hello" 0 5 (face ((:inherit ...) (:foreground "red"))))
  ;; insert it and you'll get orange text

  > (setq my-test-string "hello")
  "hello"
  > (add-face-text-property 0 5 '( :foreground "red" :inherit (:foreground
"orange")) nil my-test-string)
  nil
  > my-test-string
  #("hello" 0 5 (face (:foreground "red" :inherit (:foreground "orange"))))
  ;; insert it and you'll get orange text

  > (setq my-test-string "hello")
  "hello"
  > (add-face-text-property 0 5 '(:inherit (:foreground "orange")
:foreground "red") nil my-test-string)
  nil
  > my-test-string
  #("hello" 0 5 (face (:inherit (:foreground "orange") :foreground "red")))
  ;; insert it and you'll get red text

As you can see, it's a matter of properties. No matter how you add them,
using
propertize, add-text-properties or add-face-text-property.



On Wed, 28 Nov 2018 at 22:37, Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Stephen Berman <stephen.berman@gmx.net>
> > Cc: help-gnu-emacs@gnu.org
> > Date: Wed, 28 Nov 2018 21:01:36 +0100
> >
> > It would be helpful to know from precisely which part of the
> > documentation it follows that evaluating this:
> >
> > (insert (propertize "hello" 'face '(:foreground "red" :inherit
> > (:foreground "orange"))))
> >
> > displays "hello" in orange while evaluating this:
> >
> > (insert (propertize "hello" 'face '(:inherit (:foreground "orange")
> > :foreground "red")))
> >
> > displays "hello" in red.
>
> So this is only about what propertize does?  And only when some of the
> later properties override earlier ones?
>
> > I don't see how it follows from the passage in the Lisp manual I
> > cited ("Faces occurring earlier in the list have higher priority")
>
> It doesn't, because what you cited is not related to propertize, it's
> related to how we process faces that come from several different
> sources that affect the same piece of text.
>
>

-- 
Cheers,
Boris


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Overriding inherited face attributes
  2018-11-28 21:44                 ` Boris Buliga
@ 2018-11-29  7:08                   ` Eli Zaretskii
  0 siblings, 0 replies; 17+ messages in thread
From: Eli Zaretskii @ 2018-11-29  7:08 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Boris Buliga <boris@d12frosted.io>
> Date: Wed, 28 Nov 2018 23:44:47 +0200
> Cc: help-gnu-emacs@gnu.org
> 
> I don't see how it's specific to propetize. I can attach face differently, for
> example, by using add-text-properties or add-face-text-property:

propetize calls add-text-properties internally, so it's small wonder
you see the same results.

It is important to distinguish between 2 issues:

  1) How propertize and add-text-properties deal with lists of face
     attributes when later attributes override earlier ones.  This is
     what you seem to be asking about.

  2) How the Emacs display engine handles face attributes that come
     from different sources for the same display position.  This is
     what the ELisp manual talks about, mainly.

These two are different, because when propertize has done its thing,
the face attributes for the text it processed will be coming from a
single source: the face information associated with that text.



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Overriding inherited face attributes
  2018-11-28 21:34                 ` Stephen Berman
@ 2018-11-29  7:14                   ` Eli Zaretskii
  2018-11-29 17:30                     ` Stephen Berman
  0 siblings, 1 reply; 17+ messages in thread
From: Eli Zaretskii @ 2018-11-29  7:14 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Stephen Berman <stephen.berman@gmx.net>
> Cc: help-gnu-emacs@gnu.org
> Date: Wed, 28 Nov 2018 22:34:43 +0100
> 
> > So this is only about what propertize does?  And only when some of the
> > later properties override earlier ones?
> 
> Well, it's at least about what propertize does, since that was the OP's
> example (the first form above), which lead to my observation of the
> difference with the second form.

My reading of the code is that later face attributes override the
earlier once, i.e. the attributes are processed in order, and :inherit
doesn't have any precedence in this case.  Which seems like a sensible
thing, but I'm not sure we want to document this implementation
detail.  In general, having conflicting face attributes in the face
definition is not a good idea anyway; the only sensible use case is
when you want to change (i.e. override) some attribute of an existing
face, and for that, putting the overriding attribute at the end is the
natural thing to do.  IOW, Emacs seems to do what users should expect.



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Overriding inherited face attributes
  2018-11-29  7:14                   ` Eli Zaretskii
@ 2018-11-29 17:30                     ` Stephen Berman
  0 siblings, 0 replies; 17+ messages in thread
From: Stephen Berman @ 2018-11-29 17:30 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

On Thu, 29 Nov 2018 09:14:52 +0200 Eli Zaretskii <eliz@gnu.org> wrote:

>> From: Stephen Berman <stephen.berman@gmx.net>
>> Cc: help-gnu-emacs@gnu.org
>> Date: Wed, 28 Nov 2018 22:34:43 +0100
>> 
>> > So this is only about what propertize does?  And only when some of the
>> > later properties override earlier ones?
>> 
>> Well, it's at least about what propertize does, since that was the OP's
>> example (the first form above), which lead to my observation of the
>> difference with the second form.
>
> My reading of the code is that later face attributes override the
> earlier once, i.e. the attributes are processed in order, and :inherit
> doesn't have any precedence in this case.  Which seems like a sensible
> thing, but I'm not sure we want to document this implementation
> detail.  In general, having conflicting face attributes in the face
> definition is not a good idea anyway; the only sensible use case is
> when you want to change (i.e. override) some attribute of an existing
> face, and for that, putting the overriding attribute at the end is the
> natural thing to do.  IOW, Emacs seems to do what users should expect.

This makes sense and maybe it's not worth documenting.  On the other
hand, it wasn't obvious to me from looking in the Lisp manual that the
way prioritize and add-text-properties work is not related to what is
documented about the `face' property (giving priority to earlier not
later elements in the list).  Maybe I didn't read carefully enough.

Steve Berman



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2018-11-29 17:30 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-27 20:18 Overriding inherited face attributes Boris Buliga
2018-11-27 21:33 ` Stephen Berman
2018-11-28  6:19   ` Eli Zaretskii
2018-11-28 12:24     ` Stephen Berman
2018-11-28 13:06       ` Eli Zaretskii
2018-11-28 13:13         ` Stephen Berman
2018-11-28 16:18           ` Eli Zaretskii
2018-11-28 20:01             ` Stephen Berman
2018-11-28 20:35               ` Eli Zaretskii
2018-11-28 21:34                 ` Stephen Berman
2018-11-29  7:14                   ` Eli Zaretskii
2018-11-29 17:30                     ` Stephen Berman
2018-11-28 21:44                 ` Boris Buliga
2018-11-29  7:08                   ` Eli Zaretskii
2018-11-28  7:39   ` Boris Buliga
2018-11-28  7:51     ` Eli Zaretskii
2018-11-28  8:42       ` Boris Buliga

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).