aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-11-19 11:12:16 +0000
committerRichard M. Stallman1994-11-19 11:12:16 +0000
commit4099a32dc9944ee967eb31ea4db225c795dfaff5 (patch)
tree7f05e5eec23911d74b15607401fb9d764e8a07a6
parent5f5a1fec3cb6b6553c92ce3bf6577857b23436f1 (diff)
downloademacs-4099a32dc9944ee967eb31ea4db225c795dfaff5.tar.gz
emacs-4099a32dc9944ee967eb31ea4db225c795dfaff5.zip
(face-color-supported-p): New function.
(face-try-color-list): Use that.
-rw-r--r--lisp/faces.el77
1 files changed, 46 insertions, 31 deletions
diff --git a/lisp/faces.el b/lisp/faces.el
index 666a56c1640..a25d3c546f4 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -965,6 +965,25 @@ selected frame."
965 (set-face-font face font frame)))) 965 (set-face-font face font frame))))
966 (error nil))) 966 (error nil)))
967 967
968;; Assuming COLOR is a valid color name,
969;; return t if it can be displayed on FRAME.
970(defun face-color-supported-p (frame color background-p)
971 (or (x-display-color-p frame)
972 ;; A black-and-white display can implement these.
973 (member color '("black" "white"))
974 ;; A black-and-white display can fake these for background.
975 (and background-p
976 (member color '("gray" "gray1" "gray3")))
977 ;; A grayscale display can implement colors that are gray (more or less).
978 (and (x-display-grayscale-p frame)
979 (let* ((values (x-color-values color frame))
980 (r (nth 0 values))
981 (g (nth 1 values))
982 (b (nth 2 values)))
983 (and (< (abs (- r g)) (/ (abs (+ r g)) 20))
984 (< (abs (- g b)) (/ (abs (+ g b)) 20))
985 (< (abs (- b r)) (/ (abs (+ b r)) 20)))))))
986
968;; Use FUNCTION to store a color in FACE on FRAME. 987;; Use FUNCTION to store a color in FACE on FRAME.
969;; COLORS is either a single color or a list of colors. 988;; COLORS is either a single color or a list of colors.
970;; If it is a list, try the colors one by one until one of them 989;; If it is a list, try the colors one by one until one of them
@@ -973,41 +992,37 @@ selected frame."
973;; That can't fail, so any subsequent elements after the t are ignored. 992;; That can't fail, so any subsequent elements after the t are ignored.
974(defun face-try-color-list (function face colors frame) 993(defun face-try-color-list (function face colors frame)
975 (if (stringp colors) 994 (if (stringp colors)
976 (if (and (not (member colors '("gray" "gray1" "gray3"))) 995 (if (face-color-supported-p frame colors
977 (or (not (x-display-color-p)) 996 (eq function 'set-face-background))
978 (= (x-display-planes) 1))) 997 (funcall function face colors frame))
979 nil
980 (funcall function face colors frame))
981 (if (eq colors t) 998 (if (eq colors t)
982 (invert-face face frame) 999 (invert-face face frame)
983 (let (done) 1000 (let (done)
984 (while (and colors (not done)) 1001 (while (and colors (not done))
985 (if (and (stringp (car colors)) 1002 (if (or (eq (car colors) t)
986 (and (not (member (car colors) '("gray" "gray1" "gray3"))) 1003 (face-color-supported-p frame (car colors)
987 (or (not (x-display-color-p)) 1004 (eq function 'set-face-background)))
988 (= (x-display-planes) 1)))) 1005 (if (cdr colors)
989 nil 1006 ;; If there are more colors to try, catch errors
990 (if (cdr colors) 1007 ;; and set `done' if we succeed.
991 ;; If there are more colors to try, catch errors 1008 (condition-case nil
992 ;; and set `done' if we succeed. 1009 (progn
993 (condition-case nil 1010 (cond ((eq (car colors) t)
994 (progn 1011 (invert-face face frame))
995 (cond ((eq (car colors) t) 1012 ((eq (car colors) 'underline)
996 (invert-face face frame)) 1013 (set-face-underline-p face t frame))
997 ((eq (car colors) 'underline) 1014 (t
998 (set-face-underline-p face t frame)) 1015 (funcall function face (car colors) frame)))
999 (t 1016 (setq done t))
1000 (funcall function face (car colors) frame))) 1017 (error nil))
1001 (setq done t)) 1018 ;; If this is the last color, let the error get out if it fails.
1002 (error nil)) 1019 ;; If it succeeds, we will exit anyway after this iteration.
1003 ;; If this is the last color, let the error get out if it fails. 1020 (cond ((eq (car colors) t)
1004 ;; If it succeeds, we will exit anyway after this iteration. 1021 (invert-face face frame))
1005 (cond ((eq (car colors) t) 1022 ((eq (car colors) 'underline)
1006 (invert-face face frame)) 1023 (set-face-underline-p face t frame))
1007 ((eq (car colors) 'underline) 1024 (t
1008 (set-face-underline-p face t frame)) 1025 (funcall function face (car colors) frame)))))
1009 (t
1010 (funcall function face (car colors) frame)))))
1011 (setq colors (cdr colors))))))) 1026 (setq colors (cdr colors)))))))
1012 1027
1013;; If we are already using x-window frames, initialize faces for them. 1028;; If we are already using x-window frames, initialize faces for them.