all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Kévin Le Gouguec" <kevin.legouguec@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Mixing named and anonymous faces in text properties
Date: Thu, 25 Apr 2019 20:28:00 +0200	[thread overview]
Message-ID: <875zr2aqj3.fsf@gmail.com> (raw)

Hello,

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

(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
below):

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

https://lists.gnu.org/archive/html/emacs-orgmode/2019-04/msg00101.html


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)))
	      (font-lock-prepend-text-property
	       (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	other threads:[~2019-04-25 18:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-25 18:28 Kévin Le Gouguec [this message]
2019-04-26 16:39 ` Mixing named and anonymous faces in text properties Stefan Monnier
2019-04-26 17:21 ` Kévin Le Gouguec
2019-04-29 21:31   ` Stefan Monnier
2019-04-30  6:11     ` Kévin Le Gouguec

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

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

  git send-email \
    --in-reply-to=875zr2aqj3.fsf@gmail.com \
    --to=kevin.legouguec@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.