From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Dave Goel Newsgroups: gmane.emacs.devel Subject: How to figure out the chased attribute when (point) has multiple faces? Date: Sat, 28 Dec 2019 05:42:55 -0500 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000089d19b059ac1466a" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="218885"; mail-complaints-to="usenet@blaine.gmane.org" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 28 11:43:19 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1il9Z0-000ur3-Uz for ged-emacs-devel@m.gmane.org; Sat, 28 Dec 2019 11:43:19 +0100 Original-Received: from localhost ([::1]:42410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1il9Yz-0001yF-5Z for ged-emacs-devel@m.gmane.org; Sat, 28 Dec 2019 05:43:17 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40123) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1il9Yr-0001y8-6Y for emacs-devel@gnu.org; Sat, 28 Dec 2019 05:43:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1il9Yp-0002zb-P4 for emacs-devel@gnu.org; Sat, 28 Dec 2019 05:43:09 -0500 Original-Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]:42793) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1il9Yp-0002wf-EP for emacs-devel@gnu.org; Sat, 28 Dec 2019 05:43:07 -0500 Original-Received: by mail-io1-xd2a.google.com with SMTP id n11so20986401iom.9 for ; Sat, 28 Dec 2019 02:43:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=LMunfCH9XmFoCNce1WApyI99zdOsqzAIrWug48GDV9o=; b=tZwWMzRMYynR9+oM6XnMzQqiBkGHlcyFIIU7iXuWeUCRTY05uSGjBMG/sKI7Ofj63w HmeMj9T2W0/hU/Sdq7+xcFfmClQwAFCdVsYZ5a28TGZWWvVJFC9wullhYZMPs7VkYAIA GKFbfltm+5dzYoWpXmk4oGREhxhlQKjwtfapzLwMUP7U4+Zlhvvfs1cjlpLSBLdrzEMT y1lHPj/j2zdNPEC5ihe0ODRIZcZNHyqNL7GbZFnAO3RsC+nFd5KqBYLMqo5pPXFqoPdJ tpoR8IOAlq4yQp5EBRFFjfeqAXGIhEoEqLLEkGVfCbLt0UurgGrDKCH1AFaJKa9e4PIu gcWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=LMunfCH9XmFoCNce1WApyI99zdOsqzAIrWug48GDV9o=; b=AfdlIOhSSnf4rQLIcyJD8UOjSoypbsvboj33B4fc4IHPZ/w2QqOTA8vc7MuS+4l9ba 1L6n7wfmViJImTI/oi4tG6t5s5V2XCHAaXoV8wg1+Tj31JpCh2XGU+2y4BRseTaJqGr2 Vbyp5RZBfc57vN3T5crcrRSUYtdMg6proGGewca5qSuVHBB/+oY4sV4bCHa2SuZHEFJk 4KyGk0KzeVc0R4gcE6251J0XIrItT0POmeDmvqTaqEOTPEK5LAcR8C5GxbZvPF3OmpQP 2MCze/2cdpP9vruLMLqNOXcR6lMK1WznBTyk/awOzKWmvTjSikZVyP7cfAsu8TVIxyYo MUfA== X-Gm-Message-State: APjAAAVoKJuBDjOzOLGdRykaDrKiOvYTEVWEs5qxj6Uev6wBJRLGzIpd p/6MsFVrQ+mcKf6LYxtNpc49/hjESD1U93wCmfSrcUlb X-Google-Smtp-Source: APXvYqx+y3CKIVFjCDZObHueoEPJ1czXF8BjbATvXB7Nqu25NFkW4M+L/C+FkJXyhMGACDj8YF+NjJ8g8GFtUikX8zg= X-Received: by 2002:a6b:8b01:: with SMTP id n1mr27389935iod.111.1577529786354; Sat, 28 Dec 2019 02:43:06 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::d2a X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:243727 Archived-At: --00000000000089d19b059ac1466a Content-Type: text/plain; charset="UTF-8" You just want to see what emacs would finally render the attribute as, after chasing all inherits. No problem! Face-attribute has a 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 t 'default) which chases mylist. Thus, face-attribute already knows how to chase mylist. --00000000000089d19b059ac1466a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

You just want to see what emacs would fi= nally render the attribute as, after chasing all inherits.=C2=A0

No = problem! Face-attribute has a <chase> option as the fourth argument! = You call (face-attribute (face-at-point) :foreground t 'default). It du= tifully chases the list of ancestors one by one recursively, resorting to t= he value from 'default if the answer is still 'unspecified.
That, however fails if (face-at-point) is a =C2=A0list. (It also fails if = it is nil.)

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

Emacs, of cou= rse, knows how to do this when rendering. Even face-attribute knows that, a= s seen in multiple ways below[1]. It just doesn't expose this to the us= er.

Here's the pseodo-code. I implemented it locally, but I fee= l like I'm reinventing the wheel, and face-attribute already does it wi= thout exposing it properly.

(defun chase (faces att)
=C2=A0 (let= * ((f1 (car faces))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; notice the merg= e!
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(faces2 (append (parents f1) (cdr f= aces)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(att1 (face-attribute faces at= t)))
=C2=A0 =C2=A0 (if (found att1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 att1<= br>=C2=A0 =C2=A0 =C2=A0 (chase faces2 att))))

Where:
a. (parents = ..) returns the parent(s) of f1, always as a list.
b. (found ..) is fals= e if argument is 'unspecified. True otherwise. Thus, nil is a valid att= ribute.
c. The last item in faces is always assumed to be 'default.<= br>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 t= he same footing as (cdr faces), and the two are simply merged for the purpo= se of the chase.
f. Special case for :fg and :bg. In that the final rend= ering also depends on the (chased) value of :inverse-video.

[1] fac= e-attribute basically already knows how to chase a list, it just doesn'= t expose it. Suppose mylist =3D (f1 f2 f3) and you want to see what it woul= d render attribute :height as. You construct a new, otherwise empty face &#= 39;newface, which :inherits-from (mylist). And, call (face-attribute 'n= ewface <attribute> t 'default) which chases mylist.=C2=A0 Thus, f= ace-attribute already knows how to chase mylist.

--00000000000089d19b059ac1466a--