[Top][All Lists]

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

How to figure out the chased attribute when (point) has multiple faces?

From: Dave Goel
Subject: How to figure out the chased attribute when (point) has multiple faces?
Date: Sat, 28 Dec 2019 05:42:55 -0500

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)
      (chase faces2 att))))

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.

reply via email to

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