[Top][All Lists]

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

Re: C equivalent for: (face-attribute 'region :background (selected-fram

From: Keith David Bershatsky
Subject: Re: C equivalent for: (face-attribute 'region :background (selected-frame) 'default)
Date: Tue, 26 Sep 2017 15:11:38 -0700

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 
  (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 
            (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 
  Lisp_Object value = Finternal_get_lisp_face_attribute (face, attribute, 
  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, 
  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 
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 
    ((not (face-attribute-relative-p attribute value))
    ((null faces)
    ((consp faces)
        (mc-face-attribute-merged-with attribute value (car faces) frame)
        (cdr faces)
      (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,
(attribute, value, XCAR (faces), frame),
                                           XCDR (faces),
  return Fmerge_face_attribute (attribute,
                                Fmc_face_attribute (faces, attribute, frame, 

reply via email to

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