comparison lisp/faces.el @ 40399:3e67855bb4bf

(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'.
author Miles Bader <miles@gnu.org>
date Sun, 28 Oct 2001 10:19:33 +0000
parents a44d4a7dd8de
children ce83eda9592d
comparison
equal deleted inserted replaced
40398:560b1c474b1a 40399:3e67855bb4bf
353 (defun face-name (face) 353 (defun face-name (face)
354 "Return the name of face FACE." 354 "Return the name of face FACE."
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.
360 If the optional argument FRAME is given, report on face FACE in that frame. 360 If the optional argument FRAME is given, report on face FACE in that frame.
361 If FRAME is t, report on the defaults for face FACE (for new frames). 361 If FRAME is t, report on the defaults for face FACE (for new frames).
362 If FRAME is omitted or nil, use the selected frame." 362 If FRAME is omitted or nil, use the selected frame.
363 (internal-get-lisp-face-attribute face attribute frame)) 363
364 364 If INHERIT is nil, only attributes directly defined by FACE are considered,
365 365 so the return value may be `unspecified', or a relative value.
366 (defun face-foreground (face &optional frame) 366 If 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.
369 If 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
372 To ensure that the return value is always specified and absolute, use a
373 value of `default' for INHERIT; this will resolve any unspecified or
374 relative values by merging with the `default' face (which is always
375 completely 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.
392 FACES 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)))))
408
409
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.
368 If the optional argument FRAME is given, report on face FACE in that frame. 420 If the optional argument FRAME is given, report on face FACE in that frame.
369 If FRAME is t, report on the defaults for face FACE (for new frames). 421 If FRAME is t, report on the defaults for face FACE (for new frames).
370 If FRAME is omitted or nil, use the selected frame." 422 If FRAME is omitted or nil, use the selected frame.
371 (let ((value (internal-get-lisp-face-attribute face :foreground frame))) 423
372 (if (eq value 'unspecified) 424 If INHERIT is nil, only a foreground color directly defined by FACE is
373 nil 425 considered, so the return value may be nil.
374 value))) 426 If INHERIT is t, and FACE doesn't define a foreground color, then any
375 427 foreground color that FACE inherits through its `:inherit' attribute
376 428 is considered as well; however the return value may still be nil.
377 (defun face-background (face &optional frame) 429 If INHERIT is a face or a list of faces, then it is used to try to
430 resolve an unspecified foreground color.
431
432 To ensure that a valid color is always returned, use a value of
433 `default' for INHERIT; this will resolve any unspecified values by
434 merging 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.
379 If the optional argument FRAME is given, report on face FACE in that frame. 440 If the optional argument FRAME is given, report on face FACE in that frame.
380 If FRAME is t, report on the defaults for face FACE (for new frames). 441 If FRAME is t, report on the defaults for face FACE (for new frames).
381 If FRAME is omitted or nil, use the selected frame." 442 If FRAME is omitted or nil, use the selected frame.
382 (let ((value (internal-get-lisp-face-attribute face :background frame))) 443
383 (if (eq value 'unspecified) 444 If INHERIT is nil, only a background color directly defined by FACE is
384 nil 445 considered, so the return value may be nil.
385 value))) 446 If INHERIT is t, and FACE doesn't define a background color, then any
386 447 background color that FACE inherits through its `:inherit' attribute
387 448 is considered as well; however the return value may still be nil.
388 (defun face-stipple (face &optional frame) 449 If INHERIT is a face or a list of faces, then it is used to try to
450 resolve an unspecified background color.
451
452 To ensure that a valid color is always returned, use a value of
453 `default' for INHERIT; this will resolve any unspecified values by
454 merging 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.
390 If the optional argument FRAME is given, report on face FACE in that frame. 460 If the optional argument FRAME is given, report on face FACE in that frame.
391 If FRAME is t, report on the defaults for face FACE (for new frames). 461 If FRAME is t, report on the defaults for face FACE (for new frames).
392 If FRAME is omitted or nil, use the selected frame." 462 If 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) 464 If INHERIT is nil, only a stipple directly defined by FACE is
395 nil 465 considered, so the return value may be nil.
396 value))) 466 If 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.
469 If INHERIT is a face or a list of faces, then it is used to try to
470 resolve an unspecified stipple.
471
472 To 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
474 with 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)
400 480
401 481