From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Keith David Bershatsky Newsgroups: gmane.emacs.devel Subject: Re: C equivalent for: (face-attribute 'region :background (selected-frame) 'default) Date: Tue, 26 Sep 2017 15:11:38 -0700 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Trace: blaine.gmane.org 1506463944 20648 195.159.176.226 (26 Sep 2017 22:12:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 26 Sep 2017 22:12:24 +0000 (UTC) Cc: Philipp Stephani To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Sep 27 00:12:19 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dwy5S-0004qH-Ly for ged-emacs-devel@m.gmane.org; Wed, 27 Sep 2017 00:12:19 +0200 Original-Received: from localhost ([::1]:51295 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dwy5W-000860-Vs for ged-emacs-devel@m.gmane.org; Tue, 26 Sep 2017 18:12:23 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dwy4v-00084d-Sj for emacs-devel@gnu.org; Tue, 26 Sep 2017 18:11:46 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dwy4q-0006y5-U8 for emacs-devel@gnu.org; Tue, 26 Sep 2017 18:11:45 -0400 Original-Received: from gateway34.websitewelcome.com ([192.185.148.164]:49922) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dwy4q-0006xq-MM for emacs-devel@gnu.org; Tue, 26 Sep 2017 18:11:40 -0400 Original-Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway34.websitewelcome.com (Postfix) with ESMTP id DDDD87F7A6E for ; Tue, 26 Sep 2017 17:11:39 -0500 (CDT) Original-Received: from gator3053.hostgator.com ([50.87.144.69]) by cmsmtp with SMTP id wy4bdfmXyRtUXwy4cdyDSs; Tue, 26 Sep 2017 17:11:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lawlist.com ; s=default; h=Content-Type:MIME-Version:Subject:Cc:To:From:Message-ID:Date: Sender:Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Xj1TbjzYLciMWnCCcGOXaRKgkNh7g+PO1iokI4R6Iuw=; b=AuUMm9iZY+7IdQbG2iL3s0F2xv UfYOT7uYOJrTyqQJRIPBCEApOO8HT7YkWK1Tns6XjhqtqpRMnbzhTFuuNsZpNIFUmcSjZvqU9+8OW Y39MI4nHpkLRUF6TfzPYwoZx1ZEmkh6kmWixDG+jyORa3LXn+/w7rWV+DQrlYlUf7mrvd2c8AnnDa 6aLXJ4rDWfEvGMeYi54KnVL9vtWqv8b8ml/YI+rGz6txxaUHZnYfTlLML34LqNARIyvx/31xdqTDg 0Ng/HaGgCaG62qzhQqxTZhv3GLaa7dTQq7vPpHShzEMt6lk28e91rdmddxAbS1XpMRmtYl3iY8ocU /+bdCAdg==; Original-Received: from cpe-45-48-239-195.socal.res.rr.com ([45.48.239.195]:49819 helo=server.private) by gator3053.hostgator.com with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.87) (envelope-from ) id 1dwy4p-002yHM-0a; Tue, 26 Sep 2017 17:11:39 -0500 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3053.hostgator.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lawlist.com X-BWhitelist: no X-Source-IP: 45.48.239.195 X-Exim-ID: 1dwy4p-002yHM-0a X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: cpe-45-48-239-195.socal.res.rr.com (server.private) [45.48.239.195]:49819 X-Source-Auth: lawlist X-Email-Count: 4 X-Source-Cap: bGF3bGlzdDtsYXdsaXN0O2dhdG9yMzA1My5ob3N0Z2F0b3IuY29t X-Local-Domain: yes X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 192.185.148.164 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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:218814 Archived-At: Here is a first draft of the conversion from Lisp to C. It has everything (I think?) except for the `condition-case` statement, because I haven't learned how to do that yet in C. If anyone sees an error, or if anyone could teach me how to properly incorporate the missing `condition_case` statement in `mc-face-attribute`, that would be greatly appreciated. DEFUN ("mc-face-attribute", Fmc_face_attribute, Smc_face_attribute, 2, 4, 0, doc: /* Return the value of FACE's ATTRIBUTE on FRAME. 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). */) (Lisp_Object face, Lisp_Object attribute, Lisp_Object frame, Lisp_Object inherit) { /* (let ((value (internal-get-lisp-face-attribute face attribute frame))) (when (and inherit (face-attribute-relative-p attribute value)) (let ((inh-from (mc-face-attribute face :inherit frame))) (unless (or (null inh-from) (eq inh-from 'unspecified)) (condition-case nil (setq value (mc-face-attribute-merged-with attribute value inh-from frame)) (error nil))))) (when (and inherit (not (eq inherit t)) (face-attribute-relative-p attribute value)) (setq value (mc-face-attribute-merged-with attribute value inherit frame))) value) */ Lisp_Object value = Finternal_get_lisp_face_attribute (face, attribute, frame); if (!EQ (inherit, Qnil) && EQ (Fface_attribute_relative_p (attribute, value), Qt)) { Lisp_Object inh_from = Fmc_face_attribute (face, intern (":inherit"), frame, Qnil); if (!EQ (inh_from, Qnil) && !EQ (inh_from, intern ("unspecified"))) /* FIXME: learn how to use `Fcondition_case' here! */ value = Fmc_face_attribute_merged_with (attribute, value, inh_from, frame); } if (!EQ (inherit, Qnil) && !EQ (inherit, Qt) && EQ (Fface_attribute_relative_p (attribute, value), Qt)) value = Fmc_face_attribute_merged_with (attribute, value, inherit, frame); return value; } DEFUN ("mc-face-attribute-merged-with", Fmc_face_attribute_merged_with, Smc_face_attribute_merged_with, 3, 4, 0, doc: /* Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute. FACES may be either a single face or a list of faces. [This is an internal function.] */) (Lisp_Object attribute, Lisp_Object value, Lisp_Object faces, Lisp_Object frame) { /* (cond ((not (face-attribute-relative-p attribute value)) value) ((null faces) value) ((consp faces) (mc-face-attribute-merged-with attribute (mc-face-attribute-merged-with attribute value (car faces) frame) (cdr faces) frame)) (t (merge-face-attribute attribute value (mc-face-attribute faces attribute frame t)))) */ if (EQ (Fface_attribute_relative_p (attribute, value), Qnil)) return value; if (EQ (faces, Qnil)) return value; if (CONSP (faces)) return Fmc_face_attribute_merged_with (attribute, Fmc_face_attribute_merged_with (attribute, value, XCAR (faces), frame), XCDR (faces), frame); return Fmerge_face_attribute (attribute, value, Fmc_face_attribute (faces, attribute, frame, Qt)); }