Fix maintainer address.
[emacs.git] / lisp / faces.el
blob57cb19b6e183bd6050a6ee0c7e2d02848f19d2de
1 ;;; faces.el --- Lisp faces
3 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998
4 ;; Free Software Foundation, Inc.
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
23 ;;; Commentary:
25 ;;; Code:
27 (eval-when-compile
28 (require 'custom)
29 (require 'cl))
31 (require 'cus-face)
34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35 ;;; Font selection.
36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 (defgroup font-selection nil
39 "Influencing face font selection."
40 :group 'faces)
43 (defcustom face-font-selection-order
44 '(:width :height :weight :slant)
45 "*A list specifying how face font selection chooses fonts.
46 Each of the four symbols `:width', `:height', `:weight', and `:slant'
47 must appear once in the list, and the list must not contain any other
48 elements. Font selection tries to find a best matching font for
49 those face attributes first that appear first in the list. For
50 example, if `:slant' appears before `:height', font selection first
51 tries to find a font with a suitable slant, even if this results in
52 a font height that isn't optimal."
53 :tag "Font selection order."
54 :group 'font-selection
55 :set #'(lambda (symbol value)
56 (set-default symbol value)
57 (internal-set-font-selection-order value)))
60 (defcustom face-font-family-alternatives
61 '(("courier" "fixed")
62 ("helv" "helvetica" "fixed"))
63 "*Alist of alternative font family names.
64 Each element has the the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
65 If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
66 ALTERNATIVE2 etc."
67 :tag "Alternative font families to try."
68 :group 'font-selection
69 :set #'(lambda (symbol value)
70 (set-default symbol value)
71 (internal-set-alternative-font-family-alist value)))
75 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
76 ;;; Creation, copying.
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
80 (defun face-list ()
81 "Return a list of all defined face names."
82 (mapcar #'car face-new-frame-defaults))
85 ;;; ### If not frame-local initialize by what X resources?
87 (defun make-face (face &optional no-init-from-resources)
88 "Define a new face with name FACE, a symbol.
89 NO-INIT-FROM-RESOURCES non-nil means don't initialize frame-local
90 variants of FACE from X resources. (X resources recognized are found
91 in the global variable `face-x-resources'.) If FACE is already known
92 as a face, leave it unmodified. Value is FACE."
93 (interactive "SMake face: ")
94 (unless (facep face)
95 ;; Make frame-local faces (this also makes the global one).
96 (dolist (frame (frame-list))
97 (internal-make-lisp-face face frame))
98 ;; Add the face to the face menu.
99 (when (fboundp 'facemenu-add-new-face)
100 (facemenu-add-new-face face))
101 ;; Define frame-local faces for all frames from X resources.
102 (unless no-init-from-resources
103 (make-face-x-resource-internal face)))
104 face)
107 (defun make-empty-face (face)
108 "Define a new, empty face with name FACE.
109 If the face already exists, it is left unmodified. Value is FACE."
110 (interactive "SMake empty face: ")
111 (make-face face 'no-init-from-resources))
114 (defun copy-face (old-face new-face &optional frame new-frame)
115 "Define a face just like OLD-FACE, with name NEW-FACE.
117 If NEW-FACE already exists as a face, it is modified to be like
118 OLD-FACE. If it doesn't already exist, it is created.
120 If the optional argument FRAME is given as a frame, NEW-FACE is
121 changed on FRAME only.
122 If FRAME is t, the frame-independent default specification for OLD-FACE
123 is copied to NEW-FACE.
124 If FRAME is nil, copying is done for the frame-independent defaults
125 and for each existing frame.
127 If the optional fourth argument NEW-FRAME is given,
128 copy the information from face OLD-FACE on frame FRAME
129 to NEW-FACE on frame NEW-FRAME."
130 (let ((inhibit-quit t))
131 (if (null frame)
132 (progn
133 (dolist (frame (frame-list))
134 (copy-face old-face new-face frame))
135 (copy-face old-face new-face t))
136 (internal-copy-lisp-face old-face new-face frame new-frame))
137 new-face))
141 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
142 ;;; Obsolete functions
143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
145 ;; The functions in this section are defined because Lisp packages use
146 ;; them, despite the prefix `internal-' suggesting that they are
147 ;; private to the face implementation.
149 (defun internal-find-face (name &optional frame)
150 "Retrieve the face named NAME.
151 Return nil if there is no such face.
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.
157 This function is defined for compatibility with Emacs 20.2. It
158 should not be used anymore."
159 (facep name))
162 (defun internal-get-face (name &optional frame)
163 "Retrieve the face named NAME; error if there is none.
164 If the optional argument FRAME is given, this gets the face NAME for
165 that frame; otherwise, it uses the selected frame.
166 If FRAME is the symbol t, then the global, non-frame face is returned.
167 If NAME is already a face, it is simply returned.
169 This function is defined for compatibility with Emacs 20.2. It
170 should not be used anymore."
171 (or (internal-find-face name frame)
172 (check-face name)))
176 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
177 ;;; Predicates, type checks.
178 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
180 (defun facep (face)
181 "Return non-nil if FACE is a face name."
182 (internal-lisp-face-p face))
185 (defun check-face (face)
186 "Signal an error if FACE doesn't name a face.
187 Value is FACE."
188 (unless (facep face)
189 (error "Not a face: %s" face))
190 face)
193 ;; The ID returned is not to be confused with the internally used IDs
194 ;; of realized faces. The ID assigned to Lisp faces is used to
195 ;; support faces in display table entries.
197 (defun face-id (face &optional frame)
198 "Return the interNal ID of face with name FACE.
199 If optional argument FRAME is nil or omitted, use the selected frame."
200 (check-face face)
201 (get face 'face))
204 (defun face-equal (face1 face2 &optional frame)
205 "Non-nil if faces FACE1 and FACE2 are equal.
206 Faces are considered equal if all their attributes are equal.
207 If the optional argument FRAME is given, report on face FACE in that frame.
208 If FRAME is t, report on the defaults for face FACE (for new frames).
209 If FRAME is omitted or nil, use the selected frame."
210 (internal-lisp-face-equal-p face1 face2 frame))
213 (defun face-differs-from-default-p (face &optional frame)
214 "Non-nil if FACE displays differently from the default face.
215 If the optional argument FRAME is given, report on face FACE in that frame.
216 If FRAME is t, report on the defaults for face FACE (for new frames).
217 If FRAME is omitted or nil, use the selected frame.
218 A face is considered to be ``the same'' as the default face if it is
219 actually specified in the same way (equal attributes) or if it is
220 fully-unspecified, and thus inherits the attributes of any face it
221 is displayed on top of."
222 (or (internal-lisp-face-empty-p face frame)
223 (not (internal-lisp-face-equal-p face 'default frame))))
226 (defun face-nontrivial-p (face &optional frame)
227 "True if face FACE has some non-nil attribute.
228 If the optional argument FRAME is given, report on face FACE in that frame.
229 If FRAME is t, report on the defaults for face FACE (for new frames).
230 If FRAME is omitted or nil, use the selected frame."
231 (not (internal-lisp-face-empty-p face frame)))
235 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
236 ;;; Setting face attributes from X resources.
237 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
239 (defcustom face-x-resources
240 '((:family (".attributeFamily" . "Face.AttributeFamily"))
241 (:width (".attributeWidth" . "Face.AttributeWidth"))
242 (:height (".attributeHeight" . "Face.AttributeHeight"))
243 (:weight (".attributeWeight" . "Face.AttributeWeight"))
244 (:slant (".attributeSlant" . "Face.AttributeSlant"))
245 (:foreground (".attributeForeground" . "Face.AttributeForeground"))
246 (:background (".attributeBackground" . "Face.AttributeBackground"))
247 (:overline (".attributeOverline" . "Face.AttributeOverline"))
248 (:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough"))
249 (:box (".attributeBox" . "Face.AttributeBox"))
250 (:underline (".attributeUnderline" . "Face.AttributeUnderline"))
251 (:inverse-video (".attributeInverse" . "Face.AttributeInverse"))
252 (:stipple
253 (".attributeStipple" . "Face.AttributeStipple")
254 (".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap"))
255 (:font (".attributeFont" . "Face.AttributeFont"))
256 (:bold (".attributeBold" . "Face.AttributeBold"))
257 (:italic (".attributeItalic" . "Face.AttributeItalic"))
258 (:font (".attributeFont" . "Face.AttributeFont")))
259 "*List of X resources and classes for face attributes.
260 Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
261 the name of a face attribute, and each ENTRY is a cons of the form
262 (RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
263 X resource class for the attribute."
264 :type 'sexp
265 :group 'faces)
268 (defun set-face-attribute-from-resource (face attribute resource class frame)
269 "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
270 Value is the attribute value specified by the resource, or nil
271 if not present. This function displays a message if the resource
272 specifies an invalid attribute."
273 (let* ((face-name (face-name face))
274 (value (internal-face-x-get-resource (concat face-name resource)
275 class frame)))
276 (when value
277 (condition-case ()
278 (internal-set-lisp-face-attribute-from-resource
279 face attribute (downcase value) frame)
280 (error
281 (message "Face %s, frame %s: invalid attribute %s %s from X resource"
282 face-name frame attribute value))))
283 value))
286 (defun set-face-attributes-from-resources (face frame)
287 "Set attributes of FACE from X resources for FRAME."
288 (when (memq (framep frame) '(x w32))
289 (dolist (definition face-x-resources)
290 (let ((attribute (car definition)))
291 (dolist (entry (cdr definition))
292 (set-face-attribute-from-resource face attribute (car entry)
293 (cdr entry) frame))))))
296 (defun make-face-x-resource-internal (face &optional frame)
297 "Fill frame-local FACE on FRAME from X resources.
298 FRAME nil or not specified means do it for all frames."
299 (if (null frame)
300 (dolist (frame (frame-list))
301 (set-face-attributes-from-resources face frame))
302 (set-face-attributes-from-resources face frame)))
306 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
307 ;;; Retrieving face attributes.
308 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
310 (defun face-name (face)
311 "Return the name of face FACE."
312 (symbol-name (check-face face)))
315 (defun face-attribute (face attribute &optional frame)
316 "Return the value of FACE's ATTRIBUTE on FRAME.
317 If the optional argument FRAME is given, report on face FACE in that frame.
318 If FRAME is t, report on the defaults for face FACE (for new frames).
319 If FRAME is omitted or nil, use the selected frame."
320 (internal-get-lisp-face-attribute face attribute frame))
323 (defun face-foreground (face &optional frame)
324 "Return the foreground color name of FACE, or nil if unspecified.
325 If the optional argument FRAME is given, report on face FACE in that frame.
326 If FRAME is t, report on the defaults for face FACE (for new frames).
327 If FRAME is omitted or nil, use the selected frame."
328 (internal-get-lisp-face-attribute face :foreground frame))
331 (defun face-background (face &optional frame)
332 "Return the background color name of FACE, or nil if unspecified.
333 If the optional argument FRAME is given, report on face FACE in that frame.
334 If FRAME is t, report on the defaults for face FACE (for new frames).
335 If FRAME is omitted or nil, use the selected frame."
336 (internal-get-lisp-face-attribute face :background frame))
339 (defun face-stipple (face &optional frame)
340 "Return the stipple pixmap name of FACE, or nil if unspecified.
341 If the optional argument FRAME is given, report on face FACE in that frame.
342 If FRAME is t, report on the defaults for face FACE (for new frames).
343 If FRAME is omitted or nil, use the selected frame."
344 (internal-get-lisp-face-attribute face :stipple frame))
347 (defalias 'face-background-pixmap 'face-stipple)
350 (defun face-underline-p (face &optional frame)
351 "Return non-nil if FACE is underlined.
352 If the optional argument FRAME is given, report on face FACE in that frame.
353 If FRAME is t, report on the defaults for face FACE (for new frames).
354 If FRAME is omitted or nil, use the selected frame."
355 (eq (face-attribute face :underline frame) t))
358 (defun face-inverse-video-p (face &optional frame)
359 "Return non-nil if FACE is in inverse video on 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).
362 If FRAME is omitted or nil, use the selected frame."
363 (eq (face-attribute face :inverse-video frame) t))
366 (defun face-bold-p (face &optional frame)
367 "Return non-nil if the font of FACE is bold on FRAME.
368 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).
370 If FRAME is omitted or nil, use the selected frame.
371 Use `face-attribute' for finer control."
372 (let ((bold (face-attribute face :weight frame)))
373 (not (memq bold '(normal unspecified)))))
376 (defun face-italic-p (face &optional frame)
377 "Return non-nil if the font of FACE is italic on FRAME.
378 If the optional argument FRAME is given, report on face FACE in that frame.
379 If FRAME is t, report on the defaults for face FACE (for new frames).
380 If FRAME is omitted or nil, use the selected frame.
381 Use `face-attribute' for finer control."
382 (let ((italic (face-attribute face :slant frame)))
383 (not (memq italic '(normal unspecified)))))
389 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
390 ;;; Face documentation.
391 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
393 (defun face-documentation (face)
394 "Get the documentation string for FACE."
395 (get face 'face-documentation))
398 (defun set-face-documentation (face string)
399 "Set the documentation string for FACE to STRING."
400 (put face 'face-documentation string))
403 (defalias 'face-doc-string 'face-documentation)
404 (defalias 'set-face-doc-string 'set-face-documentation)
408 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
409 ;; Setting face attributes.
410 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
413 (defun set-face-attribute (face frame &rest args)
414 "Set attributes of FACE on FRAME from ARGS.
416 FRAME nil means change attributes on all frames. FRAME t means change
417 the default for new frames (this is done automatically each time an
418 attribute is changed on all frames).
420 ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a valid
421 face attribute name. All attributes can be set to `unspecified';
422 this fact is not further mentioned below.
424 The following attributes are recognized:
426 `:family'
428 VALUE must be a string specifying the font family, e.g. ``courier'',
429 or a fontset alias name. If a font family is specified, wild-cards `*'
430 and `?' are allowed.
432 `:width'
434 VALUE specifies the relative proportionate width of the font to use.
435 It must be one of the symbols `ultra-condensed', `extra-condensed',
436 `condensed', `semi-condensed', `normal', `semi-expanded', `expanded',
437 `extra-expanded', or `ultra-expanded'.
439 `:height'
441 VALUE must be an integer specifying the height of the font to use in
442 1/10 pt.
444 `:weight'
446 VALUE specifies the weight of the font to use. It must be one of the
447 symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal',
448 `semi-light', `light', `extra-light', `ultra-light'.
450 `:slant'
452 VALUE specifies the slant of the font to use. It must be one of the
453 symbols `italic', `oblique', `normal', `reverse-italic', or
454 `reverse-oblique'.
456 `:foreground', `:background'
458 VALUE must be a color name, a string.
460 `:underline'
462 VALUE specifies whether characters in FACE should be underlined. If
463 VALUE is t, underline with foreground color of the face. If VALUE is
464 a string, underline with that color. If VALUE is nil, explicitly
465 don't underline.
467 `:overline'
469 VALUE specifies whether characters in FACE should be overlined. If
470 VALUE is t, overline with foreground color of the face. If VALUE is a
471 string, overline with that color. If VALUE is nil, explicitly don't
472 overline.
474 `:strike-through'
476 VALUE specifies whether characters in FACE should be drawn with a line
477 striking through them. If VALUE is t, use the foreground color of the
478 face. If VALUE is a string, strike-through with that color. If VALUE
479 is nil, explicitly don't strike through.
481 `:box'
483 VALUE specifies whether characters in FACE should have a box drawn
484 around them. If VALUE is nil, explicitly don't draw boxes. If
485 VALUE is t, draw a box with lines of width 1 in the foreground color
486 of the face. If VALUE is a string, the string must be a color name,
487 and the box is drawn in that color with a line width of 1. Otherwise,
488 VALUE must be a property list of the form `(:line-width WIDTH
489 :color COLOR :style STYLE)'. If a keyword/value pair is missing from
490 the property list, a default value will be used for the value, as
491 specified below. WIDTH specifies the width of the lines to draw; it
492 defaults to 1. COLOR is the name of the color to draw in, default is
493 the foreground color of the face for simple boxes, and the background
494 color of the face for 3D boxes. STYLE specifies whether a 3D box
495 should be draw. If STYLE is `released-button', draw a box looking
496 like a released 3D button. If STYLE is `pressed-button' draw a box
497 that appears like a pressed button. If STYLE is nil, the default if
498 the property list doesn't contain a style specification, draw a 2D
499 box.
501 `:inverse-video'
503 VALUE specifies whether characters in FACE should be displayed in
504 inverse video. VALUE must be one of t or nil.
506 `:stipple'
508 If VALUE is a string, it must be the name of a file of pixmap data.
509 The directories listed in the `x-bitmap-file-path' variable are
510 searched. Alternatively, VALUE may be a list of the form (WIDTH
511 HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
512 is a string containing the raw bits of the bitmap. VALUE nil means
513 explicitly don't use a stipple pattern.
515 For convenience, attributes `:family', `:width', `:height', `:weight',
516 and `:slant' may also be set in one step from an X font name:
518 `:font'
520 Set font-related face attributes from VALUE. VALUE must be a valid
521 XLFD font name. If it is a font name pattern, the first matching font
522 will be used.
524 For compatibility with Emacs 20, keywords `:bold' and `:italic' can
525 be used to specify that a bold or italic font should be used. VALUE
526 must be t or nil in that case. A value of `unspecified' is not allowed."
527 (cond ((null frame)
528 ;; Change face on all frames.
529 (dolist (frame (frame-list))
530 (apply #'set-face-attribute face frame args))
531 ;; Record that as a default for new frames.
532 (apply #'set-face-attribute face t args))
534 (while args
535 (internal-set-lisp-face-attribute face (car args)
536 (car (cdr args)) frame)
537 (setq args (cdr (cdr args)))))))
540 (defun make-face-bold (face &optional frame)
541 "Make the font of FACE be bold, if possible.
542 FRAME nil or not specified means change face on all frames.
543 Use `set-face-attribute' for finer control of the font weight."
544 (interactive (list (read-face-name "Make which face bold: ")))
545 (set-face-attribute face frame :weight 'bold))
548 (defun make-face-unbold (face &optional frame)
549 "Make the font of FACE be non-bold, if possible.
550 FRAME nil or not specified means change face on all frames."
551 (interactive (list (read-face-name "Make which face non-bold: ")))
552 (set-face-attribute face frame :weight 'normal))
555 (defun make-face-italic (face &optional frame)
556 "Make the font of FACE be italic, if possible.
557 FRAME nil or not specified means change face on all frames.
558 Use `set-face-attribute' for finer control of the font slant."
559 (interactive (list (read-face-name "Make which face italic: ")))
560 (set-face-attribute face frame :slant 'italic))
563 (defun make-face-unitalic (face &optional frame)
564 "Make the font of FACE be non-italic, if possible.
565 FRAME nil or not specified means change face on all frames."
566 (interactive (list (read-face-name "Make which face non-italic: ")))
567 (set-face-attribute face frame :slant 'normal))
570 (defun make-face-bold-italic (face &optional frame)
571 "Make the font of FACE be bold and italic, if possible.
572 FRAME nil or not specified means change face on all frames.
573 Use `set-face-attribute' for finer control of font weight and slant."
574 (interactive (list (read-face-name "Make which face bold-italic: ")))
575 (set-face-attribute face frame :weight 'bold :slant 'italic))
578 (defun set-face-font (face font &optional frame)
579 "Change font-related attributes of FACE to those of FONT (a string).
580 FRAME nil or not specified means change face on all frames.
581 This sets the attributes `:family', `:width', `:height', `:weight',
582 and `:slant'. When called interactively, prompt for the face and font."
583 (interactive (read-face-and-attribute :font))
584 (set-face-attribute face frame :font font))
587 ;; Implementation note: Emulating gray background colors with a
588 ;; stipple pattern is now part of the face realization process, and is
589 ;; done in C depending on the frame on which the face is realized.
591 (defun set-face-background (face color &optional frame)
592 "Change the background color of face FACE to COLOR (a string).
593 FRAME nil or not specified means change face on all frames.
594 When called interactively, prompt for the face and color."
595 (interactive (read-face-and-attribute :background))
596 (set-face-attribute face frame :background color))
599 (defun set-face-foreground (face color &optional frame)
600 "Change the foreground color of face FACE to COLOR (a string).
601 FRAME nil or not specified means change face on all frames.
602 When called interactively, prompt for the face and color."
603 (interactive (read-face-and-attribute :foreground))
604 (set-face-attribute face frame :foreground color))
607 (defun set-face-stipple (face stipple &optional frame)
608 "Change the stipple pixmap of face FACE to STIPPLE.
609 FRAME nil or not specified means change face on all frames.
610 STIPPLE. should be a string, the name of a file of pixmap data.
611 The directories listed in the `x-bitmap-file-path' variable are searched.
613 Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
614 where WIDTH and HEIGHT are the size in pixels,
615 and DATA is a string, containing the raw bits of the bitmap."
616 (interactive (read-face-and-attribute :stipple))
617 (set-face-attribute face frame :stipple stipple))
620 (defun set-face-underline (face underline &optional frame)
621 "Specify whether face FACE is underlined.
622 UNDERLINE nil means FACE explicitly doesn't underline.
623 UNDERLINE non-nil means FACE explicitly does underlining
624 with the same of the foreground color.
625 If UNDERLINE is a string, underline with the color named UNDERLINE.
626 FRAME nil or not specified means change face on all frames.
627 Use `set-face-attribute' to ``unspecify'' underlining."
628 (interactive
629 (let ((list (read-face-and-attribute :underline)))
630 (list (car list) (eq (car (cdr list)) t))))
631 (set-face-attribute face frame :underline underline))
634 (defun set-face-underline-p (face underline-p &optional frame)
635 "Specify whether face FACE is underlined.
636 UNDERLINE-P nil means FACE explicitly doesn't underline.
637 UNDERLINE-P non-nil means FACE explicitly does underlining.
638 FRAME nil or not specified means change face on all frames.
639 Use `set-face-attribute' to ``unspecify'' underlining."
640 (interactive
641 (let ((list (read-face-and-attribute :underline)))
642 (list (car list) (eq (car (cdr list)) t))))
643 (set-face-attribute face frame :underline underline-p))
646 (defun set-face-inverse-video-p (face inverse-video-p &optional frame)
647 "Specify whether face FACE is in inverse video.
648 INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video.
649 INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video.
650 FRAME nil or not specified means change face on all frames.
651 Use `set-face-attribute' to ``unspecify'' the inverse video attribute."
652 (interactive
653 (let ((list (read-face-and-attribute :inverse-video)))
654 (list (car list) (eq (car (cdr list)) t))))
655 (set-face-attribute face frame :inverse-video inverse-video-p))
658 (defun set-face-bold-p (face bold-p &optional frame)
659 "Specify whether face FACE is bold.
660 BOLD-P non-nil means FACE should explicitly display bold.
661 BOLD-P nil means FACE should explicitly display non-bold.
662 FRAME nil or not specified means change face on all frames.
663 Use `set-face-attribute' or `modify-face' for finer control."
664 (if (null bold-p)
665 (make-face-unbold face frame)
666 (make-face-bold face frame)))
669 (defun set-face-italic-p (face italic-p &optional frame)
670 "Specify whether face FACE is italic.
671 ITALIC-P non-nil means FACE should explicitly display italic.
672 ITALIC-P nil means FACE should explicitly display non-italic.
673 FRAME nil or not specified means change face on all frames.
674 Use `set-face-attribute' or `modify-face' for finer control."
675 (if (null italic-p)
676 (make-face-unitalic face frame)
677 (make-face-italic face frame)))
680 (defalias 'set-face-background-pixmap 'set-face-stipple)
683 (defun invert-face (face &optional frame)
684 "Swap the foreground and background colors of FACE.
685 FRAME nil or not specified means change face on all frames.
686 If FACE specifies neither foreground nor background color,
687 set its foreground and background to the background and foreground
688 of the default face. Value is FACE."
689 (interactive (list (read-face-name "Invert face: ")))
690 (let ((fg (face-attribute face :foreground frame))
691 (bg (face-attribute face :background frame)))
692 (if (or fg bg)
693 (set-face-attribute face frame :foreground bg :background fg)
694 (set-face-attribute face frame
695 :foreground
696 (face-attribute 'default :background frame)
697 :background
698 (face-attribute 'default :foreground frame))))
699 face)
702 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
703 ;;; Interactively modifying faces.
704 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
706 (defun read-face-name (prompt)
707 "Read and return a face symbol, prompting with PROMPT.
708 Value is a symbol naming a known face."
709 (let ((face-list (mapcar #'(lambda (x) (cons (symbol-name x) x))
710 (face-list)))
711 face)
712 (while (equal "" (setq face (completing-read prompt face-list nil t))))
713 (intern face)))
716 (defun face-valid-attribute-values (attribute &optional frame)
717 "Return valid values for face attribute ATTRIBUTE.
718 The optional argument FRAME is used to determine available fonts
719 and colors. If it is nil or not specified, the selected frame is
720 used. Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value
721 out of a set of discrete values. Value is `integerp' if ATTRIBUTE expects
722 an integer value."
723 (let (valid)
724 (setq valid
725 (case attribute
726 (:family
727 (if window-system
728 (mapcar #'(lambda (x) (cons (car x) (car x)))
729 (x-font-family-list))
730 ;; Only one font on TTYs.
731 (list (cons "default" "default"))))
732 ((:width :weight :slant :inverse-video)
733 (mapcar #'(lambda (x) (cons (symbol-name x) x))
734 (internal-lisp-face-attribute-values attribute)))
735 ((:underline :overline :strike-through :box)
736 (if window-system
737 (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x))
738 (internal-lisp-face-attribute-values attribute))
739 (mapcar #'(lambda (c) (cons c c))
740 (x-defined-colors frame)))
741 (mapcar #'(lambda (x) (cons (symbol-name x) x))
742 (internal-lisp-face-attribute-values attribute))))
743 ((:foreground :background)
744 (mapcar #'(lambda (c) (cons c c))
745 (or (and window-system (x-defined-colors frame))
746 (tty-defined-colors))))
747 ((:height)
748 'integerp)
749 (:stipple
750 (and (memq window-system '(x w32))
751 (mapcar #'list
752 (apply #'nconc (mapcar #'directory-files
753 x-bitmap-file-path)))))
755 (error "Internal error"))))
756 (if (listp valid)
757 (nconc (list (cons "unspecified" 'unspecified)) valid)
758 valid)))
762 (defvar face-attribute-name-alist
763 '((:family . "font family")
764 (:width . "character set width")
765 (:height . "height in 1/10 pt")
766 (:weight . "weight")
767 (:slant . "slant")
768 (:underline . "underline")
769 (:overline . "overline")
770 (:strike-through . "strike-through")
771 (:box . "box")
772 (:inverse-video . "inverse-video display")
773 (:foreground . "foreground color")
774 (:background . "background color")
775 (:stipple . "background stipple"))
776 "An alist of descriptive names for face attributes.
777 Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where
778 ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and
779 DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.")
782 (defun face-descriptive-attribute-name (attribute)
783 "Return a descriptive name for ATTRIBUTE."
784 (cdr (assq attribute face-attribute-name-alist)))
787 (defun face-read-string (face default name &optional completion-alist)
788 "Interactively read a face attribute string value.
789 FACE is the face whose attribute is read. DEFAULT is the default
790 value to return if no new value is entered. NAME is a descriptive
791 name of the attribute for prompting. COMPLETION-ALIST is an alist
792 of valid values, if non-nil.
794 Entering nothing accepts the default value DEFAULT.
795 Value is the new attribute value."
796 (let* ((completion-ignore-case t)
797 (value (completing-read
798 (if default
799 (format "Set face %s %s (default %s): "
800 face name (downcase (if (symbolp default)
801 (symbol-name default)
802 default)))
803 (format "Set face %s %s: " face name))
804 completion-alist)))
805 (if (equal value "") default value)))
808 (defun face-read-integer (face default name)
809 "Interactively read an integer face attribute value.
810 FACE is the face whose attribute is read. DEFAULT is the default
811 value to return if no new value is entered. NAME is a descriptive
812 name of the attribute for prompting. Value is the new attribute value."
813 (let ((new-value
814 (face-read-string face
815 (if (eq default 'unspecified)
816 'unspecified
817 (int-to-string default))
818 name
819 (list (cons "unspecified" 'unspecified)))))
820 (if (eq new-value 'unspecified)
821 new-value
822 (string-to-int new-value))))
825 (defun read-face-attribute (face attribute &optional frame)
826 "Interactively read a new value for FACE's ATTRIBUTE.
827 Optional argument FRAME nil or unspecified means read an attribute value
828 of a global face. Value is the new attribute value."
829 (let* ((old-value (face-attribute face attribute frame))
830 (attribute-name (face-descriptive-attribute-name attribute))
831 (valid (face-valid-attribute-values attribute frame))
832 new-value)
833 ;; Represent complex attribute values as strings by printing them
834 ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be
835 ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow
836 ;; SHADOW)'.
837 (when (and (or (eq attribute :stipple)
838 (eq attribute :box))
839 (or (consp old-value)
840 (vectorp old-value)))
841 (setq old-value (prin1-to-string old-value)))
842 (cond ((listp valid)
843 (setq new-value
844 (face-read-string face old-value attribute-name valid))
845 (unless (eq new-value 'unspecified)
846 (setq new-value (cdr (assoc new-value valid)))))
847 ((eq valid 'integerp)
848 (setq new-value (face-read-integer face old-value attribute-name)))
849 (t (error "Internal error")))
850 ;; Convert stipple and box value text we read back to a list or
851 ;; vector if it looks like one. This makes the assumption that a
852 ;; pixmap file name won't start with an open-paren.
853 (when (and (or (eq attribute :stipple)
854 (eq attribute :box))
855 (stringp new-value)
856 (string-match "^[[(]" new-value))
857 (setq new-value (read new-value)))
858 new-value))
861 (defun read-face-font (face &optional frame)
862 "Read the name of a font for FACE on FRAME.
863 If optional argument FRAME Is nil or omitted, use the selected frame."
864 (let ((completion-ignore-case t))
865 (completing-read "Set font attributes of face %s from font: "
866 face (x-list-fonts "*" nil frame))))
869 (defun read-all-face-attributes (face &optional frame)
870 "Interactively read all attributes for FACE.
871 If optional argument FRAME Is nil or omitted, use the selected frame.
872 Value is a property list of attribute names and new values."
873 (let (result)
874 (dolist (attribute face-attribute-name-alist result)
875 (setq result (cons (car attribute)
876 (cons (read-face-attribute face (car attribute) frame)
877 result))))))
880 (defun modify-face (&optional frame)
881 "Modify attributes of faces interactively.
882 If optional argument FRAME is nil or omitted, modify the face used
883 for newly created frame, i.e. the global face."
884 (interactive)
885 (let ((face (read-face-name "Modify face: ")))
886 (apply #'set-face-attribute face frame
887 (read-all-face-attributes face frame))))
890 (defun read-face-and-attribute (attribute &optional frame)
891 "Read face name and face attribute value.
892 ATTRIBUTE is the attribute whose new value is read.
893 FRAME nil or unspecified means read attribute value of global face.
894 Value is a list (FACE NEW-VALUE) where FACE is the face read
895 (a symbol), and NEW-VALUE is value read."
896 (cond ((eq attribute :font)
897 (let* ((prompt (format "Set font-related attributes of face: "))
898 (face (read-face-name prompt))
899 (font (read-face-font face frame)))
900 (list face font)))
902 (let* ((attribute-name (face-descriptive-attribute-name attribute))
903 (prompt (format "Set %s of face: " attribute-name))
904 (face (read-face-name prompt))
905 (new-value (read-face-attribute face attribute frame)))
906 (list face new-value)))))
910 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
911 ;;; Listing faces.
912 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
914 (defvar list-faces-sample-text
915 "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
916 "*Text string to display as the sample text for `list-faces-display'.")
919 ;; The name list-faces would be more consistent, but let's avoid a
920 ;; conflict with Lucid, which uses that name differently.
922 (defun list-faces-display ()
923 "List all faces, using the same sample text in each.
924 The sample text is a string that comes from the variable
925 `list-faces-sample-text'."
926 (interactive)
927 (let ((faces (sort (face-list) #'string-lessp))
928 (face nil)
929 (frame (selected-frame))
930 disp-frame window)
931 (with-output-to-temp-buffer "*Faces*"
932 (save-excursion
933 (set-buffer standard-output)
934 (setq truncate-lines t)
935 (while faces
936 (setq face (car faces))
937 (setq faces (cdr faces))
938 (insert (format "%25s " (face-name face)))
939 (let ((beg (point)))
940 (insert list-faces-sample-text)
941 (insert "\n")
942 (put-text-property beg (1- (point)) 'face face)
943 ;; If the sample text has multiple lines, line up all of them.
944 (goto-char beg)
945 (forward-line 1)
946 (while (not (eobp))
947 (insert " ")
948 (forward-line 1))))
949 (goto-char (point-min)))
950 (print-help-return-message))
951 ;; If the *Faces* buffer appears in a different frame,
952 ;; copy all the face definitions from FRAME,
953 ;; so that the display will reflect the frame that was selected.
954 (setq window (get-buffer-window (get-buffer "*Faces*") t))
955 (setq disp-frame (if window (window-frame window)
956 (car (frame-list))))
957 (or (eq frame disp-frame)
958 (let ((faces (face-list)))
959 (while faces
960 (copy-face (car faces) (car faces) frame disp-frame)
961 (setq faces (cdr faces)))))))
964 (defun describe-face (face &optional frame)
965 "Display the properties of face FACE on FRAME.
966 If the optional argument FRAME is given, report on face FACE in that frame.
967 If FRAME is t, report on the defaults for face FACE (for new frames).
968 If FRAME is omitted or nil, use the selected frame."
969 (interactive (list (read-face-name "Describe face: ")))
970 (let* ((attrs '((:family . "Family")
971 (:width . "Width")
972 (:height . "Height")
973 (:weight . "Weight")
974 (:slant . "Slant")
975 (:foreground . "Foreground")
976 (:background . "Background")
977 (:underline . "Underline")
978 (:overline . "Overline")
979 (:strike-through . "Strike-through")
980 (:box . "Box")
981 (:inverse-video . "Inverse")
982 (:stipple . "Stipple")))
983 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x)))
984 attrs))))
985 (with-output-to-temp-buffer "*Help*"
986 (save-excursion
987 (set-buffer standard-output)
988 (dolist (a attrs)
989 (let ((attr (face-attribute face (car a) frame)))
990 (insert (make-string (- max-width (length (cdr a))) ?\ )
991 (cdr a) ": " (format "%s" attr) "\n")))
992 (insert "\nDocumentation:\n\n"
993 (or (face-documentation face)
994 "not documented as a face.")))
995 (print-help-return-message))))
1000 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1001 ;;; Face specifications (defface).
1002 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1004 ;; Parameter FRAME Is kept for call compatibility to with previous
1005 ;; face implementation.
1007 (defun face-attr-construct (face &optional frame)
1008 "Return a defface-style attribute list for FACE on FRAME.
1009 Value is a property list of pairs ATTRIBUTE VALUE for all specified
1010 face attributes of FACE where ATTRIBUTE is the attribute name and
1011 VALUE is the specified value of that attribute."
1012 (let (result)
1013 (dolist (entry face-attribute-name-alist result)
1014 (let* ((attribute (car entry))
1015 (value (face-attribute face attribute)))
1016 (unless (eq value 'unspecified)
1017 (setq result (nconc (list attribute value) result)))))))
1020 (defun face-spec-set-match-display (display frame)
1021 "Non-nil if DISPLAY matches FRAME.
1022 DISPLAY is part of a spec such as can be used in `defface'.
1023 If FRAME is nil, the current FRAME is used."
1024 (let* ((conjuncts display)
1025 conjunct req options
1026 ;; t means we have succeeded against all the conjuncts in
1027 ;; DISPLAY that have been tested so far.
1028 (match t))
1029 (if (eq conjuncts t)
1030 (setq conjuncts nil))
1031 (while (and conjuncts match)
1032 (setq conjunct (car conjuncts)
1033 conjuncts (cdr conjuncts)
1034 req (car conjunct)
1035 options (cdr conjunct)
1036 match (cond ((eq req 'type)
1037 (or (memq window-system options)
1038 (and (null window-system)
1039 (memq 'tty options))))
1040 ((eq req 'class)
1041 (memq (frame-parameter frame 'display-type) options))
1042 ((eq req 'background)
1043 (memq (frame-parameter frame 'background-mode)
1044 options))
1045 (t (error "Unknown req `%S' with options `%S'"
1046 req options)))))
1047 match))
1050 (defun face-spec-choose (spec &optional frame)
1051 "Choose the proper attributes for FRAME, out of SPEC."
1052 (unless frame
1053 (setq frame (selected-frame)))
1054 (let ((tail spec)
1055 result)
1056 (while tail
1057 (let* ((entry (car tail))
1058 (display (nth 0 entry))
1059 (attrs (nth 1 entry)))
1060 (setq tail (cdr tail))
1061 (when (face-spec-set-match-display display frame)
1062 (setq result attrs tail nil))))
1063 result))
1066 (defun face-spec-reset-face (face &optional frame)
1067 "Reset all attributes of FACE on FRAME to unspecified."
1068 (let ((attrs face-attribute-name-alist)
1069 params)
1070 (while attrs
1071 (let ((attr-and-name (car attrs)))
1072 (setq params (cons (car attr-and-name) (cons 'unspecified params))))
1073 (setq attrs (cdr attrs)))
1074 (apply #'set-face-attribute face frame params)))
1077 (defun face-spec-set (face spec &optional frame)
1078 "Set FACE's attributes according to the first matching entry in SPEC.
1079 FRAME is the frame whose frame-local face is set. FRAME nil means
1080 do it on all frames. See `defface' for information about SPEC."
1081 (let ((attrs (face-spec-choose spec frame))
1082 params)
1083 (while attrs
1084 (let ((attribute (car attrs))
1085 (value (car (cdr attrs))))
1086 ;; Support some old-style attribute names and values.
1087 (case attribute
1088 (:bold (setq attribute :weight value (if value 'bold 'normal)))
1089 (:italic (setq attribute :slant value (if value 'italic 'normal))))
1090 (setq params (cons attribute (cons value params))))
1091 (setq attrs (cdr (cdr attrs))))
1092 (face-spec-reset-face face frame)
1093 (apply #'set-face-attribute face frame params)))
1096 (defun face-attr-match-p (face attrs &optional frame)
1097 "Value is non-nil if attributes of FACE match values in plist ATTRS.
1098 Optional parameter FRAME is the frame whose definition of FACE
1099 is used. If nil or omitted, use the selected frame."
1100 (unless frame
1101 (setq frame (selected-frame)))
1102 (let ((list face-attribute-name-alist)
1103 (match t))
1104 (while (and match (not (null list)))
1105 (let* ((attr (car (car list)))
1106 (specified-value (plist-get attrs attr))
1107 (value-now (face-attribute face attr frame)))
1108 (when specified-value
1109 (setq match (equal specified-value value-now)))
1110 (setq list (cdr list))))
1111 match))
1114 (defun face-spec-match-p (face spec &optional frame)
1115 "Return t if FACE, on FRAME, matches what SPEC says it should look like."
1116 (face-attr-match-p face (face-spec-choose spec frame) frame))
1120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1121 ;;; Background mode.
1122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1124 (defcustom frame-background-mode nil
1125 "*The brightness of the background.
1126 Set this to the symbol `dark' if your background color is dark, `light' if
1127 your background is light, or nil (default) if you want Emacs to
1128 examine the brightness for you."
1129 :group 'faces
1130 :set #'(lambda (var value)
1131 (set var value)
1132 (mapcar 'frame-set-background-mode (frame-list)))
1133 :initialize 'custom-initialize-changed
1134 :type '(choice (choice-item dark)
1135 (choice-item light)
1136 (choice-item :tag "default" nil)))
1139 (defun frame-set-background-mode (frame)
1140 "Set up the `background-mode' and `display-type' frame parameters for FRAME."
1141 (let* ((bg-resource
1142 (and window-system
1143 (x-get-resource ".backgroundMode" "BackgroundMode")))
1144 (params (frame-parameters frame))
1145 (bg-mode (cond (frame-background-mode)
1146 ((null window-system)
1147 ;; No way to determine this automatically (?).
1148 'dark)
1149 (bg-resource
1150 (intern (downcase bg-resource)))
1151 ((< (apply '+ (x-color-values
1152 (cdr (assq 'background-color
1153 params))
1154 frame))
1155 ;; Just looking at the screen, colors whose
1156 ;; values add up to .6 of the white total
1157 ;; still look dark to me.
1158 (* (apply '+ (x-color-values "white" frame)) .6))
1159 'dark)
1160 (t 'light)))
1161 (display-type (cond ((null window-system)
1162 (if (tty-display-color-p) 'color 'mono))
1163 ((x-display-color-p frame)
1164 'color)
1165 ((x-display-grayscale-p frame)
1166 'grayscale)
1167 (t 'mono))))
1168 (modify-frame-parameters frame
1169 (list (cons 'background-mode bg-mode)
1170 (cons 'display-type display-type))))
1172 ;; For all named faces, choose face specs matching the new frame
1173 ;; parameters.
1174 (let ((face-list (face-list)))
1175 (while face-list
1176 (let* ((face (car face-list))
1177 (spec (get face 'face-defface-spec)))
1178 (when spec
1179 (face-spec-set face spec frame))
1180 (setq face-list (cdr face-list))))))
1185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1186 ;;; Frame creation.
1187 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1189 (defun x-handle-named-frame-geometry (parameters)
1190 "Add geometry parameters for a named frame to parameter list PARAMETERS.
1191 Value is the new parameter list."
1192 (let* ((name (or (cdr (assq 'name parameters))
1193 (cdr (assq 'name default-frame-alist))))
1194 (x-resource-name name)
1195 (res-geometry (if name (x-get-resource "geometry" "Geometry"))))
1196 (when res-geometry
1197 (let ((parsed (x-parse-geometry res-geometry)))
1198 ;; If the resource specifies a position, call the position
1199 ;; and size "user-specified".
1200 (when (or (assq 'top parsed)
1201 (assq 'left parsed))
1202 (setq parsed (append '((user-position . t) (user-size . t)) parsed)))
1203 ;; Put the geometry parameters at the end. Copy
1204 ;; default-frame-alist so that they go after it.
1205 (setq parameters (append parameters default-frame-alist parsed))))
1206 parameters))
1209 (defun x-handle-reverse-video (frame parameters)
1210 "Handle the reverse-video frame parameter and X resource.
1211 `x-create-frame' does not handle this one."
1212 (when (cdr (or (assq 'reverse parameters)
1213 (assq 'reverse default-frame-alist)
1214 (let ((resource (x-get-resource "reverseVideo"
1215 "ReverseVideo")))
1216 (if resource
1217 (cons nil (member (downcase resource)
1218 '("on" "true")))))))
1219 (let* ((params (frame-parameters frame))
1220 (bg (cdr (assq 'foreground-color params)))
1221 (fg (cdr (assq 'background-color params))))
1222 (modify-frame-parameters frame
1223 (list (cons 'foreground-color fg)
1224 (cons 'background-color bg)))
1225 (if (equal bg (cdr (assq 'border-color params)))
1226 (modify-frame-parameters frame
1227 (list (cons 'border-color fg))))
1228 (if (equal bg (cdr (assq 'mouse-color params)))
1229 (modify-frame-parameters frame
1230 (list (cons 'mouse-color fg))))
1231 (if (equal bg (cdr (assq 'cursor-color params)))
1232 (modify-frame-parameters frame
1233 (list (cons 'cursor-color fg)))))))
1236 (defun x-create-frame-with-faces (&optional parameters)
1237 "Create a frame from optional frame parameters PARAMETERS.
1238 Parameters not specified by PARAMETERS are taken from
1239 `default-frame-alist'. If PARAMETERS specify a frame name,
1240 handle X geometry resources for that name. If either PARAMETERS
1241 or `default-frame-alist' contains a `reverse' parameter, or
1242 the X resource ``reverseVideo'' is present, handle that.
1243 Value is the new frame created."
1244 (setq parameters (x-handle-named-frame-geometry parameters))
1245 (let ((visibility-spec (assq 'visibility parameters))
1246 (frame-list (frame-list))
1247 (frame (x-create-frame (cons '(visibility . nil) parameters)))
1248 success)
1249 (unwind-protect
1250 (progn
1251 (x-handle-reverse-video frame parameters)
1252 (frame-set-background-mode frame)
1253 (face-set-after-frame-default frame)
1254 (if (or (null frame-list) (null visibility-spec))
1255 (make-frame-visible frame)
1256 (modify-frame-parameters frame (list visibility-spec)))
1257 (setq success t))
1258 (unless success
1259 (delete-frame frame)))
1260 frame))
1263 (defun face-set-after-frame-default (frame)
1264 "Set frame-local faces of FRAME from face specs and resources."
1265 (dolist (face (face-list))
1266 (let ((spec (or (get face 'saved-face)
1267 (get face 'face-defface-spec))))
1268 (when spec
1269 (face-spec-set face spec frame))
1270 (internal-merge-in-global-face face frame)
1271 (when (memq window-system '(x w32))
1272 (make-face-x-resource-internal face frame)))))
1275 (defun tty-create-frame-with-faces (&optional parameters)
1276 "Create a frame from optional frame parameters PARAMETERS.
1277 Parameters not specified by PARAMETERS are taken from
1278 `default-frame-alist'. If either PARAMETERS or `default-frame-alist'
1279 contains a `reverse' parameter, handle that. Value is the new frame
1280 created."
1281 (let ((frame (make-terminal-frame parameters))
1282 success)
1283 (unwind-protect
1284 (progn
1285 (frame-set-background-mode frame)
1286 (face-set-after-frame-default frame)
1287 (setq success t))
1288 (unless success
1289 (delete-frame frame)))
1290 frame))
1293 ;; Called from C function init_display to initialize faces of the
1294 ;; dumped terminal frame on startup.
1296 (defun tty-set-up-initial-frame-faces ()
1297 (let ((frame (selected-frame)))
1298 (frame-set-background-mode frame)
1299 (face-set-after-frame-default frame)))
1304 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1305 ;;; Compatiblity with 20.2
1306 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1308 ;; Update a frame's faces when we change its default font.
1310 (defun frame-update-faces (frame)
1311 nil)
1314 ;; Update the colors of FACE, after FRAME's own colors have been
1315 ;; changed.
1317 (defun frame-update-face-colors (frame)
1318 (frame-set-background-mode frame))
1322 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1323 ;;; Standard faces.
1324 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1326 ;; Make the standard faces. The C code knows faces `default',
1327 ;; `modeline', `toolbar' and `region', so they must be the first faces
1328 ;; made. Unspecified attributes of these three faces are filled-in
1329 ;; from frame parameters in the C code.
1331 (defgroup basic-faces nil
1332 "The standard faces of Emacs."
1333 :group 'faces)
1336 (defface default
1337 '((t nil))
1338 "Basic default face."
1339 :group 'basic-faces)
1342 (defface modeline
1343 '((((type x) (class color))
1344 (:box (:line-width 2 :style released-button) :background "grey75"))
1346 (:inverse-video t)))
1347 "Basic mode line face."
1348 :group 'basic-faces)
1351 (defface top-line
1352 '((((type x) (class color))
1353 (:box (:line-width 2 :style released-button) :background "grey75"))
1355 (:inverse-video t)))
1356 "Basic top line face."
1357 :group 'basic-faces)
1360 (defface toolbar
1361 '((((type x) (class color))
1362 (:box (:line-width 1 :style released-button) :background "grey75"))
1363 (((type x) (class mono))
1364 (:box (:line-width 1 :style released-button) :background "grey"))
1366 ()))
1367 "Basic toolbar face."
1368 :group 'basic-faces)
1371 (defface region
1372 '((((type tty) (class color))
1373 (:background "blue" :foreground "white"))
1374 (((type tty) (class mono))
1375 (:inverse-video t))
1376 (((class color) (background dark))
1377 (:background "blue"))
1378 (((class color) (background light))
1379 (:background "lightblue"))
1380 (t (:background "gray")))
1381 "Basic face for highlight the region."
1382 :group 'basic-faces)
1385 (defface bitmap-area
1386 '((((class color))
1387 (:background "grey95"))
1388 (((class mono))
1389 (:background "white"))
1391 (:background "gray")))
1392 "Basic face for bitmap areas under X."
1393 :version "21.1"
1394 :group 'basic-faces)
1397 (defface bold '((t (:weight bold)))
1398 "Basic bold face."
1399 :group 'basic-faces)
1402 (defface italic '((t (:slant italic)))
1403 "Basic italic font."
1404 :group 'basic-faces)
1407 (defface bold-italic '((t (:weight bold :slant italic)))
1408 "Basic bold-italic face."
1409 :group 'basic-faces)
1412 (defface underline '((t (:underline t)))
1413 "Basic underlined face."
1414 :group 'basic-faces)
1417 (defface highlight
1418 '((((type tty) (class color))
1419 (:background "green"))
1420 (((class color) (background light))
1421 (:background "darkseagreen2"))
1422 (((class color) (background dark))
1423 (:background "darkolivegreen"))
1424 (t (:inverse-video t)))
1425 "Basic face for highlighting.")
1428 (defface secondary-selection
1429 '((((type tty) (class color))
1430 (:background "cyan"))
1431 (((class color) (background light))
1432 (:background "paleturquoise"))
1433 (((class color) (background dark))
1434 (:background "darkslateblue"))
1435 (t (:inverse-video t)))
1436 "Basic face for displaying the secondary selection.")
1439 (defface fixed-pitch '((t (:family "courier*")))
1440 "The basic fixed-pitch face."
1441 :group 'basic-faces)
1444 (defface variable-pitch '((t (:family "helv*")))
1445 "The basic variable-pitch face."
1446 :group 'basic-faces)
1449 (defface trailing-whitespace
1450 '((((class color) (background light))
1451 (:background "red"))
1452 (((class color) (background dark))
1453 (:background "red"))
1454 (t (:inverse-video t)))
1455 "Basic face for highlighting trailing whitespace.")
1459 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1460 ;;; Manipulating font names.
1461 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1463 ;; This is here for compatibilty with Emacs 20.2. For example,
1464 ;; international/fontset.el uses these functions to manipulate font
1465 ;; names. The following functions are not used in the face
1466 ;; implementation itself.
1468 (defvar x-font-regexp nil)
1469 (defvar x-font-regexp-head nil)
1470 (defvar x-font-regexp-weight nil)
1471 (defvar x-font-regexp-slant nil)
1473 (defconst x-font-regexp-weight-subnum 1)
1474 (defconst x-font-regexp-slant-subnum 2)
1475 (defconst x-font-regexp-swidth-subnum 3)
1476 (defconst x-font-regexp-adstyle-subnum 4)
1478 ;;; Regexps matching font names in "Host Portable Character Representation."
1480 (let ((- "[-?]")
1481 (foundry "[^-]+")
1482 (family "[^-]+")
1483 (weight "\\(bold\\|demibold\\|medium\\)") ; 1
1484 ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1
1485 (weight\? "\\([^-]*\\)") ; 1
1486 (slant "\\([ior]\\)") ; 2
1487 ; (slant\? "\\([ior?*]?\\)") ; 2
1488 (slant\? "\\([^-]?\\)") ; 2
1489 ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3
1490 (swidth "\\([^-]*\\)") ; 3
1491 ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4
1492 (adstyle "\\([^-]*\\)") ; 4
1493 (pixelsize "[0-9]+")
1494 (pointsize "[0-9][0-9]+")
1495 (resx "[0-9][0-9]+")
1496 (resy "[0-9][0-9]+")
1497 (spacing "[cmp?*]")
1498 (avgwidth "[0-9]+")
1499 (registry "[^-]+")
1500 (encoding "[^-]+")
1502 (setq x-font-regexp
1503 (concat "\\`\\*?[-?*]"
1504 foundry - family - weight\? - slant\? - swidth - adstyle -
1505 pixelsize - pointsize - resx - resy - spacing - avgwidth -
1506 registry - encoding "\\*?\\'"
1508 (setq x-font-regexp-head
1509 (concat "\\`[-?*]" foundry - family - weight\? - slant\?
1510 "\\([-*?]\\|\\'\\)"))
1511 (setq x-font-regexp-slant (concat - slant -))
1512 (setq x-font-regexp-weight (concat - weight -))
1513 nil)
1516 (defun x-resolve-font-name (pattern &optional face frame)
1517 "Return a font name matching PATTERN.
1518 All wildcards in PATTERN become substantiated.
1519 If PATTERN is nil, return the name of the frame's base font, which never
1520 contains wildcards.
1521 Given optional arguments FACE and FRAME, return a font which is
1522 also the same size as FACE on FRAME, or fail."
1523 (or (symbolp face)
1524 (setq face (face-name face)))
1525 (and (eq frame t)
1526 (setq frame nil))
1527 (if pattern
1528 ;; Note that x-list-fonts has code to handle a face with nil as its font.
1529 (let ((fonts (x-list-fonts pattern face frame 1)))
1530 (or fonts
1531 (if face
1532 (if (string-match "\\*" pattern)
1533 (if (null (face-font face))
1534 (error "No matching fonts are the same height as the frame default font")
1535 (error "No matching fonts are the same height as face `%s'" face))
1536 (if (null (face-font face))
1537 (error "Height of font `%s' doesn't match the frame default font"
1538 pattern)
1539 (error "Height of font `%s' doesn't match face `%s'"
1540 pattern face)))
1541 (error "No fonts match `%s'" pattern)))
1542 (car fonts))
1543 (cdr (assq 'font (frame-parameters (selected-frame))))))
1546 (defun x-frob-font-weight (font which)
1547 (let ((case-fold-search t))
1548 (cond ((string-match x-font-regexp font)
1549 (concat (substring font 0
1550 (match-beginning x-font-regexp-weight-subnum))
1551 which
1552 (substring font (match-end x-font-regexp-weight-subnum)
1553 (match-beginning x-font-regexp-adstyle-subnum))
1554 ;; Replace the ADD_STYLE_NAME field with *
1555 ;; because the info in it may not be the same
1556 ;; for related fonts.
1558 (substring font (match-end x-font-regexp-adstyle-subnum))))
1559 ((string-match x-font-regexp-head font)
1560 (concat (substring font 0 (match-beginning 1)) which
1561 (substring font (match-end 1))))
1562 ((string-match x-font-regexp-weight font)
1563 (concat (substring font 0 (match-beginning 1)) which
1564 (substring font (match-end 1)))))))
1567 (defun x-frob-font-slant (font which)
1568 (let ((case-fold-search t))
1569 (cond ((string-match x-font-regexp font)
1570 (concat (substring font 0
1571 (match-beginning x-font-regexp-slant-subnum))
1572 which
1573 (substring font (match-end x-font-regexp-slant-subnum)
1574 (match-beginning x-font-regexp-adstyle-subnum))
1575 ;; Replace the ADD_STYLE_NAME field with *
1576 ;; because the info in it may not be the same
1577 ;; for related fonts.
1579 (substring font (match-end x-font-regexp-adstyle-subnum))))
1580 ((string-match x-font-regexp-head font)
1581 (concat (substring font 0 (match-beginning 2)) which
1582 (substring font (match-end 2))))
1583 ((string-match x-font-regexp-slant font)
1584 (concat (substring font 0 (match-beginning 1)) which
1585 (substring font (match-end 1)))))))
1588 (defun x-make-font-bold (font)
1589 "Given an X font specification, make a bold version of it.
1590 If that can't be done, return nil."
1591 (x-frob-font-weight font "bold"))
1594 (defun x-make-font-demibold (font)
1595 "Given an X font specification, make a demibold version of it.
1596 If that can't be done, return nil."
1597 (x-frob-font-weight font "demibold"))
1600 (defun x-make-font-unbold (font)
1601 "Given an X font specification, make a non-bold version of it.
1602 If that can't be done, return nil."
1603 (x-frob-font-weight font "medium"))
1606 (defun x-make-font-italic (font)
1607 "Given an X font specification, make an italic version of it.
1608 If that can't be done, return nil."
1609 (x-frob-font-slant font "i"))
1612 (defun x-make-font-oblique (font) ; you say tomayto...
1613 "Given an X font specification, make an oblique version of it.
1614 If that can't be done, return nil."
1615 (x-frob-font-slant font "o"))
1618 (defun x-make-font-unitalic (font)
1619 "Given an X font specification, make a non-italic version of it.
1620 If that can't be done, return nil."
1621 (x-frob-font-slant font "r"))
1624 (defun x-make-font-bold-italic (font)
1625 "Given an X font specification, make a bold and italic version of it.
1626 If that can't be done, return nil."
1627 (and (setq font (x-make-font-bold font))
1628 (x-make-font-italic font)))
1631 (provide 'faces)
1633 ;;; end of faces.el