428
|
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
|
3027
|
5 ;; Copyright (C) 1995, 1996, 2002, 2005 Ben Wing
|
428
|
6
|
|
7 ;; Author: Ben Wing <ben@xemacs.org>
|
|
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@jwz.org>
|
|
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
|
771
|
49 ;; To elude the warnings for font functions. (Normally autoloaded when
|
|
50 ;; font-create-object is called)
|
|
51 (eval-when-compile
|
3094
|
52 (require 'font)
|
|
53 (load "cl-macs"))
|
771
|
54
|
428
|
55 (defgroup faces nil
|
|
56 "Support for multiple text attributes (fonts, colors, ...)
|
|
57 Such a collection of attributes is called a \"face\"."
|
|
58 :group 'emacs)
|
|
59
|
|
60
|
|
61 (defun read-face-name (prompt)
|
|
62 (let (face)
|
|
63 (while (= (length face) 0) ; nil or ""
|
|
64 (setq face (completing-read prompt
|
|
65 (mapcar (lambda (x) (list (symbol-name x)))
|
|
66 (face-list))
|
|
67 nil t)))
|
|
68 (intern face)))
|
|
69
|
|
70 (defun face-interactive (what &optional bool)
|
|
71 (let* ((fn (intern (concat "face-" what "-instance")))
|
|
72 (face (read-face-name (format "Set %s of face: " what)))
|
|
73 (default (if (fboundp fn)
|
|
74 ;; #### we should distinguish here between
|
|
75 ;; explicitly setting the value to be the
|
|
76 ;; same as the default face's value, and
|
|
77 ;; not setting a value at all.
|
|
78 (funcall fn face)))
|
|
79 (value (if bool
|
|
80 (y-or-n-p (format "Should face %s be %s? "
|
|
81 (symbol-name face) bool))
|
|
82 (read-string (format "Set %s of face %s to: "
|
|
83 what (symbol-name face))
|
|
84 (cond ((font-instance-p default)
|
|
85 (font-instance-name default))
|
|
86 ((color-instance-p default)
|
|
87 (color-instance-name default))
|
|
88 ((image-instance-p default)
|
|
89 (image-instance-file-name default))
|
|
90 (t default))))))
|
|
91 (list face (if (equal value "") nil value))))
|
|
92
|
|
93 (defconst built-in-face-specifiers
|
|
94 (built-in-face-specifiers)
|
|
95 "A list of the built-in face properties that are specifiers.")
|
|
96
|
|
97 (defun face-property (face property &optional locale tag-set exact-p)
|
|
98 "Return FACE's value of the given PROPERTY.
|
|
99
|
3027
|
100 NOTE: If you are looking for the \"value\" of a built-in face property
|
|
101 (`foreground', `background', `font', `background-pixmap', etc.), you
|
|
102 are probably better off calling `face-property-instance'. The return
|
|
103 value of `face-property' for built-in properties describes the original
|
|
104 specification used to determine the face property, which may be nil,
|
|
105 a list of instantiators, or something else that is unexpected. For
|
|
106 example, if you ask for a face property in a particular buffer (by
|
|
107 specifying a buffer for LOCALE), you will get a non-nil return value
|
|
108 only if a buffer-local specification for that particular buffer had
|
|
109 previously been given.
|
|
110
|
|
111 For a full list of built-in property names and their semantics, see
|
|
112 `set-face-property'.
|
428
|
113
|
3027
|
114 If LOCALE is omitted, the FACE's actual value for PROPERTY will be
|
|
115 returned. In this case, this function appears to behave rather
|
|
116 differently depending on whether PROPERTY is a built-in face property of
|
|
117 a user-defined face property. This is because the most basic value of a
|
|
118 user-defined property is simply whatever was set using
|
|
119 `set-face-property', but for a built-in property it's always a specifier,
|
|
120 which is an abstract object encapsulating all the specifications for that
|
|
121 particular property.
|
|
122
|
|
123 LOCALE, if supplied, will generally be a buffer, frame or
|
|
124 `global' (for the global value), but there are other possibilities -- see
|
|
125 the following paragraph. This mostly applies to built-in properties. In
|
|
126 this case, the return value will not be a specifier object but the
|
|
127 specification(s) for the given locale or locale type will be returned
|
|
128 (equivalent to calling `specifier-specs' on the specifier).
|
|
129 (Technically, the same thing happens if the basic value of a user-
|
|
130 defined property is a specifier, although this usage is rare.)
|
428
|
131
|
|
132 The return value will be a list of instantiators (e.g. strings
|
|
133 specifying a font or color name), or a list of specifications, each
|
|
134 of which is a cons of a locale and a list of instantiators.
|
|
135 Specifically, if LOCALE is a particular locale (a buffer, window,
|
3027
|
136 frame, device, or `global'), a list of instantiators for that locale
|
428
|
137 will be returned. Otherwise, if LOCALE is a locale type (one of
|
3027
|
138 the symbols `buffer', `window', `frame', or `device'), the specifications
|
428
|
139 for all locales of that type will be returned. Finally, if LOCALE is
|
3027
|
140 `all', the specifications for all locales of all types will be returned.
|
428
|
141
|
|
142 The specifications in a specifier determine what the value of
|
|
143 PROPERTY will be in a particular \"domain\" or set of circumstances,
|
3027
|
144 which is typically a particular Emacs window -- which in turn defines
|
|
145 a buffer (the buffer in the window), a frame (the frame that the window
|
|
146 is in), and a device (the device that the frame is in). The value is
|
442
|
147 derived from the instantiator associated with the most specific
|
3027
|
148 locale (in the order buffer, window, frame, device, and `global')
|
428
|
149 that matches the domain in question. In other words, given a domain
|
442
|
150 (i.e. an Emacs window, usually), the specifier for PROPERTY will
|
|
151 first be searched for a specification whose locale is the buffer
|
|
152 contained within that window; then for a specification whose locale
|
|
153 is the window itself; then for a specification whose locale is the
|
|
154 frame that the window is contained within; etc. The first
|
|
155 instantiator that is valid for the domain (usually this means that
|
|
156 the instantiator is recognized by the device [i.e. MS Windows, the X
|
3027
|
157 server or TTY device]) will be \"instantiated\", which generates
|
|
158 a Lisp object encapsulating the original instantiator and the underlying
|
|
159 window-system object describing the property. The function
|
|
160 `face-property-instance' actually does all this."
|
428
|
161
|
|
162 (setq face (get-face face))
|
|
163 (let ((value (get face property)))
|
|
164 (if (and locale
|
|
165 (or (memq property built-in-face-specifiers)
|
|
166 (specifierp value)))
|
|
167 (setq value (specifier-specs value locale tag-set exact-p)))
|
|
168 value))
|
|
169
|
|
170 (defun convert-face-property-into-specifier (face property)
|
|
171 "Convert PROPERTY on FACE into a specifier, if it's not already."
|
|
172 (setq face (get-face face))
|
|
173 (let ((specifier (get face property)))
|
|
174 ;; if a user-property does not have a specifier but a
|
|
175 ;; locale was specified, put a specifier there.
|
|
176 ;; If there was already a value there, convert it to a
|
3027
|
177 ;; specifier with the value as its `global' instantiator.
|
428
|
178 (unless (specifierp specifier)
|
|
179 (let ((new-specifier (make-specifier 'generic)))
|
|
180 (if (or (not (null specifier))
|
|
181 ;; make sure the nil returned from `get' wasn't
|
|
182 ;; actually the value of the property
|
|
183 (null (get face property t)))
|
|
184 (add-spec-to-specifier new-specifier specifier))
|
|
185 (setq specifier new-specifier)
|
|
186 (put face property specifier)))))
|
|
187
|
|
188 (defun face-property-instance (face property
|
872
|
189 &optional domain default no-fallback)
|
428
|
190 "Return the instance of FACE's PROPERTY in the specified DOMAIN.
|
|
191
|
|
192 Under most circumstances, DOMAIN will be a particular window,
|
|
193 and the returned instance describes how the specified property
|
|
194 actually is displayed for that window and the particular buffer
|
|
195 in it. Note that this may not be the same as how the property
|
|
196 appears when the buffer is displayed in a different window or
|
|
197 frame, or how the property appears in the same window if you
|
|
198 switch to another buffer in that window; and in those cases,
|
|
199 the returned instance would be different.
|
|
200
|
|
201 The returned instance will typically be a color-instance,
|
3027
|
202 font-instance, or image-instance object, and you can query
|
428
|
203 it using the appropriate object-specific functions. For example,
|
|
204 you could use `color-instance-rgb-components' to find out the
|
3027
|
205 RGB (red, green, and blue) components of how the `background'
|
|
206 property of the `highlight' face is displayed in a particular
|
428
|
207 window. The results might be different from the results
|
|
208 you would get for another window (perhaps the user
|
|
209 specified a different color for the frame that window is on;
|
|
210 or perhaps the same color was specified but the window is
|
|
211 on a different X server, and that X server has different RGB
|
|
212 values for the color from this one).
|
|
213
|
|
214 DOMAIN defaults to the selected window if omitted.
|
|
215
|
|
216 DOMAIN can be a frame or device, instead of a window. The value
|
|
217 returned for a such a domain is used in special circumstances
|
|
218 when a more specific domain does not apply; for example, a frame
|
|
219 value might be used for coloring a toolbar, which is conceptually
|
|
220 attached to a frame rather than a particular window. The value
|
|
221 is also useful in determining what the value would be for a
|
|
222 particular window within the frame or device, if it is not
|
|
223 overridden by a more specific specification.
|
|
224
|
|
225 If PROPERTY does not name a built-in property, its value will
|
|
226 simply be returned unless it is a specifier object, in which case
|
|
227 it will be instanced using `specifier-instance'.
|
|
228
|
|
229 Optional arguments DEFAULT and NO-FALLBACK are the same as in
|
|
230 `specifier-instance'."
|
|
231
|
|
232 (setq face (get-face face))
|
|
233 (let ((value (get face property)))
|
|
234 (if (specifierp value)
|
|
235 (setq value (specifier-instance value domain default no-fallback)))
|
|
236 value))
|
|
237
|
|
238 (defun face-property-matching-instance (face property matchspec
|
872
|
239 &optional domain default
|
|
240 no-fallback)
|
428
|
241 "Return the instance of FACE's PROPERTY matching MATCHSPEC in DOMAIN.
|
|
242 Currently the only useful value for MATCHSPEC is a charset, when used
|
|
243 in conjunction with the face's font; this allows you to retrieve a
|
|
244 font that can be used to display a particular charset, rather than just
|
|
245 any font.
|
|
246
|
|
247 Other than MATCHSPEC, this function is identical to `face-property-instance'.
|
|
248 See also `specifier-matching-instance' for a fuller description of the
|
|
249 matching process."
|
|
250
|
|
251 (setq face (get-face face))
|
|
252 (let ((value (get face property)))
|
3659
|
253 (when (specifierp value)
|
|
254 (setq value (specifier-matching-instance value matchspec domain
|
|
255 default no-fallback)))
|
428
|
256 value))
|
|
257
|
|
258 (defun set-face-property (face property value &optional locale tag-set
|
872
|
259 how-to-add)
|
428
|
260 "Change a property of FACE.
|
|
261
|
|
262 NOTE: If you want to remove a property from a face, use `remove-face-property'
|
|
263 rather than attempting to set a value of nil for the property.
|
|
264
|
|
265 For built-in properties, the actual value of the property is a
|
|
266 specifier and you cannot change this; but you can change the
|
|
267 specifications within the specifier, and that is what this function
|
|
268 will do. For user-defined properties, you can use this function
|
|
269 to either change the actual value of the property or, if this value
|
|
270 is a specifier, change the specifications within it.
|
|
271
|
|
272 If PROPERTY is a built-in property, the specifications to be added to
|
|
273 this property can be supplied in many different ways:
|
|
274
|
|
275 -- If VALUE is a simple instantiator (e.g. a string naming a font or
|
|
276 color) or a list of instantiators, then the instantiator(s) will
|
|
277 be added as a specification of the property for the given LOCALE
|
3027
|
278 (which defaults to `global' if omitted).
|
428
|
279 -- If VALUE is a list of specifications (each of which is a cons of
|
|
280 a locale and a list of instantiators), then LOCALE must be nil
|
|
281 (it does not make sense to explicitly specify a locale in this
|
|
282 case), and specifications will be added as given.
|
|
283 -- If VALUE is a specifier (as would be returned by `face-property'
|
|
284 if no LOCALE argument is given), then some or all of the
|
|
285 specifications in the specifier will be added to the property.
|
|
286 In this case, the function is really equivalent to
|
|
287 `copy-specifier' and LOCALE has the same semantics (if it is
|
|
288 a particular locale, the specification for the locale will be
|
|
289 copied; if a locale type, specifications for all locales of
|
3027
|
290 that type will be copied; if nil or `all', then all
|
428
|
291 specifications will be copied).
|
|
292
|
3027
|
293 HOW-TO-ADD should be either nil or one of the symbols `prepend',
|
|
294 `append', `remove-tag-set-prepend', `remove-tag-set-append', `remove-locale',
|
|
295 `remove-locale-type', or `remove-all'. See `copy-specifier' and
|
428
|
296 `add-spec-to-specifier' for a description of what each of
|
|
297 these means. Most of the time, you do not need to worry about
|
|
298 this argument; the default behavior usually is fine.
|
|
299
|
|
300 In general, it is OK to pass an instance object (e.g. as returned
|
|
301 by `face-property-instance') as an instantiator in place of
|
|
302 an actual instantiator. In such a case, the instantiator used
|
|
303 to create that instance object will be used (for example, if
|
3027
|
304 you set a font-instance object as the value of the `font'
|
428
|
305 property, then the font name used to create that object will
|
|
306 be used instead). If some cases, however, doing this
|
|
307 conversion does not make sense, and this will be noted in
|
|
308 the documentation for particular types of instance objects.
|
|
309
|
|
310 If PROPERTY is not a built-in property, then this function will
|
|
311 simply set its value if LOCALE is nil. However, if LOCALE is
|
|
312 given, then this function will attempt to add VALUE as the
|
|
313 instantiator for the given LOCALE, using `add-spec-to-specifier'.
|
|
314 If the value of the property is not a specifier, it will
|
3027
|
315 automatically be converted into a `generic' specifier.
|
428
|
316
|
|
317
|
|
318 The following symbols have predefined meanings:
|
|
319
|
|
320 foreground The foreground color of the face.
|
442
|
321 For valid instantiators, see `make-color-specifier'.
|
428
|
322
|
|
323 background The background color of the face.
|
442
|
324 For valid instantiators, see `make-color-specifier'.
|
428
|
325
|
|
326 font The font used to display text covered by this face.
|
442
|
327 For valid instantiators, see `make-font-specifier'.
|
428
|
328
|
|
329 display-table The display table of the face.
|
|
330 This should be a vector of 256 elements.
|
|
331
|
|
332 background-pixmap The pixmap displayed in the background of the face.
|
442
|
333 Only used by faces on X and MS Windows devices.
|
|
334 For valid instantiators, see `make-image-specifier'.
|
428
|
335
|
|
336 underline Underline all text covered by this face.
|
442
|
337 For valid instantiators, see `make-face-boolean-specifier'.
|
428
|
338
|
|
339 strikethru Draw a line through all text covered by this face.
|
442
|
340 For valid instantiators, see `make-face-boolean-specifier'.
|
428
|
341
|
|
342 highlight Highlight all text covered by this face.
|
|
343 Only used by faces on TTY devices.
|
442
|
344 For valid instantiators, see `make-face-boolean-specifier'.
|
428
|
345
|
|
346 dim Dim all text covered by this face.
|
442
|
347 For valid instantiators, see `make-face-boolean-specifier'.
|
428
|
348
|
|
349 blinking Blink all text covered by this face.
|
|
350 Only used by faces on TTY devices.
|
442
|
351 For valid instantiators, see `make-face-boolean-specifier'.
|
428
|
352
|
|
353 reverse Reverse the foreground and background colors.
|
|
354 Only used by faces on TTY devices.
|
442
|
355 For valid instantiators, see `make-face-boolean-specifier'.
|
428
|
356
|
3027
|
357 inherit Face name or face object from which to inherit attributes,
|
|
358 or a list of such elements. Attributes from inherited
|
|
359 faces are merged into the face like an underlying face
|
|
360 would be, with higher priority than underlying faces.
|
|
361
|
428
|
362 doc-string Description of what the face's normal use is.
|
|
363 NOTE: This is not a specifier, unlike all
|
|
364 the other built-in properties, and cannot
|
|
365 contain locale-specific values."
|
|
366
|
|
367 (setq face (get-face face))
|
|
368 (if (memq property built-in-face-specifiers)
|
|
369 (set-specifier (get face property) value locale tag-set how-to-add)
|
|
370
|
|
371 ;; This section adds user defined properties.
|
|
372 (if (not locale)
|
|
373 (put face property value)
|
|
374 (convert-face-property-into-specifier face property)
|
|
375 (add-spec-to-specifier (get face property) value locale tag-set
|
|
376 how-to-add)))
|
|
377 value)
|
|
378
|
|
379 (defun remove-face-property (face property &optional locale tag-set exact-p)
|
|
380 "Remove a property from FACE.
|
|
381 For built-in properties, this is analogous to `remove-specifier'.
|
|
382 See `remove-specifier' for the meaning of the LOCALE, TAG-SET, and EXACT-P
|
|
383 arguments."
|
|
384 (or locale (setq locale 'all))
|
|
385 (if (memq property built-in-face-specifiers)
|
|
386 (remove-specifier (face-property face property) locale tag-set exact-p)
|
|
387 (if (eq locale 'all)
|
|
388 (remprop (get-face face) property)
|
|
389 (convert-face-property-into-specifier face property)
|
|
390 (remove-specifier (face-property face property) locale tag-set
|
|
391 exact-p))))
|
|
392
|
|
393 (defun reset-face (face &optional locale tag-set exact-p)
|
|
394 "Clear all existing built-in specifications from FACE.
|
3027
|
395 This makes FACE inherit all its display properties from `default'.
|
428
|
396 WARNING: Be absolutely sure you want to do this!!! It is a dangerous
|
|
397 operation and is not undoable.
|
|
398
|
|
399 The arguments LOCALE, TAG-SET and EXACT-P are the same as for
|
|
400 `remove-specifier'."
|
|
401 (mapc (lambda (x)
|
|
402 (remove-specifier (face-property face x) locale tag-set exact-p))
|
|
403 built-in-face-specifiers)
|
|
404 nil)
|
|
405
|
|
406 (defun set-face-parent (face parent &optional locale tag-set how-to-add)
|
|
407 "Set the parent of FACE to PARENT, for all properties.
|
|
408 This makes all properties of FACE inherit from PARENT."
|
|
409 (setq parent (get-face parent))
|
|
410 (mapcar (lambda (x)
|
|
411 (set-face-property face x (vector parent) locale tag-set
|
|
412 how-to-add))
|
3027
|
413 (set-difference built-in-face-specifiers
|
|
414 '(display-table background-pixmap inherit)))
|
428
|
415 (set-face-background-pixmap face (vector 'inherit ':face parent)
|
|
416 locale tag-set how-to-add)
|
|
417 nil)
|
|
418
|
|
419 (defun face-doc-string (face)
|
|
420 "Return the documentation string for FACE."
|
|
421 (face-property face 'doc-string))
|
|
422
|
|
423 (defun set-face-doc-string (face doc-string)
|
|
424 "Change the documentation string of FACE to DOC-STRING."
|
|
425 (interactive (face-interactive "doc-string"))
|
|
426 (set-face-property face 'doc-string doc-string))
|
|
427
|
|
428 (defun face-font-name (face &optional domain charset)
|
|
429 "Return the font name of FACE in DOMAIN, or nil if it is unspecified.
|
3027
|
430 DOMAIN is as in `face-font-instance'.
|
|
431
|
|
432 Font names are strings, as described in `make-font-specifier'."
|
428
|
433 (let ((f (face-font-instance face domain charset)))
|
|
434 (and f (font-instance-name f))))
|
|
435
|
|
436 (defun face-font (face &optional locale tag-set exact-p)
|
3027
|
437 "Return the font spec of FACE in LOCALE, or nil if it is unspecified.
|
|
438
|
|
439 NOTE: This returns a locale-specific specification, not any sort of value
|
|
440 corresponding to the actual font being used. If you want to know the
|
|
441 actual font used in a particular domain, use `face-font-instance', or
|
|
442 `face-font-name' for its name (i.e. the instantiator used to create it).
|
428
|
443
|
|
444 FACE may be either a face object or a symbol representing a face.
|
|
445
|
|
446 LOCALE may be a locale (the instantiators for that particular locale
|
|
447 will be returned), a locale type (the specifications for all locales
|
3027
|
448 of that type will be returned), `all' (all specifications will be
|
428
|
449 returned), or nil (the actual specifier object will be returned).
|
|
450
|
|
451 See `face-property' for more information."
|
|
452 (face-property face 'font locale tag-set exact-p))
|
|
453
|
|
454 (defun face-font-instance (face &optional domain charset)
|
|
455 "Return the instance of FACE's font in DOMAIN.
|
|
456
|
3027
|
457 Return value will be a font instance object; query its properties using
|
|
458 `font-instance-name', `font-instance-height', `font-instance-width', etc.
|
|
459
|
428
|
460 FACE may be either a face object or a symbol representing a face.
|
|
461
|
|
462 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
463 and an instance object describing how the font appears in that
|
|
464 particular window and buffer will be returned.
|
|
465
|
3659
|
466 CHARSET is a Mule charset (meaning return the font used for that charset) or
|
|
467 nil (meaning return the font used for ASCII.)
|
|
468
|
428
|
469 See `face-property-instance' for more information."
|
3659
|
470 (if (null charset)
|
|
471 (face-property-instance face 'font domain)
|
|
472 (let (matchspec)
|
|
473 ;; get-charset signals an error if its argument doesn't have an
|
|
474 ;; associated charset.
|
|
475 (setq charset (get-charset charset)
|
|
476 matchspec (cons charset nil))
|
|
477 (or (null (setcdr matchspec 'initial))
|
|
478 (face-property-matching-instance
|
|
479 face 'font matchspec domain)
|
|
480 (null (setcdr matchspec 'final))
|
|
481 (face-property-matching-instance
|
|
482 face 'font matchspec domain)))))
|
428
|
483
|
|
484 (defun set-face-font (face font &optional locale tag-set how-to-add)
|
|
485 "Change the font of FACE to FONT in LOCALE.
|
|
486
|
|
487 FACE may be either a face object or a symbol representing a face.
|
|
488
|
3659
|
489 FONT should be an instantiator (see `make-font-specifier'; a common
|
|
490 instantiator is a platform-dependent string naming the font), a list
|
|
491 of instantiators, an alist of specifications (each mapping a locale
|
|
492 to an instantiator list), or a font specifier object.
|
428
|
493
|
3659
|
494 If FONT is an alist, LOCALE must be omitted. If FONT is a specifier
|
|
495 object, LOCALE can be a locale, a locale type, `all', or nil; see
|
|
496 `copy-specifier' for its semantics. Common LOCALEs are buffer
|
|
497 objects, window objects, device objects and `global'. Otherwise
|
|
498 LOCALE specifies the locale under which the specified
|
|
499 instantiator(s) will be added, and defaults to `global'.
|
428
|
500
|
|
501 See `set-face-property' for more information."
|
|
502 (interactive (face-interactive "font"))
|
|
503 (set-face-property face 'font font locale tag-set how-to-add))
|
|
504
|
|
505 (defun face-foreground (face &optional locale tag-set exact-p)
|
3027
|
506 "Return the foreground spec of FACE in LOCALE, or nil if it is unspecified.
|
|
507
|
|
508 NOTE: This returns a locale-specific specification, not any sort of value
|
|
509 corresponding to the actual foreground being used. If you want to know the
|
|
510 actual foreground color used in a particular domain, use
|
|
511 `face-foreground-instance', or `face-foreground-name' for its name
|
|
512 \(i.e. the instantiator used to create it).
|
428
|
513
|
|
514 FACE may be either a face object or a symbol representing a face.
|
|
515
|
|
516 LOCALE may be a locale (the instantiators for that particular locale
|
|
517 will be returned), a locale type (the specifications for all locales
|
3027
|
518 of that type will be returned), `all' (all specifications will be
|
428
|
519 returned), or nil (the actual specifier object will be returned).
|
|
520
|
|
521 See `face-property' for more information."
|
|
522 (face-property face 'foreground locale tag-set exact-p))
|
|
523
|
|
524 (defun face-foreground-instance (face &optional domain default no-fallback)
|
|
525 "Return the instance of FACE's foreground in DOMAIN.
|
|
526
|
3027
|
527 Return value will be a color instance object; query its properties using
|
|
528 `color-instance-name' or `color-instance-rgb-properties'.
|
|
529
|
428
|
530 FACE may be either a face object or a symbol representing a face.
|
|
531
|
|
532 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
533 and an instance object describing how the foreground appears in that
|
|
534 particular window and buffer will be returned.
|
|
535
|
|
536 See `face-property-instance' for more information."
|
|
537 (face-property-instance face 'foreground domain default no-fallback))
|
|
538
|
|
539 (defun face-foreground-name (face &optional domain default no-fallback)
|
|
540 "Return the name of FACE's foreground color in DOMAIN.
|
|
541
|
|
542 FACE may be either a face object or a symbol representing a face.
|
|
543
|
|
544 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
545 and an instance object describing how the background appears in that
|
|
546 particular window and buffer will be returned.
|
|
547
|
|
548 See `face-property-instance' for more information."
|
|
549 (color-instance-name (face-foreground-instance
|
|
550 face domain default no-fallback)))
|
|
551
|
|
552 (defun set-face-foreground (face color &optional locale tag-set how-to-add)
|
|
553 "Change the foreground color of FACE to COLOR in LOCALE.
|
|
554
|
|
555 FACE may be either a face object or a symbol representing a face.
|
|
556
|
442
|
557 COLOR should be an instantiator (see `make-color-specifier'), a list of
|
428
|
558 instantiators, an alist of specifications (each mapping a locale to
|
|
559 an instantiator list), or a color specifier object.
|
|
560
|
|
561 If COLOR is an alist, LOCALE must be omitted. If COLOR is a
|
3027
|
562 specifier object, LOCALE can be a locale, a locale type, `all',
|
428
|
563 or nil; see `copy-specifier' for its semantics. Otherwise LOCALE
|
|
564 specifies the locale under which the specified instantiator(s)
|
3027
|
565 will be added, and defaults to `global'.
|
428
|
566
|
|
567 See `set-face-property' for more information."
|
|
568 (interactive (face-interactive "foreground"))
|
|
569 (set-face-property face 'foreground color locale tag-set how-to-add))
|
|
570
|
|
571 (defun face-background (face &optional locale tag-set exact-p)
|
|
572 "Return the background color of FACE in LOCALE, or nil if it is unspecified.
|
|
573
|
3027
|
574 NOTE: This returns a locale-specific specification, not any sort of value
|
|
575 corresponding to the actual background being used. If you want to know the
|
|
576 actual background color used in a particular domain, use
|
|
577 `face-background-instance', or `face-background-name' for its name
|
|
578 \(i.e. the instantiator used to create it).
|
|
579
|
428
|
580 FACE may be either a face object or a symbol representing a face.
|
|
581
|
|
582 LOCALE may be a locale (the instantiators for that particular locale
|
|
583 will be returned), a locale type (the specifications for all locales
|
3027
|
584 of that type will be returned), `all' (all specifications will be
|
428
|
585 returned), or nil (the actual specifier object will be returned).
|
|
586
|
|
587 See `face-property' for more information."
|
|
588 (face-property face 'background locale tag-set exact-p))
|
|
589
|
|
590 (defun face-background-instance (face &optional domain default no-fallback)
|
|
591 "Return the instance of FACE's background in DOMAIN.
|
|
592
|
3027
|
593 Return value will be a color instance object; query its properties using
|
|
594 `color-instance-name' or `color-instance-rgb-properties'.
|
|
595
|
428
|
596 FACE may be either a face object or a symbol representing a face.
|
|
597
|
|
598 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
599 and an instance object describing how the background appears in that
|
|
600 particular window and buffer will be returned.
|
|
601
|
|
602 See `face-property-instance' for more information."
|
|
603 (face-property-instance face 'background domain default no-fallback))
|
|
604
|
|
605 (defun face-background-name (face &optional domain default no-fallback)
|
|
606 "Return the name of FACE's background color in DOMAIN.
|
|
607
|
|
608 FACE may be either a face object or a symbol representing a face.
|
|
609
|
|
610 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
611 and an instance object describing how the background appears in that
|
|
612 particular window and buffer will be returned.
|
|
613
|
|
614 See `face-property-instance' for more information."
|
|
615 (color-instance-name (face-background-instance
|
|
616 face domain default no-fallback)))
|
|
617
|
|
618 (defun set-face-background (face color &optional locale tag-set how-to-add)
|
|
619 "Change the background color of FACE to COLOR in LOCALE.
|
|
620
|
|
621 FACE may be either a face object or a symbol representing a face.
|
|
622
|
442
|
623 COLOR should be an instantiator (see `make-color-specifier'), a list of
|
428
|
624 instantiators, an alist of specifications (each mapping a locale to
|
|
625 an instantiator list), or a color specifier object.
|
|
626
|
|
627 If COLOR is an alist, LOCALE must be omitted. If COLOR is a
|
3027
|
628 specifier object, LOCALE can be a locale, a locale type, `all',
|
428
|
629 or nil; see `copy-specifier' for its semantics. Otherwise LOCALE
|
|
630 specifies the locale under which the specified instantiator(s)
|
3027
|
631 will be added, and defaults to `global'.
|
428
|
632
|
|
633 See `set-face-property' for more information."
|
|
634 (interactive (face-interactive "background"))
|
|
635 (set-face-property face 'background color locale tag-set how-to-add))
|
|
636
|
|
637 (defun face-background-pixmap (face &optional locale tag-set exact-p)
|
3027
|
638 "Return the background pixmap spec of FACE in LOCALE, or nil if unspecified.
|
428
|
639 This property is only used on window system devices.
|
|
640
|
3027
|
641 NOTE: This returns a locale-specific specification, not any sort of value
|
|
642 corresponding to the actual background pixmap being used. If you want to
|
|
643 know the actual background pixmap used in a particular domain, use
|
|
644 `face-background-pixmap-instance'.
|
|
645
|
428
|
646 FACE may be either a face object or a symbol representing a face.
|
|
647
|
|
648 LOCALE may be a locale (the instantiators for that particular locale
|
|
649 will be returned), a locale type (the specifications for all locales
|
3027
|
650 of that type will be returned), `all' (all specifications will be
|
428
|
651 returned), or nil (the actual specifier object will be returned).
|
|
652
|
|
653 See `face-property' for more information."
|
|
654 (face-property face 'background-pixmap locale tag-set exact-p))
|
|
655
|
|
656 (defun face-background-pixmap-instance (face &optional domain default
|
|
657 no-fallback)
|
|
658 "Return the instance of FACE's background pixmap in DOMAIN.
|
|
659
|
3027
|
660 Return value will be an image instance object; query its properties using
|
|
661 `image-instance-instantiator' (the original instantiator used to create
|
|
662 the image, which may be a complex beast -- see `make-image-specifier'),
|
|
663 `image-instance-file-name' (the file, if any, from which the image was
|
|
664 created), `image-instance-height', etc.
|
|
665
|
428
|
666 FACE may be either a face object or a symbol representing a face.
|
|
667
|
|
668 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
669 and an instance object describing how the background appears in that
|
|
670 particular window and buffer will be returned.
|
|
671
|
|
672 See `face-property-instance' for more information."
|
|
673 (face-property-instance face 'background-pixmap domain default no-fallback))
|
|
674
|
|
675 (defun set-face-background-pixmap (face pixmap &optional locale tag-set
|
|
676 how-to-add)
|
|
677 "Change the background pixmap of FACE to PIXMAP in LOCALE.
|
|
678 This property is only used on window system devices.
|
|
679
|
|
680 FACE may be either a face object or a symbol representing a face.
|
|
681
|
442
|
682 PIXMAP should be an instantiator (see `make-image-specifier'), a list
|
428
|
683 of instantiators, an alist of specifications (each mapping a locale
|
|
684 to an instantiator list), or an image specifier object.
|
|
685
|
|
686 If PIXMAP is an alist, LOCALE must be omitted. If PIXMAP is a
|
3027
|
687 specifier object, LOCALE can be a locale, a locale type, `all',
|
428
|
688 or nil; see `copy-specifier' for its semantics. Otherwise LOCALE
|
|
689 specifies the locale under which the specified instantiator(s)
|
3027
|
690 will be added, and defaults to `global'.
|
428
|
691
|
|
692 See `set-face-property' for more information."
|
|
693 (interactive (face-interactive "background-pixmap"))
|
|
694 (set-face-property face 'background-pixmap pixmap locale tag-set how-to-add))
|
|
695
|
1137
|
696 (defvar background-pixmap-file-history nil
|
|
697 ;; History for `set-face-background-pixmap-file'
|
|
698 )
|
|
699
|
|
700 (defun set-face-background-pixmap-file (face file)
|
|
701 "Read (and set) the background pixmap of FACE from FILE.
|
|
702 This function is a simplified version of `set-face-background-pixmap',
|
|
703 designed for interactive use."
|
|
704 (interactive
|
|
705 (let* ((face (read-face-name "Set background pixmap of face: "))
|
1139
|
706 (default (and (face-background-pixmap-instance face)
|
|
707 ((image-instance-file-name
|
|
708 (face-background-pixmap-instance face)))))
|
1137
|
709 (file (read-file-name
|
|
710 (format "Set background pixmap of face %s to: "
|
|
711 (symbol-name face))
|
1139
|
712 nil default t nil
|
1137
|
713 'background-pixmap-file-history)))
|
|
714 (list face (if (equal file "") nil file))))
|
|
715 (set-face-property face 'background-pixmap file))
|
|
716
|
428
|
717 (defun face-display-table (face &optional locale tag-set exact-p)
|
3027
|
718 "Return the display table spec of FACE in LOCALE, or nil if unspecified..
|
428
|
719
|
3027
|
720 NOTE: This returns a locale-specific specification, not any sort of value
|
|
721 corresponding to the actual display table being used. If you want to
|
|
722 know the actual display table used in a particular domain, use
|
|
723 `face-display-table-instance'.
|
|
724
|
|
725 FACE may be either a face object or a symbol representing a face.
|
428
|
726
|
|
727 LOCALE may be a locale (the instantiators for that particular locale
|
|
728 will be returned), a locale type (the specifications for all locales
|
3027
|
729 of that type will be returned), `all' (all specifications will be
|
428
|
730 returned), or nil (the actual specifier object will be returned).
|
|
731
|
|
732 See `face-property' for more information."
|
|
733 (face-property face 'display-table locale tag-set exact-p))
|
|
734
|
|
735 (defun face-display-table-instance (face &optional domain default no-fallback)
|
|
736 "Return the instance of FACE's display table in DOMAIN.
|
3027
|
737
|
|
738 Return value will be a vector, char table or range table; see
|
|
739 `current-display-table'.
|
|
740
|
|
741 FACE may be either a face object or a symbol representing a face.
|
428
|
742
|
3027
|
743 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
744 and the actual display table used in that particular window and buffer
|
|
745 will be returned.
|
|
746
|
|
747 See `face-property-instance' for more information."
|
428
|
748 (face-property-instance face 'display-table domain default no-fallback))
|
|
749
|
|
750 (defun set-face-display-table (face display-table &optional locale tag-set
|
872
|
751 how-to-add)
|
428
|
752 "Change the display table of FACE to DISPLAY-TABLE in LOCALE.
|
|
753 DISPLAY-TABLE should be a vector as returned by `make-display-table'.
|
|
754
|
|
755 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
756 HOW-TO-ADD arguments."
|
|
757 (interactive (face-interactive "display-table"))
|
|
758 (set-face-property face 'display-table display-table locale tag-set
|
|
759 how-to-add))
|
|
760
|
|
761 ;; The following accessors and mutators are, IMHO, good
|
|
762 ;; implementation. Cf. with `make-face-bold'.
|
|
763
|
|
764 (defun face-underline-p (face &optional domain default no-fallback)
|
|
765 "Return t if FACE is underlined in DOMAIN.
|
|
766 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
767 (face-property-instance face 'underline domain default no-fallback))
|
|
768
|
|
769 (defun set-face-underline-p (face underline-p &optional locale tag-set
|
872
|
770 how-to-add)
|
428
|
771 "Change the underline property of FACE to UNDERLINE-P.
|
|
772 UNDERLINE-P is normally a face-boolean instantiator; see
|
442
|
773 `make-face-boolean-specifier'.
|
428
|
774 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
775 HOW-TO-ADD arguments."
|
|
776 (interactive (face-interactive "underline-p" "underlined"))
|
|
777 (set-face-property face 'underline underline-p locale tag-set how-to-add))
|
|
778
|
|
779 (defun face-strikethru-p (face &optional domain default no-fallback)
|
|
780 "Return t if FACE is strikethru-d (i.e. struck through) in DOMAIN.
|
|
781 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
782 (face-property-instance face 'strikethru domain default no-fallback))
|
|
783
|
|
784 (defun set-face-strikethru-p (face strikethru-p &optional locale tag-set
|
872
|
785 how-to-add)
|
428
|
786 "Change whether FACE is strikethru-d (i.e. struck through) in LOCALE.
|
|
787 STRIKETHRU-P is normally a face-boolean instantiator; see
|
442
|
788 `make-face-boolean-specifier'.
|
428
|
789 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
790 HOW-TO-ADD arguments."
|
|
791 (interactive (face-interactive "strikethru-p" "strikethru-d"))
|
|
792 (set-face-property face 'strikethru strikethru-p locale tag-set how-to-add))
|
|
793
|
|
794 (defun face-highlight-p (face &optional domain default no-fallback)
|
|
795 "Return t if FACE is highlighted in DOMAIN (TTY domains only).
|
|
796 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
797 (face-property-instance face 'highlight domain default no-fallback))
|
|
798
|
|
799 (defun set-face-highlight-p (face highlight-p &optional locale tag-set
|
872
|
800 how-to-add)
|
428
|
801 "Change whether FACE is highlighted in LOCALE (TTY locales only).
|
|
802 HIGHLIGHT-P is normally a face-boolean instantiator; see
|
442
|
803 `make-face-boolean-specifier'.
|
428
|
804 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
805 HOW-TO-ADD arguments."
|
|
806 (interactive (face-interactive "highlight-p" "highlighted"))
|
|
807 (set-face-property face 'highlight highlight-p locale tag-set how-to-add))
|
|
808
|
|
809 (defun face-dim-p (face &optional domain default no-fallback)
|
|
810 "Return t if FACE is dimmed in DOMAIN.
|
|
811 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
812 (face-property-instance face 'dim domain default no-fallback))
|
|
813
|
|
814 (defun set-face-dim-p (face dim-p &optional locale tag-set how-to-add)
|
|
815 "Change whether FACE is dimmed in LOCALE.
|
|
816 DIM-P is normally a face-boolean instantiator; see
|
442
|
817 `make-face-boolean-specifier'.
|
428
|
818 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
819 HOW-TO-ADD arguments."
|
|
820 (interactive (face-interactive "dim-p" "dimmed"))
|
|
821 (set-face-property face 'dim dim-p locale tag-set how-to-add))
|
|
822
|
|
823 (defun face-blinking-p (face &optional domain default no-fallback)
|
|
824 "Return t if FACE is blinking in DOMAIN (TTY domains only).
|
|
825 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
826 (face-property-instance face 'blinking domain default no-fallback))
|
|
827
|
|
828 (defun set-face-blinking-p (face blinking-p &optional locale tag-set
|
872
|
829 how-to-add)
|
428
|
830 "Change whether FACE is blinking in LOCALE (TTY locales only).
|
|
831 BLINKING-P is normally a face-boolean instantiator; see
|
442
|
832 `make-face-boolean-specifier'.
|
428
|
833 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
834 HOW-TO-ADD arguments."
|
|
835 (interactive (face-interactive "blinking-p" "blinking"))
|
|
836 (set-face-property face 'blinking blinking-p locale tag-set how-to-add))
|
|
837
|
|
838 (defun face-reverse-p (face &optional domain default no-fallback)
|
|
839 "Return t if FACE is reversed in DOMAIN (TTY domains only).
|
|
840 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
841 (face-property-instance face 'reverse domain default no-fallback))
|
|
842
|
|
843 (defun set-face-reverse-p (face reverse-p &optional locale tag-set how-to-add)
|
|
844 "Change whether FACE is reversed in LOCALE (TTY locales only).
|
|
845 REVERSE-P is normally a face-boolean instantiator; see
|
442
|
846 `make-face-boolean-specifier'.
|
428
|
847 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
848 HOW-TO-ADD arguments."
|
|
849 (interactive (face-interactive "reverse-p" "reversed"))
|
|
850 (set-face-property face 'reverse reverse-p locale tag-set how-to-add))
|
|
851
|
|
852
|
|
853 (defun face-property-equal (face1 face2 prop domain)
|
|
854 (equal (face-property-instance face1 prop domain)
|
|
855 (face-property-instance face2 prop domain)))
|
|
856
|
|
857 (defun face-equal-loop (props face1 face2 domain)
|
|
858 (while (and props
|
|
859 (face-property-equal face1 face2 (car props) domain))
|
|
860 (setq props (cdr props)))
|
|
861 (null props))
|
|
862
|
|
863 (defun face-equal (face1 face2 &optional domain)
|
|
864 "Return t if FACE1 and FACE2 will display in the same way in DOMAIN.
|
|
865 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
866 (if (null domain) (setq domain (selected-window)))
|
|
867 (if (not (valid-specifier-domain-p domain))
|
|
868 (error "Invalid specifier domain"))
|
|
869 (let ((device (dfw-device domain))
|
|
870 (common-props '(foreground background font display-table underline
|
3027
|
871 dim inherit))
|
428
|
872 (win-props '(background-pixmap strikethru))
|
|
873 (tty-props '(highlight blinking reverse)))
|
|
874
|
|
875 ;; First check the properties which are used in common between the
|
|
876 ;; x and tty devices. Then, check those properties specific to
|
|
877 ;; the particular device type.
|
|
878 (and (face-equal-loop common-props face1 face2 domain)
|
|
879 (cond ((eq 'tty (device-type device))
|
|
880 (face-equal-loop tty-props face1 face2 domain))
|
872
|
881 ((console-on-window-system-p (device-console device))
|
428
|
882 (face-equal-loop win-props face1 face2 domain))
|
|
883 (t t)))))
|
|
884
|
|
885 (defun face-differs-from-default-p (face &optional domain)
|
|
886 "Return t if FACE will display differently from the default face in DOMAIN.
|
|
887 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
888 (not (face-equal face 'default domain)))
|
|
889
|
|
890 (defun try-font-name (name &optional device)
|
872
|
891 "Return NAME if it's a valid font name on DEVICE, else nil."
|
428
|
892 ;; yes, name really should be here twice.
|
|
893 (and name (make-font-instance name device t) name))
|
|
894
|
|
895
|
872
|
896
|
|
897 (defcustom face-frob-from-locale-first nil
|
|
898 "*If non nil, use kludgy way of frobbing fonts suitable for non-mule
|
|
899 multi-charset environments."
|
|
900 :group 'faces
|
|
901 :type 'boolean)
|
|
902
|
428
|
903 ;; This function is a terrible, disgusting hack!!!! Need to
|
|
904 ;; separate out the font elements as separate face properties!
|
|
905
|
|
906 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
907 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
908 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
909 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
910 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
911 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
912 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
913 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
914 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
915 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
916 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
917 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
918 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
919 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
920 ;; WE DEMAND LEXICAL SCOPING!!!
|
872
|
921
|
|
922 ;; When we are initializing a device, it won't be selected; we communicate
|
|
923 ;; the device to consider as selected using this variable.
|
|
924 (defvar Face-frob-property-device-considered-current nil)
|
428
|
925
|
872
|
926 (defun Face-frob-property (face locale tag-set exact-p
|
|
927 unfrobbed-face frobbed-face
|
|
928 win-prop tty-props
|
|
929 frob-mapping standard-face-mapping)
|
|
930 ;; implement the semantics of `make-face-bold' et al. FACE, LOCALE, TAG-SET
|
|
931 ;; and EXACT-P are as in that call. UNFROBBED-FACE and FROBBED-FACE are
|
|
932 ;; what we expect the original face and the result to look like,
|
|
933 ;; respectively. TTY-PROPS is a list of face properties to frob in place
|
|
934 ;; of `font' for TTY's. FROB-MAPPING is either a plist mapping device
|
|
935 ;; types to functions of two args (NAME DEVICE) that will frob the
|
|
936 ;; instantiator as appropriate for the device type (this includes TTY's),
|
|
937 ;; or a function to handle the mapping for all device types.
|
|
938 ;; STANDARD-FACE-MAPPING is an alist of mappings of inheritance
|
|
939 ;; instantiators to be replaced with other inheritance instantiators, meant
|
|
940 ;; for e.g. converting [bold] into [bold-italic].
|
|
941
|
|
942 ;; #### it would be nice if this function could be generalized to be
|
|
943 ;; a general specifier frobber. but so much of what it does is specific
|
|
944 ;; to faces -- e.g. handling of inheritance, standard faces,
|
|
945 ;; special-casing in various ways for tty's, etc. i've already extracted
|
|
946 ;; as much of the functionality as i can into subfunctions in the
|
|
947 ;; heuristic section of specifier.el.
|
442
|
948
|
872
|
949 ;; #### Note: The old code was totally different (and there was much less
|
|
950 ;; of it). It didn't bother with trying to frob all the instantiators,
|
|
951 ;; or handle inheritance vectors as instantiators, or do something
|
|
952 ;; sensible with buffer locales, or many other things. (It always, or
|
|
953 ;; usually, did a specifier-instance and frobbed the result.) But it did
|
|
954 ;; do three things we don't:
|
|
955 ;;
|
|
956 ;; (1) Map over all devices when processing global or buffer locales.
|
|
957 ;; Should we be doing this in stages 2 and/or 3? The fact that we
|
|
958 ;; now process all fallback instantiators seems to make this less
|
|
959 ;; necessary, at least for global locales.
|
|
960 ;;
|
|
961 ;; (2) Remove all instantiators tagged with `default' when putting the
|
|
962 ;; instantiators back. I don't see why this is necessary, but maybe
|
|
963 ;; it is.
|
|
964 ;;
|
|
965 ;; (3) Pay attention to the face-frob-from-locale-first variable. ####
|
|
966 ;; I don't understand its purpose. Undocumented hacks like this,
|
|
967 ;; clearly added after-the-fact, don't deserve to live. DOCUMENT
|
|
968 ;; THIS SHIT!
|
428
|
969
|
872
|
970 (flet
|
|
971 (
|
|
972
|
|
973 ;; non-nil if either instantiator non-nil, or nil instantiators allowed.
|
|
974 (nil-instantiator-ok (inst devtype-spec)
|
|
975 (or inst (eq devtype-spec 'tty)))
|
|
976
|
|
977 ;; if LOCALE is a global locale (all, nil, global), return 'global,
|
|
978 ;; else nil.
|
|
979 (global-locale (locale)
|
|
980 (and (memq locale '(all nil global)) 'global))
|
444
|
981
|
872
|
982 ;; Given a locale and the inst-list from that locale, frob the
|
|
983 ;; instantiators according to FROB-MAPPING, a plist mapping device
|
|
984 ;; types to functions that frob instantiators of that device type.
|
|
985 ;; NOTE: TAG-SET and FROB-MAPPING from environment.
|
|
986 (frob-face-inst-list (locale inst-list prop devtype-spec)
|
|
987 (let* ((ffpdev Face-frob-property-device-considered-current)
|
|
988 (results
|
|
989 ;; for each inst-pair, frob it (the result will be 0 or
|
|
990 ;; more inst-pairs; we may get more than one if, e.g. the
|
|
991 ;; instantiator specifies inheritance and we expand the
|
|
992 ;; inheritance); then nconc the results together
|
|
993 (loop for (tag-set . x) in inst-list
|
|
994 for devtype = (derive-device-type-from-locale-and-tag-set
|
|
995 locale tag-set devtype-spec ffpdev)
|
|
996 ;; devtype may be nil if it fails to match DEVTYPE-SPEC
|
|
997 if devtype
|
3360
|
998 if (let* ((mapper
|
|
999 (cond ((functionp frob-mapping) frob-mapping)
|
|
1000 ((plist-get frob-mapping devtype))
|
|
1001 (t (error 'unimplemented "mapper" devtype))))
|
872
|
1002 (result
|
|
1003 (cond
|
|
1004 ;; if a vector ...
|
|
1005 ((vectorp x)
|
|
1006 (let ((change-to
|
|
1007 (cdr (assoc x standard-face-mapping))))
|
|
1008 (cond
|
|
1009 ;; (1) handle standard mappings/null vectors
|
|
1010 ((or change-to (null (length x)))
|
|
1011 (list (cons tag-set
|
|
1012 (cond ((eq change-to t) x)
|
|
1013 (change-to)
|
|
1014 (t x)))))
|
|
1015 ;; (2) inheritance vectors. retrieve the
|
|
1016 ;; inherited value and recursively frob.
|
|
1017 ;; stick the tag-set into the result.
|
|
1018 (t (let*
|
|
1019 ((subprop
|
|
1020 (if (> (length x) 1) (elt x 1)
|
|
1021 prop))
|
|
1022 (subinsts
|
|
1023 (frob-face-inst-list
|
|
1024 locale
|
|
1025 (cdar
|
|
1026 (specifier-spec-list
|
|
1027 (face-property (elt x 0)
|
|
1028 subprop)))
|
|
1029 subprop devtype-spec)))
|
|
1030 ;; #### we don't currently handle
|
|
1031 ;; the "reverse the sense" flag on
|
|
1032 ;; tty inheritance vectors.
|
|
1033 (add-tag-to-inst-list subinsts
|
|
1034 tag-set))))))
|
|
1035 ;; (3) not a vector. just process it.
|
|
1036 (t
|
|
1037 (let ((value
|
|
1038 (if (eq devtype-spec 'tty)
|
|
1039 (funcall mapper x)
|
|
1040 (funcall mapper x
|
|
1041 (derive-domain-from-locale
|
|
1042 locale devtype-spec
|
|
1043 ffpdev)))))
|
|
1044 (and (nil-instantiator-ok value devtype-spec)
|
|
1045 (list (cons tag-set value))))))))
|
|
1046 ;; if we're adding to a tty, we need to tag our
|
|
1047 ;; additions with `tty'; see [note 1] below. we leave
|
|
1048 ;; the old spec in place, however -- if e.g. we're
|
|
1049 ;; italicizing a font that was always set to be
|
|
1050 ;; underlined, even on window systems, then we still
|
|
1051 ;; want the underline there. unless we put the old
|
|
1052 ;; spec back, the underline will disappear, since
|
|
1053 ;; the new specs are all tagged with `tty'. this
|
|
1054 ;; doesn't apply to the [note 1] situations below
|
|
1055 ;; because there we're just adding, not substituting.
|
|
1056 (if (and (eq 'tty devtype-spec)
|
|
1057 (not (or (eq 'tty tag-set)
|
|
1058 (memq 'tty tag-set))))
|
|
1059 (nconc (add-tag-to-inst-list result 'tty)
|
|
1060 (list (cons tag-set x)))
|
|
1061 result))
|
|
1062 nconc it)))
|
|
1063 (delete-duplicates results :test #'equal)))
|
428
|
1064
|
872
|
1065 ;; Frob INST-LIST, which came from LOCALE, and put the new value back
|
|
1066 ;; into SP at LOCALE. THUNK is a cons of (PROP . DEVTYPE-SPEC), the
|
|
1067 ;; property being processed and whether this is a TTY property or a
|
|
1068 ;; win property.
|
|
1069 (frob-locale (sp locale inst-list thunk)
|
|
1070 (let ((newinst (frob-face-inst-list locale inst-list
|
|
1071 (car thunk) (cdr thunk))))
|
|
1072 (remove-specifier sp locale tag-set exact-p)
|
|
1073 (add-spec-list-to-specifier sp (list (cons locale newinst))))
|
|
1074 ;; map-specifier should keep going
|
|
1075 nil)
|
428
|
1076
|
872
|
1077 ;; map over all specified locales in LOCALE; for each locale,
|
|
1078 ;; frob the instantiators in that locale in the specifier in both
|
|
1079 ;; WIN-PROP and TTY-PROPS in FACE. Takes values from environment.
|
|
1080 (map-over-locales (locale)
|
|
1081 (map-specifier (get face win-prop) #'frob-locale locale
|
|
1082 (cons win-prop 'window-system)
|
|
1083 tag-set exact-p)
|
|
1084 (loop for prop in tty-props do
|
|
1085 (map-specifier (get face prop) #'frob-locale locale
|
|
1086 (cons prop 'tty)
|
|
1087 tag-set exact-p)))
|
|
1088
|
|
1089 ;; end of flets
|
|
1090 )
|
|
1091
|
|
1092 ;; the function itself
|
452
|
1093
|
872
|
1094 (let* ((ffpdev Face-frob-property-device-considered-current)
|
|
1095 (do-later-stages
|
|
1096 (or (global-locale locale)
|
|
1097 (valid-specifier-domain-p locale)
|
|
1098 (bufferp locale)))
|
|
1099 (domain (and do-later-stages
|
|
1100 (derive-domain-from-locale locale 'window-system
|
|
1101 ffpdev)))
|
|
1102 (check-differences
|
|
1103 (and unfrobbed-face frobbed-face domain
|
|
1104 (not (memq (face-name face)
|
|
1105 '(default bold italic bold-italic)))))
|
|
1106 (orig-instance
|
|
1107 (and check-differences
|
|
1108 (face-property-instance face win-prop domain))))
|
|
1109
|
|
1110 ;; first do the frobbing
|
|
1111 (setq face (get-face face))
|
|
1112 (map-over-locales locale)
|
|
1113
|
|
1114 (when do-later-stages
|
|
1115
|
|
1116 (if (global-locale locale) (setq locale 'global))
|
428
|
1117
|
872
|
1118 ;; now do the second stage -- if there's nothing there, try
|
|
1119 ;; harder to find an instantiator, and frob it.
|
|
1120 (let (do-something)
|
|
1121 (loop for prop in (cons win-prop tty-props)
|
|
1122 for propspec = (get face prop)
|
|
1123 for devtype-spec = (if (eq prop win-prop) 'window-system 'tty)
|
|
1124 if propspec
|
|
1125 do
|
|
1126 (or (specifier-spec-list propspec locale)
|
|
1127 (let ((doit (derive-specifier-specs-from-locale
|
|
1128 propspec locale devtype-spec ffpdev
|
|
1129 ;; #### does this make sense? When no tags
|
|
1130 ;; given, frob the whole list of fallbacks when
|
|
1131 ;; global, else just retrieve a current-device
|
|
1132 ;; value. this tries to mirror normal practices,
|
|
1133 ;; where with no tags you want everything frobbed,
|
|
1134 ;; but with a tag you want only the tag frobbed
|
|
1135 ;; and hence you probably don't want lots and lots
|
|
1136 ;; of items there. (#### Perhaps the best way --
|
|
1137 ;; or at least a way with some theoretical
|
|
1138 ;; justifiability -- is to fetch the fallbacks
|
|
1139 ;; that match the TAG-SET/EXACT-P, and if none,
|
|
1140 ;; fall back onto doing the selected-device
|
|
1141 ;; trick.)
|
|
1142 (and (not tag-set) (not exact-p)))))
|
|
1143 (if (and (not doit) (eq locale 'global))
|
|
1144 (error
|
|
1145 "No fallback for specifier property %s in face %s???"
|
|
1146 prop face))
|
|
1147 ;; [note 1] whenever we add to a tty property,
|
|
1148 ;; make sure we tag our additions with `tty' to
|
|
1149 ;; avoid accidentally messing things up on window
|
|
1150 ;; systems (e.g. when making things italic we
|
|
1151 ;; don't want to set the underline property on
|
|
1152 ;; window systems)
|
|
1153 (when doit
|
|
1154 (add-spec-list-to-specifier
|
|
1155 propspec
|
|
1156 (list (cons locale
|
|
1157 (add-tag-to-inst-list
|
|
1158 doit
|
|
1159 (append (if (listp tag-set) tag-set
|
|
1160 (list tag-set))
|
|
1161 (if (eq devtype-spec 'tty) '(tty)))
|
|
1162 ))))
|
|
1163 (setq do-something t)))))
|
|
1164 (when do-something
|
|
1165 (map-over-locales (or (global-locale locale) locale))))
|
|
1166
|
|
1167 ;; then do the third stage -- check for whether we have to do
|
|
1168 ;; the inheritance trick.
|
|
1169
|
|
1170 (when (and check-differences
|
|
1171 (let ((new-instance
|
|
1172 (face-property-instance face win-prop domain)))
|
|
1173 (and
|
|
1174 (equal orig-instance new-instance)
|
|
1175 (equal orig-instance
|
|
1176 (face-property-instance unfrobbed-face win-prop
|
|
1177 domain)))))
|
|
1178 (set-face-property face win-prop (vector frobbed-face)
|
|
1179 (or (global-locale locale) locale) tag-set))))))
|
428
|
1180
|
707
|
1181 ;; WE DEMAND FOUNDRY FROBBING!
|
|
1182
|
|
1183 ;; Family frobbing
|
|
1184 ;; Thx Jan Vroonhof, Ref xemacs-beta <87oflypbum.fsf@petteflet.ntlworld.com>
|
|
1185 ;; Brainlessly derived from make-face-size by Stephen; don't blame Jan.
|
|
1186 ;; I'm long since flown to Rio, it does you little good to blame me, either.
|
872
|
1187 (defun make-face-family (face family &optional locale tags exact-p)
|
|
1188 "Set FACE's family to FAMILY in LOCALE, if possible."
|
|
1189 (interactive (list (read-face-name "Set family of which face: ")
|
|
1190 (read-string "Family to set: ")))
|
707
|
1191
|
872
|
1192 (Face-frob-property face locale tags exact-p
|
|
1193 nil nil 'font nil
|
|
1194 `(lambda (f d)
|
707
|
1195 ;; keep the dependency on font.el for now
|
872
|
1196 (let ((fo (font-create-object f d)))
|
|
1197 (set-font-family fo ,family)
|
707
|
1198 (font-create-name fo d)))
|
872
|
1199 nil))
|
707
|
1200
|
|
1201 ;; Style (ie, typographical face) frobbing
|
872
|
1202 (defun make-face-bold (face &optional locale tags exact-p)
|
428
|
1203 "Make FACE bold in LOCALE, if possible.
|
872
|
1204 This will attempt to make the font bold for window-system locales and will
|
|
1205 set the highlight flag for TTY locales.
|
|
1206
|
|
1207 The actual behavior of this function is somewhat messy, in an attempt to
|
|
1208 get more intuitive behavior in quite a lot of different circumstances. (You
|
|
1209 might view this as indicative of design failures with specifiers, but in
|
|
1210 fact almost all code that attempts to interface to humans and produce
|
|
1211 \"intuitive\" results gets messy, particularly with a system as complicated
|
|
1212 as specifiers, whose complexity results from an attempt to work well in
|
|
1213 many different circumstances.)
|
|
1214
|
|
1215 The meaning of LOCALE is the same as for `specifier-spec-list', i.e.:
|
|
1216
|
|
1217 -- If LOCALE is nil, omitted, or `all', this will attempt to \"frob\" all
|
|
1218 font specifications for FACE to make them appear bold (i.e. the
|
|
1219 specifications are replaced with equivalent specifications, where the
|
|
1220 font names have been changed to the closest bold font).
|
|
1221
|
|
1222 -- If LOCALE is a locale type \(`buffer', `window', etc.), this frobs all
|
|
1223 font specifications for locales of that type.
|
|
1224
|
|
1225 -- If LOCALE is a particular locale, this frobs all font specifications for
|
|
1226 that locale.
|
428
|
1227
|
872
|
1228 If TAGS is given, this only processes instantiators whose tag set includes
|
|
1229 all tags mentioned in TAGS. In addition, if EXACT-P is non-nil, only
|
|
1230 instantiators whose tag set exactly matches TAGS are processed; otherwise,
|
|
1231 additional tags may be present in the instantiator's tag set.
|
|
1232
|
|
1233 This function proceeeds in three stages.
|
|
1234
|
|
1235 STAGE 1: Frob the settings that are already present.
|
|
1236 STAGE 2: (if called for) Ensure that *some* setting exists in the locale
|
|
1237 that was given, finding it in various ways and frobbing it as in
|
|
1238 stage 1. This ensures that there is an actual setting for
|
|
1239 the locale, so you will get the expected buffer-local/frame-local
|
|
1240 behavior -- changes to the global value, to other locales, won't
|
|
1241 affect this locale, (b) the face will actually look bold in
|
|
1242 the locale.
|
1137
|
1243 STAGE 3: (if called for)
|
872
|
1244
|
|
1245 The way the frobbing works depends on the device type -- first on whether
|
|
1246 or not it's TTY, and second, if it's a window-system device type, on which
|
|
1247 particular window-system device type. For locales with a specific device
|
|
1248 type, we do the frobbing in the context of that device type -- this means
|
|
1249 that for TTY device types we set the highlight flag, and for window-system
|
|
1250 device types we modify the font spec according to the rules for font specs
|
|
1251 of that device type. For global locales, we may process both the highlight
|
|
1252 flag and the font specs (depending on the device types compiled into this
|
|
1253 XEmacs). When processing font specs, we check the tag set associated with
|
|
1254 each font spec to see if it's specific to a particular device type; if so,
|
|
1255 we frob it in the context of that type, else we use the type of the current
|
|
1256 device. (A hack, but works well in practice -- and if a new device is
|
|
1257 created, we will automatically frob all the standard fonts to make sure
|
|
1258 they display OK on that device.)
|
|
1259
|
|
1260 If LOCALE is not a locale type, and both TAGS and EXACT-P are omitted, we
|
|
1261 do further frobbing in an attempt to give more intuitive behavior.
|
428
|
1262
|
872
|
1263 First, if there are no specifications in LOCALE (if LOCALE is `all', we act
|
|
1264 as if it were `global' for this step), we do our utmost to put a
|
|
1265 specification there; otherwise, this function will have no effect. For
|
|
1266 device, frame, or window locales, the face's font is instantiated using the
|
|
1267 locale as a domain, and the resulting font is frobbed and added back as a
|
|
1268 specification for this locale. If LOCALE is `global', we retrieve the
|
|
1269 fallback specs and frob them. If LOCALE is a buffer, things get tricky
|
|
1270 since you can't instantiate a specifier in a buffer domain \(the buffer can
|
|
1271 appear in multiple places, or in different places over time, so this
|
|
1272 operation is not well-defined). We used to signal an error in this case,
|
|
1273 but now we instead try to do something logical so that we work somewhat
|
|
1274 similarly to buffer-local variables. Specifically, we use
|
|
1275 `get-buffer-window' to find a window viewing the buffer, and if there is
|
|
1276 one, use this as a domain to instantiate the font, and frob the resulting
|
|
1277 value. Otherwise, we use the selected window for the same purpose.
|
|
1278
|
|
1279 Finally, if the frobbing didn't actually make the font look any different
|
|
1280 in whatever domain we instantiated the font in (this happens, for example,
|
|
1281 if your font specification is already bold or has no bold equivalent; note
|
|
1282 that in this step, we use the selected device in place of `global' or `all'
|
|
1283 -- another hack, but works well in practice since there's usually only one
|
|
1284 device), and the font currently looks like the font of the `default' face,
|
|
1285 it is set to inherit from the `bold' face.
|
|
1286
|
|
1287 NOTE: For the other functions defined below, the identity of these two
|
|
1288 standard faces mentioned in the previous paragraph, and the TTY properties
|
|
1289 that are modified, may be different, and whether the TTY property or
|
|
1290 properties are set or unset may be different. For example, for
|
|
1291 `make-face-unitalic', the last sentence in the previous paragraph would
|
|
1292 read \"... and the font currently looks like the font of the `italic' face,
|
|
1293 it is set to inherit from the `default' face.\", and the second sentence in
|
|
1294 the first paragraph would read \"This will attempt to make the font
|
|
1295 non-italic for window-system locales and will unset the underline flag for
|
|
1296 TTY locales.\"
|
|
1297
|
|
1298 Here's a table indicating the behavior differences with the different
|
|
1299 functions:
|
|
1300
|
|
1301 function face1 face2 tty-props tty-val
|
|
1302 ----------------------------------------------------------------------------
|
|
1303 make-face-bold default bold highlight t
|
|
1304 make-face-italic default italic underline t
|
|
1305 make-face-bold-italic default bold-italic highlight,underline t
|
|
1306 make-face-unbold bold default highlight nil
|
|
1307 make-face-unitalic italic default underline nil
|
|
1308 "
|
428
|
1309 (interactive (list (read-face-name "Make which face bold: ")))
|
872
|
1310 (Face-frob-property face locale tags exact-p
|
|
1311 'default 'bold 'font '(highlight)
|
|
1312 '(tty (lambda (x) t)
|
|
1313 x x-make-font-bold
|
|
1314 gtk gtk-make-font-bold
|
|
1315 mswindows mswindows-make-font-bold
|
|
1316 msprinter mswindows-make-font-bold)
|
|
1317 '(([default] . [bold])
|
|
1318 ([bold] . t)
|
|
1319 ([italic] . [bold-italic])
|
|
1320 ([bold-italic] . t))))
|
428
|
1321
|
872
|
1322 (defun make-face-italic (face &optional locale tags exact-p)
|
428
|
1323 "Make FACE italic in LOCALE, if possible.
|
442
|
1324 This will attempt to make the font italic for X/MS Windows locales and
|
|
1325 will set the underline flag for TTY locales. See `make-face-bold' for
|
|
1326 the semantics of the LOCALE argument and for more specifics on exactly
|
|
1327 how this function works."
|
428
|
1328 (interactive (list (read-face-name "Make which face italic: ")))
|
872
|
1329 (Face-frob-property face locale tags exact-p
|
|
1330 'default 'italic 'font '(underline)
|
|
1331 '(tty (lambda (x) t)
|
|
1332 x x-make-font-italic
|
|
1333 gtk gtk-make-font-italic
|
|
1334 mswindows mswindows-make-font-italic
|
|
1335 msprinter mswindows-make-font-italic)
|
|
1336 '(([default] . [italic])
|
|
1337 ([bold] . [bold-italic])
|
|
1338 ([italic] . t)
|
|
1339 ([bold-italic] . t))))
|
428
|
1340
|
872
|
1341 (defun make-face-bold-italic (face &optional locale tags exact-p)
|
428
|
1342 "Make FACE bold and italic in LOCALE, if possible.
|
442
|
1343 This will attempt to make the font bold-italic for X/MS Windows
|
|
1344 locales and will set the highlight and underline flags for TTY
|
|
1345 locales. See `make-face-bold' for the semantics of the LOCALE
|
|
1346 argument and for more specifics on exactly how this function works."
|
428
|
1347 (interactive (list (read-face-name "Make which face bold-italic: ")))
|
872
|
1348 (Face-frob-property face locale tags exact-p
|
|
1349 'default 'bold-italic 'font '(underline highlight)
|
|
1350 '(tty (lambda (x) t)
|
|
1351 x x-make-font-bold-italic
|
|
1352 gtk gtk-make-font-bold-italic
|
|
1353 mswindows mswindows-make-font-bold-italic
|
|
1354 msprinter mswindows-make-font-bold-italic)
|
|
1355 '(([default] . [italic])
|
|
1356 ([bold] . [bold-italic])
|
|
1357 ([italic] . [bold-italic])
|
|
1358 ([bold-italic] . t))))
|
428
|
1359
|
872
|
1360
|
|
1361 (defun make-face-unbold (face &optional locale tags exact-p)
|
428
|
1362 "Make FACE non-bold in LOCALE, if possible.
|
442
|
1363 This will attempt to make the font non-bold for X/MS Windows locales
|
|
1364 and will unset the highlight flag for TTY locales. See
|
|
1365 `make-face-bold' for the semantics of the LOCALE argument and for more
|
|
1366 specifics on exactly how this function works."
|
428
|
1367 (interactive (list (read-face-name "Make which face non-bold: ")))
|
872
|
1368 (Face-frob-property face locale tags exact-p
|
|
1369 'bold 'default 'font '(highlight)
|
|
1370 '(tty (lambda (x) nil)
|
|
1371 x x-make-font-unbold
|
|
1372 gtk gtk-make-font-unbold
|
|
1373 mswindows mswindows-make-font-unbold
|
|
1374 msprinter mswindows-make-font-unbold)
|
|
1375 '(([default] . t)
|
|
1376 ([bold] . [default])
|
|
1377 ([italic] . t)
|
|
1378 ([bold-italic] . [italic]))))
|
428
|
1379
|
872
|
1380 (defun make-face-unitalic (face &optional locale tags exact-p)
|
428
|
1381 "Make FACE non-italic in LOCALE, if possible.
|
442
|
1382 This will attempt to make the font non-italic for X/MS Windows locales
|
|
1383 and will unset the underline flag for TTY locales. See
|
|
1384 `make-face-bold' for the semantics of the LOCALE argument and for more
|
|
1385 specifics on exactly how this function works."
|
428
|
1386 (interactive (list (read-face-name "Make which face non-italic: ")))
|
872
|
1387 (Face-frob-property face locale tags exact-p
|
|
1388 'italic 'default 'font '(underline)
|
|
1389 '(tty (lambda (x) nil)
|
|
1390 x x-make-font-unitalic
|
|
1391 gtk gtk-make-font-unitalic
|
|
1392 mswindows mswindows-make-font-unitalic
|
|
1393 msprinter mswindows-make-font-unitalic)
|
|
1394 '(([default] . t)
|
|
1395 ([bold] . t)
|
|
1396 ([italic] . [default])
|
|
1397 ([bold-italic] . [bold]))))
|
428
|
1398
|
|
1399
|
707
|
1400 ;; Size frobbing
|
|
1401 ;; Thx Jan Vroonhof, Ref xemacs-beta <87oflypbum.fsf@petteflet.ntlworld.com>
|
1137
|
1402 ;; Jan had a separate helper function
|
872
|
1403 (defun make-face-size (face size &optional locale tags exact-p)
|
|
1404 "Adjust FACE to SIZE in LOCALE, if possible."
|
|
1405 (interactive (list (read-face-name "Set size of which face: ")
|
|
1406 (read-number "Size to set: " t 10)))
|
|
1407 (Face-frob-property face locale tags exact-p
|
|
1408 nil nil 'font nil
|
|
1409 `(lambda (f d)
|
|
1410 ;; keep the dependency on font.el for now
|
|
1411 (let ((fo (font-create-object f d)))
|
|
1412 (set-font-size fo ,size)
|
|
1413 (font-create-name fo d)))
|
|
1414 nil))
|
707
|
1415
|
428
|
1416 ;; Why do the following two functions lose so badly in so many
|
|
1417 ;; circumstances?
|
|
1418
|
872
|
1419 (defun make-face-smaller (face &optional locale tags exact-p)
|
428
|
1420 "Make the font of FACE be smaller, if possible.
|
|
1421 LOCALE works as in `make-face-bold' et al., but the ``inheriting-
|
|
1422 from-the-bold-face'' operations described there are not done
|
|
1423 because they don't make sense in this context."
|
|
1424 (interactive (list (read-face-name "Shrink which face: ")))
|
872
|
1425 (Face-frob-property face locale tags exact-p
|
|
1426 nil nil 'font nil
|
|
1427 '(x x-find-smaller-font
|
|
1428 gtk gtk-find-smaller-font
|
|
1429 mswindows mswindows-find-smaller-font
|
|
1430 msprinter mswindows-find-smaller-font)
|
|
1431 nil))
|
428
|
1432
|
872
|
1433 (defun make-face-larger (face &optional locale tags exact-p)
|
428
|
1434 "Make the font of FACE be larger, if possible.
|
|
1435 See `make-face-smaller' for the semantics of the LOCALE argument."
|
|
1436 (interactive (list (read-face-name "Enlarge which face: ")))
|
872
|
1437 (Face-frob-property face locale tags exact-p
|
|
1438 nil nil 'font nil
|
|
1439 '(x x-find-larger-font
|
|
1440 gtk gtk-find-larger-font
|
|
1441 mswindows mswindows-find-larger-font
|
|
1442 msprinter mswindows-find-larger-font)
|
|
1443 nil))
|
428
|
1444
|
|
1445 (defun invert-face (face &optional locale)
|
|
1446 "Swap the foreground and background colors of the face."
|
|
1447 (interactive (list (read-face-name "Invert face: ")))
|
|
1448 (if (valid-specifier-domain-p locale)
|
|
1449 (let ((foreface (face-foreground-instance face locale)))
|
|
1450 (set-face-foreground face (face-background-instance face locale)
|
|
1451 locale)
|
|
1452 (set-face-background face foreface locale))
|
|
1453 (let ((forespec (copy-specifier (face-foreground face) nil locale)))
|
|
1454 (copy-specifier (face-background face) (face-foreground face) locale)
|
|
1455 (copy-specifier forespec (face-background face) locale))))
|
|
1456
|
|
1457
|
|
1458 ;;; Convenience functions
|
|
1459
|
|
1460 (defun face-ascent (face &optional domain charset)
|
|
1461 "Return the ascent of FACE in DOMAIN.
|
|
1462 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
1463 (font-ascent (face-font face) domain charset))
|
|
1464
|
|
1465 (defun face-descent (face &optional domain charset)
|
|
1466 "Return the descent of FACE in DOMAIN.
|
|
1467 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
1468 (font-descent (face-font face) domain charset))
|
|
1469
|
|
1470 (defun face-width (face &optional domain charset)
|
|
1471 "Return the width of FACE in DOMAIN.
|
|
1472 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
1473 (font-width (face-font face) domain charset))
|
|
1474
|
|
1475 (defun face-height (face &optional domain charset)
|
|
1476 "Return the height of FACE in DOMAIN.
|
|
1477 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
1478 (+ (face-ascent face domain charset) (face-descent face domain charset)))
|
|
1479
|
|
1480 (defun face-proportional-p (face &optional domain charset)
|
|
1481 "Return t if FACE is proportional in DOMAIN.
|
|
1482 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
1483 (font-proportional-p (face-font face) domain charset))
|
|
1484
|
|
1485
|
|
1486 ;; Functions that used to be in cus-face.el, but logically go here.
|
|
1487
|
|
1488 (defcustom frame-background-mode nil
|
|
1489 "*The brightness of the background.
|
|
1490 Set this to the symbol dark if your background color is dark, light if
|
|
1491 your background is light, or nil (default) if you want Emacs to
|
|
1492 examine the brightness for you."
|
|
1493 :group 'faces
|
|
1494 :type '(choice (choice-item dark)
|
|
1495 (choice-item light)
|
|
1496 (choice-item :tag "Auto" nil)))
|
|
1497
|
|
1498 ;; The old variable that many people still have in .emacs files.
|
|
1499 (define-obsolete-variable-alias 'custom-background-mode
|
|
1500 'frame-background-mode)
|
|
1501
|
|
1502 (defun get-frame-background-mode (frame)
|
|
1503 "Detect background mode for FRAME."
|
|
1504 (let* ((color-instance (face-background-instance 'default frame))
|
|
1505 (mode (condition-case nil
|
|
1506 (if (< (apply '+ (color-instance-rgb-components
|
|
1507 color-instance)) 65536)
|
|
1508 'dark 'light)
|
872
|
1509 ;; Here, we get an error on a TTY (Return value from
|
|
1510 ;; color-instance-rgb-components is nil), and on the
|
|
1511 ;; initial stream device (Return value from
|
|
1512 ;; face-background-instance is nil). As we don't have a
|
|
1513 ;; good way of detecting whether a TTY is light or dark,
|
|
1514 ;; we'll guess it's dark.
|
428
|
1515 (error 'dark))))
|
|
1516 (set-frame-property frame 'background-mode mode)
|
|
1517 mode))
|
|
1518
|
|
1519 (defun extract-custom-frame-properties (frame)
|
|
1520 "Return a plist with the frame properties of FRAME used by custom."
|
|
1521 (list 'type (or (frame-property frame 'display-type)
|
|
1522 (device-type (frame-device frame)))
|
|
1523 'class (device-class (frame-device frame))
|
|
1524 'background (or frame-background-mode
|
|
1525 (frame-property frame 'background-mode)
|
|
1526 (get-frame-background-mode frame))))
|
|
1527
|
|
1528 (defcustom init-face-from-resources t
|
|
1529 "If non nil, attempt to initialize faces from the resource database."
|
|
1530 :group 'faces
|
|
1531 :type 'boolean)
|
|
1532
|
|
1533 ;; Old name, used by custom. Also, FSFmacs name.
|
|
1534 (defvaralias 'initialize-face-resources 'init-face-from-resources)
|
|
1535
|
|
1536 ;; Make sure all custom setting are added with this tag so we can
|
|
1537 ;; identify-them
|
|
1538 (define-specifier-tag 'custom)
|
|
1539
|
|
1540 (defun face-spec-set (face spec &optional frame tags)
|
|
1541 "Set FACE's face attributes according to the first matching entry in SPEC.
|
|
1542 If optional FRAME is non-nil, set it for that frame only.
|
|
1543 If it is nil, then apply SPEC to each frame individually.
|
|
1544 See `defface' for information about SPEC."
|
|
1545 (if frame
|
|
1546 (progn
|
|
1547 (reset-face face frame tags)
|
|
1548 (face-display-set face spec frame tags)
|
|
1549 (init-face-from-resources face frame))
|
|
1550 (let ((frames (relevant-custom-frames)))
|
|
1551 (reset-face face nil tags)
|
|
1552 ;; This should not be needed. We only remove our own specifiers
|
|
1553 ;; (if (and (eq 'default face) (featurep 'x))
|
|
1554 ;; (x-init-global-faces))
|
|
1555 (face-display-set face spec nil tags)
|
|
1556 (while frames
|
|
1557 (face-display-set face spec (car frames) tags)
|
|
1558 (pop frames))
|
|
1559 (init-face-from-resources face))))
|
|
1560
|
|
1561 (defun face-display-set (face spec &optional frame tags)
|
|
1562 "Set FACE to the attributes to the first matching entry in SPEC.
|
|
1563 Iff optional FRAME is non-nil, set it for that frame only.
|
|
1564 See `defface' for information about SPEC."
|
|
1565 (while spec
|
|
1566 (let ((display (caar spec))
|
|
1567 (atts (cadar spec)))
|
|
1568 (pop spec)
|
|
1569 (when (face-spec-set-match-display display frame)
|
|
1570 ;; Avoid creating frame local duplicates of the global face.
|
|
1571 (unless (and frame (eq display (get face 'custom-face-display)))
|
|
1572 (apply 'face-custom-attributes-set face frame tags atts))
|
|
1573 (unless frame
|
|
1574 (put face 'custom-face-display display))
|
|
1575 (setq spec nil)))))
|
|
1576
|
|
1577 (defvar default-custom-frame-properties nil
|
|
1578 "The frame properties used for the global faces.
|
442
|
1579 Frames not matching these properties should have frame local faces.
|
428
|
1580 The value should be nil, if uninitialized, or a plist otherwise.
|
|
1581 See `defface' for a list of valid keys and values for the plist.")
|
|
1582
|
|
1583 (defun get-custom-frame-properties (&optional frame)
|
|
1584 "Return a plist with the frame properties of FRAME used by custom.
|
|
1585 If FRAME is nil, return the default frame properties."
|
|
1586 (cond (frame
|
|
1587 ;; Try to get from cache.
|
|
1588 (let ((cache (frame-property frame 'custom-properties)))
|
|
1589 (unless cache
|
|
1590 ;; Oh well, get it then.
|
|
1591 (setq cache (extract-custom-frame-properties frame))
|
|
1592 ;; and cache it...
|
|
1593 (set-frame-property frame 'custom-properties cache))
|
|
1594 cache))
|
|
1595 (default-custom-frame-properties)
|
|
1596 (t
|
|
1597 (setq default-custom-frame-properties
|
|
1598 (extract-custom-frame-properties (selected-frame))))))
|
|
1599
|
|
1600 (defun face-spec-update-all-matching (spec display plist)
|
|
1601 "Update all entries in the face spec that could match display to
|
444
|
1602 have the entries from the new plist and return the new spec."
|
428
|
1603 (mapcar
|
|
1604 (lambda (e)
|
|
1605 (let ((entries (car e))
|
|
1606 (options (cadr e))
|
|
1607 (match t)
|
|
1608 dplist
|
|
1609 (new-options plist)
|
|
1610 )
|
|
1611 (unless (eq display t)
|
|
1612 (mapc (lambda (arg)
|
|
1613 (setq dplist (plist-put dplist (car arg) (cadr arg))))
|
|
1614 display))
|
|
1615 (unless (eq entries t)
|
|
1616 (mapc (lambda (arg)
|
|
1617 (setq match (and match (eq (cadr arg)
|
|
1618 (plist-get
|
|
1619 dplist (car arg)
|
|
1620 (cadr arg))))))
|
|
1621 entries))
|
|
1622 (if (not match)
|
|
1623 e
|
|
1624 (while new-options
|
|
1625 (setq options
|
|
1626 (plist-put options (car new-options) (cadr new-options)))
|
|
1627 (setq new-options (cddr new-options)))
|
|
1628 (list entries options))))
|
|
1629 (copy-sequence spec)))
|
444
|
1630
|
|
1631
|
428
|
1632
|
|
1633 (defun face-spec-set-match-display (display &optional frame)
|
|
1634 "Return non-nil if DISPLAY matches FRAME.
|
|
1635 DISPLAY is part of a spec such as can be used in `defface'.
|
|
1636 If FRAME is nil or omitted, the selected frame is used."
|
|
1637 (if (eq display t)
|
|
1638 t
|
|
1639 (let* ((props (get-custom-frame-properties frame))
|
|
1640 (type (plist-get props 'type))
|
|
1641 (class (plist-get props 'class))
|
|
1642 (background (plist-get props 'background))
|
|
1643 (match t)
|
|
1644 (entries display)
|
|
1645 entry req options)
|
|
1646 (while (and entries match)
|
|
1647 (setq entry (car entries)
|
|
1648 entries (cdr entries)
|
|
1649 req (car entry)
|
|
1650 options (cdr entry)
|
|
1651 match (case req
|
|
1652 (type (memq type options))
|
|
1653 (class (memq class options))
|
|
1654 (background (memq background options))
|
|
1655 (t (warn "Unknown req `%S' with options `%S'"
|
|
1656 req options)
|
|
1657 nil))))
|
|
1658 match)))
|
|
1659
|
|
1660 (defun relevant-custom-frames ()
|
|
1661 "List of frames whose custom properties differ from the default."
|
|
1662 (let ((relevant nil)
|
|
1663 (default (get-custom-frame-properties))
|
|
1664 (frames (frame-list))
|
|
1665 frame)
|
|
1666 (while frames
|
|
1667 (setq frame (car frames)
|
|
1668 frames (cdr frames))
|
|
1669 (unless (equal default (get-custom-frame-properties frame))
|
|
1670 (push frame relevant)))
|
|
1671 relevant))
|
|
1672
|
|
1673 (defun initialize-custom-faces (&optional frame)
|
|
1674 "Initialize all custom faces for FRAME.
|
|
1675 If FRAME is nil or omitted, initialize them for all frames."
|
|
1676 (mapc (lambda (symbol)
|
|
1677 (let ((spec (or (get symbol 'saved-face)
|
|
1678 (get symbol 'face-defface-spec))))
|
|
1679 (when spec
|
|
1680 ;; No need to init-face-from-resources -- code in
|
|
1681 ;; `init-frame-faces' does it already.
|
|
1682 (face-display-set symbol spec frame))))
|
|
1683 (face-list)))
|
|
1684
|
|
1685 (defun custom-initialize-frame (frame)
|
|
1686 "Initialize frame-local custom faces for FRAME if necessary."
|
|
1687 (unless (equal (get-custom-frame-properties)
|
|
1688 (get-custom-frame-properties frame))
|
|
1689 (initialize-custom-faces frame)))
|
|
1690
|
440
|
1691 (defun startup-initialize-custom-faces ()
|
|
1692 "Reset faces created by defface. Only called at startup.
|
|
1693 Don't use this function in your program."
|
|
1694 (when default-custom-frame-properties
|
|
1695 ;; Reset default value to the actual frame, not stream.
|
|
1696 (setq default-custom-frame-properties
|
|
1697 (extract-custom-frame-properties (selected-frame)))
|
|
1698 ;; like initialize-custom-faces but removes property first.
|
|
1699 (mapc (lambda (symbol)
|
|
1700 (let ((spec (or (get symbol 'saved-face)
|
|
1701 (get symbol 'face-defface-spec))))
|
|
1702 (when spec
|
|
1703 ;; Reset faces created during auto-autoloads loading.
|
|
1704 (reset-face symbol)
|
|
1705 ;; And set it according to the spec.
|
|
1706 (face-display-set symbol spec nil))))
|
|
1707 (face-list))))
|
|
1708
|
428
|
1709
|
|
1710 (defun make-empty-face (name &optional doc-string temporary)
|
|
1711 "Like `make-face', but doesn't query the resource database."
|
|
1712 (let ((init-face-from-resources nil))
|
|
1713 (make-face name doc-string temporary)))
|
|
1714
|
|
1715 (defun init-face-from-resources (face &optional locale)
|
|
1716 "Initialize FACE from the resource database.
|
3027
|
1717 If LOCALE is specified, it should be a frame, device, or `global', and
|
428
|
1718 the face will be resourced over that locale. Otherwise, the face will
|
|
1719 be resourced over all possible locales (i.e. all frames, all devices,
|
3027
|
1720 and `global')."
|
428
|
1721 (cond ((null init-face-from-resources)
|
|
1722 ;; Do nothing.
|
|
1723 )
|
|
1724 ((not locale)
|
|
1725 ;; Global, set for all frames.
|
|
1726 (progn
|
|
1727 (init-face-from-resources face 'global)
|
|
1728 (let ((devices (device-list)))
|
|
1729 (while devices
|
|
1730 (init-face-from-resources face (car devices))
|
|
1731 (setq devices (cdr devices))))
|
|
1732 (let ((frames (frame-list)))
|
|
1733 (while frames
|
|
1734 (init-face-from-resources face (car frames))
|
|
1735 (setq frames (cdr frames))))))
|
|
1736 (t
|
|
1737 ;; Specific.
|
|
1738 (let ((devtype (cond ((devicep locale) (device-type locale))
|
|
1739 ((framep locale) (frame-type locale))
|
|
1740 (t nil))))
|
|
1741 (cond ((or (and (not devtype) (featurep 'x)) (eq 'x devtype))
|
502
|
1742 (declare-fboundp (x-init-face-from-resources face locale)))
|
428
|
1743 ((or (not devtype) (eq 'tty devtype))
|
|
1744 ;; Nothing to do for TTYs?
|
|
1745 ))))))
|
|
1746
|
|
1747 (defun init-device-faces (device)
|
|
1748 ;; First, add any device-local face resources.
|
|
1749 (when init-face-from-resources
|
|
1750 (loop for face in (face-list) do
|
|
1751 (init-face-from-resources face device))
|
|
1752 ;; Then do any device-specific initialization.
|
|
1753 (cond ((eq 'x (device-type device))
|
502
|
1754 (declare-fboundp (x-init-device-faces device)))
|
462
|
1755 ((eq 'gtk (device-type device))
|
502
|
1756 (declare-fboundp (gtk-init-device-faces device)))
|
428
|
1757 ((eq 'mswindows (device-type device))
|
502
|
1758 (declare-fboundp (mswindows-init-device-faces device)))
|
428
|
1759 ;; Nothing to do for TTYs?
|
|
1760 )
|
|
1761 (or (eq 'stream (device-type device))
|
|
1762 (init-other-random-faces device))))
|
|
1763
|
|
1764 (defun init-frame-faces (frame)
|
|
1765 (when init-face-from-resources
|
|
1766 ;; First, add any frame-local face resources.
|
|
1767 (loop for face in (face-list) do
|
|
1768 (init-face-from-resources face frame))
|
|
1769 ;; Then do any frame-specific initialization.
|
|
1770 (cond ((eq 'x (frame-type frame))
|
502
|
1771 (declare-fboundp (x-init-frame-faces frame)))
|
462
|
1772 ((eq 'gtk (frame-type frame))
|
502
|
1773 (declare-fboundp (gtk-init-frame-faces frame)))
|
428
|
1774 ((eq 'mswindows (frame-type frame))
|
502
|
1775 (declare-fboundp (mswindows-init-frame-faces frame)))
|
428
|
1776 ;; Is there anything which should be done for TTY's?
|
|
1777 )))
|
|
1778
|
872
|
1779 ;; Called when the first device created.
|
428
|
1780
|
872
|
1781 (defun init-global-faces (device)
|
|
1782 (let ((Face-frob-property-device-considered-current device))
|
|
1783 ;; Look for global face resources.
|
|
1784 (loop for face in (face-list) do
|
|
1785 (init-face-from-resources face 'global))
|
|
1786 ;; Further frobbing.
|
|
1787 (and (featurep 'x) (declare-fboundp (x-init-global-faces)))
|
|
1788 (and (featurep 'gtk) (declare-fboundp (gtk-init-global-faces)))
|
|
1789 (and (featurep 'mswindows) (declare-fboundp (mswindows-init-global-faces)))
|
462
|
1790
|
872
|
1791 ;; for bold and the like, make the global specification be bold etc.
|
|
1792 ;; if the user didn't already specify a value. These will also be
|
|
1793 ;; frobbed further in init-other-random-faces.
|
|
1794 (unless (face-font 'bold 'global)
|
|
1795 (make-face-bold 'bold 'global))
|
|
1796 ;;
|
|
1797 (unless (face-font 'italic 'global)
|
|
1798 (make-face-italic 'italic 'global))
|
|
1799 ;;
|
428
|
1800 (unless (face-font 'bold-italic 'global)
|
872
|
1801 (make-face-bold-italic 'bold-italic 'global)
|
|
1802 (unless (face-font 'bold-italic 'global)
|
|
1803 (copy-face 'bold 'bold-italic)
|
|
1804 (make-face-italic 'bold-italic)))
|
428
|
1805
|
872
|
1806 (when (face-equal 'bold 'bold-italic device)
|
|
1807 (copy-face 'italic 'bold-italic)
|
|
1808 (make-face-bold 'bold-italic))))
|
428
|
1809
|
|
1810
|
|
1811 ;; These warnings are there for a reason. Just specify your fonts
|
|
1812 ;; correctly. Deal with it. Additionally, one can use
|
|
1813 ;; `log-warning-minimum-level' instead of this.
|
|
1814 ;(defvar inhibit-font-complaints nil
|
|
1815 ; "Whether to suppress complaints about incomplete sets of fonts.")
|
|
1816
|
|
1817 (defun face-complain-about-font (face device)
|
|
1818 (if (symbolp face) (setq face (symbol-name face)))
|
|
1819 ;; (if (not inhibit-font-complaints)
|
707
|
1820 ;; complaining for printers is generally annoying.
|
|
1821 (unless (device-printer-p device)
|
|
1822 (display-warning
|
|
1823 'font
|
|
1824 (let ((default-name (face-font-name 'default device)))
|
|
1825 (format "%s: couldn't deduce %s %s version of the font
|
428
|
1826 %S.
|
|
1827
|
|
1828 Please specify X resources to make the %s face
|
|
1829 visually distinguishable from the default face.
|
|
1830 For example, you could add one of the following to $HOME/Emacs:
|
|
1831
|
2703
|
1832 XEmacs.%s.attributeFont: -dt-*-medium-i-*
|
428
|
1833 or
|
2703
|
1834 XEmacs.%s.attributeForeground: hotpink\n"
|
707
|
1835 invocation-name
|
|
1836 (if (string-match "\\`[aeiouAEIOU]" face) "an" "a")
|
|
1837 face
|
|
1838 default-name
|
|
1839 face
|
|
1840 face
|
|
1841 face
|
|
1842 )))))
|
428
|
1843
|
|
1844
|
|
1845 ;; #### This is quite a mess. We should use the custom mechanism for
|
|
1846 ;; most of this stuff. Currently we don't do it, because Custom
|
|
1847 ;; doesn't use specifiers (yet.) FSF does it the Right Way.
|
|
1848
|
|
1849 ;; For instance, the definition of `bold' should be something like
|
|
1850 ;; (defface bold ((t (:bold t))) "Bold text.") -- and `:bold t' should
|
|
1851 ;; make sure that everything works properly.
|
|
1852
|
|
1853 (defun init-other-random-faces (device)
|
|
1854 "Initialize the colors and fonts of the bold, italic, bold-italic,
|
|
1855 zmacs-region, list-mode-item-selected, highlight, primary-selection,
|
|
1856 secondary-selection, and isearch faces when each device is created. If
|
|
1857 you want to add code to do stuff like this, use the create-device-hook."
|
|
1858
|
|
1859 ;; try to make 'bold look different from the default on this device.
|
|
1860 ;; If that doesn't work at all, then issue a warning.
|
|
1861 (unless (face-differs-from-default-p 'bold device)
|
|
1862 (make-face-bold 'bold device)
|
|
1863 (unless (face-differs-from-default-p 'bold device)
|
|
1864 (make-face-unbold 'bold device)
|
|
1865 (unless (face-differs-from-default-p 'bold device)
|
|
1866 ;; the luser specified one of the bogus font names
|
|
1867 (face-complain-about-font 'bold device))))
|
|
1868
|
|
1869 ;; Similar for italic.
|
|
1870 ;; It's unreasonable to expect to be able to make a font italic all
|
|
1871 ;; the time. For many languages, italic is an alien concept.
|
|
1872 ;; Basically, because italic is not a globally meaningful concept,
|
440
|
1873 ;; the use of the italic face should really be obsoleted.
|
428
|
1874
|
|
1875 ;; I disagree with above. In many languages, the concept of capital
|
|
1876 ;; letters is just as alien, and yet we use them. Italic is here to
|
|
1877 ;; stay. -hniksic
|
|
1878
|
|
1879 ;; In a Solaris Japanese environment, there just aren't any italic
|
|
1880 ;; fonts - period. CDE recognizes this reality, and fonts
|
|
1881 ;; -dt-interface user-medium-r-normal-*-*-*-*-*-*-*-*-* don't come
|
|
1882 ;; in italic versions. So we first try to make the font bold before
|
|
1883 ;; complaining.
|
|
1884 (unless (face-differs-from-default-p 'italic device)
|
|
1885 (make-face-italic 'italic device)
|
|
1886 (unless (face-differs-from-default-p 'italic device)
|
|
1887 (make-face-bold 'italic device)
|
|
1888 (unless (face-differs-from-default-p 'italic device)
|
|
1889 (face-complain-about-font 'italic device))))
|
|
1890
|
|
1891 ;; similar for bold-italic.
|
|
1892 (unless (face-differs-from-default-p 'bold-italic device)
|
|
1893 (make-face-bold-italic 'bold-italic device)
|
|
1894 ;; if we couldn't get a bold-italic version, try just bold.
|
|
1895 (unless (face-differs-from-default-p 'bold-italic device)
|
|
1896 (make-face-bold 'bold-italic device)
|
|
1897 ;; if we couldn't get bold or bold-italic, then that's probably because
|
|
1898 ;; the default font is bold, so make the `bold-italic' face be unbold.
|
|
1899 (unless (face-differs-from-default-p 'bold-italic device)
|
|
1900 (make-face-unbold 'bold-italic device)
|
|
1901 (make-face-italic 'bold-italic device)
|
|
1902 (unless (face-differs-from-default-p 'bold-italic device)
|
|
1903 ;; if that didn't work, try plain italic
|
|
1904 ;; (can this ever happen? what the hell.)
|
|
1905 (make-face-italic 'bold-italic device)
|
|
1906 (unless (face-differs-from-default-p 'bold-italic device)
|
|
1907 ;; then bitch and moan.
|
|
1908 (face-complain-about-font 'bold-italic device))))))
|
|
1909
|
|
1910 ;; Set the text-cursor colors unless already specified.
|
|
1911 (when (and (not (eq 'tty (device-type device)))
|
|
1912 (not (face-background 'text-cursor 'global))
|
|
1913 (face-property-equal 'text-cursor 'default 'background device))
|
|
1914 (set-face-background 'text-cursor [default foreground] 'global
|
|
1915 nil 'append))
|
|
1916 (when (and (not (eq 'tty (device-type device)))
|
|
1917 (not (face-foreground 'text-cursor 'global))
|
|
1918 (face-property-equal 'text-cursor 'default 'foreground device))
|
|
1919 (set-face-foreground 'text-cursor [default background] 'global
|
|
1920 nil 'append))
|
|
1921 )
|
|
1922
|
442
|
1923 ;; New function with 20.1, suggested by Per Abrahamsen, coded by Kyle
|
|
1924 ;; Jones and Hrvoje Niksic.
|
428
|
1925 (defun set-face-stipple (face pixmap &optional frame)
|
|
1926 "Change the stipple pixmap of FACE to PIXMAP.
|
|
1927 This is an Emacs compatibility function; consider using
|
|
1928 set-face-background-pixmap instead.
|
|
1929
|
|
1930 PIXMAP should be a string, the name of a file of pixmap data.
|
442
|
1931 The directories listed in the variables `x-bitmap-file-path' and
|
|
1932 `mswindows-bitmap-file-path' under X and MS Windows respectively
|
|
1933 are searched.
|
428
|
1934
|
|
1935 Alternatively, PIXMAP may be a list of the form (WIDTH HEIGHT
|
|
1936 DATA) where WIDTH and HEIGHT are the size in pixels, and DATA is
|
|
1937 a string, containing the raw bits of the bitmap. XBM data is
|
|
1938 expected in this case, other types of image data will not work.
|
|
1939
|
|
1940 If the optional FRAME argument is provided, change only
|
|
1941 in that frame; otherwise change each frame."
|
|
1942 (while (not (find-face face))
|
446
|
1943 (setq face (wrong-type-argument 'facep face)))
|
502
|
1944 (let ((bitmap-path
|
|
1945 (ecase (console-type)
|
|
1946 (x (declare-boundp x-bitmap-file-path))
|
|
1947 (mswindows (declare-boundp mswindows-bitmap-file-path))))
|
442
|
1948 instantiator)
|
|
1949 (while
|
|
1950 (null
|
|
1951 (setq instantiator
|
|
1952 (cond ((stringp pixmap)
|
|
1953 (let ((file (if (file-name-absolute-p pixmap)
|
|
1954 pixmap
|
|
1955 (locate-file pixmap bitmap-path
|
|
1956 '(".xbm" "")))))
|
|
1957 (and file
|
|
1958 `[xbm :file ,file])))
|
|
1959 ((and (listp pixmap) (= (length pixmap) 3))
|
|
1960 `[xbm :data ,pixmap])
|
|
1961 (t nil))))
|
|
1962 ;; We're signaling a continuable error; let's make sure the
|
|
1963 ;; function `stipple-pixmap-p' at least exists.
|
|
1964 (flet ((stipple-pixmap-p (pixmap)
|
|
1965 (or (stringp pixmap)
|
|
1966 (and (listp pixmap) (= (length pixmap) 3)))))
|
|
1967 (setq pixmap (signal 'wrong-type-argument
|
|
1968 (list 'stipple-pixmap-p pixmap)))))
|
446
|
1969 (check-type frame (or null frame))
|
442
|
1970 (set-face-background-pixmap face instantiator frame)))
|
428
|
1971
|
|
1972
|
|
1973 ;; Create the remaining standard faces now. This way, packages that we dump
|
|
1974 ;; can reference these faces as parents.
|
|
1975 ;;
|
|
1976 ;; The default, modeline, left-margin, right-margin, text-cursor,
|
|
1977 ;; and pointer faces are created in C.
|
|
1978
|
|
1979 (make-face 'bold "Bold text.")
|
|
1980 (make-face 'italic "Italic text.")
|
|
1981 (make-face 'bold-italic "Bold-italic text.")
|
|
1982 (make-face 'underline "Underlined text.")
|
|
1983 (or (face-differs-from-default-p 'underline)
|
|
1984 (set-face-underline-p 'underline t 'global '(default)))
|
735
|
1985 (make-face 'zmacs-region "Used on highlighted region between point and mark.")
|
428
|
1986 (make-face 'isearch "Used on region matched by isearch.")
|
|
1987 (make-face 'isearch-secondary "Face to use for highlighting all matches.")
|
|
1988 (make-face 'list-mode-item-selected
|
|
1989 "Face for the selected list item in list-mode.")
|
|
1990 (make-face 'highlight "Highlight face.")
|
|
1991 (make-face 'primary-selection "Primary selection face.")
|
|
1992 (make-face 'secondary-selection "Secondary selection face.")
|
|
1993
|
|
1994 ;; Several useful color faces.
|
|
1995 (dolist (color '(red green blue yellow))
|
|
1996 (make-face color (concat (symbol-name color) " text."))
|
|
1997 (set-face-foreground color (symbol-name color) nil 'color))
|
|
1998
|
|
1999 ;; Make some useful faces. This happens very early, before creating
|
|
2000 ;; the first non-stream device.
|
|
2001
|
|
2002 (set-face-background 'text-cursor
|
711
|
2003 '(((win default) . "Red3"))
|
428
|
2004 'global)
|
|
2005
|
|
2006 ;; some older X servers don't recognize "darkseagreen2"
|
|
2007 (set-face-background 'highlight
|
711
|
2008 '(((win default color) . "darkseagreen2")
|
|
2009 ((win default color) . "green")
|
|
2010 ((win default grayscale) . "gray53"))
|
428
|
2011 'global)
|
|
2012 (set-face-background-pixmap 'highlight
|
711
|
2013 '(((win default mono) . "gray1"))
|
428
|
2014 'global)
|
|
2015
|
|
2016 (set-face-background 'zmacs-region
|
711
|
2017 '(((win default color) . "gray65")
|
|
2018 ((win default grayscale) . "gray65"))
|
428
|
2019 'global)
|
|
2020 (set-face-background-pixmap 'zmacs-region
|
711
|
2021 '(((win default mono) . "gray3"))
|
428
|
2022 'global)
|
|
2023
|
|
2024 (set-face-background 'list-mode-item-selected
|
711
|
2025 '(((win default color) . "gray68")
|
|
2026 ((win default grayscale) . "gray68")
|
|
2027 ((win default mono) . [default foreground]))
|
428
|
2028 'global)
|
|
2029 (set-face-foreground 'list-mode-item-selected
|
711
|
2030 '(((win default mono) . [default background]))
|
428
|
2031 'global)
|
|
2032
|
|
2033 (set-face-background 'primary-selection
|
711
|
2034 '(((win default color) . "gray65")
|
|
2035 ((win default grayscale) . "gray65"))
|
428
|
2036 'global)
|
|
2037 (set-face-background-pixmap 'primary-selection
|
711
|
2038 '(((win default mono) . "gray3"))
|
428
|
2039 'global)
|
|
2040
|
|
2041 (set-face-background 'secondary-selection
|
711
|
2042 '(((win default color) . "paleturquoise")
|
|
2043 ((win default color) . "green")
|
|
2044 ((win default grayscale) . "gray53"))
|
428
|
2045 'global)
|
|
2046 (set-face-background-pixmap 'secondary-selection
|
711
|
2047 '(((win default mono) . "gray1"))
|
428
|
2048 'global)
|
|
2049
|
|
2050 (set-face-background 'isearch
|
711
|
2051 '(((win default color) . "paleturquoise")
|
|
2052 ((win default color) . "green"))
|
428
|
2053 'global)
|
|
2054
|
|
2055 ;; #### This should really, I mean *really*, be converted to some form
|
|
2056 ;; of `defface' one day.
|
|
2057 (set-face-foreground 'isearch-secondary
|
711
|
2058 '(((win default color) . "red3"))
|
428
|
2059 'global)
|
|
2060
|
|
2061 ;; Define some logical color names to be used when reading the pixmap files.
|
|
2062 (if (featurep 'xpm)
|
|
2063 (setq xpm-color-symbols
|
|
2064 (list
|
444
|
2065 '("foreground" (face-foreground 'default))
|
|
2066 '("background" (face-background 'default))
|
|
2067 '("backgroundToolBarColor"
|
|
2068 (or
|
|
2069 (and
|
|
2070 (featurep 'x)
|
|
2071 (x-get-resource "backgroundToolBarColor"
|
|
2072 "BackgroundToolBarColor" 'string
|
|
2073 nil nil 'warn))
|
428
|
2074
|
444
|
2075 (face-background 'toolbar)))
|
|
2076 '("foregroundToolBarColor"
|
|
2077 (or
|
|
2078 (and
|
|
2079 (featurep 'x)
|
|
2080 (x-get-resource "foregroundToolBarColor"
|
|
2081 "ForegroundToolBarColor" 'string
|
|
2082 nil nil 'warn))
|
|
2083 (face-foreground 'toolbar)))
|
428
|
2084 )))
|
|
2085
|
|
2086 (when (featurep 'tty)
|
|
2087 (set-face-highlight-p 'bold t 'global '(default tty))
|
|
2088 (set-face-underline-p 'italic t 'global '(default tty))
|
|
2089 (set-face-highlight-p 'bold-italic t 'global '(default tty))
|
|
2090 (set-face-underline-p 'bold-italic t 'global '(default tty))
|
|
2091 (set-face-highlight-p 'highlight t 'global '(default tty))
|
|
2092 (set-face-reverse-p 'text-cursor t 'global '(default tty))
|
|
2093 (set-face-reverse-p 'modeline t 'global '(default tty))
|
|
2094 (set-face-reverse-p 'zmacs-region t 'global '(default tty))
|
|
2095 (set-face-reverse-p 'primary-selection t 'global '(default tty))
|
|
2096 (set-face-underline-p 'secondary-selection t 'global '(default tty))
|
|
2097 (set-face-reverse-p 'list-mode-item-selected t 'global '(default tty))
|
|
2098 (set-face-reverse-p 'isearch t 'global '(default tty))
|
|
2099 )
|
|
2100
|
|
2101 ;;; faces.el ends here
|