;;; face-fns.el --- face manipulation functions

;; Copyright (C) 1995, 2000 Noah S. Friedman

;; Author: Noah Friedman <friedman@splode.com>
;; Maintainer: friedman@splode.com

;; $Id: face-fns.el,v 1.3 2000/02/28 00:05:41 friedman Exp $

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, you can either send email to this
;; program's maintainer or write to: The Free Software Foundation,
;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.

;;; Commentary:
;;; Code:

;; Emacsen prior to emacs 19.29 did not have facep.
(or (fboundp 'facep)
    (defun facep (x)
      "Return t if X is a face name."
      (and (memq x (face-list)) t)))

;; Introduce some sanity and simplicity into the setting of default faces.
;; Is it too much to ask that there be just one API for setting faces,
;; and stop changing it all the time?
;;;###autoload
(defun override-face-attributes (face &rest properties)
  "Set face on all existing and future frames according to PROPERTIES.
Default faces specified with `defface' are also overridden."
  (cond ((not (facep face)))
        ((fboundp 'set-face-attribute)
         (apply 'set-face-attribute face nil properties))
        ((fboundp 'custom-set-faces)
         (require 'list-fns)
         ;; Customs insanity.
         ;; Merge specified properties with defcustom defaults and existing
         ;; user-specified preferences, if any, and store them on the
         ;; save-face property.
         (let ((props (merge-into-property-list nil
                        (face-spec-choose (get face 'face-defface-spec))
                        (face-spec-choose (get face 'saved-face))
                        properties)))
           (put face 'saved-face nil)
           (custom-set-faces (list face (list (list t props)) t))))
        (t
         (let ((settors '((:background    . set-face-background)
                          (:bold          . set-face-bold-p)
                          (:font          . set-face-font)
                          (:foreground    . set-face-foreground)
                          (:inverse-video . set-face-inverse-video-p)
                          (:italic        . set-face-italic-p)
                          (:stipple       . set-face-stipple)
                          (:underline     . set-face-underline-p))))
           (while properties
             (funcall (or (cdr (assq (nth 0 properties) settors)) 'ignore)
                      face (nth 1 properties))
             (setq properties (cdr (cdr properties))))))))

(put 'override-face-attributes 'lisp-indent-function 1)

(provide 'face-fns)

;;; face-fns.el ends here.
