Commit | Line | Data |
---|---|---|
5f5c8ee5 | 1 | ;;; faces.el --- Lisp faces |
465fceed | 2 | |
97cc3d15 | 3 | ;; Copyright (C) 1992,1993,1994,1995,1996,1998,1999,2000,2001,2002,2004 |
5f5c8ee5 | 4 | ;; Free Software Foundation, Inc. |
465fceed | 5 | |
6228c05b | 6 | ;; Maintainer: FSF |
30764597 | 7 | ;; Keywords: internal |
6228c05b | 8 | |
465fceed ER |
9 | ;; This file is part of GNU Emacs. |
10 | ||
11 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
13 | ;; the Free Software Foundation; either version 2, or (at your option) | |
14 | ;; any later version. | |
15 | ||
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
b578f267 EN |
22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 | ;; Boston, MA 02111-1307, USA. | |
465fceed ER |
25 | |
26 | ;;; Commentary: | |
27 | ||
465fceed ER |
28 | ;;; Code: |
29 | ||
39b3b754 | 30 | (eval-when-compile |
b5325e78 DL |
31 | (require 'cl) |
32 | ;; Warning suppression -- can't require x-win in batch: | |
33 | (autoload 'xw-defined-colors "x-win")) | |
5f5c8ee5 | 34 | |
5f5c8ee5 GM |
35 | \f |
36 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
37 | ;;; Font selection. | |
38 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
39 | ||
40 | (defgroup font-selection nil | |
41 | "Influencing face font selection." | |
42 | :group 'faces) | |
43 | ||
44 | ||
45 | (defcustom face-font-selection-order | |
46 | '(:width :height :weight :slant) | |
47 | "*A list specifying how face font selection chooses fonts. | |
48 | Each of the four symbols `:width', `:height', `:weight', and `:slant' | |
49 | must appear once in the list, and the list must not contain any other | |
50 | elements. Font selection tries to find a best matching font for | |
51 | those face attributes first that appear first in the list. For | |
52 | example, if `:slant' appears before `:height', font selection first | |
53 | tries to find a font with a suitable slant, even if this results in | |
54 | a font height that isn't optimal." | |
239ad97f | 55 | :tag "Font selection order" |
94354bdd | 56 | :type '(list symbol symbol symbol symbol) |
5f5c8ee5 GM |
57 | :group 'font-selection |
58 | :set #'(lambda (symbol value) | |
59 | (set-default symbol value) | |
60 | (internal-set-font-selection-order value))) | |
61 | ||
18f1dcb4 GM |
62 | |
63 | ;; This is defined originally in xfaces.c. | |
5f5c8ee5 GM |
64 | (defcustom face-font-family-alternatives |
65 | '(("courier" "fixed") | |
3855860a | 66 | ("helv" "helvetica" "arial" "fixed")) |
5f5c8ee5 | 67 | "*Alist of alternative font family names. |
86886bce | 68 | Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...). |
5f5c8ee5 GM |
69 | If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then |
70 | ALTERNATIVE2 etc." | |
239ad97f | 71 | :tag "Alternative font families to try" |
94354bdd | 72 | :type '(repeat (repeat string)) |
5f5c8ee5 GM |
73 | :group 'font-selection |
74 | :set #'(lambda (symbol value) | |
75 | (set-default symbol value) | |
76 | (internal-set-alternative-font-family-alist value))) | |
77 | ||
78 | ||
18f1dcb4 GM |
79 | ;; This is defined originally in xfaces.c. |
80 | (defcustom face-font-registry-alternatives | |
c97db4e4 | 81 | (if (eq system-type 'windows-nt) |
990d68dd JR |
82 | '(("iso8859-1" "ms-oemlatin") |
83 | ("gb2312.1980" "gb2312") | |
c97db4e4 AI |
84 | ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978") |
85 | ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987") | |
86 | ("muletibetan-2" "muletibetan-0")) | |
87 | '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk*") | |
88 | ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978") | |
89 | ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987") | |
90 | ("muletibetan-2" "muletibetan-0"))) | |
18f1dcb4 | 91 | "*Alist of alternative font registry names. |
86886bce | 92 | Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...). |
8ac2d32f KH |
93 | If fonts of registry REGISTRY can be loaded, font selection |
94 | tries to find a best matching font among all fonts of registry | |
95 | REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc." | |
239ad97f | 96 | :tag "Alternative font registries to try" |
18f1dcb4 | 97 | :type '(repeat (repeat string)) |
f676894c | 98 | :version "21.1" |
18f1dcb4 GM |
99 | :group 'font-selection |
100 | :set #'(lambda (symbol value) | |
101 | (set-default symbol value) | |
102 | (internal-set-alternative-font-registry-alist value))) | |
103 | ||
104 | ||
bdda3754 | 105 | \f |
5f5c8ee5 GM |
106 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
107 | ;;; Creation, copying. | |
108 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
109 | ||
110 | ||
111 | (defun face-list () | |
112 | "Return a list of all defined face names." | |
113 | (mapcar #'car face-new-frame-defaults)) | |
114 | ||
115 | ||
116 | ;;; ### If not frame-local initialize by what X resources? | |
117 | ||
118 | (defun make-face (face &optional no-init-from-resources) | |
119 | "Define a new face with name FACE, a symbol. | |
120 | NO-INIT-FROM-RESOURCES non-nil means don't initialize frame-local | |
121 | variants of FACE from X resources. (X resources recognized are found | |
122 | in the global variable `face-x-resources'.) If FACE is already known | |
123 | as a face, leave it unmodified. Value is FACE." | |
124 | (interactive "SMake face: ") | |
125 | (unless (facep face) | |
126 | ;; Make frame-local faces (this also makes the global one). | |
127 | (dolist (frame (frame-list)) | |
128 | (internal-make-lisp-face face frame)) | |
129 | ;; Add the face to the face menu. | |
130 | (when (fboundp 'facemenu-add-new-face) | |
131 | (facemenu-add-new-face face)) | |
132 | ;; Define frame-local faces for all frames from X resources. | |
133 | (unless no-init-from-resources | |
134 | (make-face-x-resource-internal face))) | |
135 | face) | |
136 | ||
137 | ||
138 | (defun make-empty-face (face) | |
139 | "Define a new, empty face with name FACE. | |
140 | If the face already exists, it is left unmodified. Value is FACE." | |
141 | (interactive "SMake empty face: ") | |
142 | (make-face face 'no-init-from-resources)) | |
143 | ||
144 | ||
145 | (defun copy-face (old-face new-face &optional frame new-frame) | |
146 | "Define a face just like OLD-FACE, with name NEW-FACE. | |
147 | ||
148 | If NEW-FACE already exists as a face, it is modified to be like | |
149 | OLD-FACE. If it doesn't already exist, it is created. | |
150 | ||
1c521fb0 | 151 | If the optional argument FRAME is given as a frame, NEW-FACE is |
5f5c8ee5 GM |
152 | changed on FRAME only. |
153 | If FRAME is t, the frame-independent default specification for OLD-FACE | |
154 | is copied to NEW-FACE. | |
155 | If FRAME is nil, copying is done for the frame-independent defaults | |
156 | and for each existing frame. | |
157 | ||
158 | If the optional fourth argument NEW-FRAME is given, | |
159 | copy the information from face OLD-FACE on frame FRAME | |
160 | to NEW-FACE on frame NEW-FRAME." | |
161 | (let ((inhibit-quit t)) | |
162 | (if (null frame) | |
163 | (progn | |
164 | (dolist (frame (frame-list)) | |
165 | (copy-face old-face new-face frame)) | |
166 | (copy-face old-face new-face t)) | |
167 | (internal-copy-lisp-face old-face new-face frame new-frame)) | |
168 | new-face)) | |
169 | ||
170 | ||
171 | \f | |
172 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
173 | ;;; Obsolete functions | |
174 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
175 | ||
176 | ;; The functions in this section are defined because Lisp packages use | |
177 | ;; them, despite the prefix `internal-' suggesting that they are | |
70d0c3b0 | 178 | ;; private to the face implementation. |
5f5c8ee5 GM |
179 | |
180 | (defun internal-find-face (name &optional frame) | |
181 | "Retrieve the face named NAME. | |
182 | Return nil if there is no such face. | |
183 | If the optional argument FRAME is given, this gets the face NAME for | |
184 | that frame; otherwise, it uses the selected frame. | |
185 | If FRAME is the symbol t, then the global, non-frame face is returned. | |
186 | If NAME is already a face, it is simply returned. | |
187 | ||
188 | This function is defined for compatibility with Emacs 20.2. It | |
189 | should not be used anymore." | |
190 | (facep name)) | |
2598a293 | 191 | (make-obsolete 'internal-find-face 'facep "21.1") |
5f5c8ee5 GM |
192 | |
193 | ||
194 | (defun internal-get-face (name &optional frame) | |
195 | "Retrieve the face named NAME; error if there is none. | |
196 | If the optional argument FRAME is given, this gets the face NAME for | |
197 | that frame; otherwise, it uses the selected frame. | |
198 | If FRAME is the symbol t, then the global, non-frame face is returned. | |
4b22f844 | 199 | If NAME is already a face, it is simply returned." |
3fc67165 | 200 | (or (facep name) |
5f5c8ee5 | 201 | (check-face name))) |
4b22f844 | 202 | (make-obsolete 'internal-get-face "see `facep' and `check-face'." "21.1") |
5f5c8ee5 GM |
203 | |
204 | \f | |
205 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
206 | ;;; Predicates, type checks. | |
207 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
208 | ||
209 | (defun facep (face) | |
210 | "Return non-nil if FACE is a face name." | |
211 | (internal-lisp-face-p face)) | |
212 | ||
213 | ||
214 | (defun check-face (face) | |
215 | "Signal an error if FACE doesn't name a face. | |
216 | Value is FACE." | |
217 | (unless (facep face) | |
218 | (error "Not a face: %s" face)) | |
219 | face) | |
220 | ||
221 | ||
222 | ;; The ID returned is not to be confused with the internally used IDs | |
223 | ;; of realized faces. The ID assigned to Lisp faces is used to | |
224 | ;; support faces in display table entries. | |
225 | ||
226 | (defun face-id (face &optional frame) | |
2df447f2 | 227 | "Return the internal ID of face with name FACE. |
5f5c8ee5 GM |
228 | If optional argument FRAME is nil or omitted, use the selected frame." |
229 | (check-face face) | |
230 | (get face 'face)) | |
231 | ||
232 | ||
233 | (defun face-equal (face1 face2 &optional frame) | |
234 | "Non-nil if faces FACE1 and FACE2 are equal. | |
235 | Faces are considered equal if all their attributes are equal. | |
236 | If the optional argument FRAME is given, report on face FACE in that frame. | |
237 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
238 | If FRAME is omitted or nil, use the selected frame." | |
239 | (internal-lisp-face-equal-p face1 face2 frame)) | |
240 | ||
241 | ||
242 | (defun face-differs-from-default-p (face &optional frame) | |
7e07a66d | 243 | "Return non-nil if FACE displays differently from the default face. |
5f5c8ee5 GM |
244 | If the optional argument FRAME is given, report on face FACE in that frame. |
245 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
7e07a66d MB |
246 | If FRAME is omitted or nil, use the selected frame." |
247 | (if (not (equal (face-font face frame) (face-font 'default frame))) | |
248 | ;; The font is different from the default face's font, so clearly it | |
249 | ;; differs. This only really works on window-systems; on ttys, the | |
250 | ;; "font" is a constant, with attributes layered on top of it. | |
251 | :font | |
252 | ;; General face attribute check. On graphical displays | |
253 | ;; `display-supports-face-attributes-p' just checks whether each | |
254 | ;; attribute is different that the default face, so we just check to | |
255 | ;; make sure each attribute of the merged face is not `unspecified'; | |
256 | ;; we already checked the font above, so font-related attributes are | |
257 | ;; omitted for that reason. On a tty, | |
258 | ;; display-supports-face-attributes-p actually does do further | |
259 | ;; checks, and correctly deals with the display's capabilities, so | |
260 | ;; we use it to check all attributes. | |
261 | (let ((attrs | |
262 | (if (memq (framep (or frame (selected-frame))) '(x w32 mac)) | |
263 | ;; Omit font-related attributes on a window-system | |
264 | '(:foreground :foreground :background :underline :overline | |
265 | :strike-through :box :inverse-video :stipple) | |
266 | ;; On a tty, check all attributes | |
267 | '(:family :width :height :weight :slant :foreground | |
268 | :foreground :background :underline :overline | |
269 | :strike-through :box :inverse-video :stipple))) | |
270 | (differs nil)) | |
271 | (while (and attrs (not differs)) | |
272 | (let* ((attr (pop attrs)) | |
273 | (attr-val (face-attribute face attr frame t))) | |
274 | (when (and | |
275 | (not (eq attr-val 'unspecified)) | |
276 | (display-supports-face-attributes-p (list attr attr-val) | |
277 | frame)) | |
278 | (setq differs attr)))) | |
279 | differs))) | |
5f5c8ee5 GM |
280 | |
281 | ||
282 | (defun face-nontrivial-p (face &optional frame) | |
283 | "True if face FACE has some non-nil attribute. | |
284 | If the optional argument FRAME is given, report on face FACE in that frame. | |
285 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
286 | If FRAME is omitted or nil, use the selected frame." | |
287 | (not (internal-lisp-face-empty-p face frame))) | |
288 | ||
289 | ||
290 | \f | |
291 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
292 | ;;; Setting face attributes from X resources. | |
293 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
294 | ||
295 | (defcustom face-x-resources | |
296 | '((:family (".attributeFamily" . "Face.AttributeFamily")) | |
297 | (:width (".attributeWidth" . "Face.AttributeWidth")) | |
298 | (:height (".attributeHeight" . "Face.AttributeHeight")) | |
299 | (:weight (".attributeWeight" . "Face.AttributeWeight")) | |
300 | (:slant (".attributeSlant" . "Face.AttributeSlant")) | |
301 | (:foreground (".attributeForeground" . "Face.AttributeForeground")) | |
302 | (:background (".attributeBackground" . "Face.AttributeBackground")) | |
303 | (:overline (".attributeOverline" . "Face.AttributeOverline")) | |
304 | (:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough")) | |
305 | (:box (".attributeBox" . "Face.AttributeBox")) | |
306 | (:underline (".attributeUnderline" . "Face.AttributeUnderline")) | |
307 | (:inverse-video (".attributeInverse" . "Face.AttributeInverse")) | |
308 | (:stipple | |
309 | (".attributeStipple" . "Face.AttributeStipple") | |
310 | (".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap")) | |
5f5c8ee5 GM |
311 | (:bold (".attributeBold" . "Face.AttributeBold")) |
312 | (:italic (".attributeItalic" . "Face.AttributeItalic")) | |
a0e5a5a4 MB |
313 | (:font (".attributeFont" . "Face.AttributeFont")) |
314 | (:inherit (".attributeInherit" . "Face.AttributeInherit"))) | |
5f5c8ee5 GM |
315 | "*List of X resources and classes for face attributes. |
316 | Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is | |
317 | the name of a face attribute, and each ENTRY is a cons of the form | |
2cb95d1b | 318 | \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the |
5f5c8ee5 | 319 | X resource class for the attribute." |
b5325e78 | 320 | :type '(repeat (cons symbol (repeat (cons string string)))) |
5f5c8ee5 GM |
321 | :group 'faces) |
322 | ||
323 | ||
324 | (defun set-face-attribute-from-resource (face attribute resource class frame) | |
325 | "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME. | |
326 | Value is the attribute value specified by the resource, or nil | |
327 | if not present. This function displays a message if the resource | |
328 | specifies an invalid attribute." | |
329 | (let* ((face-name (face-name face)) | |
330 | (value (internal-face-x-get-resource (concat face-name resource) | |
331 | class frame))) | |
332 | (when value | |
333 | (condition-case () | |
334 | (internal-set-lisp-face-attribute-from-resource | |
335 | face attribute (downcase value) frame) | |
336 | (error | |
337 | (message "Face %s, frame %s: invalid attribute %s %s from X resource" | |
338 | face-name frame attribute value)))) | |
339 | value)) | |
340 | ||
341 | ||
342 | (defun set-face-attributes-from-resources (face frame) | |
343 | "Set attributes of FACE from X resources for FRAME." | |
1a578e9b | 344 | (when (memq (framep frame) '(x w32 mac)) |
5f5c8ee5 GM |
345 | (dolist (definition face-x-resources) |
346 | (let ((attribute (car definition))) | |
347 | (dolist (entry (cdr definition)) | |
348 | (set-face-attribute-from-resource face attribute (car entry) | |
349 | (cdr entry) frame)))))) | |
00f51890 SS |
350 | |
351 | ||
5f5c8ee5 GM |
352 | (defun make-face-x-resource-internal (face &optional frame) |
353 | "Fill frame-local FACE on FRAME from X resources. | |
354 | FRAME nil or not specified means do it for all frames." | |
355 | (if (null frame) | |
356 | (dolist (frame (frame-list)) | |
357 | (set-face-attributes-from-resources face frame)) | |
358 | (set-face-attributes-from-resources face frame))) | |
359 | ||
360 | ||
361 | \f | |
362 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
363 | ;;; Retrieving face attributes. | |
364 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
365 | ||
feaad827 | 366 | (defun face-name (face) |
465fceed | 367 | "Return the name of face FACE." |
5f5c8ee5 GM |
368 | (symbol-name (check-face face))) |
369 | ||
370 | ||
c7f814cb | 371 | (defun face-attribute (face attribute &optional frame inherit) |
5f5c8ee5 GM |
372 | "Return the value of FACE's ATTRIBUTE on FRAME. |
373 | If the optional argument FRAME is given, report on face FACE in that frame. | |
374 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
c7f814cb | 375 | If FRAME is omitted or nil, use the selected frame. |
5f5c8ee5 | 376 | |
c7f814cb MB |
377 | If INHERIT is nil, only attributes directly defined by FACE are considered, |
378 | so the return value may be `unspecified', or a relative value. | |
379 | If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the | |
380 | faces specified by its `:inherit' attribute; however the return value | |
381 | may still be `unspecified' or relative. | |
382 | If INHERIT is a face or a list of faces, then the result is further merged | |
383 | with that face (or faces), until it becomes specified and absolute. | |
384 | ||
385 | To ensure that the return value is always specified and absolute, use a | |
386 | value of `default' for INHERIT; this will resolve any unspecified or | |
387 | relative values by merging with the `default' face (which is always | |
388 | completely specified)." | |
389 | (let ((value (internal-get-lisp-face-attribute face attribute frame))) | |
390 | (when (and inherit (face-attribute-relative-p attribute value)) | |
391 | ;; VALUE is relative, so merge with inherited faces | |
392 | (let ((inh-from (face-attribute face :inherit frame))) | |
393 | (unless (or (null inh-from) (eq inh-from 'unspecified)) | |
394 | (setq value | |
395 | (face-attribute-merged-with attribute value inh-from frame))))) | |
396 | (when (and inherit | |
397 | (not (eq inherit t)) | |
398 | (face-attribute-relative-p attribute value)) | |
b6b90dfc | 399 | ;; We should merge with INHERIT as well |
c7f814cb MB |
400 | (setq value (face-attribute-merged-with attribute value inherit frame))) |
401 | value)) | |
5f5c8ee5 | 402 | |
c7f814cb MB |
403 | (defun face-attribute-merged-with (attribute value faces &optional frame) |
404 | "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute. | |
405 | FACES may be either a single face or a list of faces. | |
406 | \[This is an internal function]" | |
407 | (cond ((not (face-attribute-relative-p attribute value)) | |
408 | value) | |
409 | ((null faces) | |
410 | value) | |
411 | ((consp faces) | |
412 | (face-attribute-merged-with | |
413 | attribute | |
414 | (face-attribute-merged-with attribute value (car faces) frame) | |
415 | (cdr faces) | |
416 | frame)) | |
417 | (t | |
418 | (merge-face-attribute attribute | |
419 | value | |
420 | (face-attribute faces attribute frame t))))) | |
421 | ||
422 | ||
423 | (defmacro face-attribute-specified-or (value &rest body) | |
424 | "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result." | |
425 | (let ((temp (make-symbol "value"))) | |
426 | `(let ((,temp ,value)) | |
427 | (if (not (eq ,temp 'unspecified)) | |
428 | ,temp | |
429 | ,@body)))) | |
430 | ||
431 | (defun face-foreground (face &optional frame inherit) | |
5f5c8ee5 GM |
432 | "Return the foreground color name of FACE, or nil if unspecified. |
433 | If the optional argument FRAME is given, report on face FACE in that frame. | |
434 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
c7f814cb | 435 | If FRAME is omitted or nil, use the selected frame. |
5f5c8ee5 | 436 | |
c7f814cb MB |
437 | If INHERIT is nil, only a foreground color directly defined by FACE is |
438 | considered, so the return value may be nil. | |
439 | If INHERIT is t, and FACE doesn't define a foreground color, then any | |
440 | foreground color that FACE inherits through its `:inherit' attribute | |
441 | is considered as well; however the return value may still be nil. | |
442 | If INHERIT is a face or a list of faces, then it is used to try to | |
443 | resolve an unspecified foreground color. | |
444 | ||
445 | To ensure that a valid color is always returned, use a value of | |
446 | `default' for INHERIT; this will resolve any unspecified values by | |
447 | merging with the `default' face (which is always completely specified)." | |
448 | (face-attribute-specified-or (face-attribute face :foreground frame inherit) | |
449 | nil)) | |
450 | ||
451 | (defun face-background (face &optional frame inherit) | |
5f5c8ee5 GM |
452 | "Return the background color name of FACE, or nil if unspecified. |
453 | If the optional argument FRAME is given, report on face FACE in that frame. | |
454 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
c7f814cb | 455 | If FRAME is omitted or nil, use the selected frame. |
5f5c8ee5 | 456 | |
c7f814cb MB |
457 | If INHERIT is nil, only a background color directly defined by FACE is |
458 | considered, so the return value may be nil. | |
459 | If INHERIT is t, and FACE doesn't define a background color, then any | |
460 | background color that FACE inherits through its `:inherit' attribute | |
461 | is considered as well; however the return value may still be nil. | |
462 | If INHERIT is a face or a list of faces, then it is used to try to | |
463 | resolve an unspecified background color. | |
464 | ||
465 | To ensure that a valid color is always returned, use a value of | |
466 | `default' for INHERIT; this will resolve any unspecified values by | |
467 | merging with the `default' face (which is always completely specified)." | |
468 | (face-attribute-specified-or (face-attribute face :background frame inherit) | |
469 | nil)) | |
470 | ||
471 | (defun face-stipple (face &optional frame inherit) | |
5f5c8ee5 GM |
472 | "Return the stipple pixmap name of FACE, or nil if unspecified. |
473 | If the optional argument FRAME is given, report on face FACE in that frame. | |
474 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
c7f814cb MB |
475 | If FRAME is omitted or nil, use the selected frame. |
476 | ||
477 | If INHERIT is nil, only a stipple directly defined by FACE is | |
478 | considered, so the return value may be nil. | |
479 | If INHERIT is t, and FACE doesn't define a stipple, then any stipple | |
480 | that FACE inherits through its `:inherit' attribute is considered as | |
481 | well; however the return value may still be nil. | |
482 | If INHERIT is a face or a list of faces, then it is used to try to | |
483 | resolve an unspecified stipple. | |
484 | ||
485 | To ensure that a valid stipple or nil is always returned, use a value of | |
486 | `default' for INHERIT; this will resolve any unspecified values by merging | |
487 | with the `default' face (which is always completely specified)." | |
488 | (face-attribute-specified-or (face-attribute face :stipple frame inherit) | |
489 | nil)) | |
5f5c8ee5 GM |
490 | |
491 | ||
492 | (defalias 'face-background-pixmap 'face-stipple) | |
493 | ||
494 | ||
495 | (defun face-underline-p (face &optional frame) | |
496 | "Return non-nil if FACE is underlined. | |
497 | If the optional argument FRAME is given, report on face FACE in that frame. | |
498 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
499 | If FRAME is omitted or nil, use the selected frame." | |
500 | (eq (face-attribute face :underline frame) t)) | |
501 | ||
502 | ||
503 | (defun face-inverse-video-p (face &optional frame) | |
504 | "Return non-nil if FACE is in inverse video on FRAME. | |
505 | If the optional argument FRAME is given, report on face FACE in that frame. | |
506 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
507 | If FRAME is omitted or nil, use the selected frame." | |
508 | (eq (face-attribute face :inverse-video frame) t)) | |
509 | ||
510 | ||
511 | (defun face-bold-p (face &optional frame) | |
512 | "Return non-nil if the font of FACE is bold on FRAME. | |
513 | If the optional argument FRAME is given, report on face FACE in that frame. | |
514 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
515 | If FRAME is omitted or nil, use the selected frame. | |
516 | Use `face-attribute' for finer control." | |
517 | (let ((bold (face-attribute face :weight frame))) | |
da2c7b8c | 518 | (memq bold '(semi-bold bold extra-bold ultra-bold)))) |
5f5c8ee5 GM |
519 | |
520 | ||
521 | (defun face-italic-p (face &optional frame) | |
522 | "Return non-nil if the font of FACE is italic on FRAME. | |
523 | If the optional argument FRAME is given, report on face FACE in that frame. | |
524 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
525 | If FRAME is omitted or nil, use the selected frame. | |
526 | Use `face-attribute' for finer control." | |
527 | (let ((italic (face-attribute face :slant frame))) | |
a48f6020 | 528 | (memq italic '(italic oblique)))) |
00f51890 | 529 | |
5f5c8ee5 | 530 | |
5f5c8ee5 GM |
531 | \f |
532 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
533 | ;;; Face documentation. | |
534 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
535 | ||
536 | (defun face-documentation (face) | |
537 | "Get the documentation string for FACE." | |
538 | (get face 'face-documentation)) | |
539 | ||
540 | ||
541 | (defun set-face-documentation (face string) | |
542 | "Set the documentation string for FACE to STRING." | |
291cfb96 | 543 | ;; Perhaps the text should go in DOC. |
49435801 | 544 | (put face 'face-documentation (purecopy string))) |
5f5c8ee5 GM |
545 | |
546 | ||
547 | (defalias 'face-doc-string 'face-documentation) | |
548 | (defalias 'set-face-doc-string 'set-face-documentation) | |
549 | ||
550 | ||
551 | \f | |
552 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
553 | ;; Setting face attributes. | |
554 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
555 | ||
556 | ||
557 | (defun set-face-attribute (face frame &rest args) | |
558 | "Set attributes of FACE on FRAME from ARGS. | |
559 | ||
560 | FRAME nil means change attributes on all frames. FRAME t means change | |
561 | the default for new frames (this is done automatically each time an | |
562 | attribute is changed on all frames). | |
563 | ||
564 | ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a valid | |
565 | face attribute name. All attributes can be set to `unspecified'; | |
566 | this fact is not further mentioned below. | |
567 | ||
568 | The following attributes are recognized: | |
569 | ||
570 | `:family' | |
571 | ||
572 | VALUE must be a string specifying the font family, e.g. ``courier'', | |
573 | or a fontset alias name. If a font family is specified, wild-cards `*' | |
574 | and `?' are allowed. | |
575 | ||
576 | `:width' | |
577 | ||
578 | VALUE specifies the relative proportionate width of the font to use. | |
579 | It must be one of the symbols `ultra-condensed', `extra-condensed', | |
580 | `condensed', `semi-condensed', `normal', `semi-expanded', `expanded', | |
581 | `extra-expanded', or `ultra-expanded'. | |
582 | ||
583 | `:height' | |
584 | ||
19feb949 MB |
585 | VALUE must be either an integer specifying the height of the font to use |
586 | in 1/10 pt, a floating point number specifying the amount by which to | |
587 | scale any underlying face, or a function, which is called with the old | |
588 | height (from the underlying face), and should return the new height. | |
5f5c8ee5 GM |
589 | |
590 | `:weight' | |
591 | ||
592 | VALUE specifies the weight of the font to use. It must be one of the | |
593 | symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal', | |
594 | `semi-light', `light', `extra-light', `ultra-light'. | |
595 | ||
596 | `:slant' | |
597 | ||
598 | VALUE specifies the slant of the font to use. It must be one of the | |
599 | symbols `italic', `oblique', `normal', `reverse-italic', or | |
600 | `reverse-oblique'. | |
601 | ||
602 | `:foreground', `:background' | |
603 | ||
604 | VALUE must be a color name, a string. | |
605 | ||
606 | `:underline' | |
607 | ||
608 | VALUE specifies whether characters in FACE should be underlined. If | |
609 | VALUE is t, underline with foreground color of the face. If VALUE is | |
610 | a string, underline with that color. If VALUE is nil, explicitly | |
611 | don't underline. | |
612 | ||
613 | `:overline' | |
614 | ||
615 | VALUE specifies whether characters in FACE should be overlined. If | |
616 | VALUE is t, overline with foreground color of the face. If VALUE is a | |
617 | string, overline with that color. If VALUE is nil, explicitly don't | |
618 | overline. | |
619 | ||
620 | `:strike-through' | |
621 | ||
622 | VALUE specifies whether characters in FACE should be drawn with a line | |
623 | striking through them. If VALUE is t, use the foreground color of the | |
624 | face. If VALUE is a string, strike-through with that color. If VALUE | |
625 | is nil, explicitly don't strike through. | |
626 | ||
627 | `:box' | |
628 | ||
629 | VALUE specifies whether characters in FACE should have a box drawn | |
630 | around them. If VALUE is nil, explicitly don't draw boxes. If | |
631 | VALUE is t, draw a box with lines of width 1 in the foreground color | |
632 | of the face. If VALUE is a string, the string must be a color name, | |
633 | and the box is drawn in that color with a line width of 1. Otherwise, | |
634 | VALUE must be a property list of the form `(:line-width WIDTH | |
635 | :color COLOR :style STYLE)'. If a keyword/value pair is missing from | |
636 | the property list, a default value will be used for the value, as | |
637 | specified below. WIDTH specifies the width of the lines to draw; it | |
0f937ebd KH |
638 | defaults to 1. If WIDTH is negative, the absolute value is the width |
639 | of the lines, and draw top/bottom lines inside the characters area, | |
640 | not around it. COLOR is the name of the color to draw in, default is | |
5f5c8ee5 GM |
641 | the foreground color of the face for simple boxes, and the background |
642 | color of the face for 3D boxes. STYLE specifies whether a 3D box | |
643 | should be draw. If STYLE is `released-button', draw a box looking | |
644 | like a released 3D button. If STYLE is `pressed-button' draw a box | |
645 | that appears like a pressed button. If STYLE is nil, the default if | |
646 | the property list doesn't contain a style specification, draw a 2D | |
647 | box. | |
648 | ||
649 | `:inverse-video' | |
650 | ||
651 | VALUE specifies whether characters in FACE should be displayed in | |
70d0c3b0 | 652 | inverse video. VALUE must be one of t or nil. |
5f5c8ee5 GM |
653 | |
654 | `:stipple' | |
655 | ||
656 | If VALUE is a string, it must be the name of a file of pixmap data. | |
657 | The directories listed in the `x-bitmap-file-path' variable are | |
658 | searched. Alternatively, VALUE may be a list of the form (WIDTH | |
659 | HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA | |
660 | is a string containing the raw bits of the bitmap. VALUE nil means | |
661 | explicitly don't use a stipple pattern. | |
662 | ||
663 | For convenience, attributes `:family', `:width', `:height', `:weight', | |
664 | and `:slant' may also be set in one step from an X font name: | |
665 | ||
666 | `:font' | |
667 | ||
668 | Set font-related face attributes from VALUE. VALUE must be a valid | |
669 | XLFD font name. If it is a font name pattern, the first matching font | |
670 | will be used. | |
671 | ||
672 | For compatibility with Emacs 20, keywords `:bold' and `:italic' can | |
673 | be used to specify that a bold or italic font should be used. VALUE | |
19feb949 MB |
674 | must be t or nil in that case. A value of `unspecified' is not allowed. |
675 | ||
676 | `:inherit' | |
677 | ||
678 | VALUE is the name of a face from which to inherit attributes, or a list | |
679 | of face names. Attributes from inherited faces are merged into the face | |
680 | like an underlying face would be, with higher priority than underlying faces." | |
70a267c9 GM |
681 | (let ((where (if (null frame) 0 frame))) |
682 | (setq args (purecopy args)) | |
680da3f8 RS |
683 | ;; If we set the new-frame defaults, this face is modified outside Custom. |
684 | (if (memq where '(0 t)) | |
685 | (put face 'face-modified t)) | |
70a267c9 GM |
686 | (while args |
687 | (internal-set-lisp-face-attribute face (car args) | |
688 | (purecopy (cadr args)) | |
689 | where) | |
690 | (setq args (cdr (cdr args)))))) | |
5f5c8ee5 GM |
691 | |
692 | ||
39cac3e7 | 693 | (defun make-face-bold (face &optional frame noerror) |
5f5c8ee5 GM |
694 | "Make the font of FACE be bold, if possible. |
695 | FRAME nil or not specified means change face on all frames. | |
39cac3e7 | 696 | Argument NOERROR is ignored and retained for compatibility. |
5f5c8ee5 | 697 | Use `set-face-attribute' for finer control of the font weight." |
95125512 | 698 | (interactive (list (read-face-name "Make which face bold"))) |
5f5c8ee5 GM |
699 | (set-face-attribute face frame :weight 'bold)) |
700 | ||
701 | ||
39cac3e7 | 702 | (defun make-face-unbold (face &optional frame noerror) |
5f5c8ee5 | 703 | "Make the font of FACE be non-bold, if possible. |
39cac3e7 GM |
704 | FRAME nil or not specified means change face on all frames. |
705 | Argument NOERROR is ignored and retained for compatibility." | |
95125512 | 706 | (interactive (list (read-face-name "Make which face non-bold"))) |
5f5c8ee5 GM |
707 | (set-face-attribute face frame :weight 'normal)) |
708 | ||
00f51890 | 709 | |
39cac3e7 | 710 | (defun make-face-italic (face &optional frame noerror) |
5f5c8ee5 GM |
711 | "Make the font of FACE be italic, if possible. |
712 | FRAME nil or not specified means change face on all frames. | |
39cac3e7 | 713 | Argument NOERROR is ignored and retained for compatibility. |
5f5c8ee5 | 714 | Use `set-face-attribute' for finer control of the font slant." |
95125512 | 715 | (interactive (list (read-face-name "Make which face italic"))) |
5f5c8ee5 GM |
716 | (set-face-attribute face frame :slant 'italic)) |
717 | ||
718 | ||
39cac3e7 | 719 | (defun make-face-unitalic (face &optional frame noerror) |
5f5c8ee5 | 720 | "Make the font of FACE be non-italic, if possible. |
70d0c3b0 DL |
721 | FRAME nil or not specified means change face on all frames. |
722 | Argument NOERROR is ignored and retained for compatibility." | |
95125512 | 723 | (interactive (list (read-face-name "Make which face non-italic"))) |
5f5c8ee5 GM |
724 | (set-face-attribute face frame :slant 'normal)) |
725 | ||
00f51890 | 726 | |
39cac3e7 | 727 | (defun make-face-bold-italic (face &optional frame noerror) |
5f5c8ee5 GM |
728 | "Make the font of FACE be bold and italic, if possible. |
729 | FRAME nil or not specified means change face on all frames. | |
39cac3e7 | 730 | Argument NOERROR is ignored and retained for compatibility. |
5f5c8ee5 | 731 | Use `set-face-attribute' for finer control of font weight and slant." |
95125512 | 732 | (interactive (list (read-face-name "Make which face bold-italic"))) |
5f5c8ee5 GM |
733 | (set-face-attribute face frame :weight 'bold :slant 'italic)) |
734 | ||
735 | ||
736 | (defun set-face-font (face font &optional frame) | |
737 | "Change font-related attributes of FACE to those of FONT (a string). | |
738 | FRAME nil or not specified means change face on all frames. | |
739 | This sets the attributes `:family', `:width', `:height', `:weight', | |
740 | and `:slant'. When called interactively, prompt for the face and font." | |
741 | (interactive (read-face-and-attribute :font)) | |
742 | (set-face-attribute face frame :font font)) | |
743 | ||
744 | ||
745 | ;; Implementation note: Emulating gray background colors with a | |
746 | ;; stipple pattern is now part of the face realization process, and is | |
747 | ;; done in C depending on the frame on which the face is realized. | |
748 | ||
749 | (defun set-face-background (face color &optional frame) | |
750 | "Change the background color of face FACE to COLOR (a string). | |
751 | FRAME nil or not specified means change face on all frames. | |
752 | When called interactively, prompt for the face and color." | |
753 | (interactive (read-face-and-attribute :background)) | |
78ad1cd5 | 754 | (set-face-attribute face frame :background (or color 'unspecified))) |
5f5c8ee5 GM |
755 | |
756 | ||
757 | (defun set-face-foreground (face color &optional frame) | |
758 | "Change the foreground color of face FACE to COLOR (a string). | |
759 | FRAME nil or not specified means change face on all frames. | |
760 | When called interactively, prompt for the face and color." | |
761 | (interactive (read-face-and-attribute :foreground)) | |
78ad1cd5 | 762 | (set-face-attribute face frame :foreground (or color 'unspecified))) |
5f5c8ee5 GM |
763 | |
764 | ||
765 | (defun set-face-stipple (face stipple &optional frame) | |
766 | "Change the stipple pixmap of face FACE to STIPPLE. | |
767 | FRAME nil or not specified means change face on all frames. | |
70d0c3b0 | 768 | STIPPLE should be a string, the name of a file of pixmap data. |
5f5c8ee5 GM |
769 | The directories listed in the `x-bitmap-file-path' variable are searched. |
770 | ||
771 | Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA) | |
772 | where WIDTH and HEIGHT are the size in pixels, | |
773 | and DATA is a string, containing the raw bits of the bitmap." | |
774 | (interactive (read-face-and-attribute :stipple)) | |
78ad1cd5 | 775 | (set-face-attribute face frame :stipple (or stipple 'unspecified))) |
5f5c8ee5 GM |
776 | |
777 | ||
778 | (defun set-face-underline (face underline &optional frame) | |
779 | "Specify whether face FACE is underlined. | |
780 | UNDERLINE nil means FACE explicitly doesn't underline. | |
781 | UNDERLINE non-nil means FACE explicitly does underlining | |
782 | with the same of the foreground color. | |
783 | If UNDERLINE is a string, underline with the color named UNDERLINE. | |
784 | FRAME nil or not specified means change face on all frames. | |
785 | Use `set-face-attribute' to ``unspecify'' underlining." | |
786 | (interactive | |
787 | (let ((list (read-face-and-attribute :underline))) | |
788 | (list (car list) (eq (car (cdr list)) t)))) | |
789 | (set-face-attribute face frame :underline underline)) | |
790 | ||
791 | ||
792 | (defun set-face-underline-p (face underline-p &optional frame) | |
793 | "Specify whether face FACE is underlined. | |
794 | UNDERLINE-P nil means FACE explicitly doesn't underline. | |
795 | UNDERLINE-P non-nil means FACE explicitly does underlining. | |
796 | FRAME nil or not specified means change face on all frames. | |
797 | Use `set-face-attribute' to ``unspecify'' underlining." | |
798 | (interactive | |
799 | (let ((list (read-face-and-attribute :underline))) | |
800 | (list (car list) (eq (car (cdr list)) t)))) | |
801 | (set-face-attribute face frame :underline underline-p)) | |
802 | ||
803 | ||
804 | (defun set-face-inverse-video-p (face inverse-video-p &optional frame) | |
805 | "Specify whether face FACE is in inverse video. | |
806 | INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video. | |
807 | INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video. | |
808 | FRAME nil or not specified means change face on all frames. | |
809 | Use `set-face-attribute' to ``unspecify'' the inverse video attribute." | |
810 | (interactive | |
811 | (let ((list (read-face-and-attribute :inverse-video))) | |
812 | (list (car list) (eq (car (cdr list)) t)))) | |
813 | (set-face-attribute face frame :inverse-video inverse-video-p)) | |
814 | ||
815 | ||
816 | (defun set-face-bold-p (face bold-p &optional frame) | |
817 | "Specify whether face FACE is bold. | |
818 | BOLD-P non-nil means FACE should explicitly display bold. | |
819 | BOLD-P nil means FACE should explicitly display non-bold. | |
820 | FRAME nil or not specified means change face on all frames. | |
821 | Use `set-face-attribute' or `modify-face' for finer control." | |
822 | (if (null bold-p) | |
823 | (make-face-unbold face frame) | |
824 | (make-face-bold face frame))) | |
825 | ||
826 | ||
827 | (defun set-face-italic-p (face italic-p &optional frame) | |
828 | "Specify whether face FACE is italic. | |
829 | ITALIC-P non-nil means FACE should explicitly display italic. | |
830 | ITALIC-P nil means FACE should explicitly display non-italic. | |
831 | FRAME nil or not specified means change face on all frames. | |
832 | Use `set-face-attribute' or `modify-face' for finer control." | |
833 | (if (null italic-p) | |
834 | (make-face-unitalic face frame) | |
835 | (make-face-italic face frame))) | |
836 | ||
837 | ||
838 | (defalias 'set-face-background-pixmap 'set-face-stipple) | |
839 | ||
840 | ||
841 | (defun invert-face (face &optional frame) | |
842 | "Swap the foreground and background colors of FACE. | |
e458cb49 | 843 | If FRAME is omitted or nil, it means change face on all frames. |
5f5c8ee5 GM |
844 | If FACE specifies neither foreground nor background color, |
845 | set its foreground and background to the background and foreground | |
846 | of the default face. Value is FACE." | |
95125512 | 847 | (interactive (list (read-face-name "Invert face"))) |
5f5c8ee5 GM |
848 | (let ((fg (face-attribute face :foreground frame)) |
849 | (bg (face-attribute face :background frame))) | |
e458cb49 | 850 | (if (not (and (eq fg 'unspecified) (eq bg 'unspecified))) |
5f5c8ee5 GM |
851 | (set-face-attribute face frame :foreground bg :background fg) |
852 | (set-face-attribute face frame | |
853 | :foreground | |
854 | (face-attribute 'default :background frame) | |
855 | :background | |
856 | (face-attribute 'default :foreground frame)))) | |
857 | face) | |
858 | ||
859 | \f | |
860 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
861 | ;;; Interactively modifying faces. | |
862 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
863 | ||
a482f364 RS |
864 | (defun read-face-name (prompt &optional string-describing-default multiple) |
865 | "Read a face, defaulting to the face or faces on the char after point. | |
866 | If it has a `read-face-name' property, that overrides the `face' property. | |
867 | PROMPT describes what you will do with the face (don't end in a space). | |
868 | STRING-DESCRIBING-DEFAULT describes what default you will use | |
869 | if this function returns nil. | |
870 | If MULTIPLE is non-nil, return a list of faces (possibly only one). | |
871 | Otherwise, return a single face." | |
872 | (let ((faceprop (or (get-char-property (point) 'read-face-name) | |
873 | (get-char-property (point) 'face))) | |
874 | faces) | |
875 | ;; Make a list of the named faces that the `face' property uses. | |
876 | (if (listp faceprop) | |
877 | (dolist (f faceprop) | |
878 | (if (symbolp f) | |
879 | (push f faces))) | |
880 | (if (symbolp faceprop) | |
881 | (setq faces (list faceprop)))) | |
882 | ;; If there are none, try to get a face name from the buffer. | |
883 | (if (and (null faces) | |
884 | (memq (intern-soft (thing-at-point 'symbol)) (face-list))) | |
885 | (setq faces (list (intern-soft (thing-at-point 'symbol))))) | |
886 | ||
887 | ;; If we only want one, and the default is more than one, | |
888 | ;; discard the unwanted ones now. | |
889 | (unless multiple | |
890 | (if faces | |
891 | (setq faces (list (car faces))))) | |
892 | (let* ((input | |
893 | ;; Read the input. | |
894 | (completing-read | |
895 | (if (or faces string-describing-default) | |
896 | (format "%s (default %s): " prompt | |
897 | (if faces (mapconcat 'symbol-name faces ", ") | |
898 | string-describing-default)) | |
3b4ef34b | 899 | (format "%s: " prompt)) |
a482f364 RS |
900 | obarray 'custom-facep t)) |
901 | ;; Canonicalize the output. | |
902 | (output | |
903 | (if (equal input "") | |
904 | faces | |
905 | (if (stringp input) | |
906 | (list (intern input)) | |
907 | input)))) | |
908 | ;; Return either a list of faces or just one face. | |
909 | (if multiple | |
910 | output | |
911 | (car output))))) | |
912 | ||
913 | ||
5f5c8ee5 GM |
914 | (defun face-valid-attribute-values (attribute &optional frame) |
915 | "Return valid values for face attribute ATTRIBUTE. | |
916 | The optional argument FRAME is used to determine available fonts | |
917 | and colors. If it is nil or not specified, the selected frame is | |
918 | used. Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value | |
919 | out of a set of discrete values. Value is `integerp' if ATTRIBUTE expects | |
920 | an integer value." | |
00f51890 SS |
921 | (let ((valid |
922 | (case attribute | |
923 | (:family | |
924 | (if window-system | |
925 | (mapcar #'(lambda (x) (cons (car x) (car x))) | |
926 | (x-font-family-list)) | |
927 | ;; Only one font on TTYs. | |
928 | (list (cons "default" "default")))) | |
929 | ((:width :weight :slant :inverse-video) | |
930 | (mapcar #'(lambda (x) (cons (symbol-name x) x)) | |
931 | (internal-lisp-face-attribute-values attribute))) | |
932 | ((:underline :overline :strike-through :box) | |
933 | (if window-system | |
934 | (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x)) | |
935 | (internal-lisp-face-attribute-values attribute)) | |
936 | (mapcar #'(lambda (c) (cons c c)) | |
937 | (x-defined-colors frame))) | |
938 | (mapcar #'(lambda (x) (cons (symbol-name x) x)) | |
939 | (internal-lisp-face-attribute-values attribute)))) | |
940 | ((:foreground :background) | |
941 | (mapcar #'(lambda (c) (cons c c)) | |
942 | (defined-colors frame))) | |
943 | ((:height) | |
944 | 'integerp) | |
945 | (:stipple | |
946 | (and (memq window-system '(x w32 mac)) | |
947 | (mapcar #'list | |
948 | (apply #'nconc | |
949 | (mapcar (lambda (dir) | |
950 | (and (file-readable-p dir) | |
951 | (file-directory-p dir) | |
952 | (directory-files dir))) | |
953 | x-bitmap-file-path))))) | |
954 | (:inherit | |
955 | (cons '("none" . nil) | |
956 | (mapcar #'(lambda (c) (cons (symbol-name c) c)) | |
957 | (face-list)))) | |
958 | (t | |
959 | (error "Internal error"))))) | |
19feb949 | 960 | (if (and (listp valid) (not (memq attribute '(:inherit)))) |
fbd5f1cc GM |
961 | (nconc (list (cons "unspecified" 'unspecified)) valid) |
962 | valid))) | |
5f5c8ee5 GM |
963 | |
964 | ||
965 | (defvar face-attribute-name-alist | |
966 | '((:family . "font family") | |
967 | (:width . "character set width") | |
968 | (:height . "height in 1/10 pt") | |
969 | (:weight . "weight") | |
970 | (:slant . "slant") | |
971 | (:underline . "underline") | |
972 | (:overline . "overline") | |
973 | (:strike-through . "strike-through") | |
974 | (:box . "box") | |
975 | (:inverse-video . "inverse-video display") | |
976 | (:foreground . "foreground color") | |
977 | (:background . "background color") | |
19feb949 MB |
978 | (:stipple . "background stipple") |
979 | (:inherit . "inheritance")) | |
5f5c8ee5 GM |
980 | "An alist of descriptive names for face attributes. |
981 | Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where | |
982 | ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and | |
983 | DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.") | |
984 | ||
985 | ||
986 | (defun face-descriptive-attribute-name (attribute) | |
987 | "Return a descriptive name for ATTRIBUTE." | |
988 | (cdr (assq attribute face-attribute-name-alist))) | |
989 | ||
990 | ||
991 | (defun face-read-string (face default name &optional completion-alist) | |
992 | "Interactively read a face attribute string value. | |
19feb949 MB |
993 | FACE is the face whose attribute is read. If non-nil, DEFAULT is the |
994 | default string to return if no new value is entered. NAME is a | |
995 | descriptive name of the attribute for prompting. COMPLETION-ALIST is an | |
996 | alist of valid values, if non-nil. | |
5f5c8ee5 | 997 | |
19feb949 | 998 | Entering nothing accepts the default string DEFAULT. |
5f5c8ee5 | 999 | Value is the new attribute value." |
19feb949 MB |
1000 | ;; Capitalize NAME (we don't use `capitalize' because that capitalizes |
1001 | ;; each word in a string separately). | |
1002 | (setq name (concat (upcase (substring name 0 1)) (substring name 1))) | |
5f5c8ee5 GM |
1003 | (let* ((completion-ignore-case t) |
1004 | (value (completing-read | |
1005 | (if default | |
19feb949 MB |
1006 | (format "%s for face `%s' (default %s): " |
1007 | name face default) | |
1008 | (format "%s for face `%s': " name face)) | |
5f5c8ee5 | 1009 | completion-alist))) |
fbd5f1cc | 1010 | (if (equal value "") default value))) |
5f5c8ee5 GM |
1011 | |
1012 | ||
1013 | (defun face-read-integer (face default name) | |
1014 | "Interactively read an integer face attribute value. | |
1015 | FACE is the face whose attribute is read. DEFAULT is the default | |
1016 | value to return if no new value is entered. NAME is a descriptive | |
1017 | name of the attribute for prompting. Value is the new attribute value." | |
fbd5f1cc GM |
1018 | (let ((new-value |
1019 | (face-read-string face | |
19feb949 | 1020 | (format "%s" default) |
fbd5f1cc GM |
1021 | name |
1022 | (list (cons "unspecified" 'unspecified))))) | |
19feb949 MB |
1023 | (cond ((equal new-value "unspecified") |
1024 | 'unspecified) | |
1025 | ((member new-value '("unspecified-fg" "unspecified-bg")) | |
1026 | new-value) | |
1027 | (t | |
1028 | (string-to-int new-value))))) | |
5f5c8ee5 GM |
1029 | |
1030 | ||
1031 | (defun read-face-attribute (face attribute &optional frame) | |
1032 | "Interactively read a new value for FACE's ATTRIBUTE. | |
1033 | Optional argument FRAME nil or unspecified means read an attribute value | |
1034 | of a global face. Value is the new attribute value." | |
1035 | (let* ((old-value (face-attribute face attribute frame)) | |
1036 | (attribute-name (face-descriptive-attribute-name attribute)) | |
1037 | (valid (face-valid-attribute-values attribute frame)) | |
1038 | new-value) | |
1039 | ;; Represent complex attribute values as strings by printing them | |
1040 | ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be | |
1041 | ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow | |
1042 | ;; SHADOW)'. | |
1043 | (when (and (or (eq attribute :stipple) | |
1044 | (eq attribute :box)) | |
1045 | (or (consp old-value) | |
1046 | (vectorp old-value))) | |
1047 | (setq old-value (prin1-to-string old-value))) | |
1048 | (cond ((listp valid) | |
19feb949 MB |
1049 | (let ((default |
1050 | (or (car (rassoc old-value valid)) | |
1051 | (format "%s" old-value)))) | |
1052 | (setq new-value | |
1053 | (face-read-string face default attribute-name valid)) | |
1054 | (if (equal new-value default) | |
1055 | ;; Nothing changed, so don't bother with all the stuff | |
1056 | ;; below. In particular, this avoids a non-tty color | |
1057 | ;; from being canonicalized for a tty when the user | |
1058 | ;; just uses the default. | |
1059 | (setq new-value old-value) | |
1060 | ;; Terminal frames can support colors that don't appear | |
1061 | ;; explicitly in VALID, using color approximation code | |
1062 | ;; in tty-colors.el. | |
f9056dd9 MB |
1063 | (when (and (memq attribute '(:foreground :background)) |
1064 | (not (memq window-system '(x w32 mac))) | |
1065 | (not (member new-value | |
1066 | '("unspecified" | |
1067 | "unspecified-fg" "unspecified-bg")))) | |
4385f1b0 | 1068 | (setq new-value (car (tty-color-desc new-value frame)))) |
f9056dd9 MB |
1069 | (when (assoc new-value valid) |
1070 | (setq new-value (cdr (assoc new-value valid))))))) | |
5f5c8ee5 GM |
1071 | ((eq valid 'integerp) |
1072 | (setq new-value (face-read-integer face old-value attribute-name))) | |
1073 | (t (error "Internal error"))) | |
1074 | ;; Convert stipple and box value text we read back to a list or | |
1075 | ;; vector if it looks like one. This makes the assumption that a | |
1076 | ;; pixmap file name won't start with an open-paren. | |
1077 | (when (and (or (eq attribute :stipple) | |
1078 | (eq attribute :box)) | |
1079 | (stringp new-value) | |
1080 | (string-match "^[[(]" new-value)) | |
1081 | (setq new-value (read new-value))) | |
1082 | new-value)) | |
1083 | ||
1084 | ||
1085 | (defun read-face-font (face &optional frame) | |
1086 | "Read the name of a font for FACE on FRAME. | |
1087 | If optional argument FRAME Is nil or omitted, use the selected frame." | |
1088 | (let ((completion-ignore-case t)) | |
48ec9939 | 1089 | (completing-read (format "Set font attributes of face `%s' from font: " face) |
411def8e | 1090 | (x-list-fonts "*" nil frame)))) |
5f5c8ee5 GM |
1091 | |
1092 | ||
1093 | (defun read-all-face-attributes (face &optional frame) | |
1094 | "Interactively read all attributes for FACE. | |
1095 | If optional argument FRAME Is nil or omitted, use the selected frame. | |
1096 | Value is a property list of attribute names and new values." | |
1097 | (let (result) | |
1098 | (dolist (attribute face-attribute-name-alist result) | |
1099 | (setq result (cons (car attribute) | |
1100 | (cons (read-face-attribute face (car attribute) frame) | |
1101 | result)))))) | |
1102 | ||
7cd512f2 SM |
1103 | (defun modify-face (&optional face foreground background stipple |
1104 | bold-p italic-p underline-p inverse-p frame) | |
5f5c8ee5 GM |
1105 | "Modify attributes of faces interactively. |
1106 | If optional argument FRAME is nil or omitted, modify the face used | |
7cd512f2 SM |
1107 | for newly created frame, i.e. the global face. |
1108 | For non-interactive use, `set-face-attribute' is preferred. | |
1109 | When called from elisp, if FACE is nil, all arguments but FRAME are ignored | |
1110 | and the face and its settings are obtained by querying the user." | |
5f5c8ee5 | 1111 | (interactive) |
7cd512f2 SM |
1112 | (if face |
1113 | (set-face-attribute face frame | |
1114 | :foreground (or foreground 'unspecified) | |
1115 | :background (or background 'unspecified) | |
1116 | :stipple stipple | |
1117 | :bold bold-p | |
1118 | :italic italic-p | |
1119 | :underline underline-p | |
1120 | :inverse-video inverse-p) | |
1121 | (setq face (read-face-name "Modify face")) | |
5f5c8ee5 GM |
1122 | (apply #'set-face-attribute face frame |
1123 | (read-all-face-attributes face frame)))) | |
1124 | ||
5f5c8ee5 GM |
1125 | (defun read-face-and-attribute (attribute &optional frame) |
1126 | "Read face name and face attribute value. | |
1127 | ATTRIBUTE is the attribute whose new value is read. | |
1128 | FRAME nil or unspecified means read attribute value of global face. | |
1129 | Value is a list (FACE NEW-VALUE) where FACE is the face read | |
7cd512f2 | 1130 | \(a symbol), and NEW-VALUE is value read." |
5f5c8ee5 | 1131 | (cond ((eq attribute :font) |
48ec9939 | 1132 | (let* ((prompt "Set font-related attributes of face") |
5f5c8ee5 GM |
1133 | (face (read-face-name prompt)) |
1134 | (font (read-face-font face frame))) | |
1135 | (list face font))) | |
1136 | (t | |
1137 | (let* ((attribute-name (face-descriptive-attribute-name attribute)) | |
19feb949 | 1138 | (prompt (format "Set %s of face" attribute-name)) |
5f5c8ee5 GM |
1139 | (face (read-face-name prompt)) |
1140 | (new-value (read-face-attribute face attribute frame))) | |
1141 | (list face new-value))))) | |
1142 | ||
1143 | ||
1144 | \f | |
1145 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1146 | ;;; Listing faces. | |
1147 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1148 | ||
1149 | (defvar list-faces-sample-text | |
1150 | "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
1151 | "*Text string to display as the sample text for `list-faces-display'.") | |
1152 | ||
1153 | ||
1154 | ;; The name list-faces would be more consistent, but let's avoid a | |
1155 | ;; conflict with Lucid, which uses that name differently. | |
1156 | ||
645a1038 | 1157 | (defvar help-xref-stack) |
5f5c8ee5 GM |
1158 | (defun list-faces-display () |
1159 | "List all faces, using the same sample text in each. | |
1160 | The sample text is a string that comes from the variable | |
1161 | `list-faces-sample-text'." | |
1162 | (interactive) | |
1163 | (let ((faces (sort (face-list) #'string-lessp)) | |
1164 | (face nil) | |
1165 | (frame (selected-frame)) | |
84fe35f0 | 1166 | disp-frame window face-name) |
5f5c8ee5 GM |
1167 | (with-output-to-temp-buffer "*Faces*" |
1168 | (save-excursion | |
1169 | (set-buffer standard-output) | |
1170 | (setq truncate-lines t) | |
84fe35f0 DL |
1171 | (insert |
1172 | (substitute-command-keys | |
1173 | (concat | |
1174 | "Use " | |
53c80cf6 | 1175 | (if (display-mouse-p) "\\[help-follow-mouse] or ") |
32e33f60 | 1176 | "\\[help-follow] on a face name to customize it\n" |
46057f5f | 1177 | "or on its sample text for a description of the face.\n\n"))) |
84fe35f0 | 1178 | (setq help-xref-stack nil) |
5f5c8ee5 GM |
1179 | (while faces |
1180 | (setq face (car faces)) | |
1181 | (setq faces (cdr faces)) | |
84fe35f0 DL |
1182 | (setq face-name (symbol-name face)) |
1183 | (insert (format "%25s " face-name)) | |
1184 | ;; Hyperlink to a customization buffer for the face. Using | |
1185 | ;; the help xref mechanism may not be the best way. | |
1186 | (save-excursion | |
1187 | (save-match-data | |
1188 | (search-backward face-name) | |
a482f364 RS |
1189 | (help-xref-button 0 'help-customize-face face))) |
1190 | (let ((beg (point)) | |
1191 | (line-beg (line-beginning-position))) | |
5f5c8ee5 | 1192 | (insert list-faces-sample-text) |
84fe35f0 DL |
1193 | ;; Hyperlink to a help buffer for the face. |
1194 | (save-excursion | |
1195 | (save-match-data | |
1196 | (search-backward list-faces-sample-text) | |
8940232b | 1197 | (help-xref-button 0 'help-face face))) |
5f5c8ee5 GM |
1198 | (insert "\n") |
1199 | (put-text-property beg (1- (point)) 'face face) | |
a482f364 RS |
1200 | ;; Make all face commands default to the proper face |
1201 | ;; anywhere in the line. | |
1202 | (put-text-property line-beg (1- (point)) 'read-face-name face) | |
5f5c8ee5 GM |
1203 | ;; If the sample text has multiple lines, line up all of them. |
1204 | (goto-char beg) | |
1205 | (forward-line 1) | |
1206 | (while (not (eobp)) | |
1207 | (insert " ") | |
1208 | (forward-line 1)))) | |
1209 | (goto-char (point-min))) | |
1210 | (print-help-return-message)) | |
1211 | ;; If the *Faces* buffer appears in a different frame, | |
1212 | ;; copy all the face definitions from FRAME, | |
1213 | ;; so that the display will reflect the frame that was selected. | |
1214 | (setq window (get-buffer-window (get-buffer "*Faces*") t)) | |
1215 | (setq disp-frame (if window (window-frame window) | |
1216 | (car (frame-list)))) | |
1217 | (or (eq frame disp-frame) | |
1218 | (let ((faces (face-list))) | |
1219 | (while faces | |
1220 | (copy-face (car faces) (car faces) frame disp-frame) | |
1221 | (setq faces (cdr faces))))))) | |
1222 | ||
5f5c8ee5 GM |
1223 | (defun describe-face (face &optional frame) |
1224 | "Display the properties of face FACE on FRAME. | |
6afa5404 | 1225 | Interactively, FACE defaults to the faces of the character after point |
a482f364 RS |
1226 | and FRAME defaults to the selected frame. |
1227 | ||
5f5c8ee5 GM |
1228 | If the optional argument FRAME is given, report on face FACE in that frame. |
1229 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
1230 | If FRAME is omitted or nil, use the selected frame." | |
a482f364 | 1231 | (interactive (list (read-face-name "Describe face" "= `default' face" t))) |
5f5c8ee5 GM |
1232 | (let* ((attrs '((:family . "Family") |
1233 | (:width . "Width") | |
1234 | (:height . "Height") | |
1235 | (:weight . "Weight") | |
1236 | (:slant . "Slant") | |
1237 | (:foreground . "Foreground") | |
1238 | (:background . "Background") | |
1239 | (:underline . "Underline") | |
1240 | (:overline . "Overline") | |
1241 | (:strike-through . "Strike-through") | |
1242 | (:box . "Box") | |
1243 | (:inverse-video . "Inverse") | |
b32631c8 | 1244 | (:stipple . "Stipple") |
25ac7b52 MB |
1245 | (:font . "Font or fontset") |
1246 | (:inherit . "Inherit"))) | |
5f5c8ee5 GM |
1247 | (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x))) |
1248 | attrs)))) | |
2cb95d1b | 1249 | (help-setup-xref (list #'describe-face face) (interactive-p)) |
a482f364 RS |
1250 | (unless face |
1251 | (setq face 'default)) | |
1252 | (if (not (listp face)) | |
1253 | (setq face (list face))) | |
8940232b | 1254 | (with-output-to-temp-buffer (help-buffer) |
5f5c8ee5 GM |
1255 | (save-excursion |
1256 | (set-buffer standard-output) | |
a482f364 RS |
1257 | (dolist (f face) |
1258 | (insert "Face: " (symbol-name f)) | |
1259 | (if (not (facep f)) | |
1260 | (insert " undefined face.\n") | |
1261 | (let ((customize-label "customize this face")) | |
1262 | (princ (concat " (" customize-label ")\n")) | |
1263 | (insert "Documentation: " | |
1264 | (or (face-documentation f) | |
f79f9fb2 | 1265 | "Not documented as a face.") |
a482f364 RS |
1266 | "\n\n") |
1267 | (with-current-buffer standard-output | |
1268 | (save-excursion | |
1269 | (re-search-backward | |
1270 | (concat "\\(" customize-label "\\)") nil t) | |
1271 | (help-xref-button 1 'help-customize-face f))) | |
1272 | (dolist (a attrs) | |
1273 | (let ((attr (face-attribute f (car a) frame))) | |
1274 | (insert (make-string (- max-width (length (cdr a))) ?\ ) | |
1275 | (cdr a) ": " (format "%s" attr) "\n"))))) | |
1276 | (terpri))) | |
2cb95d1b | 1277 | (print-help-return-message)))) |
8940232b | 1278 | |
5f5c8ee5 GM |
1279 | \f |
1280 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1281 | ;;; Face specifications (defface). | |
1282 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1283 | ||
1284 | ;; Parameter FRAME Is kept for call compatibility to with previous | |
1285 | ;; face implementation. | |
1286 | ||
1287 | (defun face-attr-construct (face &optional frame) | |
1288 | "Return a defface-style attribute list for FACE on FRAME. | |
1289 | Value is a property list of pairs ATTRIBUTE VALUE for all specified | |
1290 | face attributes of FACE where ATTRIBUTE is the attribute name and | |
1291 | VALUE is the specified value of that attribute." | |
1292 | (let (result) | |
1293 | (dolist (entry face-attribute-name-alist result) | |
1294 | (let* ((attribute (car entry)) | |
1295 | (value (face-attribute face attribute))) | |
1296 | (unless (eq value 'unspecified) | |
1297 | (setq result (nconc (list attribute value) result))))))) | |
00f51890 | 1298 | |
5f5c8ee5 GM |
1299 | |
1300 | (defun face-spec-set-match-display (display frame) | |
1301 | "Non-nil if DISPLAY matches FRAME. | |
1302 | DISPLAY is part of a spec such as can be used in `defface'. | |
1303 | If FRAME is nil, the current FRAME is used." | |
1304 | (let* ((conjuncts display) | |
1305 | conjunct req options | |
1306 | ;; t means we have succeeded against all the conjuncts in | |
1307 | ;; DISPLAY that have been tested so far. | |
1308 | (match t)) | |
1309 | (if (eq conjuncts t) | |
1310 | (setq conjuncts nil)) | |
1311 | (while (and conjuncts match) | |
1312 | (setq conjunct (car conjuncts) | |
1313 | conjuncts (cdr conjuncts) | |
1314 | req (car conjunct) | |
1315 | options (cdr conjunct) | |
1316 | match (cond ((eq req 'type) | |
1317 | (or (memq window-system options) | |
1695ca2b EZ |
1318 | ;; FIXME: This should be revisited to use |
1319 | ;; display-graphic-p, provided that the | |
1320 | ;; color selection depends on the number | |
1321 | ;; of supported colors, and all defface's | |
1322 | ;; are changed to look at number of colors | |
1323 | ;; instead of (type graphic) etc. | |
1324 | (and (null window-system) | |
1325 | (memq 'tty options)) | |
ee716db5 GM |
1326 | (and (memq 'motif options) |
1327 | (featurep 'motif)) | |
9b44aa8b JD |
1328 | (and (memq 'gtk options) |
1329 | (featurep 'gtk)) | |
ee716db5 GM |
1330 | (and (memq 'lucid options) |
1331 | (featurep 'x-toolkit) | |
9b44aa8b JD |
1332 | (not (featurep 'motif)) |
1333 | (not (featurep 'gtk))) | |
ee716db5 GM |
1334 | (and (memq 'x-toolkit options) |
1335 | (featurep 'x-toolkit)))) | |
03dd94f2 EZ |
1336 | ((eq req 'min-colors) |
1337 | (>= (display-color-cells frame) (car options))) | |
5f5c8ee5 GM |
1338 | ((eq req 'class) |
1339 | (memq (frame-parameter frame 'display-type) options)) | |
1340 | ((eq req 'background) | |
1341 | (memq (frame-parameter frame 'background-mode) | |
1342 | options)) | |
16320ac7 MB |
1343 | ((eq req 'supports) |
1344 | (display-supports-face-attributes-p options frame)) | |
70d0c3b0 | 1345 | (t (error "Unknown req `%S' with options `%S'" |
5f5c8ee5 GM |
1346 | req options))))) |
1347 | match)) | |
1348 | ||
1349 | ||
1350 | (defun face-spec-choose (spec &optional frame) | |
96c2938f MB |
1351 | "Choose the proper attributes for FRAME, out of SPEC. |
1352 | If SPEC is nil, return nil." | |
5f5c8ee5 GM |
1353 | (unless frame |
1354 | (setq frame (selected-frame))) | |
1355 | (let ((tail spec) | |
b6b90dfc | 1356 | result all) |
5f5c8ee5 | 1357 | (while tail |
073f69e6 MB |
1358 | (let* ((entry (pop tail)) |
1359 | (display (car entry)) | |
1360 | (attrs (cdr entry))) | |
5f5c8ee5 | 1361 | (when (face-spec-set-match-display display frame) |
b6b90dfc | 1362 | (setq result (if (null (cdr attrs)) ;; was (listp (car attrs)) |
073f69e6 MB |
1363 | ;; Old-style entry, the attribute list is the |
1364 | ;; first element. | |
1365 | (car attrs) | |
b6b90dfc SM |
1366 | attrs)) |
1367 | (if (eq display t) | |
1368 | (setq all result result nil) | |
1369 | (setq tail nil))))) | |
1370 | (if all (append result all) result))) | |
5f5c8ee5 GM |
1371 | |
1372 | ||
1373 | (defun face-spec-reset-face (face &optional frame) | |
1374 | "Reset all attributes of FACE on FRAME to unspecified." | |
bfe27647 | 1375 | (let ((attrs face-attribute-name-alist)) |
5f5c8ee5 GM |
1376 | (while attrs |
1377 | (let ((attr-and-name (car attrs))) | |
bfe27647 GM |
1378 | (set-face-attribute face frame (car attr-and-name) 'unspecified)) |
1379 | (setq attrs (cdr attrs))))) | |
5f5c8ee5 GM |
1380 | |
1381 | ||
1382 | (defun face-spec-set (face spec &optional frame) | |
1383 | "Set FACE's attributes according to the first matching entry in SPEC. | |
1384 | FRAME is the frame whose frame-local face is set. FRAME nil means | |
96c2938f MB |
1385 | do it on all frames. See `defface' for information about SPEC. |
1386 | If SPEC is nil, do nothing." | |
bfe27647 | 1387 | (let ((attrs (face-spec-choose spec frame))) |
10ab7a51 GM |
1388 | (when attrs |
1389 | (face-spec-reset-face face frame)) | |
5f5c8ee5 GM |
1390 | (while attrs |
1391 | (let ((attribute (car attrs)) | |
1392 | (value (car (cdr attrs)))) | |
1393 | ;; Support some old-style attribute names and values. | |
1394 | (case attribute | |
1395 | (:bold (setq attribute :weight value (if value 'bold 'normal))) | |
c9630862 | 1396 | (:italic (setq attribute :slant value (if value 'italic 'normal))) |
c2424847 | 1397 | ((:foreground :background) |
00f51890 | 1398 | ;; Compatibility with 20.x. Some bogus face specs seem to |
c2424847 GM |
1399 | ;; exist containing things like `:foreground nil'. |
1400 | (if (null value) (setq value 'unspecified))) | |
c9630862 GM |
1401 | (t (unless (assq attribute face-x-resources) |
1402 | (setq attribute nil)))) | |
1403 | (when attribute | |
bfe27647 | 1404 | (set-face-attribute face frame attribute value))) |
680da3f8 RS |
1405 | (setq attrs (cdr (cdr attrs))))) |
1406 | ;; When we reset the face based on its spec, then it is unmodified | |
1407 | ;; as far as Custom is concerned. | |
1408 | (if (null frame) | |
1409 | (put face 'face-modified nil))) | |
5f5c8ee5 GM |
1410 | |
1411 | ||
1412 | (defun face-attr-match-p (face attrs &optional frame) | |
a9de7d29 | 1413 | "Return t if attributes of FACE match values in plist ATTRS. |
5f5c8ee5 GM |
1414 | Optional parameter FRAME is the frame whose definition of FACE |
1415 | is used. If nil or omitted, use the selected frame." | |
1416 | (unless frame | |
1417 | (setq frame (selected-frame))) | |
1418 | (let ((list face-attribute-name-alist) | |
1419 | (match t)) | |
1420 | (while (and match (not (null list))) | |
1421 | (let* ((attr (car (car list))) | |
a9de7d29 MB |
1422 | (specified-value |
1423 | (if (plist-member attrs attr) | |
1424 | (plist-get attrs attr) | |
1425 | 'unspecified)) | |
5f5c8ee5 | 1426 | (value-now (face-attribute face attr frame))) |
a9de7d29 | 1427 | (setq match (equal specified-value value-now)) |
5f5c8ee5 GM |
1428 | (setq list (cdr list)))) |
1429 | match)) | |
1430 | ||
5f5c8ee5 GM |
1431 | (defun face-spec-match-p (face spec &optional frame) |
1432 | "Return t if FACE, on FRAME, matches what SPEC says it should look like." | |
1433 | (face-attr-match-p face (face-spec-choose spec frame) frame)) | |
1434 | ||
94fe8a31 | 1435 | (defsubst face-default-spec (face) |
96c2938f MB |
1436 | "Return the default face-spec for FACE, ignoring any user customization. |
1437 | If there is no default for FACE, return nil." | |
1438 | (get face 'face-defface-spec)) | |
5f5c8ee5 | 1439 | |
94fe8a31 MB |
1440 | (defsubst face-user-default-spec (face) |
1441 | "Return the user's customized face-spec for FACE, or the default if none. | |
7cd512f2 | 1442 | If there is neither a user setting nor a default for FACE, return nil." |
94fe8a31 MB |
1443 | (or (get face 'saved-face) |
1444 | (face-default-spec face))) | |
1445 | ||
5f5c8ee5 | 1446 | \f |
f795f633 EZ |
1447 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1448 | ;;; Frame-type independent color support. | |
1449 | ;;; We keep the old x-* names as aliases for back-compatibility. | |
1450 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1451 | ||
1452 | (defun defined-colors (&optional frame) | |
1453 | "Return a list of colors supported for a particular frame. | |
1454 | The argument FRAME specifies which frame to try. | |
1455 | The value may be different for frames on different display types. | |
1456 | If FRAME doesn't support colors, the value is nil." | |
1a578e9b | 1457 | (if (memq (framep (or frame (selected-frame))) '(x w32 mac)) |
f795f633 | 1458 | (xw-defined-colors frame) |
37462f4c | 1459 | (mapcar 'car (tty-color-alist frame)))) |
f795f633 EZ |
1460 | (defalias 'x-defined-colors 'defined-colors) |
1461 | ||
1462 | (defun color-defined-p (color &optional frame) | |
1463 | "Return non-nil if color COLOR is supported on frame FRAME. | |
1464 | If FRAME is omitted or nil, use the selected frame. | |
293b4814 EZ |
1465 | If COLOR is the symbol `unspecified' or one of the strings |
1466 | \"unspecified-fg\" or \"unspecified-bg\", the value is nil." | |
1e221c16 | 1467 | (if (member color '(unspecified "unspecified-bg" "unspecified-fg")) |
f795f633 | 1468 | nil |
1a578e9b | 1469 | (if (member (framep (or frame (selected-frame))) '(x w32 mac)) |
f795f633 | 1470 | (xw-color-defined-p color frame) |
37462f4c | 1471 | (numberp (tty-color-translate color frame))))) |
f795f633 EZ |
1472 | (defalias 'x-color-defined-p 'color-defined-p) |
1473 | ||
1474 | (defun color-values (color &optional frame) | |
1475 | "Return a description of the color named COLOR on frame FRAME. | |
1476 | The value is a list of integer RGB values--\(RED GREEN BLUE\). | |
b0285112 | 1477 | These values appear to range from 0 65535; white is \(65535 65535 65535\). |
f795f633 EZ |
1478 | If FRAME is omitted or nil, use the selected frame. |
1479 | If FRAME cannot display COLOR, the value is nil. | |
293b4814 EZ |
1480 | If COLOR is the symbol `unspecified' or one of the strings |
1481 | \"unspecified-fg\" or \"unspecified-bg\", the value is nil." | |
1e221c16 | 1482 | (if (member color '(unspecified "unspecified-fg" "unspecified-bg")) |
f795f633 | 1483 | nil |
1a578e9b | 1484 | (if (memq (framep (or frame (selected-frame))) '(x w32 mac)) |
f795f633 EZ |
1485 | (xw-color-values color frame) |
1486 | (tty-color-values color frame)))) | |
1487 | (defalias 'x-color-values 'color-values) | |
1488 | ||
1489 | (defun display-color-p (&optional display) | |
1490 | "Return t if DISPLAY supports color. | |
1491 | The optional argument DISPLAY specifies which display to ask about. | |
1492 | DISPLAY should be either a frame or a display name (a string). | |
1493 | If omitted or nil, that stands for the selected frame's display." | |
1a578e9b | 1494 | (if (memq (framep-on-display display) '(x w32 mac)) |
d5179a01 EZ |
1495 | (xw-display-color-p display) |
1496 | (tty-display-color-p display))) | |
f795f633 EZ |
1497 | (defalias 'x-display-color-p 'display-color-p) |
1498 | ||
d5179a01 EZ |
1499 | (defun display-grayscale-p (&optional display) |
1500 | "Return non-nil if frames on DISPLAY can display shades of gray." | |
1501 | (let ((frame-type (framep-on-display display))) | |
1502 | (cond | |
1503 | ((memq frame-type '(x w32 mac)) | |
1504 | (x-display-grayscale-p display)) | |
1505 | (t | |
1506 | (> (tty-color-gray-shades display) 2))))) | |
1507 | ||
6ae315b0 MB |
1508 | (defun display-supports-face-attributes-p (attributes &optional display) |
1509 | "Return non-nil if all the face attributes in ATTRIBUTES are supported. | |
1510 | The optional argument DISPLAY can be a display name, a frame, or | |
1511 | nil (meaning the selected frame's display) | |
1512 | ||
1513 | The definition of `supported' is somewhat heuristic, but basically means | |
1514 | that a face containing all the attributes in ATTRIBUTES, when merged | |
1515 | with the default face for display, can be represented in a way that's | |
1516 | ||
1517 | (1) different in appearance than the default face, and | |
1518 | (2) `close in spirit' to what the attributes specify, if not exact. | |
1519 | ||
448bcb40 | 1520 | Point (2) implies that a `:weight black' attribute will be satisfied by |
6ae315b0 MB |
1521 | any display that can display bold, and a `:foreground \"yellow\"' as long |
1522 | as it can display a yellowish color, but `:slant italic' will _not_ be | |
448bcb40 | 1523 | satisfied by the tty display code's automatic substitution of a `dim' |
6ae315b0 | 1524 | face for italic." |
16320ac7 MB |
1525 | (let ((frame |
1526 | (if (framep display) | |
1527 | display | |
1528 | (car (frames-on-display-list display))))) | |
421c91e5 MB |
1529 | (if (not (memq (framep frame) '(x w32 mac))) |
1530 | ;; On ttys, `tty-supports-face-attributes-p' does all the work we need. | |
1531 | (tty-supports-face-attributes-p attributes frame) | |
1532 | ;; For now, we assume that non-tty displays can support everything, | |
1533 | ;; and so we just check to see if any of the specified attributes is | |
1534 | ;; different from the default -- though this probably isn't always | |
1535 | ;; accurate for font-related attributes. Later, we should add the | |
1536 | ;; ability to query about specific fonts, colors, etc. | |
1537 | (while (and attributes | |
1538 | (let* ((attr (car attributes)) | |
1539 | (val (cadr attributes)) | |
1540 | (default-val (face-attribute 'default attr frame))) | |
1541 | (if (and (stringp val) (stringp default-val)) | |
1542 | ;; compare string attributes case-insensitively | |
1543 | (eq (compare-strings val nil nil default-val nil nil t) | |
1544 | t) | |
1545 | (equal val default-val)))) | |
1546 | (setq attributes (cddr attributes))) | |
1547 | (not (null attributes))))) | |
6ae315b0 | 1548 | |
f795f633 | 1549 | \f |
5f5c8ee5 GM |
1550 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1551 | ;;; Background mode. | |
1552 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1553 | ||
1554 | (defcustom frame-background-mode nil | |
1555 | "*The brightness of the background. | |
1556 | Set this to the symbol `dark' if your background color is dark, `light' if | |
1557 | your background is light, or nil (default) if you want Emacs to | |
01eac4fd GM |
1558 | examine the brightness for you. Don't set this variable with `setq'; |
1559 | this won't have the expected effect." | |
5f5c8ee5 GM |
1560 | :group 'faces |
1561 | :set #'(lambda (var value) | |
c20d5073 | 1562 | (set-default var value) |
b5325e78 | 1563 | (mapc 'frame-set-background-mode (frame-list))) |
5f5c8ee5 | 1564 | :initialize 'custom-initialize-changed |
70d0c3b0 | 1565 | :type '(choice (choice-item dark) |
5f5c8ee5 GM |
1566 | (choice-item light) |
1567 | (choice-item :tag "default" nil))) | |
1568 | ||
1569 | ||
1570 | (defun frame-set-background-mode (frame) | |
d8abcd91 MB |
1571 | "Set up display-dependent faces on FRAME. |
1572 | Display-dependent faces are those which have different definitions | |
1573 | according to the `background-mode' and `display-type' frame parameters." | |
5f5c8ee5 GM |
1574 | (let* ((bg-resource |
1575 | (and window-system | |
30aa9e51 | 1576 | (x-get-resource "backgroundMode" "BackgroundMode"))) |
772139c0 | 1577 | (bg-color (frame-parameter frame 'background-color)) |
f161d539 MB |
1578 | (bg-mode |
1579 | (cond (frame-background-mode) | |
f161d539 MB |
1580 | (bg-resource |
1581 | (intern (downcase bg-resource))) | |
772139c0 EZ |
1582 | ((and (null window-system) (null bg-color)) |
1583 | ;; No way to determine this automatically (?). | |
1584 | 'dark) | |
1585 | ;; Unspecified frame background color can only happen | |
1586 | ;; on tty's. | |
1e221c16 | 1587 | ((member bg-color '(unspecified "unspecified-bg")) |
772139c0 | 1588 | 'dark) |
1e221c16 | 1589 | ((equal bg-color "unspecified-fg") ; inverted colors |
772139c0 EZ |
1590 | 'light) |
1591 | ((>= (apply '+ (x-color-values bg-color frame)) | |
f161d539 MB |
1592 | ;; Just looking at the screen, colors whose |
1593 | ;; values add up to .6 of the white total | |
1594 | ;; still look dark to me. | |
1595 | (* (apply '+ (x-color-values "white" frame)) .6)) | |
772139c0 EZ |
1596 | 'light) |
1597 | (t 'dark))) | |
f161d539 MB |
1598 | (display-type |
1599 | (cond ((null window-system) | |
1600 | (if (tty-display-color-p frame) 'color 'mono)) | |
1601 | ((x-display-color-p frame) | |
1602 | 'color) | |
1603 | ((x-display-grayscale-p frame) | |
1604 | 'grayscale) | |
1605 | (t 'mono))) | |
1606 | (old-bg-mode | |
1607 | (frame-parameter frame 'background-mode)) | |
1608 | (old-display-type | |
1609 | (frame-parameter frame 'display-type))) | |
1610 | ||
1611 | (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type)) | |
6e424019 MB |
1612 | (let ((locally-modified-faces nil)) |
1613 | ;; Before modifying the frame parameters, we collect a list of | |
1614 | ;; faces that don't match what their face-spec says they should | |
1615 | ;; look like; we then avoid changing these faces below. A | |
1616 | ;; negative list is used on the assumption that most faces will | |
1617 | ;; be unmodified, so we can avoid consing in the common case. | |
1618 | (dolist (face (face-list)) | |
1619 | (when (not (face-spec-match-p face | |
1620 | (face-user-default-spec face) | |
1621 | (selected-frame))) | |
1622 | (push face locally-modified-faces))) | |
1623 | ;; Now change to the new frame parameters | |
1624 | (modify-frame-parameters frame | |
1625 | (list (cons 'background-mode bg-mode) | |
1626 | (cons 'display-type display-type))) | |
1627 | ;; For all named faces, choose face specs matching the new frame | |
1628 | ;; parameters, unless they have been locally modified. | |
1629 | (dolist (face (face-list)) | |
1630 | (unless (memq face locally-modified-faces) | |
1631 | (face-spec-set face (face-user-default-spec face) frame))))))) | |
5f5c8ee5 | 1632 | |
5f5c8ee5 GM |
1633 | \f |
1634 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1635 | ;;; Frame creation. | |
1636 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1637 | ||
1638 | (defun x-handle-named-frame-geometry (parameters) | |
1639 | "Add geometry parameters for a named frame to parameter list PARAMETERS. | |
1640 | Value is the new parameter list." | |
1641 | (let* ((name (or (cdr (assq 'name parameters)) | |
1642 | (cdr (assq 'name default-frame-alist)))) | |
1643 | (x-resource-name name) | |
1644 | (res-geometry (if name (x-get-resource "geometry" "Geometry")))) | |
1645 | (when res-geometry | |
1646 | (let ((parsed (x-parse-geometry res-geometry))) | |
1647 | ;; If the resource specifies a position, call the position | |
1648 | ;; and size "user-specified". | |
1649 | (when (or (assq 'top parsed) | |
1650 | (assq 'left parsed)) | |
1651 | (setq parsed (append '((user-position . t) (user-size . t)) parsed))) | |
1652 | ;; Put the geometry parameters at the end. Copy | |
1653 | ;; default-frame-alist so that they go after it. | |
1654 | (setq parameters (append parameters default-frame-alist parsed)))) | |
1655 | parameters)) | |
1656 | ||
1657 | ||
1658 | (defun x-handle-reverse-video (frame parameters) | |
1659 | "Handle the reverse-video frame parameter and X resource. | |
1660 | `x-create-frame' does not handle this one." | |
1661 | (when (cdr (or (assq 'reverse parameters) | |
1662 | (assq 'reverse default-frame-alist) | |
1663 | (let ((resource (x-get-resource "reverseVideo" | |
1664 | "ReverseVideo"))) | |
1665 | (if resource | |
1666 | (cons nil (member (downcase resource) | |
1667 | '("on" "true"))))))) | |
1668 | (let* ((params (frame-parameters frame)) | |
1669 | (bg (cdr (assq 'foreground-color params))) | |
1670 | (fg (cdr (assq 'background-color params)))) | |
1671 | (modify-frame-parameters frame | |
1672 | (list (cons 'foreground-color fg) | |
1673 | (cons 'background-color bg))) | |
1674 | (if (equal bg (cdr (assq 'border-color params))) | |
1675 | (modify-frame-parameters frame | |
1676 | (list (cons 'border-color fg)))) | |
1677 | (if (equal bg (cdr (assq 'mouse-color params))) | |
1678 | (modify-frame-parameters frame | |
1679 | (list (cons 'mouse-color fg)))) | |
1680 | (if (equal bg (cdr (assq 'cursor-color params))) | |
1681 | (modify-frame-parameters frame | |
1682 | (list (cons 'cursor-color fg))))))) | |
1683 | ||
1684 | ||
1685 | (defun x-create-frame-with-faces (&optional parameters) | |
1686 | "Create a frame from optional frame parameters PARAMETERS. | |
1687 | Parameters not specified by PARAMETERS are taken from | |
1688 | `default-frame-alist'. If PARAMETERS specify a frame name, | |
1689 | handle X geometry resources for that name. If either PARAMETERS | |
1690 | or `default-frame-alist' contains a `reverse' parameter, or | |
1691 | the X resource ``reverseVideo'' is present, handle that. | |
1692 | Value is the new frame created." | |
1693 | (setq parameters (x-handle-named-frame-geometry parameters)) | |
1694 | (let ((visibility-spec (assq 'visibility parameters)) | |
1695 | (frame-list (frame-list)) | |
1696 | (frame (x-create-frame (cons '(visibility . nil) parameters))) | |
1697 | success) | |
1698 | (unwind-protect | |
1699 | (progn | |
1700 | (x-handle-reverse-video frame parameters) | |
1701 | (frame-set-background-mode frame) | |
448bcb40 | 1702 | (face-set-after-frame-default frame) |
5f5c8ee5 GM |
1703 | (if (or (null frame-list) (null visibility-spec)) |
1704 | (make-frame-visible frame) | |
1705 | (modify-frame-parameters frame (list visibility-spec))) | |
1706 | (setq success t)) | |
1707 | (unless success | |
1708 | (delete-frame frame))) | |
1709 | frame)) | |
1710 | ||
1711 | ||
1712 | (defun face-set-after-frame-default (frame) | |
f1cae29e GM |
1713 | "Set frame-local faces of FRAME from face specs and resources. |
1714 | Initialize colors of certain faces from frame parameters." | |
1db35406 RS |
1715 | (if (face-attribute 'default :font t) |
1716 | (set-face-attribute 'default frame :font | |
1717 | (face-attribute 'default :font t)) | |
1718 | (set-face-attribute 'default frame :family | |
1719 | (face-attribute 'default :family t)) | |
1720 | (set-face-attribute 'default frame :height | |
1721 | (face-attribute 'default :height t)) | |
1722 | (set-face-attribute 'default frame :slant | |
1723 | (face-attribute 'default :slant t)) | |
1724 | (set-face-attribute 'default frame :weight | |
1725 | (face-attribute 'default :weight t)) | |
1726 | (set-face-attribute 'default frame :width | |
1727 | (face-attribute 'default :width t))) | |
5f5c8ee5 | 1728 | (dolist (face (face-list)) |
1db35406 | 1729 | ;; Don't let frame creation fail because of an invalid face spec. |
ebfa5c37 RS |
1730 | (condition-case () |
1731 | (when (not (equal face 'default)) | |
1732 | (face-spec-set face (face-user-default-spec face) frame) | |
1733 | (internal-merge-in-global-face face frame) | |
1734 | (when (and (memq window-system '(x w32 mac)) | |
1735 | (or (not (boundp 'inhibit-default-face-x-resources)) | |
1736 | (not (eq face 'default)))) | |
1737 | (make-face-x-resource-internal face frame))) | |
1738 | (error nil))) | |
f1cae29e GM |
1739 | ;; Initialize attributes from frame parameters. |
1740 | (let ((params '((foreground-color default :foreground) | |
1741 | (background-color default :background) | |
1742 | (border-color border :background) | |
1743 | (cursor-color cursor :background) | |
1744 | (scroll-bar-foreground scroll-bar :foreground) | |
1745 | (scroll-bar-background scroll-bar :background) | |
1746 | (mouse-color mouse :background)))) | |
bdc03dd9 GM |
1747 | (dolist (param params) |
1748 | (let ((frame-param (frame-parameter frame (nth 0 param))) | |
1749 | (face (nth 1 param)) | |
1750 | (attr (nth 2 param))) | |
1751 | (when (and frame-param | |
1752 | ;; Don't override face attributes explicitly | |
1753 | ;; specified for new frames. | |
1754 | (eq (face-attribute face attr t) 'unspecified)) | |
1755 | (set-face-attribute face frame attr frame-param)))))) | |
1756 | ||
5f5c8ee5 | 1757 | |
53990c84 EZ |
1758 | (defun tty-handle-reverse-video (frame parameters) |
1759 | "Handle the reverse-video frame parameter for terminal frames." | |
1760 | (when (cdr (or (assq 'reverse parameters) | |
1761 | (assq 'reverse default-frame-alist))) | |
53990c84 EZ |
1762 | (let* ((params (frame-parameters frame)) |
1763 | (bg (cdr (assq 'foreground-color params))) | |
1764 | (fg (cdr (assq 'background-color params)))) | |
1765 | (modify-frame-parameters frame | |
1766 | (list (cons 'foreground-color fg) | |
1767 | (cons 'background-color bg))) | |
1768 | (if (equal bg (cdr (assq 'mouse-color params))) | |
1769 | (modify-frame-parameters frame | |
1770 | (list (cons 'mouse-color fg)))) | |
1771 | (if (equal bg (cdr (assq 'cursor-color params))) | |
1772 | (modify-frame-parameters frame | |
1773 | (list (cons 'cursor-color fg))))))) | |
1774 | ||
5f5c8ee5 GM |
1775 | |
1776 | (defun tty-create-frame-with-faces (&optional parameters) | |
1777 | "Create a frame from optional frame parameters PARAMETERS. | |
1778 | Parameters not specified by PARAMETERS are taken from | |
1779 | `default-frame-alist'. If either PARAMETERS or `default-frame-alist' | |
1780 | contains a `reverse' parameter, handle that. Value is the new frame | |
1781 | created." | |
1782 | (let ((frame (make-terminal-frame parameters)) | |
1783 | success) | |
1784 | (unwind-protect | |
1785 | (progn | |
53990c84 | 1786 | (tty-handle-reverse-video frame (frame-parameters frame)) |
5f5c8ee5 GM |
1787 | (frame-set-background-mode frame) |
1788 | (face-set-after-frame-default frame) | |
1789 | (setq success t)) | |
1790 | (unless success | |
1791 | (delete-frame frame))) | |
1792 | frame)) | |
465fceed | 1793 | |
465fceed | 1794 | |
5f5c8ee5 GM |
1795 | ;; Called from C function init_display to initialize faces of the |
1796 | ;; dumped terminal frame on startup. | |
465fceed | 1797 | |
5f5c8ee5 GM |
1798 | (defun tty-set-up-initial-frame-faces () |
1799 | (let ((frame (selected-frame))) | |
1800 | (frame-set-background-mode frame) | |
1801 | (face-set-after-frame-default frame))) | |
00f51890 | 1802 | |
465fceed | 1803 | |
465fceed | 1804 | |
5f5c8ee5 GM |
1805 | \f |
1806 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1807 | ;;; Compatiblity with 20.2 | |
1808 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
72418504 | 1809 | |
5f5c8ee5 | 1810 | ;; Update a frame's faces when we change its default font. |
465fceed | 1811 | |
e16e7eac | 1812 | (defalias 'frame-update-faces 'ignore "") |
4b22f844 | 1813 | (make-obsolete 'frame-update-faces "no longer necessary." "21.1") |
e8e4cda0 | 1814 | |
5f5c8ee5 GM |
1815 | ;; Update the colors of FACE, after FRAME's own colors have been |
1816 | ;; changed. | |
1bcb155c | 1817 | |
c20d5073 | 1818 | (defalias 'frame-update-face-colors 'frame-set-background-mode) |
2598a293 | 1819 | (make-obsolete 'frame-update-face-colors 'frame-set-background-mode "21.1") |
d11fba25 | 1820 | |
bdda3754 | 1821 | \f |
5f5c8ee5 GM |
1822 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1823 | ;;; Standard faces. | |
1824 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
465fceed | 1825 | |
5f5c8ee5 GM |
1826 | (defgroup basic-faces nil |
1827 | "The standard faces of Emacs." | |
1828 | :group 'faces) | |
ef436392 | 1829 | |
465fceed | 1830 | |
5f5c8ee5 GM |
1831 | (defface default |
1832 | '((t nil)) | |
1833 | "Basic default face." | |
1834 | :group 'basic-faces) | |
465fceed | 1835 | |
72418504 | 1836 | |
3759f14b | 1837 | (defface mode-line |
1a578e9b | 1838 | '((((type x w32 mac) (class color)) |
b6b90dfc SM |
1839 | :box (:line-width -1 :style released-button) |
1840 | :background "grey75" :foreground "black") | |
5f5c8ee5 | 1841 | (t |
b6b90dfc | 1842 | :inverse-video t)) |
c5752dcb | 1843 | "Basic mode line face for selected window." |
a4391cf1 | 1844 | :version "21.1" |
84fe35f0 | 1845 | :group 'modeline |
5f5c8ee5 | 1846 | :group 'basic-faces) |
465fceed | 1847 | |
c5752dcb | 1848 | (defface mode-line-inactive |
b6b90dfc SM |
1849 | '((t |
1850 | :inherit mode-line) | |
1851 | (((type x w32 mac) (background light) (class color)) | |
c5752dcb KS |
1852 | :weight light |
1853 | :box (:line-width -1 :color "grey75" :style nil) | |
1854 | :foreground "grey20" :background "grey90") | |
53a2f6e1 | 1855 | (((type x w32 mac) (background dark) (class color)) |
53a2f6e1 MB |
1856 | :weight light |
1857 | :box (:line-width -1 :color "grey40" :style nil) | |
b6b90dfc | 1858 | :foreground "grey80" :background "grey30")) |
c5752dcb | 1859 | "Basic mode line face for non-selected windows." |
89e7ad59 | 1860 | :version "21.4" |
c5752dcb KS |
1861 | :group 'modeline |
1862 | :group 'basic-faces) | |
1863 | ||
3759f14b GM |
1864 | ;; Make `modeline' an alias for `mode-line', for compatibility. |
1865 | (put 'modeline 'face-alias 'mode-line) | |
c5752dcb | 1866 | (put 'modeline-inactive 'face-alias 'mode-line-inactive) |
d11fba25 | 1867 | |
e5e7779f | 1868 | (defface header-line |
411def8e SM |
1869 | '((t |
1870 | :inherit mode-line) | |
1871 | (((type tty)) | |
1cb4393e MB |
1872 | ;; This used to be `:inverse-video t', but that doesn't look very |
1873 | ;; good when combined with inverse-video mode-lines and multiple | |
1874 | ;; windows. Underlining looks better, and is more consistent with | |
1875 | ;; the window-system face variants, which deemphasize the | |
1876 | ;; header-line in relation to the mode-line face. If a terminal | |
1877 | ;; can't underline, then the header-line will end up without any | |
1878 | ;; highlighting; this may be too confusing in general, although it | |
1879 | ;; happens to look good with the only current use of header-lines, | |
1880 | ;; the info browser. XXX | |
411def8e | 1881 | :inverse-video nil ;Override the value inherited from mode-line. |
a7ac92b6 | 1882 | :underline t) |
98490598 | 1883 | (((class color grayscale) (background light)) |
bdab1d43 | 1884 | :background "grey90" :foreground "grey20" |
411def8e | 1885 | :box nil) |
98490598 | 1886 | (((class color grayscale) (background dark)) |
bdab1d43 | 1887 | :background "grey20" :foreground "grey90" |
411def8e | 1888 | :box nil) |
98490598 | 1889 | (((class mono) (background light)) |
bdab1d43 MB |
1890 | :background "white" :foreground "black" |
1891 | :inverse-video nil | |
1892 | :box nil | |
411def8e | 1893 | :underline t) |
98490598 | 1894 | (((class mono) (background dark)) |
bdab1d43 MB |
1895 | :background "black" :foreground "white" |
1896 | :inverse-video nil | |
1897 | :box nil | |
411def8e | 1898 | :underline t)) |
e5e7779f | 1899 | "Basic header-line face." |
a4391cf1 | 1900 | :version "21.1" |
5f5c8ee5 | 1901 | :group 'basic-faces) |
e8e4cda0 | 1902 | |
d11fba25 | 1903 | |
533322cd | 1904 | (defface tool-bar |
411def8e | 1905 | '((t |
b6b90dfc | 1906 | :box (:line-width 1 :style released-button) |
411def8e SM |
1907 | :foreground "black") |
1908 | (((type x w32 mac) (class color)) | |
1909 | :background "grey75") | |
9668a746 | 1910 | (((type x) (class mono)) |
411def8e | 1911 | :background "grey")) |
533322cd | 1912 | "Basic tool-bar face." |
a4391cf1 | 1913 | :version "21.1" |
5f5c8ee5 | 1914 | :group 'basic-faces) |
d11fba25 | 1915 | |
bdda3754 | 1916 | |
b6b90dfc SM |
1917 | (defface minibuffer-prompt '((((background dark)) :foreground "cyan") |
1918 | (((type pc)) :foreground "magenta") | |
1919 | (t :foreground "dark blue")) | |
31cf46d3 | 1920 | "Face for minibuffer prompts." |
89e7ad59 | 1921 | :version "21.4" |
31cf46d3 RS |
1922 | :group 'basic-faces) |
1923 | ||
1924 | (setq minibuffer-prompt-properties | |
1925 | (append minibuffer-prompt-properties (list 'face 'minibuffer-prompt))) | |
1926 | ||
5f5c8ee5 | 1927 | (defface region |
03dd94f2 EZ |
1928 | '((((class color) (min-colors 88) (background dark)) |
1929 | :background "blue3") | |
1930 | (((class color) (min-colors 88) (background light)) | |
1931 | :background "lightgoldenrod2") | |
1932 | (((class color) (min-colors 16) (background dark)) | |
1933 | :background "blue3") | |
1934 | (((class color) (min-colors 16) (background light)) | |
1935 | :background "lightgoldenrod2") | |
1936 | (((class color) (min-colors 8)) | |
b6b90dfc | 1937 | :background "blue" :foreground "white") |
5f5c8ee5 | 1938 | (((type tty) (class mono)) |
b6b90dfc | 1939 | :inverse-video t) |
b6b90dfc | 1940 | (t :background "gray")) |
62f1e1cd | 1941 | "Basic face for highlighting the region." |
b5325e78 | 1942 | :version "21.1" |
5f5c8ee5 | 1943 | :group 'basic-faces) |
66a5c2c6 | 1944 | |
bdda3754 | 1945 | |
f1cae29e | 1946 | (defface fringe |
d6d59057 | 1947 | '((((class color) (background light)) |
b6b90dfc SM |
1948 | :background "grey95") |
1949 | (((class color) (background dark)) | |
1950 | :background "grey10") | |
1951 | (t | |
1952 | :background "gray")) | |
f1cae29e GM |
1953 | "Basic face for the fringes to the left and right of windows under X." |
1954 | :version "21.1" | |
84fe35f0 | 1955 | :group 'frames |
f1cae29e GM |
1956 | :group 'basic-faces) |
1957 | ||
1958 | ||
1959 | (defface scroll-bar '() | |
1960 | "Basic face for the scroll bar colors under X." | |
1961 | :version "21.1" | |
84fe35f0 | 1962 | :group 'frames |
f1cae29e GM |
1963 | :group 'basic-faces) |
1964 | ||
1965 | ||
ee716db5 | 1966 | (defface menu |
ebd04058 MB |
1967 | '((((type tty)) |
1968 | :inverse-video t) | |
1969 | (((type x-toolkit)) | |
1970 | ) | |
1971 | (t | |
1972 | :inverse-video t)) | |
bbf63a7b | 1973 | "Basic face for the font and colors of the menu bar and popup menus." |
ee716db5 | 1974 | :version "21.1" |
84fe35f0 | 1975 | :group 'menu |
ee716db5 GM |
1976 | :group 'basic-faces) |
1977 | ||
1978 | ||
f1cae29e GM |
1979 | (defface border '() |
1980 | "Basic face for the frame border under X." | |
1981 | :version "21.1" | |
84fe35f0 | 1982 | :group 'frames |
f1cae29e GM |
1983 | :group 'basic-faces) |
1984 | ||
1985 | ||
1986 | (defface cursor '() | |
1987 | "Basic face for the cursor color under X." | |
1988 | :version "21.1" | |
84fe35f0 | 1989 | :group 'cursor |
f1cae29e GM |
1990 | :group 'basic-faces) |
1991 | ||
1992 | ||
1993 | (defface mouse '() | |
1994 | "Basic face for the mouse color under X." | |
e59176e2 | 1995 | :version "21.1" |
84fe35f0 | 1996 | :group 'mouse |
5f5c8ee5 | 1997 | :group 'basic-faces) |
bdda3754 | 1998 | |
bdda3754 | 1999 | |
b6b90dfc | 2000 | (defface bold '((t :weight bold)) |
5f5c8ee5 GM |
2001 | "Basic bold face." |
2002 | :group 'basic-faces) | |
bdda3754 | 2003 | |
bdda3754 | 2004 | |
16320ac7 MB |
2005 | (defface italic |
2006 | '((((supports :slant italic)) | |
2007 | :slant italic) | |
2008 | (((supports :underline t)) | |
2009 | :underline t) | |
2010 | (t | |
2011 | ;; default to italic, even it doesn't appear to be supported, | |
2012 | ;; because in some cases the display engine will do it's own | |
2013 | ;; workaround (to `dim' on ttys) | |
2014 | :slant italic)) | |
5f5c8ee5 GM |
2015 | "Basic italic font." |
2016 | :group 'basic-faces) | |
bdda3754 | 2017 | |
bdda3754 | 2018 | |
b6b90dfc | 2019 | (defface bold-italic '((t :weight bold :slant italic)) |
5f5c8ee5 GM |
2020 | "Basic bold-italic face." |
2021 | :group 'basic-faces) | |
465fceed | 2022 | |
17b3a11b | 2023 | |
b6b90dfc | 2024 | (defface underline '((t :underline t)) |
5f5c8ee5 GM |
2025 | "Basic underlined face." |
2026 | :group 'basic-faces) | |
465fceed | 2027 | |
2f2ddd1e | 2028 | |
5f5c8ee5 | 2029 | (defface highlight |
03dd94f2 | 2030 | '((((class color) (min-colors 88) (background light)) |
b6b90dfc | 2031 | :background "darkseagreen2") |
03dd94f2 | 2032 | (((class color) (min-colors 88) (background dark)) |
b6b90dfc | 2033 | :background "darkolivegreen") |
03dd94f2 EZ |
2034 | (((class color) (min-colors 16) (background light)) |
2035 | :background "darkseagreen2") | |
2036 | (((class color) (min-colors 16) (background dark)) | |
2037 | :background "darkolivegreen") | |
2038 | (((class color) (min-colors 8)) | |
2039 | :background "green" :foreground "black") | |
b6b90dfc | 2040 | (t :inverse-video t)) |
a4391cf1 DL |
2041 | "Basic face for highlighting." |
2042 | :group 'basic-faces) | |
465fceed | 2043 | |
465fceed | 2044 | |
5f5c8ee5 | 2045 | (defface secondary-selection |
03dd94f2 | 2046 | '((((class color) (min-colors 88) (background light)) |
b6b90dfc | 2047 | :background "yellow") |
03dd94f2 EZ |
2048 | (((class color) (min-colors 88) (background dark)) |
2049 | :background "SkyBlue4") | |
2050 | (((class color) (min-colors 16) (background light)) | |
2051 | :background "yellow") | |
2052 | (((class color) (min-colors 16) (background dark)) | |
b6b90dfc | 2053 | :background "SkyBlue4") |
03dd94f2 EZ |
2054 | (((class color) (min-colors 8)) |
2055 | :background "cyan" :foreground "black") | |
b6b90dfc | 2056 | (t :inverse-video t)) |
a4391cf1 DL |
2057 | "Basic face for displaying the secondary selection." |
2058 | :group 'basic-faces) | |
465fceed | 2059 | |
93d6fcef | 2060 | |
b6b90dfc | 2061 | (defface fixed-pitch '((t :family "courier")) |
5f5c8ee5 GM |
2062 | "The basic fixed-pitch face." |
2063 | :group 'basic-faces) | |
465fceed | 2064 | |
5f5c8ee5 | 2065 | |
b6b90dfc | 2066 | (defface variable-pitch '((t :family "helv")) |
5f5c8ee5 GM |
2067 | "The basic variable-pitch face." |
2068 | :group 'basic-faces) | |
2069 | ||
2070 | ||
2071 | (defface trailing-whitespace | |
2072 | '((((class color) (background light)) | |
b6b90dfc | 2073 | :background "red") |
5f5c8ee5 | 2074 | (((class color) (background dark)) |
b6b90dfc SM |
2075 | :background "red") |
2076 | (t :inverse-video t)) | |
a4391cf1 DL |
2077 | "Basic face for highlighting trailing whitespace." |
2078 | :version "21.1" | |
84fe35f0 | 2079 | :group 'font-lock ; like `show-trailing-whitespace' |
a4391cf1 | 2080 | :group 'basic-faces) |
465fceed ER |
2081 | |
2082 | ||
465fceed | 2083 | \f |
5f5c8ee5 GM |
2084 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2085 | ;;; Manipulating font names. | |
2086 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
2087 | ||
2088 | ;; This is here for compatibilty with Emacs 20.2. For example, | |
07f27947 DL |
2089 | ;; international/fontset.el uses x-resolve-font-name. The following |
2090 | ;; functions are not used in the face implementation itself. | |
465fceed | 2091 | |
d7fa5aa2 RS |
2092 | (defvar x-font-regexp nil) |
2093 | (defvar x-font-regexp-head nil) | |
2094 | (defvar x-font-regexp-weight nil) | |
2095 | (defvar x-font-regexp-slant nil) | |
465fceed | 2096 | |
021ca129 KH |
2097 | (defconst x-font-regexp-weight-subnum 1) |
2098 | (defconst x-font-regexp-slant-subnum 2) | |
2099 | (defconst x-font-regexp-swidth-subnum 3) | |
2100 | (defconst x-font-regexp-adstyle-subnum 4) | |
2101 | ||
465fceed ER |
2102 | ;;; Regexps matching font names in "Host Portable Character Representation." |
2103 | ;;; | |
2104 | (let ((- "[-?]") | |
2105 | (foundry "[^-]+") | |
2106 | (family "[^-]+") | |
2107 | (weight "\\(bold\\|demibold\\|medium\\)") ; 1 | |
2108 | ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1 | |
2109 | (weight\? "\\([^-]*\\)") ; 1 | |
2110 | (slant "\\([ior]\\)") ; 2 | |
2111 | ; (slant\? "\\([ior?*]?\\)") ; 2 | |
2112 | (slant\? "\\([^-]?\\)") ; 2 | |
2113 | ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3 | |
2114 | (swidth "\\([^-]*\\)") ; 3 | |
2115 | ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4 | |
c8787b81 | 2116 | (adstyle "\\([^-]*\\)") ; 4 |
465fceed ER |
2117 | (pixelsize "[0-9]+") |
2118 | (pointsize "[0-9][0-9]+") | |
2119 | (resx "[0-9][0-9]+") | |
2120 | (resy "[0-9][0-9]+") | |
2121 | (spacing "[cmp?*]") | |
2122 | (avgwidth "[0-9]+") | |
2123 | (registry "[^-]+") | |
2124 | (encoding "[^-]+") | |
2125 | ) | |
2126 | (setq x-font-regexp | |
2127 | (concat "\\`\\*?[-?*]" | |
2128 | foundry - family - weight\? - slant\? - swidth - adstyle - | |
e20d641f RS |
2129 | pixelsize - pointsize - resx - resy - spacing - avgwidth - |
2130 | registry - encoding "\\*?\\'" | |
465fceed ER |
2131 | )) |
2132 | (setq x-font-regexp-head | |
2133 | (concat "\\`[-?*]" foundry - family - weight\? - slant\? | |
2134 | "\\([-*?]\\|\\'\\)")) | |
2135 | (setq x-font-regexp-slant (concat - slant -)) | |
2136 | (setq x-font-regexp-weight (concat - weight -)) | |
70d0c3b0 | 2137 | nil) |
465fceed | 2138 | |
5f5c8ee5 | 2139 | |
281dc1c2 JB |
2140 | (defun x-resolve-font-name (pattern &optional face frame) |
2141 | "Return a font name matching PATTERN. | |
ac4c2e6b | 2142 | All wildcards in PATTERN are instantiated. |
10d89673 JB |
2143 | If PATTERN is nil, return the name of the frame's base font, which never |
2144 | contains wildcards. | |
e17dbede RS |
2145 | Given optional arguments FACE and FRAME, return a font which is |
2146 | also the same size as FACE on FRAME, or fail." | |
14e6867c RS |
2147 | (or (symbolp face) |
2148 | (setq face (face-name face))) | |
2149 | (and (eq frame t) | |
2150 | (setq frame nil)) | |
10d89673 | 2151 | (if pattern |
8db93e45 | 2152 | ;; Note that x-list-fonts has code to handle a face with nil as its font. |
abd89b80 | 2153 | (let ((fonts (x-list-fonts pattern face frame 1))) |
10d89673 JB |
2154 | (or fonts |
2155 | (if face | |
962a60aa RS |
2156 | (if (string-match "\\*" pattern) |
2157 | (if (null (face-font face)) | |
2158 | (error "No matching fonts are the same height as the frame default font") | |
2159 | (error "No matching fonts are the same height as face `%s'" face)) | |
2160 | (if (null (face-font face)) | |
2161 | (error "Height of font `%s' doesn't match the frame default font" | |
2162 | pattern) | |
2163 | (error "Height of font `%s' doesn't match face `%s'" | |
2164 | pattern face))) | |
7cf6fac1 | 2165 | (error "No fonts match `%s'" pattern))) |
10d89673 JB |
2166 | (car fonts)) |
2167 | (cdr (assq 'font (frame-parameters (selected-frame)))))) | |
281dc1c2 | 2168 | |
5f5c8ee5 | 2169 | |
465fceed | 2170 | (defun x-frob-font-weight (font which) |
b7ffee5f SM |
2171 | (let ((case-fold-search t)) |
2172 | (cond ((string-match x-font-regexp font) | |
2173 | (concat (substring font 0 | |
2174 | (match-beginning x-font-regexp-weight-subnum)) | |
2175 | which | |
2176 | (substring font (match-end x-font-regexp-weight-subnum) | |
2177 | (match-beginning x-font-regexp-adstyle-subnum)) | |
2178 | ;; Replace the ADD_STYLE_NAME field with * | |
2179 | ;; because the info in it may not be the same | |
2180 | ;; for related fonts. | |
2181 | "*" | |
2182 | (substring font (match-end x-font-regexp-adstyle-subnum)))) | |
528fbf51 RS |
2183 | ((string-match x-font-regexp-head font) |
2184 | (concat (substring font 0 (match-beginning 1)) which | |
2185 | (substring font (match-end 1)))) | |
2186 | ((string-match x-font-regexp-weight font) | |
b7ffee5f SM |
2187 | (concat (substring font 0 (match-beginning 1)) which |
2188 | (substring font (match-end 1))))))) | |
2598a293 | 2189 | (make-obsolete 'x-frob-font-weight 'make-face-... "21.1") |
5f5c8ee5 | 2190 | |
465fceed | 2191 | (defun x-frob-font-slant (font which) |
b7ffee5f SM |
2192 | (let ((case-fold-search t)) |
2193 | (cond ((string-match x-font-regexp font) | |
2194 | (concat (substring font 0 | |
2195 | (match-beginning x-font-regexp-slant-subnum)) | |
2196 | which | |
2197 | (substring font (match-end x-font-regexp-slant-subnum) | |
2198 | (match-beginning x-font-regexp-adstyle-subnum)) | |
2199 | ;; Replace the ADD_STYLE_NAME field with * | |
2200 | ;; because the info in it may not be the same | |
2201 | ;; for related fonts. | |
2202 | "*" | |
2203 | (substring font (match-end x-font-regexp-adstyle-subnum)))) | |
528fbf51 RS |
2204 | ((string-match x-font-regexp-head font) |
2205 | (concat (substring font 0 (match-beginning 2)) which | |
2206 | (substring font (match-end 2)))) | |
2207 | ((string-match x-font-regexp-slant font) | |
b7ffee5f SM |
2208 | (concat (substring font 0 (match-beginning 1)) which |
2209 | (substring font (match-end 1))))))) | |
2598a293 | 2210 | (make-obsolete 'x-frob-font-slant 'make-face-... "21.1") |
5f5c8ee5 | 2211 | |
3fc67165 EZ |
2212 | ;; These aliases are here so that we don't get warnings about obsolete |
2213 | ;; functions from the byte compiler. | |
2214 | (defalias 'internal-frob-font-weight 'x-frob-font-weight) | |
2215 | (defalias 'internal-frob-font-slant 'x-frob-font-slant) | |
2216 | ||
465fceed | 2217 | (defun x-make-font-bold (font) |
f3f31ccf RS |
2218 | "Given an X font specification, make a bold version of it. |
2219 | If that can't be done, return nil." | |
3fc67165 | 2220 | (internal-frob-font-weight font "bold")) |
2598a293 | 2221 | (make-obsolete 'x-make-font-bold 'make-face-bold "21.1") |
5f5c8ee5 | 2222 | |
465fceed | 2223 | (defun x-make-font-demibold (font) |
f3f31ccf RS |
2224 | "Given an X font specification, make a demibold version of it. |
2225 | If that can't be done, return nil." | |
3fc67165 | 2226 | (internal-frob-font-weight font "demibold")) |
2598a293 | 2227 | (make-obsolete 'x-make-font-demibold 'make-face-bold "21.1") |
5f5c8ee5 | 2228 | |
465fceed | 2229 | (defun x-make-font-unbold (font) |
f3f31ccf RS |
2230 | "Given an X font specification, make a non-bold version of it. |
2231 | If that can't be done, return nil." | |
3fc67165 | 2232 | (internal-frob-font-weight font "medium")) |
2598a293 | 2233 | (make-obsolete 'x-make-font-unbold 'make-face-unbold "21.1") |
5f5c8ee5 | 2234 | |
465fceed | 2235 | (defun x-make-font-italic (font) |
f3f31ccf RS |
2236 | "Given an X font specification, make an italic version of it. |
2237 | If that can't be done, return nil." | |
3fc67165 | 2238 | (internal-frob-font-slant font "i")) |
2598a293 | 2239 | (make-obsolete 'x-make-font-italic 'make-face-italic "21.1") |
5f5c8ee5 | 2240 | |
465fceed | 2241 | (defun x-make-font-oblique (font) ; you say tomayto... |
f3f31ccf RS |
2242 | "Given an X font specification, make an oblique version of it. |
2243 | If that can't be done, return nil." | |
3fc67165 | 2244 | (internal-frob-font-slant font "o")) |
2598a293 | 2245 | (make-obsolete 'x-make-font-oblique 'make-face-italic "21.1") |
5f5c8ee5 | 2246 | |
465fceed | 2247 | (defun x-make-font-unitalic (font) |
f3f31ccf RS |
2248 | "Given an X font specification, make a non-italic version of it. |
2249 | If that can't be done, return nil." | |
3fc67165 | 2250 | (internal-frob-font-slant font "r")) |
2598a293 | 2251 | (make-obsolete 'x-make-font-unitalic 'make-face-unitalic "21.1") |
5f5c8ee5 | 2252 | |
b7d7285c KH |
2253 | (defun x-make-font-bold-italic (font) |
2254 | "Given an X font specification, make a bold and italic version of it. | |
2255 | If that can't be done, return nil." | |
3fc67165 EZ |
2256 | (and (setq font (internal-frob-font-weight font "bold")) |
2257 | (internal-frob-font-slant font "i"))) | |
2598a293 | 2258 | (make-obsolete 'x-make-font-bold-italic 'make-face-bold-italic "21.1") |
113ab303 | 2259 | |
f0138172 JB |
2260 | (provide 'faces) |
2261 | ||
ab5796a9 | 2262 | ;;; arch-tag: 19a4759f-2963-445f-b004-425b9aadd7d6 |
70d0c3b0 | 2263 | ;;; faces.el ends here |