unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Dave Goel <deego3@gmail.com>
To: emacs-devel@gnu.org
Subject: How to figure out the chased attribute when (point) has multiple faces?
Date: Sat, 28 Dec 2019 05:42:55 -0500	[thread overview]
Message-ID: <CAOCW0DgRgsG4S30SpVLpg26PHhUjyR9w7Pc12_LMbt6BuJ63dA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2078 bytes --]

You just want to see what emacs would finally render the attribute as,
after chasing all inherits.

No problem! Face-attribute has a <chase> option as the fourth argument! You
call (face-attribute (face-at-point) :foreground t 'default). It dutifully
chases the list of ancestors one by one recursively, resorting to the value
from 'default if the answer is still 'unspecified.

That, however fails if (face-at-point) is a  list. (It also fails if it is
nil.)

Is there a built-in function that does this?  Can you point me to it?

Emacs, of course, knows how to do this when rendering. Even face-attribute
knows that, as seen in multiple ways below[1]. It just doesn't expose this
to the user.

Here's the pseodo-code. I implemented it locally, but I feel like I'm
reinventing the wheel, and face-attribute already does it without exposing
it properly.

(defun chase (faces att)
  (let* ((f1 (car faces))
         ;; notice the merge!
         (faces2 (append (parents f1) (cdr faces)))
         (att1 (face-attribute faces att)))
    (if (found att1)
        att1
      (chase faces2 att))))

Where:
a. (parents ..) returns the parent(s) of f1, always as a list.
b. (found ..) is false if argument is 'unspecified. True otherwise. Thus,
nil is a valid attribute.
c. The last item in faces is always assumed to be 'default.
d. faces is a always list of faces. A single face is treated as a list.
e. Notice how in the algo the parents of (parents (car faces)) are on the
same footing as (cdr faces), and the two are simply merged for the purpose
of the chase.
f. Special case for :fg and :bg. In that the final rendering also depends
on the (chased) value of :inverse-video.

[1] face-attribute basically already knows how to chase a list, it just
doesn't expose it. Suppose mylist = (f1 f2 f3) and you want to see what it
would render attribute :height as. You construct a new, otherwise empty
face 'newface, which :inherits-from (mylist). And, call (face-attribute
'newface <attribute> t 'default) which chases mylist.  Thus, face-attribute
already knows how to chase mylist.

[-- Attachment #2: Type: text/html, Size: 2749 bytes --]

                 reply	other threads:[~2019-12-28 10:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=CAOCW0DgRgsG4S30SpVLpg26PHhUjyR9w7Pc12_LMbt6BuJ63dA@mail.gmail.com \
    --to=deego3@gmail.com \
    --cc=emacs-devel@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 public inbox

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

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