From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "gliao.tw@pm.me" Newsgroups: gmane.emacs.devel Subject: face-attribute and face-remapping-alist Date: Tue, 30 Mar 2021 18:53:28 +0000 Message-ID: Reply-To: "gliao.tw@pm.me" Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18079"; mail-complaints-to="usenet@ciao.gmane.io" To: "emacs-devel@gnu.org" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Mar 30 20:54:57 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lRJVw-0004a3-HN for ged-emacs-devel@m.gmane-mx.org; Tue, 30 Mar 2021 20:54:56 +0200 Original-Received: from localhost ([::1]:35108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRJVv-0002XM-GP for ged-emacs-devel@m.gmane-mx.org; Tue, 30 Mar 2021 14:54:55 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45658) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRJUm-000257-HY for emacs-devel@gnu.org; Tue, 30 Mar 2021 14:53:44 -0400 Original-Received: from mail-40136.protonmail.ch ([185.70.40.136]:37906) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRJUe-00038K-Oj for emacs-devel@gnu.org; Tue, 30 Mar 2021 14:53:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1617130410; bh=pp8VY5DodQjGgJbCi5psovQnvAoGugA3Hnl0mnrqNo4=; h=Date:To:From:Reply-To:Subject:From; b=WNDe3rLXusbCVOe9dDm6r0HHiYeb3ShOSBe1fJ+7vtjK0/Pz/e2P3fL/8fNNdYSGg QQFxuC63BAzkzM964GCGxuGHFqdXdfPNv+0/KdyJI+GCK3trLDCw573hqmG2ByiWs5 +6w+fE97AGuQv2dKIkQKUR77GPk0bS3wY6v8CD100+wOHdFJPDp0pbq9lZUrGitSwp +dbP4ql3uY888yUayOsDSNqX7FTR49jQJhORfnwqHcVvG9A9DWus4hiV7vgLOQ0kJD +95Usbyud9JYmKPQ9bgOtDFk9zYiJnKR66BpJZCzbaiZ4hGV+wQNESXpo59LOD8UJH IdkrBziCYLyLQ== Received-SPF: pass client-ip=185.70.40.136; envelope-from=gliao.tw@pm.me; helo=mail-40136.protonmail.ch X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:267191 Archived-At: The `face-attribute' function defined in `faces.el' is the foundation of ma= ny face property inquiry functions such as `face-background'. However, `fac= e-attribute' is not aware of buffer-local variable 'face-remapping-alist' w= hich is used for buffer-specific theming. Since there are many modes, such as `term-mode', rely on `face-attribute' t= o obtain face information while `face-attribute' is only capabale of obtain= ing frame-specific, rather than buffer-specific face infomation, these mode= s cannot display faces sufficiently well while a buffer-local theme is appl= ied via `face-remap-add-relative' or `face-remap-set-base' (both functions,= defined in `face-remap.el', add items to buffer-specific variable `face-re= mapping-alist'). Therefore, I propose the following prototype of an enhanced version of `fac= e-attribute' function that is aware of the existence of `face-remapping-ali= st' in current buffer and return face property from `face-remapping-alist' = instead of frame-specific (single frame also means global) face property. Any comments are greatly appreciated, thanks. Kiong-G=C4=93. --------------------------- ;; (defun face-attribute (face attribute &optional frame inherit) "Return the value of FACE's ATTRIBUTE on FRAME or current buffer. If the optional argument FRAME is given, report on face FACE in that frame. If FRAME is t, report on the defaults for face FACE (for new frames). If FRAME is omitted or nil, use the selected frame. If INHERIT is nil, only attributes directly defined by FACE are considered, so the return value may be `unspecified', or a relative value. If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the faces specified by its `:inherit' attribute; however the return value may still be `unspecified' or relative. If INHERIT is a face or a list of faces, then the result is further merged with that face (or faces), until it becomes specified and absolute. To ensure that the return value is always specified and absolute, use a value of `default' for INHERIT; this will resolve any unspecified or relative values by merging with the `default' face (which is always completely specified)." ;; check if `face-remapping-alist' exist as a buffer-local variable ;; in current buffer (let* ((local-faces (if (local-variable-p 'face-remapping-alist =09=09=09=09=09 (current-buffer)) =09=09=09 ;; if so, take faces information from it =09=09=09 (buffer-local-value 'face-remapping-alist =09=09=09=09=09 (current-buffer)))) =09 ;; try to fetch buffer-local face proprety from face-remapping-alist =09 (local-face-prop (if local-faces =09=09=09 (plist-get (car (alist-get face local-faces)) =09=09=09=09=09 attribute)))) ;; if there is no inquired face informatio available in ;; face-remapping-alist, fallback to frame-specific values (or local-face-prop =09(let ((value (internal-get-lisp-face-attribute face attribute frame))) =09 (when (and inherit (face-attribute-relative-p attribute value)) =09 ;; VALUE is relative, so merge with inherited faces =09 (let ((inh-from (face-attribute face :inherit frame))) =09 (unless (or (null inh-from) (eq inh-from 'unspecified)) =09=09(condition-case nil =09=09 (setq value =09=09=09 (face-attribute-merged-with attribute value inh-from frame)) =09=09 ;; The `inherit' attribute may point to non existent faces. =09=09 (error nil))))) =09 (when (and inherit =09=09 (not (eq inherit t)) =09=09 (face-attribute-relative-p attribute value)) =09 ;; We should merge with INHERIT as well =09 (setq value (face-attribute-merged-with attribute value inherit fram= e))) =09 value)))) ----------------------------------------