209
|
1 ;;; faces.el --- Lisp interface to the C "face" structure
|
|
2
|
|
3 ;; Copyright (C) 1992-4, 1997 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995 Board of Trustees, University of Illinois
|
|
5 ;; Copyright (C) 1995, 1996 Ben Wing
|
|
6
|
|
7 ;; Author: Ben Wing <wing@666.com>
|
|
8 ;; Keywords: faces, internal, dumped
|
|
9
|
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
25 ;; Boston, MA 02111-1307, USA.
|
|
26
|
|
27 ;;; Synched up with: Not synched with FSF. Almost completely divergent.
|
|
28
|
|
29 ;;; Commentary:
|
|
30
|
|
31 ;; This file is dumped with XEmacs.
|
|
32
|
|
33 ;; face implementation #1 (used Lisp vectors and parallel C vectors;
|
|
34 ;; FSFmacs still uses this) authored by Jamie Zawinski <jwz@netscape.com>
|
|
35 ;; pre Lucid-Emacs 19.0.
|
|
36
|
|
37 ;; face implementation #2 (used one face object per frame per face)
|
|
38 ;; authored by Jamie Zawinski for 19.9.
|
|
39
|
|
40 ;; face implementation #3 (use one face object per face) originally
|
|
41 ;; authored for 19.12 by Chuck Thompson <cthomp@cs.uiuc.edu>,
|
|
42 ;; rewritten by Ben Wing with the advent of specifiers.
|
|
43
|
|
44
|
|
45 ;;; Some stuff in FSF's faces.el is in our x-faces.el.
|
|
46
|
|
47 ;;; Code:
|
|
48
|
227
|
49 (defgroup faces nil
|
|
50 "Support for multiple text attributes (fonts, colors, ...)
|
|
51 Such a collection of attributes is called a \"face\"."
|
|
52 :group 'emacs)
|
|
53
|
|
54
|
209
|
55 (defun read-face-name (prompt)
|
|
56 (let (face)
|
|
57 (while (= (length face) 0) ; nil or ""
|
|
58 (setq face (completing-read prompt
|
|
59 (mapcar (lambda (x) (list (symbol-name x)))
|
|
60 (face-list))
|
|
61 nil t)))
|
|
62 (intern face)))
|
|
63
|
|
64 (defun face-interactive (what &optional bool)
|
|
65 (let* ((fn (intern (concat "face-" what "-instance")))
|
|
66 (face (read-face-name (format "Set %s of face: " what)))
|
|
67 (default (if (fboundp fn)
|
|
68 ;; #### we should distinguish here between
|
|
69 ;; explicitly setting the value to be the
|
|
70 ;; same as the default face's value, and
|
|
71 ;; not setting a value at all.
|
|
72 (funcall fn face)))
|
|
73 (value (if bool
|
|
74 (y-or-n-p (format "Should face %s be %s? "
|
|
75 (symbol-name face) bool))
|
|
76 (read-string (format "Set %s of face %s to: "
|
|
77 what (symbol-name face))
|
|
78 (cond ((font-instance-p default)
|
|
79 (font-instance-name default))
|
|
80 ((color-instance-p default)
|
|
81 (color-instance-name default))
|
|
82 ((image-instance-p default)
|
|
83 (image-instance-file-name default))
|
|
84 (t default))))))
|
|
85 (list face (if (equal value "") nil value))))
|
|
86
|
|
87 (defconst built-in-face-specifiers
|
|
88 (built-in-face-specifiers)
|
|
89 "A list of the built-in face properties that are specifiers.")
|
|
90
|
|
91 (defun face-property (face property &optional locale tag-set exact-p)
|
|
92 "Return FACE's value of the given PROPERTY.
|
|
93
|
|
94 If LOCALE is omitted, the FACE's actual value for PROPERTY will be
|
|
95 returned. For built-in properties, this will be a specifier object
|
|
96 of a type appropriate to the property (e.g. a font or color
|
|
97 specifier). For other properties, this could be anything.
|
|
98
|
|
99 If LOCALE is supplied, then instead of returning the actual value,
|
|
100 the specification(s) for the given locale or locale type will
|
|
101 be returned. This will only work if the actual value of
|
|
102 PROPERTY is a specifier (this will always be the case for built-in
|
|
103 properties, but not or not may apply to user-defined properties).
|
|
104 If the actual value of PROPERTY is not a specifier, this value
|
|
105 will simply be returned regardless of LOCALE.
|
|
106
|
|
107 The return value will be a list of instantiators (e.g. strings
|
|
108 specifying a font or color name), or a list of specifications, each
|
|
109 of which is a cons of a locale and a list of instantiators.
|
|
110 Specifically, if LOCALE is a particular locale (a buffer, window,
|
|
111 frame, device, or 'global), a list of instantiators for that locale
|
|
112 will be returned. Otherwise, if LOCALE is a locale type (one of
|
|
113 the symbols 'buffer, 'window, 'frame, or 'device), the specifications
|
|
114 for all locales of that type will be returned. Finally, if LOCALE is
|
|
115 'all, the specifications for all locales of all types will be returned.
|
|
116
|
|
117 The specifications in a specifier determine what the value of
|
|
118 PROPERTY will be in a particular \"domain\" or set of circumstances,
|
|
119 which is typically a particular Emacs window along with the buffer
|
|
120 it contains and the frame and device it lies within. The value
|
|
121 is derived from the instantiator associated with the most specific
|
|
122 locale (in the order buffer, window, frame, device, and 'global)
|
|
123 that matches the domain in question. In other words, given a domain
|
|
124 (i.e. an Emacs window, usually), the specifier for PROPERTY will first
|
|
125 be searched for a specification whose locale is the buffer contained
|
|
126 within that window; then for a specification whose locale is the window
|
|
127 itself; then for a specification whose locale is the frame that the
|
|
128 window is contained within; etc. The first instantiator that is
|
|
129 valid for the domain (usually this means that the instantiator is
|
|
130 recognized by the device [i.e. the X server or TTY device] that the
|
|
131 domain is on. The function `face-property-instance' actually does
|
|
132 all this, and is used to determine how to display the face.
|
|
133
|
|
134 See `set-face-property' for the built-in property-names."
|
|
135
|
|
136 (setq face (get-face face))
|
|
137 (let ((value (get face property)))
|
|
138 (if (and locale
|
|
139 (or (memq property built-in-face-specifiers)
|
|
140 (specifierp value)))
|
|
141 (setq value (specifier-specs value locale tag-set exact-p)))
|
|
142 value))
|
|
143
|
|
144 (defun convert-face-property-into-specifier (face property)
|
|
145 "Convert PROPERTY on FACE into a specifier, if it's not already."
|
|
146 (setq face (get-face face))
|
|
147 (let ((specifier (get face property)))
|
|
148 ;; if a user-property does not have a specifier but a
|
272
|
149 ;; locale was specified, put a specifier there.
|
209
|
150 ;; If there was already a value there, convert it to a
|
|
151 ;; specifier with the value as its 'global instantiator.
|
|
152 (unless (specifierp specifier)
|
|
153 (let ((new-specifier (make-specifier 'generic)))
|
|
154 (if (or (not (null specifier))
|
|
155 ;; make sure the nil returned from `get' wasn't
|
|
156 ;; actually the value of the property
|
|
157 (null (get face property t)))
|
|
158 (add-spec-to-specifier new-specifier specifier))
|
|
159 (setq specifier new-specifier)
|
|
160 (put face property specifier)))))
|
|
161
|
|
162 (defun face-property-instance (face property
|
|
163 &optional domain default no-fallback)
|
|
164 "Return the instance of FACE's PROPERTY in the specified DOMAIN.
|
|
165
|
|
166 Under most circumstances, DOMAIN will be a particular window,
|
|
167 and the returned instance describes how the specified property
|
|
168 actually is displayed for that window and the particular buffer
|
|
169 in it. Note that this may not be the same as how the property
|
|
170 appears when the buffer is displayed in a different window or
|
|
171 frame, or how the property appears in the same window if you
|
|
172 switch to another buffer in that window; and in those cases,
|
|
173 the returned instance would be different.
|
|
174
|
|
175 The returned instance will typically be a color-instance,
|
|
176 font-instance, or pixmap-instance object, and you can query
|
|
177 it using the appropriate object-specific functions. For example,
|
|
178 you could use `color-instance-rgb-components' to find out the
|
|
179 RGB (red, green, and blue) components of how the 'background
|
|
180 property of the 'highlight face is displayed in a particular
|
|
181 window. The results might be different from the results
|
|
182 you would get for another window (perhaps the user
|
|
183 specified a different color for the frame that window is on;
|
|
184 or perhaps the same color was specified but the window is
|
|
185 on a different X server, and that X server has different RGB
|
|
186 values for the color from this one).
|
|
187
|
|
188 DOMAIN defaults to the selected window if omitted.
|
|
189
|
|
190 DOMAIN can be a frame or device, instead of a window. The value
|
|
191 returned for a such a domain is used in special circumstances
|
|
192 when a more specific domain does not apply; for example, a frame
|
|
193 value might be used for coloring a toolbar, which is conceptually
|
|
194 attached to a frame rather than a particular window. The value
|
|
195 is also useful in determining what the value would be for a
|
|
196 particular window within the frame or device, if it is not
|
|
197 overridden by a more specific specification.
|
|
198
|
|
199 If PROPERTY does not name a built-in property, its value will
|
|
200 simply be returned unless it is a specifier object, in which case
|
|
201 it will be instanced using `specifier-instance'.
|
|
202
|
|
203 Optional arguments DEFAULT and NO-FALLBACK are the same as in
|
|
204 `specifier-instance'."
|
|
205
|
|
206 (setq face (get-face face))
|
|
207 (let ((value (get face property)))
|
|
208 (if (specifierp value)
|
|
209 (setq value (specifier-instance value domain default no-fallback)))
|
|
210 value))
|
|
211
|
|
212 (defun face-property-matching-instance (face property matchspec
|
|
213 &optional domain default
|
|
214 no-fallback)
|
|
215 "Return the instance of FACE's PROPERTY matching MATCHSPEC in DOMAIN.
|
|
216 Currently the only useful value for MATCHSPEC is a charset, when used
|
|
217 in conjunction with the face's font; this allows you to retrieve a
|
|
218 font that can be used to display a particular charset, rather than just
|
|
219 any font.
|
|
220
|
|
221 Other than MATCHSPEC, this function is identical to `face-property-instance'.
|
|
222 See also `specifier-matching-instance' for a fuller description of the
|
|
223 matching process."
|
|
224
|
|
225 (setq face (get-face face))
|
|
226 (let ((value (get face property)))
|
|
227 (if (specifierp value)
|
|
228 (setq value (specifier-matching-instance value matchspec domain
|
|
229 default no-fallback)))
|
|
230 value))
|
|
231
|
|
232 (defun set-face-property (face property value &optional locale tag-set
|
|
233 how-to-add)
|
272
|
234 "Change a property of FACE.
|
209
|
235
|
|
236 NOTE: If you want to remove a property from a face, use `remove-face-property'
|
|
237 rather than attempting to set a value of nil for the property.
|
|
238
|
|
239 For built-in properties, the actual value of the property is a
|
|
240 specifier and you cannot change this; but you can change the
|
|
241 specifications within the specifier, and that is what this function
|
|
242 will do. For user-defined properties, you can use this function
|
|
243 to either change the actual value of the property or, if this value
|
|
244 is a specifier, change the specifications within it.
|
|
245
|
|
246 If PROPERTY is a built-in property, the specifications to be added to
|
|
247 this property can be supplied in many different ways:
|
|
248
|
|
249 -- If VALUE is a simple instantiator (e.g. a string naming a font or
|
|
250 color) or a list of instantiators, then the instantiator(s) will
|
|
251 be added as a specification of the property for the given LOCALE
|
|
252 (which defaults to 'global if omitted).
|
|
253 -- If VALUE is a list of specifications (each of which is a cons of
|
|
254 a locale and a list of instantiators), then LOCALE must be nil
|
|
255 (it does not make sense to explicitly specify a locale in this
|
|
256 case), and specifications will be added as given.
|
|
257 -- If VALUE is a specifier (as would be returned by `face-property'
|
|
258 if no LOCALE argument is given), then some or all of the
|
|
259 specifications in the specifier will be added to the property.
|
|
260 In this case, the function is really equivalent to
|
|
261 `copy-specifier' and LOCALE has the same semantics (if it is
|
|
262 a particular locale, the specification for the locale will be
|
|
263 copied; if a locale type, specifications for all locales of
|
|
264 that type will be copied; if nil or 'all, then all
|
|
265 specifications will be copied).
|
|
266
|
|
267 HOW-TO-ADD should be either nil or one of the symbols 'prepend,
|
|
268 'append, 'remove-tag-set-prepend, 'remove-tag-set-append, 'remove-locale,
|
|
269 'remove-locale-type, or 'remove-all. See `copy-specifier' and
|
|
270 `add-spec-to-specifier' for a description of what each of
|
|
271 these means. Most of the time, you do not need to worry about
|
|
272 this argument; the default behavior usually is fine.
|
|
273
|
|
274 In general, it is OK to pass an instance object (e.g. as returned
|
|
275 by `face-property-instance') as an instantiator in place of
|
|
276 an actual instantiator. In such a case, the instantiator used
|
|
277 to create that instance object will be used (for example, if
|
|
278 you set a font-instance object as the value of the 'font
|
|
279 property, then the font name used to create that object will
|
|
280 be used instead). If some cases, however, doing this
|
|
281 conversion does not make sense, and this will be noted in
|
|
282 the documentation for particular types of instance objects.
|
|
283
|
|
284 If PROPERTY is not a built-in property, then this function will
|
|
285 simply set its value if LOCALE is nil. However, if LOCALE is
|
|
286 given, then this function will attempt to add VALUE as the
|
|
287 instantiator for the given LOCALE, using `add-spec-to-specifier'.
|
|
288 If the value of the property is not a specifier, it will
|
|
289 automatically be converted into a 'generic specifier.
|
|
290
|
|
291
|
|
292 The following symbols have predefined meanings:
|
|
293
|
|
294 foreground The foreground color of the face.
|
|
295 For valid instantiators, see `color-specifier-p'.
|
272
|
296
|
209
|
297 background The background color of the face.
|
|
298 For valid instantiators, see `color-specifier-p'.
|
272
|
299
|
209
|
300 font The font used to display text covered by this face.
|
|
301 For valid instantiators, see `font-specifier-p'.
|
272
|
302
|
209
|
303 display-table The display table of the face.
|
|
304 This should be a vector of 256 elements.
|
272
|
305
|
209
|
306 background-pixmap The pixmap displayed in the background of the face.
|
|
307 Only used by faces on X devices.
|
|
308 For valid instantiators, see `image-specifier-p'.
|
|
309
|
|
310 underline Underline all text covered by this face.
|
|
311 For valid instantiators, see `face-boolean-specifier-p'.
|
|
312
|
|
313 strikethru Draw a line through all text covered by this face.
|
|
314 For valid instantiators, see `face-boolean-specifier-p'.
|
|
315
|
|
316 highlight Highlight all text covered by this face.
|
|
317 Only used by faces on TTY devices.
|
|
318 For valid instantiators, see `face-boolean-specifier-p'.
|
272
|
319
|
209
|
320 dim Dim all text covered by this face.
|
|
321 Only used by faces on TTY devices.
|
|
322 For valid instantiators, see `face-boolean-specifier-p'.
|
272
|
323
|
209
|
324 blinking Blink all text covered by this face.
|
|
325 Only used by faces on TTY devices.
|
|
326 For valid instantiators, see `face-boolean-specifier-p'.
|
272
|
327
|
209
|
328 reverse Reverse the foreground and background colors.
|
|
329 Only used by faces on TTY devices.
|
|
330 For valid instantiators, see `face-boolean-specifier-p'.
|
272
|
331
|
209
|
332 doc-string Description of what the face's normal use is.
|
|
333 NOTE: This is not a specifier, unlike all
|
|
334 the other built-in properties, and cannot
|
|
335 contain locale-specific values."
|
|
336
|
|
337 (setq face (get-face face))
|
|
338 (if (memq property built-in-face-specifiers)
|
|
339 (set-specifier (get face property) value locale tag-set how-to-add)
|
|
340
|
|
341 ;; This section adds user defined properties.
|
|
342 (if (not locale)
|
|
343 (put face property value)
|
|
344 (convert-face-property-into-specifier face property)
|
|
345 (add-spec-to-specifier (get face property) value locale tag-set
|
|
346 how-to-add)))
|
|
347 value)
|
|
348
|
|
349 (defun remove-face-property (face property &optional locale tag-set exact-p)
|
272
|
350 "Remove a property from FACE.
|
209
|
351 For built-in properties, this is analogous to `remove-specifier'.
|
|
352 See `remove-specifier' for the meaning of the LOCALE, TAG-SET, and EXACT-P
|
|
353 arguments."
|
|
354 (or locale (setq locale 'all))
|
|
355 (if (memq property built-in-face-specifiers)
|
|
356 (remove-specifier (face-property face property) locale tag-set exact-p)
|
|
357 (if (eq locale 'all)
|
|
358 (remprop (get-face face) property)
|
|
359 (convert-face-property-into-specifier face property)
|
|
360 (remove-specifier (face-property face property) locale tag-set
|
|
361 exact-p))))
|
|
362
|
|
363 (defun reset-face (face &optional locale tag-set exact-p)
|
|
364 "Clear all existing built-in specifications from FACE.
|
|
365 This makes FACE inherit all its display properties from 'default.
|
|
366 WARNING: Be absolutely sure you want to do this!!! It is a dangerous
|
|
367 operation and is not undoable.
|
|
368
|
|
369 The arguments LOCALE, TAG-SET and EXACT-P are the same as for
|
|
370 `remove-specifier'."
|
|
371 (mapc (lambda (x)
|
|
372 (remove-specifier (face-property face x) locale tag-set exact-p))
|
|
373 built-in-face-specifiers)
|
|
374 nil)
|
|
375
|
|
376 (defun set-face-parent (face parent &optional locale tag-set how-to-add)
|
|
377 "Set the parent of FACE to PARENT, for all properties.
|
|
378 This makes all properties of FACE inherit from PARENT."
|
|
379 (setq parent (get-face parent))
|
|
380 (mapcar (lambda (x)
|
|
381 (set-face-property face x (vector parent) locale tag-set
|
|
382 how-to-add))
|
|
383 (delq 'display-table
|
|
384 (delq 'background-pixmap
|
|
385 (copy-sequence built-in-face-specifiers))))
|
|
386 (set-face-background-pixmap face (vector 'inherit ':face parent)
|
|
387 locale tag-set how-to-add)
|
|
388 nil)
|
|
389
|
|
390 (defun face-doc-string (face)
|
|
391 "Return the documentation string for FACE."
|
|
392 (face-property face 'doc-string))
|
|
393
|
|
394 (defun set-face-doc-string (face doc-string)
|
|
395 "Change the documentation string of FACE to DOC-STRING."
|
|
396 (interactive (face-interactive "doc-string"))
|
|
397 (set-face-property face 'doc-string doc-string))
|
|
398
|
|
399 (defun face-font-name (face &optional domain charset)
|
272
|
400 "Return the font name of FACE in DOMAIN, or nil if it is unspecified.
|
209
|
401 DOMAIN is as in `face-font-instance'."
|
|
402 (let ((f (face-font-instance face domain charset)))
|
|
403 (and f (font-instance-name f))))
|
|
404
|
|
405 (defun face-font (face &optional locale tag-set exact-p)
|
272
|
406 "Return the font of FACE in LOCALE, or nil if it is unspecified.
|
209
|
407
|
|
408 FACE may be either a face object or a symbol representing a face.
|
|
409
|
|
410 LOCALE may be a locale (the instantiators for that particular locale
|
|
411 will be returned), a locale type (the specifications for all locales
|
|
412 of that type will be returned), 'all (all specifications will be
|
|
413 returned), or nil (the actual specifier object will be returned).
|
|
414
|
|
415 See `face-property' for more information."
|
|
416 (face-property face 'font locale tag-set exact-p))
|
|
417
|
|
418 (defun face-font-instance (face &optional domain charset)
|
272
|
419 "Return the instance of FACE's font in DOMAIN.
|
209
|
420
|
|
421 FACE may be either a face object or a symbol representing a face.
|
|
422
|
|
423 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
424 and an instance object describing how the font appears in that
|
|
425 particular window and buffer will be returned.
|
|
426
|
|
427 See `face-property-instance' for more information."
|
|
428 (if charset
|
|
429 (face-property-matching-instance face 'font charset domain)
|
|
430 (face-property-instance face 'font domain)))
|
|
431
|
|
432 (defun set-face-font (face font &optional locale tag-set how-to-add)
|
272
|
433 "Change the font of FACE to FONT in LOCALE.
|
209
|
434
|
|
435 FACE may be either a face object or a symbol representing a face.
|
|
436
|
|
437 FONT should be an instantiator (see `font-specifier-p'), a list of
|
|
438 instantiators, an alist of specifications (each mapping a
|
|
439 locale to an instantiator list), or a font specifier object.
|
|
440
|
|
441 If FONT is an alist, LOCALE must be omitted. If FONT is a
|
|
442 specifier object, LOCALE can be a locale, a locale type, 'all,
|
|
443 or nil; see `copy-specifier' for its semantics. Otherwise LOCALE
|
|
444 specifies the locale under which the specified instantiator(s)
|
|
445 will be added, and defaults to 'global.
|
|
446
|
|
447 See `set-face-property' for more information."
|
|
448 (interactive (face-interactive "font"))
|
|
449 (set-face-property face 'font font locale tag-set how-to-add))
|
|
450
|
|
451 (defun face-foreground (face &optional locale tag-set exact-p)
|
272
|
452 "Return the foreground of FACE in LOCALE, or nil if it is unspecified.
|
209
|
453
|
|
454 FACE may be either a face object or a symbol representing a face.
|
|
455
|
|
456 LOCALE may be a locale (the instantiators for that particular locale
|
|
457 will be returned), a locale type (the specifications for all locales
|
|
458 of that type will be returned), 'all (all specifications will be
|
|
459 returned), or nil (the actual specifier object will be returned).
|
|
460
|
|
461 See `face-property' for more information."
|
|
462 (face-property face 'foreground locale tag-set exact-p))
|
|
463
|
|
464 (defun face-foreground-instance (face &optional domain default no-fallback)
|
272
|
465 "Return the instance of FACE's foreground in DOMAIN.
|
209
|
466
|
|
467 FACE may be either a face object or a symbol representing a face.
|
|
468
|
|
469 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
470 and an instance object describing how the foreground appears in that
|
|
471 particular window and buffer will be returned.
|
|
472
|
|
473 See `face-property-instance' for more information."
|
|
474 (face-property-instance face 'foreground domain default no-fallback))
|
|
475
|
|
476 (defun face-foreground-name (face &optional domain default no-fallback)
|
272
|
477 "Return the name of FACE's foreground color in DOMAIN.
|
209
|
478
|
|
479 FACE may be either a face object or a symbol representing a face.
|
|
480
|
|
481 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
482 and an instance object describing how the background appears in that
|
|
483 particular window and buffer will be returned.
|
|
484
|
|
485 See `face-property-instance' for more information."
|
|
486 (color-instance-name (face-foreground-instance
|
|
487 face domain default no-fallback)))
|
|
488
|
|
489 (defun set-face-foreground (face color &optional locale tag-set how-to-add)
|
272
|
490 "Change the foreground color of FACE to COLOR in LOCALE.
|
209
|
491
|
|
492 FACE may be either a face object or a symbol representing a face.
|
|
493
|
|
494 COLOR should be an instantiator (see `color-specifier-p'), a list of
|
|
495 instantiators, an alist of specifications (each mapping a locale to
|
|
496 an instantiator list), or a color specifier object.
|
|
497
|
|
498 If COLOR is an alist, LOCALE must be omitted. If COLOR is a
|
|
499 specifier object, LOCALE can be a locale, a locale type, 'all,
|
|
500 or nil; see `copy-specifier' for its semantics. Otherwise LOCALE
|
|
501 specifies the locale under which the specified instantiator(s)
|
|
502 will be added, and defaults to 'global.
|
|
503
|
|
504 See `set-face-property' for more information."
|
|
505 (interactive (face-interactive "foreground"))
|
|
506 (set-face-property face 'foreground color locale tag-set how-to-add))
|
|
507
|
|
508 (defun face-background (face &optional locale tag-set exact-p)
|
272
|
509 "Return the background color of FACE in LOCALE, or nil if it is unspecified.
|
209
|
510
|
|
511 FACE may be either a face object or a symbol representing a face.
|
|
512
|
|
513 LOCALE may be a locale (the instantiators for that particular locale
|
|
514 will be returned), a locale type (the specifications for all locales
|
|
515 of that type will be returned), 'all (all specifications will be
|
|
516 returned), or nil (the actual specifier object will be returned).
|
|
517
|
|
518 See `face-property' for more information."
|
|
519 (face-property face 'background locale tag-set exact-p))
|
|
520
|
|
521 (defun face-background-instance (face &optional domain default no-fallback)
|
272
|
522 "Return the instance of FACE's background in DOMAIN.
|
209
|
523
|
|
524 FACE may be either a face object or a symbol representing a face.
|
|
525
|
|
526 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
527 and an instance object describing how the background appears in that
|
|
528 particular window and buffer will be returned.
|
|
529
|
|
530 See `face-property-instance' for more information."
|
|
531 (face-property-instance face 'background domain default no-fallback))
|
|
532
|
|
533 (defun face-background-name (face &optional domain default no-fallback)
|
272
|
534 "Return the name of FACE's background color in DOMAIN.
|
209
|
535
|
|
536 FACE may be either a face object or a symbol representing a face.
|
|
537
|
|
538 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
539 and an instance object describing how the background appears in that
|
|
540 particular window and buffer will be returned.
|
|
541
|
|
542 See `face-property-instance' for more information."
|
|
543 (color-instance-name (face-background-instance
|
|
544 face domain default no-fallback)))
|
|
545
|
|
546 (defun set-face-background (face color &optional locale tag-set how-to-add)
|
272
|
547 "Change the background color of FACE to COLOR in LOCALE.
|
209
|
548
|
|
549 FACE may be either a face object or a symbol representing a face.
|
|
550
|
|
551 COLOR should be an instantiator (see `color-specifier-p'), a list of
|
|
552 instantiators, an alist of specifications (each mapping a locale to
|
|
553 an instantiator list), or a color specifier object.
|
|
554
|
|
555 If COLOR is an alist, LOCALE must be omitted. If COLOR is a
|
|
556 specifier object, LOCALE can be a locale, a locale type, 'all,
|
|
557 or nil; see `copy-specifier' for its semantics. Otherwise LOCALE
|
|
558 specifies the locale under which the specified instantiator(s)
|
|
559 will be added, and defaults to 'global.
|
|
560
|
|
561 See `set-face-property' for more information."
|
|
562 (interactive (face-interactive "background"))
|
|
563 (set-face-property face 'background color locale tag-set how-to-add))
|
|
564
|
|
565 (defun face-background-pixmap (face &optional locale tag-set exact-p)
|
272
|
566 "Return the background pixmap of FACE in LOCALE, or nil if it is unspecified.
|
|
567 This property is only used on window system devices.
|
209
|
568
|
|
569 FACE may be either a face object or a symbol representing a face.
|
|
570
|
|
571 LOCALE may be a locale (the instantiators for that particular locale
|
|
572 will be returned), a locale type (the specifications for all locales
|
|
573 of that type will be returned), 'all (all specifications will be
|
|
574 returned), or nil (the actual specifier object will be returned).
|
|
575
|
|
576 See `face-property' for more information."
|
|
577 (face-property face 'background-pixmap locale tag-set exact-p))
|
|
578
|
|
579 (defun face-background-pixmap-instance (face &optional domain default
|
|
580 no-fallback)
|
272
|
581 "Return the instance of FACE's background pixmap in DOMAIN.
|
209
|
582
|
|
583 FACE may be either a face object or a symbol representing a face.
|
|
584
|
|
585 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
586 and an instance object describing how the background appears in that
|
|
587 particular window and buffer will be returned.
|
|
588
|
|
589 See `face-property-instance' for more information."
|
|
590 (face-property-instance face 'background-pixmap domain default no-fallback))
|
|
591
|
|
592 (defun set-face-background-pixmap (face pixmap &optional locale tag-set
|
|
593 how-to-add)
|
272
|
594 "Change the background pixmap of FACE to PIXMAP in LOCALE.
|
|
595 This property is only used on window system devices.
|
209
|
596
|
|
597 FACE may be either a face object or a symbol representing a face.
|
|
598
|
|
599 PIXMAP should be an instantiator (see `image-specifier-p'), a list
|
|
600 of instantiators, an alist of specifications (each mapping a locale
|
|
601 to an instantiator list), or an image specifier object.
|
|
602
|
|
603 If PIXMAP is an alist, LOCALE must be omitted. If PIXMAP is a
|
|
604 specifier object, LOCALE can be a locale, a locale type, 'all,
|
|
605 or nil; see `copy-specifier' for its semantics. Otherwise LOCALE
|
|
606 specifies the locale under which the specified instantiator(s)
|
|
607 will be added, and defaults to 'global.
|
|
608
|
|
609 See `set-face-property' for more information."
|
|
610 (interactive (face-interactive "background-pixmap"))
|
|
611 (set-face-property face 'background-pixmap pixmap locale tag-set how-to-add))
|
|
612
|
|
613 (defun face-display-table (face &optional locale tag-set exact-p)
|
272
|
614 "Return the display table of FACE in LOCALE.
|
209
|
615
|
|
616 A vector (as returned by `make-display-table') will be returned.
|
|
617
|
|
618 LOCALE may be a locale (the instantiators for that particular locale
|
|
619 will be returned), a locale type (the specifications for all locales
|
|
620 of that type will be returned), 'all (all specifications will be
|
|
621 returned), or nil (the actual specifier object will be returned).
|
|
622
|
|
623 See `face-property' for more information."
|
|
624 (face-property face 'display-table locale tag-set exact-p))
|
|
625
|
|
626 (defun face-display-table-instance (face &optional domain default no-fallback)
|
|
627 "Return the instance of FACE's display table in DOMAIN.
|
|
628 A vector (as returned by `make-display-table') will be returned.
|
|
629
|
|
630 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
631 (face-property-instance face 'display-table domain default no-fallback))
|
|
632
|
|
633 (defun set-face-display-table (face display-table &optional locale tag-set
|
|
634 how-to-add)
|
272
|
635 "Change the display table of FACE to DISPLAY-TABLE in LOCALE.
|
209
|
636 DISPLAY-TABLE should be a vector as returned by `make-display-table'.
|
|
637
|
|
638 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
639 HOW-TO-ADD arguments."
|
|
640 (interactive (face-interactive "display-table"))
|
|
641 (set-face-property face 'display-table display-table locale tag-set
|
|
642 how-to-add))
|
|
643
|
|
644 ;; The following accessors and mutators are, IMHO, good
|
|
645 ;; implementation. Cf. with `make-face-bold'.
|
|
646
|
|
647 (defun face-underline-p (face &optional domain default no-fallback)
|
272
|
648 "Return t if FACE is underlined in DOMAIN.
|
209
|
649 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
650 (face-property-instance face 'underline domain default no-fallback))
|
|
651
|
|
652 (defun set-face-underline-p (face underline-p &optional locale tag-set
|
|
653 how-to-add)
|
272
|
654 "Change the underline property of FACE to UNDERLINE-P.
|
209
|
655 UNDERLINE-P is normally a face-boolean instantiator; see
|
|
656 `face-boolean-specifier-p'.
|
|
657 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
658 HOW-TO-ADD arguments."
|
|
659 (interactive (face-interactive "underline-p" "underlined"))
|
|
660 (set-face-property face 'underline underline-p locale tag-set how-to-add))
|
|
661
|
|
662 (defun face-strikethru-p (face &optional domain default no-fallback)
|
272
|
663 "Return t if FACE is strikethru-d (i.e. struck through) in DOMAIN.
|
209
|
664 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
665 (face-property-instance face 'strikethru domain default no-fallback))
|
|
666
|
|
667 (defun set-face-strikethru-p (face strikethru-p &optional locale tag-set
|
|
668 how-to-add)
|
272
|
669 "Change whether FACE is strikethru-d (i.e. struck through) in LOCALE.
|
209
|
670 STRIKETHRU-P is normally a face-boolean instantiator; see
|
|
671 `face-boolean-specifier-p'.
|
|
672 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
673 HOW-TO-ADD arguments."
|
|
674 (interactive (face-interactive "strikethru-p" "strikethru-d"))
|
|
675 (set-face-property face 'strikethru strikethru-p locale tag-set how-to-add))
|
|
676
|
|
677 (defun face-highlight-p (face &optional domain default no-fallback)
|
272
|
678 "Return t if FACE is highlighted in DOMAIN (TTY domains only).
|
209
|
679 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
680 (face-property-instance face 'highlight domain default no-fallback))
|
|
681
|
|
682 (defun set-face-highlight-p (face highlight-p &optional locale tag-set
|
|
683 how-to-add)
|
272
|
684 "Change whether FACE is highlighted in LOCALE (TTY locales only).
|
209
|
685 HIGHLIGHT-P is normally a face-boolean instantiator; see
|
|
686 `face-boolean-specifier-p'.
|
|
687 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
688 HOW-TO-ADD arguments."
|
|
689 (interactive (face-interactive "highlight-p" "highlighted"))
|
|
690 (set-face-property face 'highlight highlight-p locale tag-set how-to-add))
|
|
691
|
|
692 (defun face-dim-p (face &optional domain default no-fallback)
|
272
|
693 "Return t if FACE is dimmed in DOMAIN (TTY domains only).
|
209
|
694 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
695 (face-property-instance face 'dim domain default no-fallback))
|
|
696
|
|
697 (defun set-face-dim-p (face dim-p &optional locale tag-set how-to-add)
|
272
|
698 "Change whether FACE is dimmed in LOCALE (TTY locales only).
|
209
|
699 DIM-P is normally a face-boolean instantiator; see
|
|
700 `face-boolean-specifier-p'.
|
|
701 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
702 HOW-TO-ADD arguments."
|
|
703 (interactive (face-interactive "dim-p" "dimmed"))
|
|
704 (set-face-property face 'dim dim-p locale tag-set how-to-add))
|
|
705
|
|
706 (defun face-blinking-p (face &optional domain default no-fallback)
|
272
|
707 "Return t if FACE is blinking in DOMAIN (TTY domains only).
|
209
|
708 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
709 (face-property-instance face 'blinking domain default no-fallback))
|
|
710
|
|
711 (defun set-face-blinking-p (face blinking-p &optional locale tag-set
|
|
712 how-to-add)
|
272
|
713 "Change whether FACE is blinking in LOCALE (TTY locales only).
|
209
|
714 BLINKING-P is normally a face-boolean instantiator; see
|
|
715 `face-boolean-specifier-p'.
|
|
716 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
717 HOW-TO-ADD arguments."
|
|
718 (interactive (face-interactive "blinking-p" "blinking"))
|
|
719 (set-face-property face 'blinking blinking-p locale tag-set how-to-add))
|
|
720
|
|
721 (defun face-reverse-p (face &optional domain default no-fallback)
|
272
|
722 "Return t if FACE is reversed in DOMAIN (TTY domains only).
|
209
|
723 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
724 (face-property-instance face 'reverse domain default no-fallback))
|
|
725
|
|
726 (defun set-face-reverse-p (face reverse-p &optional locale tag-set how-to-add)
|
272
|
727 "Change whether FACE is reversed in LOCALE (TTY locales only).
|
209
|
728 REVERSE-P is normally a face-boolean instantiator; see
|
|
729 `face-boolean-specifier-p'.
|
|
730 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
731 HOW-TO-ADD arguments."
|
|
732 (interactive (face-interactive "reverse-p" "reversed"))
|
|
733 (set-face-property face 'reverse reverse-p locale tag-set how-to-add))
|
|
734
|
|
735
|
|
736 (defun face-property-equal (face1 face2 prop domain)
|
|
737 (equal (face-property-instance face1 prop domain)
|
|
738 (face-property-instance face2 prop domain)))
|
|
739
|
|
740 (defun face-equal-loop (props face1 face2 domain)
|
|
741 (while (and props
|
|
742 (face-property-equal face1 face2 (car props) domain))
|
|
743 (setq props (cdr props)))
|
|
744 (null props))
|
|
745
|
|
746 (defun face-equal (face1 face2 &optional domain)
|
272
|
747 "Return t if FACE1 and FACE2 will display in the same way in DOMAIN.
|
209
|
748 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
749 (if (null domain) (setq domain (selected-window)))
|
|
750 (if (not (valid-specifier-domain-p domain))
|
|
751 (error "Invalid specifier domain"))
|
|
752 (let ((device (dfw-device domain))
|
|
753 (common-props '(foreground background font display-table underline))
|
|
754 (x-props '(background-pixmap strikethru))
|
|
755 (tty-props '(highlight dim blinking reverse)))
|
|
756
|
|
757 ;; First check the properties which are used in common between the
|
|
758 ;; x and tty devices. Then, check those properties specific to
|
|
759 ;; the particular device type.
|
|
760 (and (face-equal-loop common-props face1 face2 domain)
|
|
761 (cond ((eq 'tty (device-type device))
|
|
762 (face-equal-loop tty-props face1 face2 domain))
|
|
763 ((eq 'x (device-type device))
|
|
764 (face-equal-loop x-props face1 face2 domain))
|
|
765 (t t)))))
|
|
766
|
|
767 (defun face-differs-from-default-p (face &optional domain)
|
272
|
768 "Return t if FACE will display differently from the default face in DOMAIN.
|
209
|
769 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
770 (not (face-equal face 'default domain)))
|
|
771
|
|
772
|
|
773 ;; This function is a terrible, disgusting hack!!!! Need to
|
|
774 ;; separate out the font elements as separate face properties!
|
|
775
|
|
776 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
777 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
778 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
779 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
780 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
781 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
782 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
783 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
784 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
785 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
786 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
787 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
788 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
789 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
790 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
791 (defun frob-face-property (face property func &optional locale)
|
|
792 "Change the specifier for FACE's PROPERTY according to FUNC, in LOCALE.
|
|
793 This function is ugly and messy and is primarily used as an internal
|
|
794 helper function for `make-face-bold' et al., so you probably don't
|
|
795 want to use it or read the rest of the documentation. But if you do ...
|
|
796
|
|
797 FUNC should be a function of two arguments (an instance and a device)
|
|
798 that returns a modified name that is valid for the given device.
|
|
799 If LOCALE specifies a valid domain (i.e. a window, frame, or device),
|
|
800 this function instantiates the specifier over that domain, applies FUNC
|
|
801 to the resulting instance, and adds the result back as an instantiator
|
|
802 for that locale. Otherwise, LOCALE should be a locale, locale type, or
|
|
803 'all (defaults to 'all if omitted). For each specification thusly
|
|
804 included: if the locale given is a valid domain, FUNC will be
|
|
805 iterated over all valid instantiators for the device of the domain
|
|
806 until a non-nil result is found (if there is no such result, the
|
|
807 first valid instantiator is used), and that result substituted for
|
|
808 the specification; otherwise, the process just outlined is
|
|
809 iterated over each existing device and the concatenated results
|
|
810 substituted for the specification."
|
|
811 (let ((sp (face-property face property)))
|
|
812 (if (valid-specifier-domain-p locale)
|
|
813 ;; this is easy.
|
|
814 (let* ((inst (face-property-instance face property locale))
|
|
815 (name (and inst (funcall func inst (dfw-device locale)))))
|
|
816 (when name
|
|
817 (add-spec-to-specifier sp name locale)))
|
|
818 ;; otherwise, map over all specifications ...
|
|
819 ;; but first, some further kludging:
|
|
820 ;; (1) if we're frobbing the global property, make sure
|
|
821 ;; that something is there (copy from the default face,
|
|
822 ;; if necessary). Otherwise, something like
|
|
823 ;; (make-face-larger 'modeline)
|
|
824 ;; won't do anything at all if the modeline simply
|
|
825 ;; inherits its font from 'default.
|
|
826 ;; (2) if we're frobbing a particular locale, nothing would
|
|
827 ;; happen if that locale has no instantiators. So signal
|
|
828 ;; an error to indicate this.
|
|
829 (if (and (or (eq locale 'global) (eq locale 'all) (not locale))
|
|
830 (not (face-property face property 'global)))
|
|
831 (copy-specifier (face-property 'default property)
|
|
832 (face-property face property)
|
|
833 'global))
|
|
834 (if (and (valid-specifier-locale-p locale)
|
|
835 (not (face-property face property locale)))
|
|
836 (error "Property must have a specification in locale %S" locale))
|
|
837 (map-specifier
|
|
838 sp
|
|
839 (lambda (sp locale inst-list func)
|
|
840 (let* ((device (dfw-device locale))
|
|
841 ;; if a device can be derived from the locale,
|
|
842 ;; call frob-face-property-1 for that device.
|
|
843 ;; Otherwise map frob-face-property-1 over each device.
|
|
844 (result
|
|
845 (if device
|
|
846 (list (frob-face-property-1 sp device inst-list func))
|
|
847 (mapcar (lambda (device)
|
|
848 (frob-face-property-1 sp device
|
|
849 inst-list func))
|
|
850 (device-list))))
|
|
851 new-result)
|
|
852 ;; remove duplicates and nils from the obtained list of
|
|
853 ;; instantiators.
|
|
854 (mapcar (lambda (arg)
|
|
855 (when (and arg (not (member arg new-result)))
|
|
856 (setq new-result (cons arg new-result))))
|
|
857 result)
|
|
858 ;; add back in.
|
|
859 (add-spec-list-to-specifier sp (list (cons locale new-result)))
|
|
860 ;; tell map-specifier to keep going.
|
|
861 nil))
|
|
862 locale
|
|
863 func))))
|
|
864
|
|
865 (defun frob-face-property-1 (sp device inst-list func)
|
|
866 (let
|
|
867 (first-valid result)
|
|
868 (while (and inst-list (not result))
|
|
869 (let* ((inst-pair (car inst-list))
|
|
870 (tag-set (car inst-pair))
|
|
871 (sp-inst (specifier-instance-from-inst-list
|
|
872 sp device (list inst-pair))))
|
|
873 (if sp-inst
|
|
874 (progn
|
|
875 (if (not first-valid)
|
|
876 (setq first-valid inst-pair))
|
|
877 (setq result (funcall func sp-inst device))
|
|
878 (if result
|
|
879 (setq result (cons tag-set result))))))
|
|
880 (setq inst-list (cdr inst-list)))
|
|
881 (or result first-valid)))
|
|
882
|
|
883 (defun frob-face-font-2 (face locale unfrobbed-face frobbed-face
|
|
884 tty-thunk x-thunk standard-face-mapping)
|
|
885 ;; another kludge to make things more intuitive. If we're
|
|
886 ;; inheriting from a standard face in this locale, frob the
|
|
887 ;; inheritance as appropriate. Else, if, after the first X frobbing
|
|
888 ;; pass, the face hasn't changed and still looks like the standard
|
|
889 ;; unfrobbed face (e.g. 'default), make it inherit from the standard
|
|
890 ;; frobbed face (e.g. 'bold). Regardless of things, do the TTY
|
|
891 ;; frobbing.
|
|
892
|
|
893 ;; yuck -- The LOCALE argument to make-face-bold is not actually a locale,
|
|
894 ;; but is a "locale, locale-type, or nil for all". So ... do our extra
|
|
895 ;; frobbing only if it's actually a locale; or for nil, do the frobbing
|
|
896 ;; on 'global. This specifier stuff needs some rethinking.
|
|
897 (let* ((the-locale (cond ((null locale) 'global)
|
|
898 ((valid-specifier-locale-p locale) locale)
|
|
899 (t nil)))
|
|
900 (specs (and the-locale (face-font face the-locale nil t)))
|
|
901 (change-it (and specs (cdr (assoc specs standard-face-mapping)))))
|
|
902 (if (and change-it
|
|
903 (not (memq (face-name (find-face face))
|
|
904 '(default bold italic bold-italic))))
|
|
905 (progn
|
|
906 (or (equal change-it t)
|
|
907 (set-face-property face 'font change-it the-locale))
|
|
908 (funcall tty-thunk))
|
|
909 (let* ((domain (cond ((null the-locale) nil)
|
|
910 ((valid-specifier-domain-p the-locale) the-locale)
|
|
911 ;; OK, this next one is truly a kludge, but
|
|
912 ;; it results in more intuitive behavior most
|
|
913 ;; of the time. (really!)
|
|
914 ((or (eq the-locale 'global) (eq the-locale 'all))
|
|
915 (selected-device))
|
|
916 (t nil)))
|
|
917 (inst (and domain (face-property-instance face 'font domain))))
|
|
918 (funcall tty-thunk)
|
|
919 (funcall x-thunk)
|
|
920 ;; If it's reasonable to do the inherit-from-standard-face trick,
|
|
921 ;; and it's called for, then do it now.
|
|
922 (or (null domain)
|
|
923 (not (equal inst (face-property-instance face 'font domain)))
|
|
924 ;; don't do it for standard faces, or you'll get inheritance loops.
|
|
925 ;; #### This makes XEmacs seg fault! fix this bug.
|
|
926 (memq (face-name (find-face face))
|
|
927 '(default bold italic bold-italic))
|
|
928 (not (equal (face-property-instance face 'font domain)
|
|
929 (face-property-instance unfrobbed-face 'font domain)))
|
|
930 (set-face-property face 'font (vector frobbed-face)
|
|
931 the-locale))))))
|
|
932
|
|
933 (defun make-face-bold (face &optional locale)
|
272
|
934 "Make FACE bold in LOCALE, if possible.
|
209
|
935 This will attempt to make the font bold for X locales and will set the
|
|
936 highlight flag for TTY locales.
|
|
937
|
|
938 If LOCALE is nil, omitted, or `all', this will attempt to frob all
|
|
939 font specifications for FACE to make them appear bold. Similarly, if
|
|
940 LOCALE is a locale type, this frobs all font specifications for locales
|
|
941 of that type. If LOCALE is a particular locale, what happens depends on
|
|
942 what sort of locale is given. If you gave a device, frame, or window,
|
|
943 then it's always possible to determine what the font actually will be,
|
|
944 so this is determined and the resulting font is frobbed and added back as a
|
|
945 specification for this locale. If LOCALE is a buffer, however, you can't
|
|
946 determine what the font will actually be unless there's actually a
|
|
947 specification given for that particular buffer (otherwise, it depends
|
|
948 on what window and frame the buffer appears in, and might not even be
|
|
949 well-defined if the buffer appears multiple times in different places);
|
|
950 therefore you will get an error unless there's a specification for the
|
|
951 buffer.
|
|
952
|
|
953 Finally, in some cases (specifically, when LOCALE is not a locale type),
|
|
954 if the frobbing didn't actually make the font look any different
|
|
955 \(this happens, for example, if your font specification is already bold
|
|
956 or has no bold equivalent), and currently looks like the font of the
|
|
957 'default face, it is set to inherit from the 'bold face. This is kludgy
|
|
958 but it makes `make-face-bold' have more intuitive behavior in many
|
|
959 circumstances."
|
|
960 (interactive (list (read-face-name "Make which face bold: ")))
|
|
961 (frob-face-font-2
|
|
962 face locale 'default 'bold
|
|
963 (lambda ()
|
|
964 ;; handle TTY specific entries
|
|
965 (when (featurep 'tty)
|
|
966 (set-face-highlight-p face t locale 'tty)))
|
|
967 (lambda ()
|
|
968 ;; handle X specific entries
|
263
|
969 (when (featurep 'x)
|
|
970 (frob-face-property face 'font 'x-make-font-bold locale))
|
|
971 (when (featurep 'mswindows)
|
|
972 (frob-face-property face 'font 'mswindows-make-font-bold locale))
|
|
973 )
|
209
|
974 '(([default] . [bold])
|
|
975 ([bold] . t)
|
|
976 ([italic] . [bold-italic])
|
|
977 ([bold-italic] . t))))
|
|
978
|
|
979 (defun make-face-italic (face &optional locale)
|
272
|
980 "Make FACE italic in LOCALE, if possible.
|
209
|
981 This will attempt to make the font italic for X locales and will set
|
|
982 the underline flag for TTY locales.
|
|
983 See `make-face-bold' for the semantics of the LOCALE argument and
|
|
984 for more specifics on exactly how this function works."
|
|
985 (interactive (list (read-face-name "Make which face italic: ")))
|
|
986 (frob-face-font-2
|
|
987 face locale 'default 'italic
|
|
988 (lambda ()
|
|
989 ;; handle TTY specific entries
|
|
990 (when (featurep 'tty)
|
|
991 (set-face-underline-p face t locale 'tty)))
|
|
992 (lambda ()
|
|
993 ;; handle X specific entries
|
263
|
994 (when (featurep 'x)
|
|
995 (frob-face-property face 'font 'x-make-font-italic locale))
|
|
996 (when (featurep 'mswindows)
|
|
997 (frob-face-property face 'font 'mswindows-make-font-italic locale))
|
|
998 )
|
209
|
999 '(([default] . [italic])
|
|
1000 ([bold] . [bold-italic])
|
|
1001 ([italic] . t)
|
|
1002 ([bold-italic] . t))))
|
|
1003
|
|
1004 (defun make-face-bold-italic (face &optional locale)
|
272
|
1005 "Make FACE bold and italic in LOCALE, if possible.
|
209
|
1006 This will attempt to make the font bold-italic for X locales and will
|
|
1007 set the highlight and underline flags for TTY locales.
|
|
1008 See `make-face-bold' for the semantics of the LOCALE argument and
|
|
1009 for more specifics on exactly how this function works."
|
|
1010 (interactive (list (read-face-name "Make which face bold-italic: ")))
|
|
1011 (frob-face-font-2
|
|
1012 face locale 'default 'bold-italic
|
|
1013 (lambda ()
|
|
1014 ;; handle TTY specific entries
|
|
1015 (when (featurep 'tty)
|
|
1016 (set-face-highlight-p face t locale 'tty)
|
|
1017 (set-face-underline-p face t locale 'tty)))
|
|
1018 (lambda ()
|
|
1019 ;; handle X specific entries
|
263
|
1020 (when (featurep 'x)
|
|
1021 (frob-face-property face 'font 'x-make-font-bold-italic locale))
|
|
1022 (when (featurep 'mswindows)
|
|
1023 (frob-face-property face 'font 'mswindows-make-font-bold-italic locale))
|
|
1024 )
|
209
|
1025 '(([default] . [italic])
|
|
1026 ([bold] . [bold-italic])
|
|
1027 ([italic] . [bold-italic])
|
|
1028 ([bold-italic] . t))))
|
|
1029
|
|
1030 (defun make-face-unbold (face &optional locale)
|
272
|
1031 "Make FACE non-bold in LOCALE, if possible.
|
209
|
1032 This will attempt to make the font non-bold for X locales and will
|
|
1033 unset the highlight flag for TTY locales.
|
|
1034 See `make-face-bold' for the semantics of the LOCALE argument and
|
|
1035 for more specifics on exactly how this function works."
|
|
1036 (interactive (list (read-face-name "Make which face non-bold: ")))
|
|
1037 (frob-face-font-2
|
|
1038 face locale 'bold 'default
|
|
1039 (lambda ()
|
|
1040 ;; handle TTY specific entries
|
|
1041 (when (featurep 'tty)
|
|
1042 (set-face-highlight-p face nil locale 'tty)))
|
|
1043 (lambda ()
|
|
1044 ;; handle X specific entries
|
263
|
1045 (when (featurep 'x)
|
|
1046 (frob-face-property face 'font 'x-make-font-unbold locale))
|
|
1047 (when (featurep 'mswindows)
|
|
1048 (frob-face-property face 'font 'mswindows-make-font-unbold locale))
|
|
1049 )
|
209
|
1050 '(([default] . t)
|
|
1051 ([bold] . [default])
|
|
1052 ([italic] . t)
|
|
1053 ([bold-italic] . [italic]))))
|
|
1054
|
|
1055 (defun make-face-unitalic (face &optional locale)
|
272
|
1056 "Make FACE non-italic in LOCALE, if possible.
|
209
|
1057 This will attempt to make the font non-italic for X locales and will
|
|
1058 unset the underline flag for TTY locales.
|
|
1059 See `make-face-bold' for the semantics of the LOCALE argument and
|
|
1060 for more specifics on exactly how this function works."
|
|
1061 (interactive (list (read-face-name "Make which face non-italic: ")))
|
|
1062 (frob-face-font-2
|
|
1063 face locale 'italic 'default
|
|
1064 (lambda ()
|
|
1065 ;; handle TTY specific entries
|
|
1066 (when (featurep 'tty)
|
|
1067 (set-face-underline-p face nil locale 'tty)))
|
|
1068 (lambda ()
|
|
1069 ;; handle X specific entries
|
263
|
1070 (when (featurep 'x)
|
|
1071 (frob-face-property face 'font 'x-make-font-unitalic locale))
|
|
1072 (when (featurep 'mswindows)
|
|
1073 (frob-face-property face 'font 'mswindows-make-font-unitalic locale))
|
|
1074 )
|
209
|
1075 '(([default] . t)
|
|
1076 ([bold] . t)
|
|
1077 ([italic] . [default])
|
|
1078 ([bold-italic] . [bold]))))
|
|
1079
|
|
1080
|
|
1081 ;; Why do the following two functions lose so badly in so many
|
|
1082 ;; circumstances?
|
|
1083
|
|
1084 (defun make-face-smaller (face &optional locale)
|
272
|
1085 "Make the font of FACE be smaller, if possible.
|
209
|
1086 LOCALE works as in `make-face-bold' et al., but the ``inheriting-
|
|
1087 from-the-bold-face'' operations described there are not done
|
|
1088 because they don't make sense in this context."
|
|
1089 (interactive (list (read-face-name "Shrink which face: ")))
|
|
1090 ;; handle X specific entries
|
263
|
1091 (when (featurep 'x)
|
|
1092 (frob-face-property face 'font 'x-find-smaller-font locale))
|
|
1093 (when (featurep 'mswindows)
|
|
1094 (frob-face-property face 'font 'mswindows-find-smaller-font locale)))
|
209
|
1095
|
|
1096 (defun make-face-larger (face &optional locale)
|
272
|
1097 "Make the font of FACE be larger, if possible.
|
209
|
1098 See `make-face-smaller' for the semantics of the LOCALE argument."
|
|
1099 (interactive (list (read-face-name "Enlarge which face: ")))
|
|
1100 ;; handle X specific entries
|
263
|
1101 (when (featurep 'x)
|
|
1102 (frob-face-property face 'font 'x-find-larger-font locale))
|
|
1103 (when (featurep 'mswindows)
|
|
1104 (frob-face-property face 'font 'mswindows-find-larger-font locale)))
|
209
|
1105
|
|
1106 (defun invert-face (face &optional locale)
|
|
1107 "Swap the foreground and background colors of the face."
|
|
1108 (interactive (list (read-face-name "Invert face: ")))
|
|
1109 (if (valid-specifier-domain-p locale)
|
|
1110 (let ((foreface (face-foreground-instance face locale)))
|
|
1111 (set-face-foreground face (face-background-instance face locale)
|
|
1112 locale)
|
|
1113 (set-face-background face foreface locale))
|
|
1114 (let ((forespec (copy-specifier (face-foreground face) nil locale)))
|
|
1115 (copy-specifier (face-background face) (face-foreground face) locale)
|
|
1116 (copy-specifier forespec (face-background face) locale))))
|
|
1117
|
|
1118
|
|
1119 ;;; Convenience functions
|
|
1120
|
|
1121 (defun face-ascent (face &optional domain charset)
|
272
|
1122 "Return the ascent of FACE in DOMAIN.
|
209
|
1123 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
1124 (font-ascent (face-font face) domain charset))
|
|
1125
|
|
1126 (defun face-descent (face &optional domain charset)
|
272
|
1127 "Return the descent of FACE in DOMAIN.
|
209
|
1128 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
1129 (font-descent (face-font face) domain charset))
|
|
1130
|
|
1131 (defun face-width (face &optional domain charset)
|
272
|
1132 "Return the width of FACE in DOMAIN.
|
209
|
1133 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
1134 (font-width (face-font face) domain charset))
|
|
1135
|
|
1136 (defun face-height (face &optional domain charset)
|
272
|
1137 "Return the height of FACE in DOMAIN.
|
209
|
1138 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
1139 (+ (face-ascent face domain charset) (face-descent face domain charset)))
|
|
1140
|
|
1141 (defun face-proportional-p (face &optional domain charset)
|
272
|
1142 "Return t if FACE is proportional in DOMAIN.
|
209
|
1143 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
1144 (font-proportional-p (face-font face) domain charset))
|
|
1145
|
|
1146
|
|
1147 ;; Functions that used to be in cus-face.el, but logically go here.
|
|
1148
|
|
1149 (defcustom frame-background-mode nil
|
|
1150 "*The brightness of the background.
|
|
1151 Set this to the symbol dark if your background color is dark, light if
|
|
1152 your background is light, or nil (default) if you want Emacs to
|
|
1153 examine the brightness for you."
|
|
1154 :group 'faces
|
272
|
1155 :type '(choice (choice-item dark)
|
209
|
1156 (choice-item light)
|
|
1157 (choice-item :tag "Auto" nil)))
|
|
1158
|
|
1159 ;; The old variable that many people still have in .emacs files.
|
|
1160 (define-obsolete-variable-alias 'custom-background-mode
|
|
1161 'frame-background-mode)
|
|
1162
|
|
1163 (defun get-frame-background-mode (frame)
|
|
1164 "Detect background mode for FRAME."
|
|
1165 (let* ((color-instance (face-background-instance 'default frame))
|
|
1166 (mode (condition-case nil
|
|
1167 (if (< (apply '+ (color-instance-rgb-components
|
|
1168 color-instance)) 65536)
|
|
1169 'dark 'light)
|
|
1170 ;; Here, we get an error on a TTY. As we don't have
|
|
1171 ;; a good way of detecting whether a TTY is light or
|
|
1172 ;; dark, we'll guess it's dark.
|
|
1173 (error 'dark))))
|
|
1174 (set-frame-property frame 'background-mode mode)
|
|
1175 mode))
|
|
1176
|
|
1177 (defun extract-custom-frame-properties (frame)
|
|
1178 "Return a plist with the frame properties of FRAME used by custom."
|
|
1179 (list 'type (or (frame-property frame 'display-type)
|
|
1180 (device-type (frame-device frame)))
|
|
1181 'class (device-class (frame-device frame))
|
|
1182 'background (or frame-background-mode
|
|
1183 (frame-property frame 'background-mode)
|
|
1184 (get-frame-background-mode frame))))
|
|
1185
|
|
1186 (defcustom init-face-from-resources t
|
|
1187 "If non nil, attempt to initialize faces from the resource database."
|
|
1188 :group 'faces
|
|
1189 :type 'boolean)
|
|
1190
|
|
1191 ;; Old name, used by custom. Also, FSFmacs name.
|
|
1192 (defvaralias 'initialize-face-resources 'init-face-from-resources)
|
|
1193
|
|
1194 (defun face-spec-set (face spec &optional frame)
|
|
1195 "Set FACE's face attributes according to the first matching entry in SPEC.
|
|
1196 If optional FRAME is non-nil, set it for that frame only.
|
|
1197 If it is nil, then apply SPEC to each frame individually.
|
|
1198 See `defface' for information about SPEC."
|
|
1199 (if frame
|
|
1200 (progn
|
|
1201 (reset-face face frame)
|
|
1202 (face-display-set face spec frame)
|
|
1203 (init-face-from-resources face frame))
|
|
1204 (let ((frames (relevant-custom-frames)))
|
|
1205 (reset-face face)
|
|
1206 (face-display-set face spec)
|
|
1207 (while frames
|
|
1208 (face-display-set face spec (car frames))
|
|
1209 (pop frames))
|
|
1210 (init-face-from-resources face))))
|
|
1211
|
|
1212 (defun face-display-set (face spec &optional frame)
|
|
1213 "Set FACE to the attributes to the first matching entry in SPEC.
|
|
1214 Iff optional FRAME is non-nil, set it for that frame only.
|
|
1215 See `defface' for information about SPEC."
|
|
1216 (while spec
|
|
1217 (let ((display (caar spec))
|
|
1218 (atts (cadar spec)))
|
|
1219 (pop spec)
|
|
1220 (when (face-spec-set-match-display display frame)
|
|
1221 ;; Avoid creating frame local duplicates of the global face.
|
|
1222 (unless (and frame (eq display (get face 'custom-face-display)))
|
|
1223 (apply 'face-custom-attributes-set face frame atts))
|
|
1224 (unless frame
|
|
1225 (put face 'custom-face-display display))
|
|
1226 (setq spec nil)))))
|
|
1227
|
|
1228 (defvar default-custom-frame-properties nil
|
|
1229 "The frame properties used for the global faces.
|
|
1230 Frames not matching these propertiess should have frame local faces.
|
272
|
1231 The value should be nil, if uninitialized, or a plist otherwise.
|
209
|
1232 See `defface' for a list of valid keys and values for the plist.")
|
|
1233
|
|
1234 (defun get-custom-frame-properties (&optional frame)
|
|
1235 "Return a plist with the frame properties of FRAME used by custom.
|
|
1236 If FRAME is nil, return the default frame properties."
|
|
1237 (cond (frame
|
|
1238 ;; Try to get from cache.
|
|
1239 (let ((cache (frame-property frame 'custom-properties)))
|
|
1240 (unless cache
|
|
1241 ;; Oh well, get it then.
|
|
1242 (setq cache (extract-custom-frame-properties frame))
|
|
1243 ;; and cache it...
|
|
1244 (set-frame-property frame 'custom-properties cache))
|
|
1245 cache))
|
219
|
1246 ;; We avoid this cache, because various frame and device
|
|
1247 ;; properties can change.
|
|
1248 ;;(default-custom-frame-properties)
|
209
|
1249 (t
|
|
1250 (setq default-custom-frame-properties
|
|
1251 (extract-custom-frame-properties (selected-frame))))))
|
|
1252
|
272
|
1253 (defun face-spec-set-match-display (display &optional frame)
|
|
1254 "Return non-nil if DISPLAY matches FRAME.
|
209
|
1255 DISPLAY is part of a spec such as can be used in `defface'.
|
272
|
1256 If FRAME is nil or omitted, the selected frame is used."
|
209
|
1257 (if (eq display t)
|
|
1258 t
|
|
1259 (let* ((props (get-custom-frame-properties frame))
|
|
1260 (type (plist-get props 'type))
|
|
1261 (class (plist-get props 'class))
|
|
1262 (background (plist-get props 'background))
|
|
1263 (match t)
|
|
1264 (entries display)
|
|
1265 entry req options)
|
|
1266 (while (and entries match)
|
|
1267 (setq entry (car entries)
|
|
1268 entries (cdr entries)
|
|
1269 req (car entry)
|
|
1270 options (cdr entry)
|
|
1271 match (case req
|
|
1272 (type (memq type options))
|
|
1273 (class (memq class options))
|
|
1274 (background (memq background options))
|
|
1275 (t (warn "Unknown req `%S' with options `%S'"
|
|
1276 req options)
|
|
1277 nil))))
|
|
1278 match)))
|
|
1279
|
|
1280 (defun relevant-custom-frames ()
|
|
1281 "List of frames whose custom properties differ from the default."
|
|
1282 (let ((relevant nil)
|
|
1283 (default (get-custom-frame-properties))
|
|
1284 (frames (frame-list))
|
|
1285 frame)
|
|
1286 (while frames
|
|
1287 (setq frame (car frames)
|
|
1288 frames (cdr frames))
|
|
1289 (unless (equal default (get-custom-frame-properties frame))
|
|
1290 (push frame relevant)))
|
|
1291 relevant))
|
|
1292
|
|
1293 (defun initialize-custom-faces (&optional frame)
|
|
1294 "Initialize all custom faces for FRAME.
|
|
1295 If FRAME is nil or omitted, initialize them for all frames."
|
|
1296 (mapc (lambda (symbol)
|
|
1297 (let ((spec (or (get symbol 'saved-face)
|
|
1298 (get symbol 'face-defface-spec))))
|
|
1299 (when spec
|
|
1300 ;; No need to init-face-from-resources -- code in
|
|
1301 ;; `init-frame-faces' does it already.
|
|
1302 (face-display-set symbol spec frame))))
|
|
1303 (face-list)))
|
|
1304
|
|
1305 (defun custom-initialize-frame (frame)
|
|
1306 "Initialize frame-local custom faces for FRAME if necessary."
|
272
|
1307 (unless (equal (get-custom-frame-properties)
|
209
|
1308 (get-custom-frame-properties frame))
|
|
1309 (initialize-custom-faces frame)))
|
|
1310
|
|
1311
|
|
1312 (defun make-empty-face (name &optional doc-string temporary)
|
|
1313 "Like `make-face', but doesn't query the resource database."
|
|
1314 (let ((init-face-from-resources nil))
|
|
1315 (make-face name doc-string temporary)))
|
|
1316
|
|
1317 (defun init-face-from-resources (face &optional locale)
|
|
1318 "Initialize FACE from the resource database.
|
|
1319 If LOCALE is specified, it should be a frame, device, or 'global, and
|
|
1320 the face will be resourced over that locale. Otherwise, the face will
|
|
1321 be resourced over all possible locales (i.e. all frames, all devices,
|
|
1322 and 'global)."
|
|
1323 (cond ((null init-face-from-resources)
|
|
1324 ;; Do nothing.
|
|
1325 )
|
|
1326 ((not locale)
|
|
1327 ;; Global, set for all frames.
|
|
1328 (progn
|
|
1329 (init-face-from-resources face 'global)
|
|
1330 (let ((devices (device-list)))
|
|
1331 (while devices
|
|
1332 (init-face-from-resources face (car devices))
|
|
1333 (setq devices (cdr devices))))
|
|
1334 (let ((frames (frame-list)))
|
|
1335 (while frames
|
|
1336 (init-face-from-resources face (car frames))
|
|
1337 (setq frames (cdr frames))))))
|
|
1338 (t
|
|
1339 ;; Specific.
|
|
1340 (let ((devtype (cond ((devicep locale) (device-type locale))
|
|
1341 ((framep locale) (frame-type locale))
|
|
1342 (t nil))))
|
|
1343 (cond ((or (and (not devtype) (featurep 'x)) (eq 'x devtype))
|
|
1344 (x-init-face-from-resources face locale))
|
|
1345 ((or (not devtype) (eq 'tty devtype))
|
|
1346 ;; Nothing to do for TTYs?
|
|
1347 ))))))
|
|
1348
|
|
1349 (defun init-device-faces (device)
|
|
1350 ;; First, add any device-local face resources.
|
|
1351 (when init-face-from-resources
|
|
1352 (loop for face in (face-list) do
|
|
1353 (init-face-from-resources face device))
|
|
1354 ;; Then do any device-specific initialization.
|
|
1355 (cond ((eq 'x (device-type device))
|
|
1356 (x-init-device-faces device))
|
213
|
1357 ((eq 'mswindows (device-type device))
|
|
1358 (mswindows-init-device-faces device))
|
209
|
1359 ;; Nothing to do for TTYs?
|
|
1360 )
|
|
1361 (init-other-random-faces device)))
|
|
1362
|
|
1363 (defun init-frame-faces (frame)
|
|
1364 (when init-face-from-resources
|
|
1365 ;; First, add any frame-local face resources.
|
|
1366 (loop for face in (face-list) do
|
|
1367 (init-face-from-resources face frame))
|
|
1368 ;; Then do any frame-specific initialization.
|
|
1369 (cond ((eq 'x (frame-type frame))
|
|
1370 (x-init-frame-faces frame))
|
213
|
1371 ((eq 'mswindows (frame-type frame))
|
|
1372 (mswindows-init-frame-faces frame))
|
209
|
1373 ;; Is there anything which should be done for TTY's?
|
|
1374 )))
|
|
1375
|
|
1376 ;; #### This is somewhat X-specific, and is called when the first
|
|
1377 ;; X device is created (even if there were TTY devices created
|
|
1378 ;; beforehand). The concept of resources has not been generalized
|
|
1379 ;; outside of X-specificness, so we have to live with this
|
|
1380 ;; breach of device-independence.
|
|
1381
|
|
1382 (defun init-global-faces ()
|
|
1383 ;; Look for global face resources.
|
|
1384 (loop for face in (face-list) do
|
|
1385 (init-face-from-resources face 'global))
|
|
1386 ;; Further X frobbing.
|
265
|
1387 (x-init-global-faces)
|
209
|
1388 ;; for bold and the like, make the global specification be bold etc.
|
|
1389 ;; if the user didn't already specify a value. These will also be
|
|
1390 ;; frobbed further in init-other-random-faces.
|
|
1391 (unless (face-font 'bold 'global)
|
|
1392 (make-face-bold 'bold 'global))
|
|
1393 ;;
|
|
1394 (unless (face-font 'italic 'global)
|
|
1395 (make-face-italic 'italic 'global))
|
|
1396 ;;
|
|
1397 (unless (face-font 'bold-italic 'global)
|
|
1398 (make-face-bold-italic 'bold-italic 'global)
|
|
1399 (unless (face-font 'bold-italic 'global)
|
|
1400 (copy-face 'bold 'bold-italic)
|
|
1401 (make-face-italic 'bold-italic)))
|
|
1402
|
|
1403 (when (face-equal 'bold 'bold-italic)
|
|
1404 (copy-face 'italic 'bold-italic)
|
|
1405 (make-face-bold 'bold-italic))
|
|
1406 ;;
|
|
1407 ;; Nothing more to be done for X or TTY's?
|
|
1408 )
|
|
1409
|
|
1410
|
|
1411 ;; These warnings are there for a reason. Just specify your fonts
|
|
1412 ;; correctly. Deal with it. Additionally, one can use
|
|
1413 ;; `log-warning-minimum-level' instead of this.
|
|
1414 ;(defvar inhibit-font-complaints nil
|
|
1415 ; "Whether to suppress complaints about incomplete sets of fonts.")
|
|
1416
|
|
1417 (defun face-complain-about-font (face device)
|
|
1418 (if (symbolp face) (setq face (symbol-name face)))
|
|
1419 ;; (if (not inhibit-font-complaints)
|
|
1420 (display-warning
|
|
1421 'font
|
|
1422 (let ((default-name (face-font-name 'default device)))
|
|
1423 (format "%s: couldn't deduce %s %s version of the font
|
|
1424 %S.
|
|
1425
|
|
1426 Please specify X resources to make the %s face
|
|
1427 visually distinguishable from the default face.
|
|
1428 For example, you could add one of the following to $HOME/Emacs:
|
|
1429
|
|
1430 Emacs.%s.attributeFont: -dt-*-medium-i-*
|
|
1431 or
|
|
1432 Emacs.%s.attributeForeground: hotpink\n"
|
|
1433 invocation-name
|
|
1434 (if (string-match "\\`[aeiouAEIOU]" face) "an" "a")
|
|
1435 face
|
|
1436 default-name
|
|
1437 face
|
|
1438 face
|
|
1439 face
|
|
1440 ))))
|
|
1441
|
|
1442
|
|
1443 ;; #### This is quite a mess. We should use the custom mechanism for
|
|
1444 ;; most of this stuff. Currently we don't do it, because Custom
|
|
1445 ;; doesn't use specifiers (yet.) FSF does it the Right Way.
|
|
1446
|
|
1447 ;; For instance, the definition of `bold' should be something like
|
|
1448 ;; (defface bold ((t (:bold t))) "Bold text.") -- and `:bold t' should
|
|
1449 ;; make sure that everything works properly.
|
|
1450
|
|
1451 (defun init-other-random-faces (device)
|
272
|
1452 "Initialize the colors and fonts of the bold, italic, bold-italic,
|
209
|
1453 zmacs-region, list-mode-item-selected, highlight, primary-selection,
|
|
1454 secondary-selection, and isearch faces when each device is created. If
|
|
1455 you want to add code to do stuff like this, use the create-device-hook."
|
|
1456
|
|
1457 ;; try to make 'bold look different from the default on this device.
|
|
1458 ;; If that doesn't work at all, then issue a warning.
|
|
1459 (unless (face-differs-from-default-p 'bold device)
|
|
1460 (make-face-bold 'bold device)
|
|
1461 (unless (face-differs-from-default-p 'bold device)
|
|
1462 (make-face-unbold 'bold device)
|
|
1463 (unless (face-differs-from-default-p 'bold device)
|
|
1464 ;; the luser specified one of the bogus font names
|
|
1465 (face-complain-about-font 'bold device))))
|
|
1466
|
|
1467 ;; Similar for italic.
|
|
1468 ;; It's unreasonable to expect to be able to make a font italic all
|
|
1469 ;; the time. For many languages, italic is an alien concept.
|
|
1470 ;; Basically, because italic is not a globally meaningful concept,
|
|
1471 ;; the use of the italic face should really be oboleted.
|
272
|
1472
|
209
|
1473 ;; I disagree with above. In many languages, the concept of capital
|
|
1474 ;; letters is just as alien, and yet we use them. Italic is here to
|
|
1475 ;; stay. -hniksic
|
|
1476
|
|
1477 ;; In a Solaris Japanese environment, there just aren't any italic
|
|
1478 ;; fonts - period. CDE recognizes this reality, and fonts
|
|
1479 ;; -dt-interface user-medium-r-normal-*-*-*-*-*-*-*-*-* don't come
|
|
1480 ;; in italic versions. So we first try to make the font bold before
|
|
1481 ;; complaining.
|
|
1482 (unless (face-differs-from-default-p 'italic device)
|
|
1483 (make-face-italic 'italic device)
|
|
1484 (unless (face-differs-from-default-p 'italic device)
|
|
1485 (make-face-bold 'italic device)
|
|
1486 (unless (face-differs-from-default-p 'italic device)
|
|
1487 (face-complain-about-font 'italic device))))
|
|
1488
|
|
1489 ;; similar for bold-italic.
|
|
1490 (unless (face-differs-from-default-p 'bold-italic device)
|
|
1491 (make-face-bold-italic 'bold-italic device)
|
|
1492 ;; if we couldn't get a bold-italic version, try just bold.
|
|
1493 (unless (face-differs-from-default-p 'bold-italic device)
|
|
1494 (make-face-bold 'bold-italic device)
|
|
1495 ;; if we couldn't get bold or bold-italic, then that's probably because
|
|
1496 ;; the default font is bold, so make the `bold-italic' face be unbold.
|
|
1497 (unless (face-differs-from-default-p 'bold-italic device)
|
|
1498 (make-face-unbold 'bold-italic device)
|
|
1499 (make-face-italic 'bold-italic device)
|
|
1500 (unless (face-differs-from-default-p 'bold-italic device)
|
|
1501 ;; if that didn't work, try plain italic
|
|
1502 ;; (can this ever happen? what the hell.)
|
|
1503 (make-face-italic 'bold-italic device)
|
|
1504 (unless (face-differs-from-default-p 'bold-italic device)
|
|
1505 ;; then bitch and moan.
|
|
1506 (face-complain-about-font 'bold-italic device))))))
|
|
1507
|
|
1508 ;; Set the text-cursor colors unless already specified.
|
|
1509 (when (and (not (eq 'tty (device-type device)))
|
|
1510 (not (face-background 'text-cursor 'global))
|
|
1511 (face-property-equal 'text-cursor 'default 'background device))
|
|
1512 (set-face-background 'text-cursor [default foreground] 'global
|
|
1513 nil 'append))
|
|
1514 (when (and (not (eq 'tty (device-type device)))
|
|
1515 (not (face-foreground 'text-cursor 'global))
|
|
1516 (face-property-equal 'text-cursor 'default 'foreground device))
|
|
1517 (set-face-foreground 'text-cursor [default background] 'global
|
|
1518 nil 'append))
|
|
1519 )
|
|
1520
|
|
1521 ;; New function with 20.1, suggested by Per Abrahamsen, coded by Kyle Jones.
|
|
1522 (defun set-face-stipple (face pixmap &optional frame)
|
272
|
1523 "Change the stipple pixmap of FACE to PIXMAP.
|
209
|
1524 This is an Emacs compatibility function; consider using
|
|
1525 set-face-background-pixmap instead.
|
|
1526
|
|
1527 PIXMAP should be a string, the name of a file of pixmap data.
|
|
1528 The directories listed in the `x-bitmap-file-path' variable are searched.
|
|
1529
|
|
1530 Alternatively, PIXMAP may be a list of the form (WIDTH HEIGHT
|
|
1531 DATA) where WIDTH and HEIGHT are the size in pixels, and DATA is
|
|
1532 a string, containing the raw bits of the bitmap. XBM data is
|
|
1533 expected in this case, other types of image data will not work.
|
|
1534
|
|
1535 If the optional FRAME argument is provided, change only
|
|
1536 in that frame; otherwise change each frame."
|
|
1537 (while (not (find-face face))
|
|
1538 (setq face (signal 'wrong-type-argument (list 'facep face))))
|
213
|
1539 (locate-file pixmap x-bitmap-file-path ".xbm:" 4)
|
209
|
1540 (while (cond ((stringp pixmap)
|
|
1541 (unless (file-readable-p pixmap)
|
|
1542 (setq pixmap `[xbm :file ,pixmap]))
|
|
1543 nil)
|
|
1544 ((and (consp pixmap) (= (length pixmap) 3))
|
|
1545 (setq pixmap `[xbm :data ,pixmap])
|
|
1546 nil)
|
|
1547 (t t))
|
|
1548 (setq pixmap (signal 'wrong-type-argument
|
|
1549 (list 'stipple-pixmap-p pixmap))))
|
|
1550 (while (and frame (not (framep frame)))
|
|
1551 (setq frame (signal 'wrong-type-argument (list 'framep frame))))
|
|
1552 (set-face-background-pixmap face pixmap frame))
|
|
1553
|
|
1554
|
|
1555 ;; Create the remaining standard faces now. This way, packages that we dump
|
|
1556 ;; can reference these faces as parents.
|
|
1557 ;;
|
|
1558 ;; The default, modeline, left-margin, right-margin, text-cursor,
|
|
1559 ;; and pointer faces are created in C.
|
|
1560
|
|
1561 (make-face 'bold "Bold text.")
|
|
1562 (make-face 'italic "Italic text.")
|
|
1563 (make-face 'bold-italic "Bold-italic text.")
|
|
1564 (make-face 'underline "Underlined text.")
|
|
1565 (or (face-differs-from-default-p 'underline)
|
265
|
1566 (set-face-underline-p 'underline t 'global '(default)))
|
209
|
1567 (make-face 'zmacs-region "Used on highlightes region between point and mark.")
|
|
1568 (make-face 'isearch "Used on region matched by isearch.")
|
|
1569 (make-face 'list-mode-item-selected
|
|
1570 "Face for the selected list item in list-mode.")
|
|
1571 (make-face 'highlight "Highlight face.")
|
|
1572 (make-face 'primary-selection "Primary selection face.")
|
|
1573 (make-face 'secondary-selection "Secondary selection face.")
|
|
1574
|
|
1575 ;; Several useful color faces.
|
|
1576 (eval-when-compile (load "cl-macs"))
|
|
1577 (dolist (color '(red green blue yellow))
|
|
1578 (make-face color (concat (symbol-name color) " text."))
|
|
1579 (set-face-foreground color (symbol-name color) nil 'color))
|
|
1580
|
|
1581 ;; Make some useful faces. This happens very early, before creating
|
265
|
1582 ;; the first non-stream device.
|
|
1583
|
|
1584 (set-face-background 'text-cursor
|
269
|
1585 '(((x default) . "Red3")
|
|
1586 ((mswindows default) . "Red3"))
|
265
|
1587 'global)
|
|
1588
|
269
|
1589 ;; some older X servers don't recognize "darkseagreen2"
|
265
|
1590 (set-face-background 'highlight
|
269
|
1591 '(((x default color) . "darkseagreen2")
|
|
1592 ((x default color) . "green")
|
|
1593 ((x default grayscale) . "gray53")
|
|
1594 ((mswindows default color) . "darkseagreen2")
|
|
1595 ((mswindows default color) . "green")
|
|
1596 ((mswindows default grayscale) . "gray53"))
|
265
|
1597 'global)
|
269
|
1598 (set-face-background-pixmap 'highlight
|
|
1599 '(((x default mono) . "gray1")
|
|
1600 ((mswindows default mono) . "gray1"))
|
|
1601 'global)
|
265
|
1602
|
269
|
1603 (set-face-background 'zmacs-region
|
|
1604 '(((x default color) . "gray65")
|
|
1605 ((x default grayscale) . "gray65")
|
|
1606 ((mswindows default color) . "gray65")
|
|
1607 ((mswindows default grayscale) . "gray65"))
|
|
1608 'global)
|
|
1609 (set-face-background-pixmap 'zmacs-region
|
|
1610 '(((x default mono) . "gray3")
|
|
1611 ((mswindows default mono) . "gray3"))
|
|
1612 'global)
|
|
1613
|
265
|
1614 (set-face-background 'list-mode-item-selected
|
269
|
1615 '(((x default color) . "gray68")
|
|
1616 ((x default grayscale) . "gray68")
|
|
1617 ((x default mono) . [default foreground])
|
|
1618 ((mswindows default color) . "gray68")
|
|
1619 ((mswindows default grayscale) . "gray68")
|
|
1620 ((mswindows default mono) . [default foreground]))
|
|
1621 'global)
|
265
|
1622 (set-face-foreground 'list-mode-item-selected
|
269
|
1623 '(((x default mono) . [default background])
|
|
1624 ((mswindows default mono) . [default background]))
|
|
1625 'global)
|
265
|
1626
|
269
|
1627 (set-face-background 'primary-selection
|
|
1628 '(((x default color) . "gray65")
|
|
1629 ((x default grayscale) . "gray65")
|
|
1630 ((mswindows default color) . "gray65")
|
|
1631 ((mswindows default grayscale) . "gray65"))
|
|
1632 'global)
|
|
1633 (set-face-background-pixmap 'primary-selection
|
|
1634 '(((x default mono) . "gray3")
|
|
1635 ((mswindows default mono) . "gray3"))
|
|
1636 'global)
|
265
|
1637
|
|
1638 (set-face-background 'secondary-selection
|
269
|
1639 '(((x default color) . "paleturquoise")
|
|
1640 ((x default color) . "green")
|
|
1641 ((x default grayscale) . "gray53")
|
|
1642 ((mswindows default color) . "paleturquoise")
|
|
1643 ((mswindows default color) . "green")
|
|
1644 ((mswindows default grayscale) . "gray53"))
|
265
|
1645 'global)
|
269
|
1646 (set-face-background-pixmap 'secondary-selection
|
|
1647 '(((x default mono) . "gray1")
|
|
1648 ((mswindows default mono) . "gray1"))
|
|
1649 'global)
|
265
|
1650
|
|
1651 (set-face-background 'isearch
|
269
|
1652 '(((x default color) . "paleturquoise")
|
|
1653 ((x default color) . "green")
|
|
1654 ((mswindows default color) . "paleturquoise")
|
|
1655 ((mswindows default color) . "green"))
|
265
|
1656 'global)
|
209
|
1657
|
|
1658 (when (featurep 'tty)
|
265
|
1659 (set-face-highlight-p 'bold t 'global '(default tty))
|
|
1660 (set-face-underline-p 'italic t 'global '(default tty))
|
|
1661 (set-face-highlight-p 'bold-italic t 'global '(default tty))
|
|
1662 (set-face-underline-p 'bold-italic t 'global '(default tty))
|
|
1663 (set-face-highlight-p 'highlight t 'global '(default tty))
|
|
1664 (set-face-reverse-p 'text-cursor t 'global '(default tty))
|
|
1665 (set-face-reverse-p 'modeline t 'global '(default tty))
|
|
1666 (set-face-reverse-p 'zmacs-region t 'global '(default tty))
|
|
1667 (set-face-reverse-p 'primary-selection t 'global '(default tty))
|
|
1668 (set-face-underline-p 'secondary-selection t 'global '(default tty))
|
|
1669 (set-face-reverse-p 'list-mode-item-selected t 'global '(default tty))
|
|
1670 (set-face-reverse-p 'isearch t 'global '(default tty))
|
209
|
1671 )
|
|
1672
|
|
1673 ;;; faces.el ends here
|