annotate lisp/custom/cus-face.el @ 112:48d667d6f17f r20-1b8

Import from CVS: tag r20-1b8
author cvs
date Mon, 13 Aug 2007 09:20:48 +0200
parents d620409f5eb8
children c53a95d3c46d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
1 ;;; cus-face.el -- XEmacs specific custom support.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
2 ;;
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
4 ;;
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
6 ;; Keywords: help, faces
34
d620409f5eb8 Import from CVS: tag r19-15b100
cvs
parents: 32
diff changeset
7 ;; Version: 1.64
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
9
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
10 ;;; Commentary:
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
11 ;;
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
12 ;; See `custom.el'.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
13
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
14 ;;; Code:
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
15
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
16 (require 'custom)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
17
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
18 (eval-and-compile (require 'cl))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
19
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
20 ;;; Compatibility.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
21
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
22 (eval-and-compile
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
23 (unless (fboundp 'frame-property)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
24 ;; XEmacs function missing in Emacs 19.34.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
25 (defun frame-property (frame property &optional default)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
26 "Return FRAME's value for property PROPERTY."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
27 (or (cdr (assq property (frame-parameters frame)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
28 default)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
29
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
30 (unless (fboundp 'face-doc-string)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
31 ;; XEmacs function missing in Emacs.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
32 (defun face-doc-string (face)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
33 "Get the documentation string for FACE."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
34 (get face 'face-doc-string)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
35
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
36 (unless (fboundp 'set-face-doc-string)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
37 ;; XEmacs function missing in Emacs.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
38 (defun set-face-doc-string (face string)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
39 "Set the documentation string for FACE to STRING."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
40 (put face 'face-doc-string string))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
41
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
42 (unless (fboundp 'x-color-values)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
43 ;; Emacs function missing in XEmacs 19.14.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
44 (defun x-color-values (color &optional frame)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
45 "Return a description of the color named COLOR on frame FRAME.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
46 The value is a list of integer RGB values--(RED GREEN BLUE).
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
47 These values appear to range from 0 to 65280 or 65535, depending
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
48 on the system; white is (65280 65280 65280) or (65535 65535 65535).
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
49 If FRAME is omitted or nil, use the selected frame."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
50 (color-instance-rgb-components (make-color-instance color))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
51
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
52 ;; XEmacs and Emacs have different definitions of `facep'.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
53 ;; The Emacs definition is the useful one, so emulate that.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
54 (cond ((not (fboundp 'facep))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
55 (defun custom-facep (face)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
56 "No faces"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
57 nil))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
58 ((string-match "XEmacs" emacs-version)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
59 (defalias 'custom-facep 'find-face))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
60 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
61 (defalias 'custom-facep 'facep)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
62
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
63 (unless (fboundp 'make-empty-face)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
64 ;; This should be moved to `faces.el'.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
65 (if (string-match "XEmacs" emacs-version)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
66 ;; Give up for old XEmacs pre 19.15/20.1.
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
67 (defalias 'make-empty-face 'make-face)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
68 ;; Define for Emacs pre 19.35.
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
69 (defun make-empty-face (name)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
70 "Define a new FACE on all frames, ignoring X resources."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
71 (interactive "SMake face: ")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
72 (or (internal-find-face name)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
73 (let ((face (make-vector 8 nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
74 (aset face 0 'face)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
75 (aset face 1 name)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
76 (let* ((frames (frame-list))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
77 (inhibit-quit t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
78 (id (internal-next-face-id)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
79 (make-face-internal id)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
80 (aset face 2 id)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
81 (while frames
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
82 (set-frame-face-alist (car frames)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
83 (cons (cons name (copy-sequence face))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
84 (frame-face-alist (car frames))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
85 (setq frames (cdr frames)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
86 (setq global-face-data (cons (cons name face) global-face-data)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
87 ;; add to menu
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
88 (if (fboundp 'facemenu-add-new-face)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
89 (facemenu-add-new-face name))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
90 face))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
91 name)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
92
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
93 (defcustom initialize-face-resources t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
94 "If non nil, allow X resources to initialize face properties.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
95 This only affects faces declared with `defface', and only NT or X11 frames."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
96 :group 'customize
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
97 :type 'boolean)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
98
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
99 (cond ((fboundp 'initialize-face-resources)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
100 ;; Already bound, do nothing.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
101 )
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
102 ((fboundp 'make-face-x-resource-internal)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
103 ;; Emacs or new XEmacs.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
104 (defun initialize-face-resources (face &optional frame)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
105 "Initialize face according to the X11 resources.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
106 This might overwrite existing face properties.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
107 Does nothing when the variable initialize-face-resources is nil."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
108 (when initialize-face-resources
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
109 (make-face-x-resource-internal face frame t))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
110 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
111 ;; Too hard to do right on XEmacs.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
112 (defalias 'initialize-face-resources 'ignore)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
113
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
114 (if (string-match "XEmacs" emacs-version)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
115 ;; Xemacs.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
116 (defun custom-invert-face (face &optional frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
117 "Swap the foreground and background colors of face FACE.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
118 If the colors are not specified in the face, use the default colors."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
119 (interactive (list (read-face-name "Reverse face: ")))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
120 (let ((fg (color-name (face-foreground face frame) frame))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
121 (bg (color-name (face-background face frame) frame)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
122 (set-face-foreground face bg frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
123 (set-face-background face fg frame)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
124 ;; Emacs.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
125 (defun custom-invert-face (face &optional frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
126 "Swap the foreground and background colors of face FACE.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
127 If the colors are not specified in the face, use the default colors."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
128 (interactive (list (read-face-name "Reverse face: ")))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
129 (let ((fg (or (face-foreground face frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
130 (face-foreground 'default frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
131 (frame-property (or frame (selected-frame))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
132 'foreground-color)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
133 "black"))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
134 (bg (or (face-background face frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
135 (face-background 'default frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
136 (frame-property (or frame (selected-frame))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
137 'background-color)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
138 "white")))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
139 (set-face-foreground face bg frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
140 (set-face-background face fg frame))))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
141
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
142 (defcustom custom-background-mode nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
143 "The brightness of the background.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
144 Set this to the symbol dark if your background color is dark, light if
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
145 your background is light, or nil (default) if you want Emacs to
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
146 examine the brightness for you."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
147 :group 'customize
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
148 :type '(choice (choice-item dark)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
149 (choice-item light)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
150 (choice-item :tag "default" nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
151
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
152 (defun custom-background-mode (frame)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
153 "Kludge to detect background mode for FRAME."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
154 (let* ((bg-resource
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
155 (condition-case ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
156 (x-get-resource ".backgroundMode" "BackgroundMode" 'string)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
157 (error nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
158 color
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
159 (mode (cond (bg-resource
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
160 (intern (downcase bg-resource)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
161 ((and (setq color (condition-case ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
162 (or (frame-property
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
163 frame
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
164 'background-color)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
165 (color-instance-name
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
166 (specifier-instance
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
167 (face-background 'default))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
168 (error nil)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
169 (or (string-match "XEmacs" emacs-version)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
170 window-system)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
171 (< (apply '+ (x-color-values color))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
172 (/ (apply '+ (x-color-values "white"))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
173 3)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
174 'dark)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
175 (t 'light))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
176 (modify-frame-parameters frame (list (cons 'background-mode mode)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
177 mode))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
178
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
179 (eval-and-compile
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
180 (if (string-match "XEmacs" emacs-version)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
181 ;; XEmacs.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
182 (defun custom-extract-frame-properties (frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
183 "Return a plist with the frame properties of FRAME used by custom."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
184 (list 'type (device-type (frame-device frame))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
185 'class (device-class (frame-device frame))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
186 'background (or custom-background-mode
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
187 (frame-property frame
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
188 'background-mode)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
189 (custom-background-mode frame))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
190 ;; Emacs.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
191 (defun custom-extract-frame-properties (frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
192 "Return a plist with the frame properties of FRAME used by custom."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
193 (list 'type window-system
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
194 'class (frame-property frame 'display-type)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
195 'background (or custom-background-mode
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
196 (frame-property frame 'background-mode)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
197 (custom-background-mode frame))))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
198
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
199 ;;; Declaring a face.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
200
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
201 ;;;###autoload
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
202 (defun custom-declare-face (face spec doc &rest args)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
203 "Like `defface', but FACE is evaluated as a normal argument."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
204 (when (fboundp 'load-gc)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
205 ;; This should be allowed, somehow.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
206 (error "Attempt to declare a face during dump"))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
207 (unless (get face 'factory-face)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
208 (put face 'factory-face spec)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
209 (when (fboundp 'facep)
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
210 (unless (custom-facep face)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
211 ;; If the user has already created the face, respect that.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
212 (let ((value (or (get face 'saved-face) spec))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
213 (frames (custom-relevant-frames))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
214 frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
215 ;; Create global face.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
216 (make-empty-face face)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
217 (custom-face-display-set face value)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
218 ;; Create frame local faces
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
219 (while frames
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
220 (setq frame (car frames)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
221 frames (cdr frames))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
222 (custom-face-display-set face value frame))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
223 (initialize-face-resources face))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
224 (when (and doc (null (face-doc-string face)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
225 (set-face-doc-string face doc))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
226 (custom-handle-all-keywords face args 'custom-face)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
227 (run-hooks 'custom-define-hook))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
228 face)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
229
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
230 ;;; Font Attributes.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
231
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
232 (defconst custom-face-attributes
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
233 '((:bold (toggle :format "Bold: %[%v%]\n"
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
234 :help-echo "Control whether a bold font should be used.")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
235 custom-set-face-bold)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
236 (:italic (toggle :format "Italic: %[%v%]\n"
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
237 :help-echo "\
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
238 Control whether an italic font should be used.")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
239 custom-set-face-italic)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
240 (:underline (toggle :format "Underline: %[%v%]\n"
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
241 :help-echo "\
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
242 Control whether the text should be underlined.")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
243 set-face-underline-p)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
244 (:foreground (color :tag "Foreground"
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
245 :value "black"
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
246 :help-echo "Set foreground color.")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
247 set-face-foreground)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
248 (:background (color :tag "Background"
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
249 :value "white"
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
250 :help-echo "Set background color.")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
251 set-face-background)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
252 (:invert (const :format "Invert Face\n"
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
253 :sibling-args (:help-echo "\
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
254 Reverse the foreground and background color.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
255 If you haven't specified them for the face, the default colors will be used.")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
256 t)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
257 (lambda (face value &optional frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
258 ;; We don't use VALUE.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
259 (custom-invert-face face frame)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
260 (:stipple (editable-field :format "Stipple: %v"
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
261 :help-echo "Name of background bitmap file.")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
262 set-face-stipple))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
263 "Alist of face attributes.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
264
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
265 The elements are of the form (KEY TYPE SET) where KEY is a symbol
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
266 identifying the attribute, TYPE is a widget type for editing the
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
267 attibute, SET is a function for setting the attribute value.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
268
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
269 The SET function should take three arguments, the face to modify, the
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
270 value of the attribute, and optionally the frame where the face should
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
271 be changed.")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
272
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
273 (defun custom-face-attributes-set (face frame &rest atts)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
274 "For FACE on FRAME set the attributes [KEYWORD VALUE]....
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
275 Each keyword should be listed in `custom-face-attributes'.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
276
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
277 If FRAME is nil, set the default face."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
278 (while atts
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
279 (let* ((name (nth 0 atts))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
280 (value (nth 1 atts))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
281 (fun (nth 2 (assq name custom-face-attributes))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
282 (setq atts (cdr (cdr atts)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
283 (condition-case nil
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
284 (funcall fun face value frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
285 (error nil)))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
286
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
287 (defun custom-set-face-bold (face value &optional frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
288 "Set the bold property of FACE to VALUE."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
289 (if value
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
290 (make-face-bold face frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
291 (make-face-unbold face frame)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
292
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
293 (defun custom-set-face-italic (face value &optional frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
294 "Set the italic property of FACE to VALUE."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
295 (if value
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
296 (make-face-italic face frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
297 (make-face-unitalic face frame)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
298
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
299 (when (string-match "XEmacs" emacs-version)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
300 ;; Support for special XEmacs font attributes.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
301 (autoload 'font-create-object "font" nil)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
302
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
303 (unless (fboundp 'face-font-name)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
304 (defun face-font-name (face &rest args)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
305 (apply 'face-font face args)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
306
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
307 (defun custom-set-face-font-size (face size &rest args)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
308 "Set the font of FACE to SIZE"
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
309 (let* ((font (apply 'face-font-name face args))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
310 (fontobj (font-create-object font)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
311 (set-font-size fontobj size)
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
312 (apply 'font-set-face-font face fontobj args)))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
313
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
314 (defun custom-set-face-font-family (face family &rest args)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
315 "Set the font of FACE to FAMILY"
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
316 (let* ((font (apply 'face-font-name face args))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
317 (fontobj (font-create-object font)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
318 (set-font-family fontobj family)
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
319 (apply 'font-set-face-font face fontobj args)))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
320
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
321 (nconc custom-face-attributes
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
322 '((:family (editable-field :format "Font Family: %v"
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
323 :help-echo "\
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
324 Name of font family to use (e.g. times).")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
325 custom-set-face-font-family)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
326 (:size (editable-field :format "Size: %v"
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
327 :help-echo "\
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
328 Text size (e.g. 9pt or 2mm).")
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
329 custom-set-face-font-size))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
330
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
331 ;;; Frames.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
332
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
333 (defun custom-face-display-set (face spec &optional frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
334 "Set FACE to the attributes to the first matching entry in SPEC.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
335 Iff optional FRAME is non-nil, set it for that frame only.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
336 See `defface' for information about SPEC."
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
337 (when (fboundp 'make-face)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
338 (while spec
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
339 (let* ((entry (car spec))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
340 (display (nth 0 entry))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
341 (atts (nth 1 entry)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
342 (setq spec (cdr spec))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
343 (when (custom-display-match-frame display frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
344 ;; Avoid creating frame local duplicates of the global face.
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
345 (unless (and frame (eq display (get face 'custom-face-display)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
346 (apply 'custom-face-attributes-set face frame atts))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
347 (unless frame
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
348 (put face 'custom-face-display display))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
349 (setq spec nil))))))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
350
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
351 (defvar custom-default-frame-properties nil
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
352 "The frame properties used for the global faces.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
353 Frames who doesn't match these propertiess should have frame local faces.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
354 The value should be nil, if uninitialized, or a plist otherwise.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
355 See `defface' for a list of valid keys and values for the plist.")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
356
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
357 (defun custom-get-frame-properties (&optional frame)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
358 "Return a plist with the frame properties of FRAME used by custom.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
359 If FRAME is nil, return the default frame properties."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
360 (cond (frame
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
361 ;; Try to get from cache.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
362 (let ((cache (frame-property frame 'custom-properties)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
363 (unless cache
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
364 ;; Oh well, get it then.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
365 (setq cache (custom-extract-frame-properties frame))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
366 ;; and cache it...
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
367 (modify-frame-parameters frame
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
368 (list (cons 'custom-properties cache))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
369 cache))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
370 (custom-default-frame-properties)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
371 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
372 (setq custom-default-frame-properties
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
373 (custom-extract-frame-properties (selected-frame))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
374
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
375 (defun custom-display-match-frame (display frame)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
376 "Non-nil iff DISPLAY matches FRAME.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
377 If FRAME is nil, the current FRAME is used."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
378 ;; This is a kludge to get started, we really should use specifiers!
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
379 (if (eq display t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
380 t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
381 (let* ((props (custom-get-frame-properties frame))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
382 (type (plist-get props 'type))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
383 (class (plist-get props 'class))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
384 (background (plist-get props 'background))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
385 (match t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
386 (entries display)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
387 entry req options)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
388 (while (and entries match)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
389 (setq entry (car entries)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
390 entries (cdr entries)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
391 req (car entry)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
392 options (cdr entry)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
393 match (cond ((eq req 'type)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
394 (memq type options))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
395 ((eq req 'class)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
396 (memq class options))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
397 ((eq req 'background)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
398 (memq background options))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
399 (t
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
400 (error "Unknown req `%S' with options `%S'"
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
401 req options)))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
402 match)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
403
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
404 (defun custom-relevant-frames ()
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
405 "List of frames whose custom properties differ from the default."
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
406 (let ((relevant nil)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
407 (default (custom-get-frame-properties))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
408 (frames (frame-list))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
409 frame)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
410 (while frames
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
411 (setq frame (car frames)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
412 frames (cdr frames))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
413 (unless (equal default (custom-get-frame-properties frame))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
414 (push frame relevant)))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
415 relevant))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
416
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
417 (defun custom-initialize-faces (&optional frame)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
418 "Initialize all custom faces for FRAME.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
419 If FRAME is nil or omitted, initialize them for all frames."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
420 (mapcar (lambda (symbol)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
421 (let ((spec (or (get symbol 'saved-face)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
422 (get symbol 'factory-face))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
423 (when spec
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
424 (custom-face-display-set symbol spec frame)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
425 (initialize-face-resources symbol frame))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
426 (face-list)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
427
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
428 (defun custom-initialize-frame (&optional frame)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
429 "Initialize local faces for FRAME if necessary.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
430 If FRAME is missing or nil, the first member (frame-list) is used."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
431 (unless frame
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
432 (setq frame (car (frame-list))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
433 (unless (equal (custom-get-frame-properties)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
434 (custom-get-frame-properties frame))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
435 (custom-initialize-faces frame)))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
436
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
437 ;; Enable. This should go away when bundled with Emacs.
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
438 (unless (string-match "XEmacs" emacs-version)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
439 (add-hook 'after-make-frame-hook 'custom-initialize-frame))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
440
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
441 ;;; Initializing.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
442
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
443 (and (fboundp 'make-face)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
444 (make-face 'custom-face-empty))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
445
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
446 ;;;###autoload
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
447 (defun custom-set-faces (&rest args)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
448 "Initialize faces according to user preferences.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
449 The arguments should be a list where each entry has the form:
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
450
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
451 (FACE SPEC [NOW])
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
452
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
453 SPEC will be stored as the saved value for FACE. If NOW is present
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
454 and non-nil, FACE will also be created according to SPEC.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
455
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
456 See `defface' for the format of SPEC."
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
457 (while args
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
458 (let ((entry (car args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
459 (if (listp entry)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
460 (let ((face (nth 0 entry))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
461 (spec (nth 1 entry))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
462 (now (nth 2 entry)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
463 (put face 'saved-face spec)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
464 (when now
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
465 (put face 'force-face t))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
466 (when (or now (custom-facep face))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
467 (when (fboundp 'copy-face)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
468 (copy-face 'custom-face-empty face))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
469 (custom-face-display-set face spec))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
470 (setq args (cdr args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
471 ;; Old format, a plist of FACE SPEC pairs.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
472 (let ((face (nth 0 args))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
473 (spec (nth 1 args)))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
474 (put face 'saved-face spec))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
475 (setq args (cdr (cdr args)))))))
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
476
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
477 ;;; The End.
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
478
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
479 (provide 'cus-face)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
480
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents:
diff changeset
481 ;; cus-face.el ends here