[Top][All Lists]

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

Mixing named and anonymous faces in text properties

From: Kévin Le Gouguec
Subject: Mixing named and anonymous faces in text properties
Date: Thu, 25 Apr 2019 20:28:00 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)


I am trying to understand whether the `face' text property can contain
a list mixing face names with anonymous faces.  The behaviour I
observe seems somewhat inconsistent, unless I am misunderstanding the

(elisp)Special Properties says:

> The value of the property can be the following:
> • A face name (a symbol or string).
> • An anonymous face: a property list of the form ‘(KEYWORD VALUE
>   ...)’, where each KEYWORD is a face attribute name and VALUE
>   is a value for that attribute.
> • A list of faces.  Each list element should be either a face
>   name or an anonymous face.  This specifies a face which is an
>   aggregate of the attributes of each of the listed faces.
>   Faces occurring earlier in the list have higher priority.

>From what I can tell, in a face list, face names provided *after*
anonymous faces are ignored, even when the anonymous face's attributes
do not overlap with those of the named face.

A (somewhat academic) example (my motivating issue is given further

- C-x b newbuffer RET
- foobarbaz RET foobarbaz RET
- M-: (add-text-properties 1 3 '(face '(italic :weight bold))) RET
- M-: (add-text-properties 11 13 '(face '(:weight bold italic))) RET

On my setup (emacs -Q on master, version 27.0.50, commit c53e7f2),

- "foo" on the first line is displayed in both bold and italic,
- whereas "foo" on the second line only shows up in bold.

Is this expected?  I am asking this on help-gnu-emacs because I am not
sure whether this is a bug, a documentation issue, or me just not
understanding something.

My motivating issue comes from org-mode: if I use strike-through
markers in an Org heading (e.g. "* +some crossed-off heading+"), the
marked words lose the header face.  I reported this problem on the
emacs-orgmode mailing list (with a patch fixing^Wworking around the
issue), but haven't heard back yet.

Thanks in advance for any pointers!

PS: a last-minute experiment showed that the following works:

- C-x b newerbuffer RET
- foobarbaz RET
- M-: (add-text-properties 1 3 '(face '((:weight bold) italic))) RET

Unfortunately I haven't found a way to make this work in Org, which
does the following in org-do-emphasis-faces:

(pcase-let ((`(,_ ,face ,_) (assoc marker org-emphasis-alist)))
               (match-beginning 2) (match-end 2) 'face face)

Presumably the text already has the org-level-1 face, and this snippet
prepends the (:strike-through t) anonymous face.  I haven't yet dug
into font-lock-prepend-text-property to figure why the property ends
up being

    (:strike-through t org-level-1)

rather than

    ((:strike-through t) org-level-1)

I will take a look later if nobody beats me to it…

reply via email to

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