unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* How to figure out the chased attribute when (point) has multiple faces?
@ 2019-12-28 10:42 Dave Goel
  0 siblings, 0 replies; only message in thread
From: Dave Goel @ 2019-12-28 10:42 UTC (permalink / raw)
  To: emacs-devel

[-- 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 --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-12-28 10:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-28 10:42 How to figure out the chased attribute when (point) has multiple faces? Dave Goel

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