]> code.delx.au - gnu-emacs/blob - lisp/faces.el
Re-arranged stuff to put defsubst accessors at the top
[gnu-emacs] / lisp / faces.el
1 ;;; faces.el --- Lisp interface to the c "face" structure
2
3 ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc.
4
5 ;; This file is part of GNU Emacs.
6
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; any later version.
11
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 ;;; Commentary:
22
23 ;; Mostly derived from Lucid.
24
25 ;;; Code:
26
27 \f
28 ;;;; Functions for manipulating face vectors.
29
30 ;;; A face vector is a vector of the form:
31 ;;; [face ID FONT FOREGROUND BACKGROUND BACKGROUND-PIXMAP UNDERLINE]
32
33 ;;; Type checkers.
34 (defsubst internal-facep (x)
35 (and (vectorp x) (= (length x) 8) (eq (aref x 0) 'face)))
36
37 (defmacro internal-check-face (face)
38 (` (while (not (internal-facep (, face)))
39 (setq (, face) (signal 'wrong-type-argument (list 'internal-facep (, face)))))))
40
41 ;;; Accessors.
42 (defsubst face-name (face)
43 "Return the name of face FACE."
44 (aref (internal-get-face face) 1))
45
46 (defsubst face-id (face)
47 "Return the internal ID number of face FACE."
48 (aref (internal-get-face face) 2))
49
50 (defsubst face-font (face &optional frame)
51 "Return the font name of face FACE, or nil if it is unspecified.
52 If the optional argument FRAME is given, report on face FACE in that frame.
53 Otherwise report on the defaults for face FACE (for new frames)."
54 (aref (internal-get-face face frame) 3))
55
56 (defsubst face-foreground (face &optional frame)
57 "Return the foreground color name of face FACE, or nil if unspecified.
58 If the optional argument FRAME is given, report on face FACE in that frame.
59 Otherwise report on the defaults for face FACE (for new frames)."
60 (aref (internal-get-face face frame) 4))
61
62 (defsubst face-background (face &optional frame)
63 "Return the background color name of face FACE, or nil if unspecified.
64 If the optional argument FRAME is given, report on face FACE in that frame.
65 Otherwise report on the defaults for face FACE (for new frames)."
66 (aref (internal-get-face face frame) 5))
67
68 (defsubst face-background-pixmap (face &optional frame)
69 "Return the background pixmap name of face FACE, or nil if unspecified.
70 If the optional argument FRAME is given, report on face FACE in that frame.
71 Otherwise report on the defaults for face FACE (for new frames)."
72 (aref (internal-get-face face frame) 6))
73
74 (defsubst face-underline-p (face &optional frame)
75 "Return t if face FACE is underlined.
76 If the optional argument FRAME is given, report on face FACE in that frame.
77 Otherwise report on the defaults for face FACE (for new frames)."
78 (aref (internal-get-face face frame) 7))
79
80 \f
81 ;;; Mutators.
82
83 (defsubst set-face-font (face font &optional frame)
84 "Change the font of face FACE to FONT (a string).
85 If the optional FRAME argument is provided, change only
86 in that frame; otherwise change each frame."
87 (interactive (internal-face-interactive "font"))
88 (internal-set-face-1 face 'font font 3 frame))
89
90 (defsubst set-face-foreground (face color &optional frame)
91 "Change the foreground color of face FACE to COLOR (a string).
92 If the optional FRAME argument is provided, change only
93 in that frame; otherwise change each frame."
94 (interactive (internal-face-interactive "foreground"))
95 (internal-set-face-1 face 'foreground color 4 frame))
96
97 (defsubst set-face-background (face color &optional frame)
98 "Change the background color of face FACE to COLOR (a string).
99 If the optional FRAME argument is provided, change only
100 in that frame; otherwise change each frame."
101 (interactive (internal-face-interactive "background"))
102 (internal-set-face-1 face 'background color 5 frame))
103
104 (defsubst set-face-background-pixmap (face name &optional frame)
105 "Change the background pixmap of face FACE to PIXMAP.
106 PIXMAP should be a string, the name of a file of pixmap data.
107 The directories listed in the `x-bitmap-file-path' variable are searched.
108
109 Alternatively, PIXMAP may be a list of the form (WIDTH HEIGHT DATA)
110 where WIDTH and HEIGHT are the size in pixels,
111 and DATA is a string, containing the raw bits of the bitmap.
112
113 If the optional FRAME argument is provided, change only
114 in that frame; otherwise change each frame."
115 (interactive (internal-face-interactive "background-pixmap"))
116 (internal-set-face-1 face 'background-pixmap name 6 frame))
117
118 (defsubst set-face-underline-p (face underline-p &optional frame)
119 "Specify whether face FACE is underlined. (Yes if UNDERLINE-P is non-nil.)
120 If the optional FRAME argument is provided, change only
121 in that frame; otherwise change each frame."
122 (interactive (internal-face-interactive "underline-p" "underlined"))
123 (internal-set-face-1 face 'underline underline-p 7 frame))
124
125 \f
126 ;;;; Associating face names (symbols) with their face vectors.
127
128 (defvar global-face-data nil "do not use this")
129
130 (defun face-list ()
131 "Returns a list of all defined face names."
132 (mapcar 'car global-face-data))
133
134 (defun internal-find-face (name &optional frame)
135 "Retrieve the face named NAME. Return nil if there is no such face.
136 If the optional argument FRAME is given, this gets the face NAME for
137 that frame; otherwise, it uses the selected frame.
138 If FRAME is the symbol t, then the global, non-frame face is returned.
139 If NAME is already a face, it is simply returned."
140 (if (and (eq frame t) (not (symbolp name)))
141 (setq name (face-name name)))
142 (if (symbolp name)
143 (cdr (assq name
144 (if (eq frame t)
145 global-face-data
146 (frame-face-alist (or frame (selected-frame))))))
147 (internal-check-face name)
148 name))
149
150 (defun internal-get-face (name &optional frame)
151 "Retrieve the face named NAME; error if there is none.
152 If the optional argument FRAME is given, this gets the face NAME for
153 that frame; otherwise, it uses the selected frame.
154 If FRAME is the symbol t, then the global, non-frame face is returned.
155 If NAME is already a face, it is simply returned."
156 (or (internal-find-face name frame)
157 (internal-check-face name)))
158
159
160 (defun internal-set-face-1 (face name value index frame)
161 (let ((inhibit-quit t))
162 (if (null frame)
163 (let ((frames (frame-list)))
164 (while frames
165 (internal-set-face-1 (face-name face) name value index (car frames))
166 (setq frames (cdr frames)))
167 (aset (internal-get-face (if (symbolp face) face (face-name face)) t)
168 index value)
169 value)
170 (or (eq frame t)
171 (set-face-attribute-internal (face-id face) name value frame))
172 (aset (internal-get-face face frame) index value))))
173
174
175 (defun read-face-name (prompt)
176 (let (face)
177 (while (= (length face) 0)
178 (setq face (completing-read prompt
179 (mapcar '(lambda (x) (list (symbol-name x)))
180 (face-list))
181 nil t)))
182 (intern face)))
183
184 (defun internal-face-interactive (what &optional bool)
185 (let* ((fn (intern (concat "face-" what)))
186 (prompt (concat "Set " what " of face"))
187 (face (read-face-name (concat prompt ": ")))
188 (default (if (fboundp fn)
189 (or (funcall fn face (selected-frame))
190 (funcall fn 'default (selected-frame)))))
191 (value (if bool
192 (y-or-n-p (concat "Should face " (symbol-name face)
193 " be " bool "? "))
194 (read-string (concat prompt " " (symbol-name face) " to: ")
195 default))))
196 (list face (if (equal value "") nil value))))
197
198
199
200 (defun make-face (name)
201 "Define a new FACE on all frames.
202 You can modify the font, color, etc of this face with the set-face- functions.
203 If the face already exists, it is unmodified."
204 (or (internal-find-face name)
205 (let ((face (make-vector 8 nil)))
206 (aset face 0 'face)
207 (aset face 1 name)
208 (let* ((frames (frame-list))
209 (inhibit-quit t)
210 (id (internal-next-face-id)))
211 (make-face-internal id)
212 (aset face 2 id)
213 (while frames
214 (set-frame-face-alist (car frames)
215 (cons (cons name (copy-sequence face))
216 (frame-face-alist (car frames))))
217 (setq frames (cdr frames)))
218 (setq global-face-data (cons (cons name face) global-face-data)))
219 ;; when making a face after frames already exist
220 (if (eq window-system 'x)
221 (make-face-x-resource-internal face))
222 face)))
223
224 ;; Fill in a face by default based on X resources, for all existing frames.
225 ;; This has to be done when a new face is made.
226 (defun make-face-x-resource-internal (face &optional frame set-anyway)
227 (cond ((null frame)
228 (let ((frames (frame-list)))
229 (while frames
230 (make-face-x-resource-internal (face-name face)
231 (car frames) set-anyway)
232 (setq frames (cdr frames)))))
233 (t
234 (setq face (internal-get-face (face-name face) frame))
235 ;;
236 ;; These are things like "attributeForeground" instead of simply
237 ;; "foreground" because people tend to do things like "*foreground",
238 ;; which would cause all faces to be fully qualified, making faces
239 ;; inherit attributes in a non-useful way. So we've made them slightly
240 ;; less obvious to specify in order to make them work correctly in
241 ;; more random environments.
242 ;;
243 ;; I think these should be called "face.faceForeground" instead of
244 ;; "face.attributeForeground", but they're the way they are for
245 ;; hysterical reasons.
246 ;;
247 (let* ((name (symbol-name (face-name face)))
248 (fn (or (x-get-resource (concat name ".attributeFont")
249 "Face.AttributeFont")
250 (and set-anyway (face-font face))))
251 (fg (or (x-get-resource (concat name ".attributeForeground")
252 "Face.AttributeForeground")
253 (and set-anyway (face-foreground face))))
254 (bg (or (x-get-resource (concat name ".attributeBackground")
255 "Face.AttributeBackground")
256 (and set-anyway (face-background face))))
257 ;; (bgp (or (x-get-resource (concat name ".attributeBackgroundPixmap")
258 ;; "Face.AttributeBackgroundPixmap")
259 ;; (and set-anyway (face-background-pixmap face))))
260 (ulp (or (x-get-resource (concat name ".attributeUnderline")
261 "Face.AttributeUnderline")
262 (and set-anyway (face-underline-p face))))
263 )
264 (if fn
265 (condition-case ()
266 (set-face-font face fn frame)
267 (error (message "font `%s' not found for face `%s'" fn name))))
268 (if fg
269 (condition-case ()
270 (set-face-foreground face fg frame)
271 (error (message "color `%s' not allocated for face `%s'" fg name))))
272 (if bg
273 (condition-case ()
274 (set-face-background face bg frame)
275 (error (message "color `%s' not allocated for face `%s'" bg name))))
276 ;; (if bgp
277 ;; (condition-case ()
278 ;; (set-face-background-pixmap face bgp frame)
279 ;; (error (message "pixmap `%s' not found for face `%s'" bgp name))))
280 (if (or ulp set-anyway)
281 (set-face-underline-p face ulp frame))
282 )))
283 face)
284
285 (defun copy-face (old-face new-name &optional frame)
286 "Define a face just like OLD-FACE, with name NEW-NAME.
287 If NEW-NAME already exists as a face, it is modified to be like OLD-FACE.
288 If the optional argument FRAME is given, this applies only to that frame.
289 Otherwise it applies to each frame separately."
290 (setq old-face (internal-get-face old-face frame))
291 (let* ((inhibit-quit t)
292 (new-face (or (internal-find-face new-name frame)
293 (make-face new-name))))
294 (if (null frame)
295 (let ((frames (frame-list)))
296 (while frames
297 (copy-face old-face new-name (car frames))
298 (setq frames (cdr frames)))
299 (copy-face old-face new-name t))
300 (set-face-font new-face (face-font old-face frame) frame)
301 (set-face-foreground new-face (face-foreground old-face frame) frame)
302 (set-face-background new-face (face-background old-face frame) frame)
303 (set-face-background-pixmap
304 new-face (face-background-pixmap old-face frame) frame)
305 (set-face-underline-p new-face (face-underline-p old-face frame)
306 frame))
307 new-face))
308
309 (defun face-equal (face1 face2 &optional frame)
310 "True if the faces FACE1 and FACE2 display in the the same way."
311 (setq face1 (internal-get-face face1 frame)
312 face2 (internal-get-face face2 frame))
313 (and (equal (face-foreground face1 frame) (face-foreground face2 frame))
314 (equal (face-background face1 frame) (face-background face2 frame))
315 (equal (face-font face1 frame) (face-font face2 frame))
316 (equal (face-background-pixmap face1 frame)
317 (face-background-pixmap face2 frame))))
318
319 (defun face-differs-from-default-p (face &optional frame)
320 "True if face FACE displays differently from the default face, on FRAME.
321 A face is considered to be ``the same'' as the default face if it is
322 actually specified in the same way (equivalent fonts, etc) or if it is
323 fully unspecified, and thus inherits the attributes of any face it
324 is displayed on top of."
325 (let ((default (internal-get-face 'default frame)))
326 (setq face (internal-get-face face frame))
327 (not (and (or (equal (face-foreground default frame)
328 (face-foreground face frame))
329 (null (face-foreground face frame)))
330 (or (equal (face-background default frame)
331 (face-background face frame))
332 (null (face-background face frame)))
333 (or (equal (face-font default frame) (face-font face frame))
334 (null (face-font face frame)))
335 (or (equal (face-background-pixmap default frame)
336 (face-background-pixmap face frame))
337 (null (face-background-pixmap face frame)))
338 (equal (face-underline-p default frame)
339 (face-underline-p face frame))
340 ))))
341
342
343 (defun invert-face (face &optional frame)
344 "Swap the foreground and background colors of face FACE.
345 If the face doesn't specify both foreground and background, then
346 its foreground and background are set to the background and
347 foreground of the default face."
348 (interactive (list (read-face-name "Invert face: ")))
349 (setq face (internal-get-face face frame))
350 (let ((fg (face-foreground face frame))
351 (bg (face-background face frame)))
352 (if (or fg bg)
353 (progn
354 (set-face-foreground face bg frame)
355 (set-face-background face fg frame))
356 (set-face-foreground face (face-background 'default frame) frame)
357 (set-face-background face (face-foreground 'default frame) frame)))
358 face)
359
360
361 (defun internal-try-face-font (face font &optional frame)
362 "Like set-face-font, but returns nil on failure instead of an error."
363 (condition-case ()
364 (set-face-font face font frame)
365 (error nil)))
366
367
368 (defun set-default-font (font)
369 "Sets the font used for normal text and the modeline to FONT in all frames.
370 For finer-grained control, use set-face-font."
371 (interactive (list (read-string "Set default font: "
372 (face-font 'default (selected-frame)))))
373 (set-face-font 'default font)
374 (set-face-font 'modeline font))
375 \f
376 ;; Manipulating font names.
377
378 (defconst x-font-regexp nil)
379 (defconst x-font-regexp-head nil)
380 (defconst x-font-regexp-weight nil)
381 (defconst x-font-regexp-slant nil)
382
383 ;;; Regexps matching font names in "Host Portable Character Representation."
384 ;;;
385 (let ((- "[-?]")
386 (foundry "[^-]+")
387 (family "[^-]+")
388 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
389 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
390 (weight\? "\\([^-]*\\)") ; 1
391 (slant "\\([ior]\\)") ; 2
392 ; (slant\? "\\([ior?*]?\\)") ; 2
393 (slant\? "\\([^-]?\\)") ; 2
394 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
395 (swidth "\\([^-]*\\)") ; 3
396 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
397 (adstyle "[^-]*") ; 4
398 (pixelsize "[0-9]+")
399 (pointsize "[0-9][0-9]+")
400 (resx "[0-9][0-9]+")
401 (resy "[0-9][0-9]+")
402 (spacing "[cmp?*]")
403 (avgwidth "[0-9]+")
404 (registry "[^-]+")
405 (encoding "[^-]+")
406 )
407 (setq x-font-regexp
408 (concat "\\`\\*?[-?*]"
409 foundry - family - weight\? - slant\? - swidth - adstyle -
410 pixelsize - pointsize - resx - resy - spacing - registry -
411 encoding "[-?*]\\*?\\'"
412 ))
413 (setq x-font-regexp-head
414 (concat "\\`[-?*]" foundry - family - weight\? - slant\?
415 "\\([-*?]\\|\\'\\)"))
416 (setq x-font-regexp-slant (concat - slant -))
417 (setq x-font-regexp-weight (concat - weight -))
418 nil)
419
420 (defun x-frob-font-weight (font which)
421 (if (or (string-match x-font-regexp font)
422 (string-match x-font-regexp-head font)
423 (string-match x-font-regexp-weight font))
424 (concat (substring font 0 (match-beginning 1)) which
425 (substring font (match-end 1)))
426 nil))
427
428 (defun x-frob-font-slant (font which)
429 (cond ((or (string-match x-font-regexp font)
430 (string-match x-font-regexp-head font))
431 (concat (substring font 0 (match-beginning 2)) which
432 (substring font (match-end 2))))
433 ((string-match x-font-regexp-slant font)
434 (concat (substring font 0 (match-beginning 1)) which
435 (substring font (match-end 1))))
436 (t nil)))
437
438
439 (defun x-make-font-bold (font)
440 "Given an X font specification, this attempts to make a `bold' version
441 of it. If it fails, it returns nil."
442 (x-frob-font-weight font "bold"))
443
444 (defun x-make-font-demibold (font)
445 "Given an X font specification, this attempts to make a `demibold' version
446 of it. If it fails, it returns nil."
447 (x-frob-font-weight font "demibold"))
448
449 (defun x-make-font-unbold (font)
450 "Given an X font specification, this attempts to make a non-bold version
451 of it. If it fails, it returns nil."
452 (x-frob-font-weight font "medium"))
453
454 (defun x-make-font-italic (font)
455 "Given an X font specification, this attempts to make an `italic' version
456 of it. If it fails, it returns nil."
457 (x-frob-font-slant font "i"))
458
459 (defun x-make-font-oblique (font) ; you say tomayto...
460 "Given an X font specification, this attempts to make an `italic' version
461 of it. If it fails, it returns nil."
462 (x-frob-font-slant font "o"))
463
464 (defun x-make-font-unitalic (font)
465 "Given an X font specification, this attempts to make a non-italic version
466 of it. If it fails, it returns nil."
467 (x-frob-font-slant font "r"))
468
469 \f
470 ;;; non-X-specific interface
471
472 (defun make-face-bold (face &optional frame noerror)
473 "Make the font of the given face be bold, if possible.
474 If NOERROR is non-nil, return nil on failure."
475 (interactive (list (read-face-name "Make which face bold: ")))
476 (let ((ofont (face-font face frame))
477 font f2)
478 (if (null frame)
479 (let ((frames (frame-list)))
480 (while frames
481 (make-face-bold face (car frames))
482 (setq frames (cdr frames))))
483 (setq face (internal-get-face face frame))
484 (setq font (or (face-font face frame)
485 (face-font face t)
486 (face-font 'default frame)
487 (cdr (assq 'font (frame-parameters frame)))))
488 (or (and (setq f2 (x-make-font-bold font))
489 (internal-try-face-font face f2))
490 (and (setq f2 (x-make-font-demibold font))
491 (internal-try-face-font face f2))))
492 (or (not (equal ofont (face-font face)))
493 (and (not noerror)
494 (error "No %s version of %S" face ofont)))))
495
496 (defun make-face-italic (face &optional frame noerror)
497 "Make the font of the given face be italic, if possible.
498 If NOERROR is non-nil, return nil on failure."
499 (interactive (list (read-face-name "Make which face italic: ")))
500 (let ((ofont (face-font face frame))
501 font f2)
502 (if (null frame)
503 (let ((frames (frame-list)))
504 (while frames
505 (make-face-italic face (car frames))
506 (setq frames (cdr frames))))
507 (setq face (internal-get-face face frame))
508 (setq font (or (face-font face frame)
509 (face-font face t)
510 (face-font 'default frame)
511 (cdr (assq 'font (frame-parameters frame)))))
512 (or (and (setq f2 (x-make-font-italic font))
513 (internal-try-face-font face f2))
514 (and (setq f2 (x-make-font-oblique font))
515 (internal-try-face-font face f2))))
516 (or (not (equal ofont (face-font face)))
517 (and (not noerror)
518 (error "No %s version of %S" face ofont)))))
519
520 (defun make-face-bold-italic (face &optional frame noerror)
521 "Make the font of the given face be bold and italic, if possible.
522 If NOERROR is non-nil, return nil on failure."
523 (interactive (list (read-face-name "Make which face bold-italic: ")))
524 (let ((ofont (face-font face frame))
525 font f2 f3)
526 (if (null frame)
527 (let ((frames (frame-list)))
528 (while frames
529 (make-face-bold-italic face (car frames))
530 (setq frames (cdr frames))))
531 (setq face (internal-get-face face frame))
532 (setq font (or (face-font face frame)
533 (face-font face t)
534 (face-font 'default frame)
535 (cdr (assq 'font (frame-parameters frame)))))
536 (or (and (setq f2 (x-make-font-italic font))
537 (not (equal font f2))
538 (setq f3 (x-make-font-bold f2))
539 (not (equal f2 f3))
540 (internal-try-face-font face f3))
541 (and (setq f2 (x-make-font-oblique font))
542 (not (equal font f2))
543 (setq f3 (x-make-font-bold f2))
544 (not (equal f2 f3))
545 (internal-try-face-font face f3))
546 (and (setq f2 (x-make-font-italic font))
547 (not (equal font f2))
548 (setq f3 (x-make-font-demibold f2))
549 (not (equal f2 f3))
550 (internal-try-face-font face f3))
551 (and (setq f2 (x-make-font-oblique font))
552 (not (equal font f2))
553 (setq f3 (x-make-font-demibold f2))
554 (not (equal f2 f3))
555 (internal-try-face-font face f3))))
556 (or (not (equal ofont (face-font face)))
557 (and (not noerror)
558 (error "No %s version of %S" face ofont)))))
559
560 (defun make-face-unbold (face &optional frame noerror)
561 "Make the font of the given face be non-bold, if possible.
562 If NOERROR is non-nil, return nil on failure."
563 (interactive (list (read-face-name "Make which face non-bold: ")))
564 (let ((ofont (face-font face frame))
565 font font1)
566 (if (null frame)
567 (let ((frames (frame-list)))
568 (while frames
569 (make-face-unbold face (car frames))
570 (setq frames (cdr frames))))
571 (setq face (internal-get-face face frame))
572 (setq font1 (or (face-font face frame)
573 (face-font face t)
574 (face-font 'default frame)
575 (cdr (assq 'font (frame-parameters frame)))))
576 (setq font (x-make-font-unbold font1))
577 (if font (internal-try-face-font face font)))
578 (or (not (equal ofont (face-font face)))
579 (and (not noerror)
580 (error "No %s version of %S" face ofont)))))
581
582 (defun make-face-unitalic (face &optional frame noerror)
583 "Make the font of the given face be non-italic, if possible.
584 If NOERROR is non-nil, return nil on failure."
585 (interactive (list (read-face-name "Make which face non-italic: ")))
586 (let ((ofont (face-font face frame))
587 font font1)
588 (if (null frame)
589 (let ((frames (frame-list)))
590 (while frames
591 (make-face-unitalic face (car frames))
592 (setq frames (cdr frames))))
593 (setq face (internal-get-face face frame))
594 (setq font1 (or (face-font face frame)
595 (face-font face t)
596 (face-font 'default frame)
597 (cdr (assq 'font (frame-parameters frame)))))
598 (setq font (x-make-font-unitalic font1))
599 (if font (internal-try-face-font face font)))
600 (or (not (equal ofont (face-font face)))
601 (and (not noerror)
602 (error "No %s version of %S" face ofont)))))
603 \f
604 ;;; Make the builtin faces; the C code knows these as faces 0, 1, and 2,
605 ;;; respectively, so they must be the first three faces made.
606
607 (if (internal-find-face 'default)
608 nil
609 (make-face 'default)
610 (make-face 'modeline)
611 (make-face 'highlight)
612 ;;
613 ;; These aren't really special in any way, but they're nice to have around.
614 ;; The X-specific code is clever at them.
615 ;;
616 (make-face 'bold)
617 (make-face 'italic)
618 (make-face 'bold-italic)
619 (make-face 'primary-selection)
620 (make-face 'secondary-selection))
621 \f
622 ;;; This really belongs in setting a frame's own font.
623 ;;; ;;
624 ;;; ;; No font specified in the resource database; try to cope.
625 ;;; ;;
626 ;;; (internal-try-face-font default "-*-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-*"
627 ;;; frame)
628 ;;; (internal-try-face-font default "-*-courier-*-r-*-*-*-120-*-*-*-*-iso8859-*"
629 ;;; frame)
630 ;;; (internal-try-face-font default "-*-*-medium-r-*-*-*-120-*-*-m-*-iso8859-*" frame)
631 ;;; (internal-try-face-font default "-*-*-medium-r-*-*-*-120-*-*-c-*-iso8859-*" frame)
632 ;;; (internal-try-face-font default "-*-*-*-r-*-*-*-120-*-*-m-*-iso8859-*" frame)
633 ;;; (internal-try-face-font default "-*-*-*-r-*-*-*-120-*-*-c-*-iso8859-*" frame)
634 ;;; (internal-try-face-font default "-*-*-*-r-*-*-*-120-*-*-*-*-iso8859-*" frame)
635
636
637 ;;; This is called from make-screen-initial-faces to make sure that the
638 ;;; "default" and "modeline" faces for this screen have enough attributes
639 ;;; specified for emacs to be able to display anything on it. This had
640 ;;; better not signal an error.
641 ;;;
642 (defun x-initialize-frame-faces (frame)
643 (or (face-differs-from-default-p 'bold frame)
644 (make-face-bold 'bold frame t)
645 ;; if default font is bold, then make the `bold' face be unbold.
646 (make-face-unbold 'bold frame t)
647 ;; otherwise the luser specified one of the bogus font names
648 (internal-x-complain-about-font 'bold frame)
649 )
650
651 (or (face-differs-from-default-p 'italic frame)
652 (make-face-italic 'italic frame t)
653 (progn
654 (make-face-bold 'italic frame t)
655 (internal-x-complain-about-font 'italic frame))
656 )
657
658 (or (face-differs-from-default-p 'bold-italic frame)
659 (make-face-bold-italic 'bold-italic frame t)
660 ;; if we couldn't get a bold-italic version, try just bold.
661 (make-face-bold 'bold-italic frame t)
662 ;; if we couldn't get bold or bold-italic, then that's probably because
663 ;; the default font is bold, so make the `bold-italic' face be unbold.
664 (and (make-face-unbold 'bold-italic frame t)
665 (make-face-italic 'bold-italic frame t))
666 ;; if that didn't work, try italic (can this ever happen? what the hell.)
667 (progn
668 (make-face-italic 'bold-italic frame t)
669 ;; then bitch and moan.
670 (internal-x-complain-about-font 'bold-italic frame))
671 )
672
673 (or (face-differs-from-default-p 'highlight frame)
674 (condition-case ()
675 (if (x-display-color-p)
676 (condition-case ()
677 (set-face-background 'highlight "darkseagreen2" frame)
678 (error (set-face-background 'highlight "green" frame)))
679 (set-face-background-pixmap 'highlight "gray1" frame)
680 )
681 (error (invert-face 'highlight frame))))
682
683 (or (face-differs-from-default-p 'primary-selection frame)
684 (condition-case ()
685 (if (x-display-color-p)
686 (set-face-background 'primary-selection "gray" frame)
687 (set-face-background-pixmap 'primary-selection "gray3" frame)
688 )
689 (error (invert-face 'primary-selection frame))))
690
691 (or (face-differs-from-default-p 'secondary-selection frame)
692 (condition-case ()
693 (if (x-display-color-p)
694 (condition-case ()
695 ;; some older X servers don't have this one.
696 (set-face-background 'secondary-selection "paleturquoise"
697 frame)
698 (error
699 (set-face-background 'secondary-selection "green" frame)))
700 (set-face-background-pixmap 'secondary-selection "gray1" frame)
701 )
702 (error (invert-face 'secondary-selection frame))))
703 )
704
705 (defun internal-x-complain-about-font (face frame)
706 (message "No %s version of %S"
707 face
708 (or (face-font face frame)
709 (face-font face t)
710 (face-font 'default frame)
711 (cdr (assq 'font (frame-parameters frame)))))
712 (sit-for 1))
713 \f
714 ;; Like x-create-frame but also set up the faces.
715
716 (defun x-create-frame-with-faces (&optional parameters)
717 (let* ((frame (x-create-frame parameters))
718 (faces (copy-alist global-face-data))
719 (rest faces)
720 default modeline)
721 (set-frame-face-alist frame faces)
722
723 ;; Copy the vectors that represent the faces.
724 ;; Also fill them in from X resources.
725 (while rest
726 (setcdr (car rest) (copy-sequence (cdr (car rest))))
727 (make-face-x-resource-internal (cdr (car rest)) frame t)
728 (setq rest (cdr rest)))
729
730 (setq default (internal-get-face 'default frame)
731 modeline (internal-get-face 'modeline frame))
732
733 (x-initialize-frame-faces frame)
734
735 ;;; ;; Make sure the modeline face is fully qualified.
736 ;;; (if (and (not (face-font modeline frame)) (face-font default frame))
737 ;;; (set-face-font modeline (face-font default frame) frame))
738 ;;; (if (and (not (face-background modeline frame))
739 ;;; (face-background default frame))
740 ;;; (set-face-background modeline (face-background default frame) frame))
741 ;;; (if (and (not (face-foreground modeline frame))
742 ;;; (face-foreground default frame))
743 ;;; (set-face-foreground modeline (face-foreground default frame) frame))
744 frame))
745
746 ;; Set up the faces of all existing frames.
747 (let ((frames (frame-list)))
748 (while frames
749 (if (eq (framep (car frames)) 'x)
750 (x-initialize-frame-faces (car frames)))
751 (setq frames (cdr frames))))
752
753 (provide 'faces)
754
755 ;;; faces.el ends here