aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiles Bader2001-10-28 10:19:33 +0000
committerMiles Bader2001-10-28 10:19:33 +0000
commitc7f814cb6d19b8bc0bca071eb96ac0221dd1b395 (patch)
tree4eb4bf480b40b67220b120fa183b533f924a9f12
parentcdfaafa9cc7fd972ba8f80aa9e260714fb677923 (diff)
downloademacs-c7f814cb6d19b8bc0bca071eb96ac0221dd1b395.tar.gz
emacs-c7f814cb6d19b8bc0bca071eb96ac0221dd1b395.zip
(face-attribute): Add INHERIT argument, consider face inheritance if non-nil.
(face-attribute-merged-with): New function. (face-attribute-specified-or): New macro. (face-foreground, face-background, face-stipple): Add INHERIT argument. Use `face-attribute-specified-or'.
-rw-r--r--lisp/faces.el126
1 files changed, 103 insertions, 23 deletions
diff --git a/lisp/faces.el b/lisp/faces.el
index 6cbe12230bf..bb9d4471da3 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -355,45 +355,125 @@ FRAME nil or not specified means do it for all frames."
355 (symbol-name (check-face face))) 355 (symbol-name (check-face face)))
356 356
357 357
358(defun face-attribute (face attribute &optional frame) 358(defun face-attribute (face attribute &optional frame inherit)
359 "Return the value of FACE's ATTRIBUTE on FRAME. 359 "Return the value of FACE's ATTRIBUTE on FRAME.
360If the optional argument FRAME is given, report on face FACE in that frame. 360If the optional argument FRAME is given, report on face FACE in that frame.
361If FRAME is t, report on the defaults for face FACE (for new frames). 361If FRAME is t, report on the defaults for face FACE (for new frames).
362If FRAME is omitted or nil, use the selected frame." 362If FRAME is omitted or nil, use the selected frame.
363 (internal-get-lisp-face-attribute face attribute frame)) 363
364If INHERIT is nil, only attributes directly defined by FACE are considered,
365 so the return value may be `unspecified', or a relative value.
366If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
367 faces specified by its `:inherit' attribute; however the return value
368 may still be `unspecified' or relative.
369If INHERIT is a face or a list of faces, then the result is further merged
370 with that face (or faces), until it becomes specified and absolute.
371
372To ensure that the return value is always specified and absolute, use a
373value of `default' for INHERIT; this will resolve any unspecified or
374relative values by merging with the `default' face (which is always
375completely specified)."
376 (let ((value (internal-get-lisp-face-attribute face attribute frame)))
377 (when (and inherit (face-attribute-relative-p attribute value))
378 ;; VALUE is relative, so merge with inherited faces
379 (let ((inh-from (face-attribute face :inherit frame)))
380 (unless (or (null inh-from) (eq inh-from 'unspecified))
381 (setq value
382 (face-attribute-merged-with attribute value inh-from frame)))))
383 (when (and inherit
384 (not (eq inherit t))
385 (face-attribute-relative-p attribute value))
386 ;; We should merge with INHERIT as well
387 (setq value (face-attribute-merged-with attribute value inherit frame)))
388 value))
389
390(defun face-attribute-merged-with (attribute value faces &optional frame)
391 "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
392FACES may be either a single face or a list of faces.
393\[This is an internal function]"
394 (cond ((not (face-attribute-relative-p attribute value))
395 value)
396 ((null faces)
397 value)
398 ((consp faces)
399 (face-attribute-merged-with
400 attribute
401 (face-attribute-merged-with attribute value (car faces) frame)
402 (cdr faces)
403 frame))
404 (t
405 (merge-face-attribute attribute
406 value
407 (face-attribute faces attribute frame t)))))
364 408
365 409
366(defun face-foreground (face &optional frame) 410(defmacro face-attribute-specified-or (value &rest body)
411 "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result."
412 (let ((temp (make-symbol "value")))
413 `(let ((,temp ,value))
414 (if (not (eq ,temp 'unspecified))
415 ,temp
416 ,@body))))
417
418(defun face-foreground (face &optional frame inherit)
367 "Return the foreground color name of FACE, or nil if unspecified. 419 "Return the foreground color name of FACE, or nil if unspecified.
368If the optional argument FRAME is given, report on face FACE in that frame. 420If the optional argument FRAME is given, report on face FACE in that frame.
369If FRAME is t, report on the defaults for face FACE (for new frames). 421If FRAME is t, report on the defaults for face FACE (for new frames).
370If FRAME is omitted or nil, use the selected frame." 422If FRAME is omitted or nil, use the selected frame.
371 (let ((value (internal-get-lisp-face-attribute face :foreground frame)))
372 (if (eq value 'unspecified)
373 nil
374 value)))
375
376 423
377(defun face-background (face &optional frame) 424If INHERIT is nil, only a foreground color directly defined by FACE is
425 considered, so the return value may be nil.
426If INHERIT is t, and FACE doesn't define a foreground color, then any
427 foreground color that FACE inherits through its `:inherit' attribute
428 is considered as well; however the return value may still be nil.
429If INHERIT is a face or a list of faces, then it is used to try to
430 resolve an unspecified foreground color.
431
432To ensure that a valid color is always returned, use a value of
433`default' for INHERIT; this will resolve any unspecified values by
434merging with the `default' face (which is always completely specified)."
435 (face-attribute-specified-or (face-attribute face :foreground frame inherit)
436 nil))
437
438(defun face-background (face &optional frame inherit)
378 "Return the background color name of FACE, or nil if unspecified. 439 "Return the background color name of FACE, or nil if unspecified.
379If the optional argument FRAME is given, report on face FACE in that frame. 440If the optional argument FRAME is given, report on face FACE in that frame.
380If FRAME is t, report on the defaults for face FACE (for new frames). 441If FRAME is t, report on the defaults for face FACE (for new frames).
381If FRAME is omitted or nil, use the selected frame." 442If FRAME is omitted or nil, use the selected frame.
382 (let ((value (internal-get-lisp-face-attribute face :background frame)))
383 (if (eq value 'unspecified)
384 nil
385 value)))
386
387 443
388(defun face-stipple (face &optional frame) 444If INHERIT is nil, only a background color directly defined by FACE is
445 considered, so the return value may be nil.
446If INHERIT is t, and FACE doesn't define a background color, then any
447 background color that FACE inherits through its `:inherit' attribute
448 is considered as well; however the return value may still be nil.
449If INHERIT is a face or a list of faces, then it is used to try to
450 resolve an unspecified background color.
451
452To ensure that a valid color is always returned, use a value of
453`default' for INHERIT; this will resolve any unspecified values by
454merging with the `default' face (which is always completely specified)."
455 (face-attribute-specified-or (face-attribute face :background frame inherit)
456 nil))
457
458(defun face-stipple (face &optional frame inherit)
389 "Return the stipple pixmap name of FACE, or nil if unspecified. 459 "Return the stipple pixmap name of FACE, or nil if unspecified.
390If the optional argument FRAME is given, report on face FACE in that frame. 460If the optional argument FRAME is given, report on face FACE in that frame.
391If FRAME is t, report on the defaults for face FACE (for new frames). 461If FRAME is t, report on the defaults for face FACE (for new frames).
392If FRAME is omitted or nil, use the selected frame." 462If FRAME is omitted or nil, use the selected frame.
393 (let ((value (internal-get-lisp-face-attribute face :stipple frame))) 463
394 (if (eq value 'unspecified) 464If INHERIT is nil, only a stipple directly defined by FACE is
395 nil 465 considered, so the return value may be nil.
396 value))) 466If INHERIT is t, and FACE doesn't define a stipple, then any stipple
467 that FACE inherits through its `:inherit' attribute is considered as
468 well; however the return value may still be nil.
469If INHERIT is a face or a list of faces, then it is used to try to
470 resolve an unspecified stipple.
471
472To ensure that a valid stipple or nil is always returned, use a value of
473`default' for INHERIT; this will resolve any unspecified values by merging
474with the `default' face (which is always completely specified)."
475 (face-attribute-specified-or (face-attribute face :stipple frame inherit)
476 nil))
397 477
398 478
399(defalias 'face-background-pixmap 'face-stipple) 479(defalias 'face-background-pixmap 'face-stipple)