Commit | Line | Data |
---|---|---|
5f5c8ee5 | 1 | ;;; faces.el --- Lisp faces |
465fceed | 2 | |
0d30b337 | 3 | ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, |
409cc4a3 | 4 | ;; 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
465fceed | 5 | |
6228c05b | 6 | ;; Maintainer: FSF |
30764597 | 7 | ;; Keywords: internal |
6228c05b | 8 | |
465fceed ER |
9 | ;; This file is part of GNU Emacs. |
10 | ||
11 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
b4aa6026 | 13 | ;; the Free Software Foundation; either version 3, or (at your option) |
465fceed ER |
14 | ;; any later version. |
15 | ||
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
b578f267 | 22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
086add15 LK |
23 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 | ;; Boston, MA 02110-1301, USA. | |
465fceed ER |
25 | |
26 | ;;; Commentary: | |
27 | ||
465fceed ER |
28 | ;;; Code: |
29 | ||
39b3b754 | 30 | (eval-when-compile |
f31b1257 DN |
31 | (require 'cl)) |
32 | ||
33 | (declare-function xw-defined-colors "term/x-win" (&optional frame)) | |
5f5c8ee5 | 34 | |
b782a458 | 35 | (defvar help-xref-stack-item) |
5f5c8ee5 GM |
36 | \f |
37 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
38 | ;;; Font selection. | |
39 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
40 | ||
41 | (defgroup font-selection nil | |
42 | "Influencing face font selection." | |
43 | :group 'faces) | |
44 | ||
45 | ||
46 | (defcustom face-font-selection-order | |
47 | '(:width :height :weight :slant) | |
48 | "*A list specifying how face font selection chooses fonts. | |
49 | Each of the four symbols `:width', `:height', `:weight', and `:slant' | |
50 | must appear once in the list, and the list must not contain any other | |
7c626e9d | 51 | elements. Font selection first tries to find a best matching font |
b73f65b6 | 52 | for those face attributes that appear before in the list. For |
5f5c8ee5 GM |
53 | example, if `:slant' appears before `:height', font selection first |
54 | tries to find a font with a suitable slant, even if this results in | |
55 | a font height that isn't optimal." | |
239ad97f | 56 | :tag "Font selection order" |
94354bdd | 57 | :type '(list symbol symbol symbol symbol) |
5f5c8ee5 GM |
58 | :group 'font-selection |
59 | :set #'(lambda (symbol value) | |
60 | (set-default symbol value) | |
61 | (internal-set-font-selection-order value))) | |
62 | ||
18f1dcb4 GM |
63 | |
64 | ;; This is defined originally in xfaces.c. | |
5f5c8ee5 GM |
65 | (defcustom face-font-family-alternatives |
66 | '(("courier" "fixed") | |
3855860a | 67 | ("helv" "helvetica" "arial" "fixed")) |
5f5c8ee5 | 68 | "*Alist of alternative font family names. |
86886bce | 69 | Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...). |
5f5c8ee5 GM |
70 | If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then |
71 | ALTERNATIVE2 etc." | |
239ad97f | 72 | :tag "Alternative font families to try" |
94354bdd | 73 | :type '(repeat (repeat string)) |
5f5c8ee5 GM |
74 | :group 'font-selection |
75 | :set #'(lambda (symbol value) | |
76 | (set-default symbol value) | |
77 | (internal-set-alternative-font-family-alist value))) | |
78 | ||
79 | ||
18f1dcb4 GM |
80 | ;; This is defined originally in xfaces.c. |
81 | (defcustom face-font-registry-alternatives | |
c97db4e4 | 82 | (if (eq system-type 'windows-nt) |
990d68dd | 83 | '(("iso8859-1" "ms-oemlatin") |
e38c812e | 84 | ("gb2312.1980" "gb2312" "gbk" "gb18030") |
c97db4e4 AI |
85 | ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978") |
86 | ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987") | |
87 | ("muletibetan-2" "muletibetan-0")) | |
e38c812e | 88 | '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk" "gb18030") |
c97db4e4 AI |
89 | ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978") |
90 | ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987") | |
91 | ("muletibetan-2" "muletibetan-0"))) | |
18f1dcb4 | 92 | "*Alist of alternative font registry names. |
86886bce | 93 | Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...). |
8ac2d32f KH |
94 | If fonts of registry REGISTRY can be loaded, font selection |
95 | tries to find a best matching font among all fonts of registry | |
96 | REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc." | |
239ad97f | 97 | :tag "Alternative font registries to try" |
18f1dcb4 | 98 | :type '(repeat (repeat string)) |
f676894c | 99 | :version "21.1" |
18f1dcb4 GM |
100 | :group 'font-selection |
101 | :set #'(lambda (symbol value) | |
102 | (set-default symbol value) | |
103 | (internal-set-alternative-font-registry-alist value))) | |
104 | ||
105 | ||
35acfcc3 | 106 | (defcustom font-weight-table |
b0f7845d JR |
107 | (if (eq system-type 'windows-nt) |
108 | '((thin . 100) | |
9c7f8459 | 109 | (ultralight . 199) (ultra-light . 200) (extra-light . 201) |
b0f7845d | 110 | (light . 300) |
986845af | 111 | (semilight . 330) (semi-light . 331) |
b0f7845d | 112 | (book . 350) |
9c7f8459 | 113 | (normal . 400) (regular . 401) |
986845af | 114 | (medium . 500) |
9c7f8459 | 115 | (semibold . 599) (semi-bold . 600) (demibold . 601) (demi . 602) |
b0f7845d | 116 | (bold . 700) |
9c7f8459 SM |
117 | (extrabold . 799) (extra-bold . 800) |
118 | (ultrabold . 801) (ultra-bold . 802) | |
119 | (black . 900) (heavy . 901)) | |
b0f7845d | 120 | '((thin . 0) |
9c7f8459 | 121 | (ultralight . 39) (ultra-light . 40) (extra-light . 41) |
b0f7845d | 122 | (light . 50) |
9c7f8459 | 123 | (semilight . 65) (semi-light . 66) |
b0f7845d | 124 | (book . 75) |
9c7f8459 SM |
125 | (medium . 99) (regular . 100) (normal . 101) |
126 | (semibold . 179) (semi-bold . 180) (demibold . 181) (demi . 182) | |
b0f7845d | 127 | (bold . 200) |
9c7f8459 SM |
128 | (extrabold . 204) (extra-bold . 205) |
129 | (ultrabold . 206) (ultra-bold . 207) | |
130 | (black . 210) (heavy . 211))) | |
35acfcc3 KH |
131 | "*Alist of font weight symbols vs the corresponding numeric values." |
132 | :tag "Font weight table" | |
133 | :version "23.1" | |
134 | :group 'font-selection | |
135 | :type '(repeat (cons symbol integer)) | |
136 | :set #'(lambda (symbol value) | |
137 | (set-default symbol value) | |
138 | (if (fboundp 'internal-set-font-style-table) | |
139 | (internal-set-font-style-table :weight value)))) | |
140 | ||
141 | (defcustom font-slant-table | |
142 | '((ro . 0) | |
143 | (ri . 10) | |
36c8e4a6 | 144 | (r . 98) (roman . 99) (normal . 100) |
9c7f8459 SM |
145 | (i . 199) (italic . 200) (ot . 201) |
146 | (o . 210) (oblique . 211)) | |
35acfcc3 KH |
147 | "*Alist of font slant symbols vs the corresponding numeric values." |
148 | :tag "Font slant table" | |
149 | :version "23.1" | |
150 | :group 'font-selection | |
151 | :type '(repeat (cons symbol integer)) | |
152 | :set #'(lambda (symbol value) | |
153 | (set-default symbol value) | |
154 | (if (fboundp 'internal-set-font-style-table) | |
155 | (internal-set-font-style-table :slant value)))) | |
156 | ||
157 | (defcustom font-swidth-table | |
9c7f8459 SM |
158 | '((ultracondensed . 50) (ultra-condensed . 51) |
159 | (extracondensed . 63) (extra-condensed . 64) | |
160 | (narrow . 74) (compressed . 75) (condensed . 76) | |
161 | (semi-condensed . 87) (semicondensed . 88) | |
162 | (medium . 99) (normal . 100) (regular . 101) | |
163 | (semiexpanded . 112) (semi-expanded . 113) (demiexpanded . 114) | |
35acfcc3 | 164 | (expanded . 125) |
9c7f8459 SM |
165 | (extraexpanded . 150) (extra-expanded . 151) |
166 | (ultraexpanded . 199) (ultra-expanded . 200) (wide . 201)) | |
35acfcc3 KH |
167 | "*Alist of font swidth symbols vs the corresponding numeric values." |
168 | :tag "Font swidth table" | |
169 | :version "23.1" | |
170 | :group 'font-selection | |
171 | :type '(repeat (cons symbol integer)) | |
172 | :set #'(lambda (symbol value) | |
173 | (set-default symbol value) | |
174 | (if (fboundp 'internal-set-font-style-table) | |
175 | (internal-set-font-style-table :width value)))) | |
bdda3754 | 176 | \f |
5f5c8ee5 GM |
177 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
178 | ;;; Creation, copying. | |
179 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
180 | ||
181 | ||
182 | (defun face-list () | |
183 | "Return a list of all defined face names." | |
184 | (mapcar #'car face-new-frame-defaults)) | |
185 | ||
186 | ||
187 | ;;; ### If not frame-local initialize by what X resources? | |
188 | ||
189 | (defun make-face (face &optional no-init-from-resources) | |
190 | "Define a new face with name FACE, a symbol. | |
191 | NO-INIT-FROM-RESOURCES non-nil means don't initialize frame-local | |
192 | variants of FACE from X resources. (X resources recognized are found | |
193 | in the global variable `face-x-resources'.) If FACE is already known | |
194 | as a face, leave it unmodified. Value is FACE." | |
195 | (interactive "SMake face: ") | |
196 | (unless (facep face) | |
197 | ;; Make frame-local faces (this also makes the global one). | |
198 | (dolist (frame (frame-list)) | |
199 | (internal-make-lisp-face face frame)) | |
200 | ;; Add the face to the face menu. | |
201 | (when (fboundp 'facemenu-add-new-face) | |
202 | (facemenu-add-new-face face)) | |
203 | ;; Define frame-local faces for all frames from X resources. | |
204 | (unless no-init-from-resources | |
205 | (make-face-x-resource-internal face))) | |
206 | face) | |
207 | ||
208 | ||
209 | (defun make-empty-face (face) | |
210 | "Define a new, empty face with name FACE. | |
211 | If the face already exists, it is left unmodified. Value is FACE." | |
212 | (interactive "SMake empty face: ") | |
213 | (make-face face 'no-init-from-resources)) | |
214 | ||
215 | ||
216 | (defun copy-face (old-face new-face &optional frame new-frame) | |
217 | "Define a face just like OLD-FACE, with name NEW-FACE. | |
218 | ||
219 | If NEW-FACE already exists as a face, it is modified to be like | |
220 | OLD-FACE. If it doesn't already exist, it is created. | |
221 | ||
1c521fb0 | 222 | If the optional argument FRAME is given as a frame, NEW-FACE is |
5f5c8ee5 GM |
223 | changed on FRAME only. |
224 | If FRAME is t, the frame-independent default specification for OLD-FACE | |
225 | is copied to NEW-FACE. | |
226 | If FRAME is nil, copying is done for the frame-independent defaults | |
227 | and for each existing frame. | |
228 | ||
229 | If the optional fourth argument NEW-FRAME is given, | |
230 | copy the information from face OLD-FACE on frame FRAME | |
341a1bfb | 231 | to NEW-FACE on frame NEW-FRAME. In this case, FRAME may not be nil." |
5f5c8ee5 GM |
232 | (let ((inhibit-quit t)) |
233 | (if (null frame) | |
234 | (progn | |
341a1bfb RS |
235 | (when new-frame |
236 | (error "Copying face %s from all frames to one frame" | |
237 | old-face)) | |
238 | (make-empty-face new-face) | |
5f5c8ee5 GM |
239 | (dolist (frame (frame-list)) |
240 | (copy-face old-face new-face frame)) | |
241 | (copy-face old-face new-face t)) | |
341a1bfb | 242 | (make-empty-face new-face) |
5f5c8ee5 GM |
243 | (internal-copy-lisp-face old-face new-face frame new-frame)) |
244 | new-face)) | |
245 | ||
246 | ||
247 | \f | |
248 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
249 | ;;; Obsolete functions | |
250 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
251 | ||
252 | ;; The functions in this section are defined because Lisp packages use | |
253 | ;; them, despite the prefix `internal-' suggesting that they are | |
70d0c3b0 | 254 | ;; private to the face implementation. |
5f5c8ee5 GM |
255 | |
256 | (defun internal-find-face (name &optional frame) | |
257 | "Retrieve the face named NAME. | |
258 | Return nil if there is no such face. | |
39a897a5 JB |
259 | If NAME is already a face, it is simply returned. |
260 | The optional argument FRAME is ignored." | |
5f5c8ee5 | 261 | (facep name)) |
2598a293 | 262 | (make-obsolete 'internal-find-face 'facep "21.1") |
5f5c8ee5 GM |
263 | |
264 | ||
265 | (defun internal-get-face (name &optional frame) | |
266 | "Retrieve the face named NAME; error if there is none. | |
39a897a5 JB |
267 | If NAME is already a face, it is simply returned. |
268 | The optional argument FRAME is ignored." | |
3fc67165 | 269 | (or (facep name) |
5f5c8ee5 | 270 | (check-face name))) |
4b22f844 | 271 | (make-obsolete 'internal-get-face "see `facep' and `check-face'." "21.1") |
5f5c8ee5 GM |
272 | |
273 | \f | |
274 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
275 | ;;; Predicates, type checks. | |
276 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
277 | ||
278 | (defun facep (face) | |
20d29b0b RS |
279 | "Return non-nil if FACE is a face name; nil otherwise. |
280 | A face name can be a string or a symbol." | |
5f5c8ee5 GM |
281 | (internal-lisp-face-p face)) |
282 | ||
283 | ||
284 | (defun check-face (face) | |
285 | "Signal an error if FACE doesn't name a face. | |
286 | Value is FACE." | |
287 | (unless (facep face) | |
288 | (error "Not a face: %s" face)) | |
289 | face) | |
290 | ||
291 | ||
292 | ;; The ID returned is not to be confused with the internally used IDs | |
293 | ;; of realized faces. The ID assigned to Lisp faces is used to | |
294 | ;; support faces in display table entries. | |
295 | ||
296 | (defun face-id (face &optional frame) | |
2df447f2 | 297 | "Return the internal ID of face with name FACE. |
b2d5aa46 | 298 | If FACE is a face-alias, return the ID of the target face. |
9ae89a1a RS |
299 | The optional argument FRAME is ignored, since the internal face ID |
300 | of a face name is the same for all frames." | |
5f5c8ee5 | 301 | (check-face face) |
b2d5aa46 JB |
302 | (or (get face 'face) |
303 | (face-id (get face 'face-alias)))) | |
5f5c8ee5 GM |
304 | |
305 | (defun face-equal (face1 face2 &optional frame) | |
306 | "Non-nil if faces FACE1 and FACE2 are equal. | |
307 | Faces are considered equal if all their attributes are equal. | |
a09be93a JB |
308 | If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame. |
309 | If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames). | |
5f5c8ee5 GM |
310 | If FRAME is omitted or nil, use the selected frame." |
311 | (internal-lisp-face-equal-p face1 face2 frame)) | |
312 | ||
313 | ||
314 | (defun face-differs-from-default-p (face &optional frame) | |
7e07a66d | 315 | "Return non-nil if FACE displays differently from the default face. |
5f5c8ee5 GM |
316 | If the optional argument FRAME is given, report on face FACE in that frame. |
317 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
7e07a66d | 318 | If FRAME is omitted or nil, use the selected frame." |
1151d617 | 319 | (let ((attrs |
833547aa | 320 | (delq :inherit (mapcar 'car face-attribute-name-alist))) |
1151d617 MB |
321 | (differs nil)) |
322 | (while (and attrs (not differs)) | |
323 | (let* ((attr (pop attrs)) | |
324 | (attr-val (face-attribute face attr frame t))) | |
325 | (when (and | |
326 | (not (eq attr-val 'unspecified)) | |
327 | (display-supports-face-attributes-p (list attr attr-val) | |
328 | frame)) | |
329 | (setq differs attr)))) | |
330 | differs)) | |
5f5c8ee5 GM |
331 | |
332 | ||
333 | (defun face-nontrivial-p (face &optional frame) | |
334 | "True if face FACE has some non-nil attribute. | |
335 | If the optional argument FRAME is given, report on face FACE in that frame. | |
336 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
337 | If FRAME is omitted or nil, use the selected frame." | |
338 | (not (internal-lisp-face-empty-p face frame))) | |
339 | ||
340 | ||
341 | \f | |
342 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
343 | ;;; Setting face attributes from X resources. | |
344 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
345 | ||
346 | (defcustom face-x-resources | |
347 | '((:family (".attributeFamily" . "Face.AttributeFamily")) | |
348 | (:width (".attributeWidth" . "Face.AttributeWidth")) | |
349 | (:height (".attributeHeight" . "Face.AttributeHeight")) | |
350 | (:weight (".attributeWeight" . "Face.AttributeWeight")) | |
351 | (:slant (".attributeSlant" . "Face.AttributeSlant")) | |
352 | (:foreground (".attributeForeground" . "Face.AttributeForeground")) | |
353 | (:background (".attributeBackground" . "Face.AttributeBackground")) | |
354 | (:overline (".attributeOverline" . "Face.AttributeOverline")) | |
355 | (:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough")) | |
356 | (:box (".attributeBox" . "Face.AttributeBox")) | |
357 | (:underline (".attributeUnderline" . "Face.AttributeUnderline")) | |
358 | (:inverse-video (".attributeInverse" . "Face.AttributeInverse")) | |
359 | (:stipple | |
360 | (".attributeStipple" . "Face.AttributeStipple") | |
361 | (".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap")) | |
5f5c8ee5 GM |
362 | (:bold (".attributeBold" . "Face.AttributeBold")) |
363 | (:italic (".attributeItalic" . "Face.AttributeItalic")) | |
a0e5a5a4 MB |
364 | (:font (".attributeFont" . "Face.AttributeFont")) |
365 | (:inherit (".attributeInherit" . "Face.AttributeInherit"))) | |
5f5c8ee5 GM |
366 | "*List of X resources and classes for face attributes. |
367 | Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is | |
368 | the name of a face attribute, and each ENTRY is a cons of the form | |
2cb95d1b | 369 | \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the |
5f5c8ee5 | 370 | X resource class for the attribute." |
b5325e78 | 371 | :type '(repeat (cons symbol (repeat (cons string string)))) |
5f5c8ee5 GM |
372 | :group 'faces) |
373 | ||
374 | ||
375 | (defun set-face-attribute-from-resource (face attribute resource class frame) | |
376 | "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME. | |
377 | Value is the attribute value specified by the resource, or nil | |
378 | if not present. This function displays a message if the resource | |
379 | specifies an invalid attribute." | |
380 | (let* ((face-name (face-name face)) | |
381 | (value (internal-face-x-get-resource (concat face-name resource) | |
382 | class frame))) | |
383 | (when value | |
384 | (condition-case () | |
385 | (internal-set-lisp-face-attribute-from-resource | |
386 | face attribute (downcase value) frame) | |
387 | (error | |
388 | (message "Face %s, frame %s: invalid attribute %s %s from X resource" | |
389 | face-name frame attribute value)))) | |
390 | value)) | |
391 | ||
392 | ||
393 | (defun set-face-attributes-from-resources (face frame) | |
394 | "Set attributes of FACE from X resources for FRAME." | |
1a578e9b | 395 | (when (memq (framep frame) '(x w32 mac)) |
5f5c8ee5 GM |
396 | (dolist (definition face-x-resources) |
397 | (let ((attribute (car definition))) | |
398 | (dolist (entry (cdr definition)) | |
399 | (set-face-attribute-from-resource face attribute (car entry) | |
400 | (cdr entry) frame)))))) | |
00f51890 SS |
401 | |
402 | ||
5f5c8ee5 GM |
403 | (defun make-face-x-resource-internal (face &optional frame) |
404 | "Fill frame-local FACE on FRAME from X resources. | |
405 | FRAME nil or not specified means do it for all frames." | |
406 | (if (null frame) | |
407 | (dolist (frame (frame-list)) | |
408 | (set-face-attributes-from-resources face frame)) | |
409 | (set-face-attributes-from-resources face frame))) | |
410 | ||
411 | ||
412 | \f | |
413 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
414 | ;;; Retrieving face attributes. | |
415 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
416 | ||
feaad827 | 417 | (defun face-name (face) |
465fceed | 418 | "Return the name of face FACE." |
5f5c8ee5 GM |
419 | (symbol-name (check-face face))) |
420 | ||
421 | ||
833547aa RS |
422 | (defun face-all-attributes (face &optional frame) |
423 | "Return an alist stating the attributes of FACE. | |
424 | Each element of the result has the form (ATTR-NAME . ATTR-VALUE). | |
425 | Normally the value describes the default attributes, | |
426 | but if you specify FRAME, the value describes the attributes | |
427 | of FACE on FRAME." | |
606c9f59 RS |
428 | (mapcar (lambda (pair) |
429 | (let ((attr (car pair))) | |
430 | (cons attr (face-attribute face attr (or frame t))))) | |
833547aa RS |
431 | face-attribute-name-alist)) |
432 | ||
c7f814cb | 433 | (defun face-attribute (face attribute &optional frame inherit) |
5f5c8ee5 GM |
434 | "Return the value of FACE's ATTRIBUTE on FRAME. |
435 | If the optional argument FRAME is given, report on face FACE in that frame. | |
436 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
c7f814cb | 437 | If FRAME is omitted or nil, use the selected frame. |
5f5c8ee5 | 438 | |
c7f814cb MB |
439 | If INHERIT is nil, only attributes directly defined by FACE are considered, |
440 | so the return value may be `unspecified', or a relative value. | |
441 | If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the | |
442 | faces specified by its `:inherit' attribute; however the return value | |
443 | may still be `unspecified' or relative. | |
444 | If INHERIT is a face or a list of faces, then the result is further merged | |
445 | with that face (or faces), until it becomes specified and absolute. | |
446 | ||
447 | To ensure that the return value is always specified and absolute, use a | |
448 | value of `default' for INHERIT; this will resolve any unspecified or | |
449 | relative values by merging with the `default' face (which is always | |
450 | completely specified)." | |
451 | (let ((value (internal-get-lisp-face-attribute face attribute frame))) | |
452 | (when (and inherit (face-attribute-relative-p attribute value)) | |
453 | ;; VALUE is relative, so merge with inherited faces | |
454 | (let ((inh-from (face-attribute face :inherit frame))) | |
455 | (unless (or (null inh-from) (eq inh-from 'unspecified)) | |
621e71ee SM |
456 | (condition-case nil |
457 | (setq value | |
458 | (face-attribute-merged-with attribute value inh-from frame)) | |
459 | ;; The `inherit' attribute may point to non existent faces. | |
460 | (error nil))))) | |
c7f814cb MB |
461 | (when (and inherit |
462 | (not (eq inherit t)) | |
463 | (face-attribute-relative-p attribute value)) | |
b6b90dfc | 464 | ;; We should merge with INHERIT as well |
c7f814cb MB |
465 | (setq value (face-attribute-merged-with attribute value inherit frame))) |
466 | value)) | |
5f5c8ee5 | 467 | |
c7f814cb MB |
468 | (defun face-attribute-merged-with (attribute value faces &optional frame) |
469 | "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute. | |
470 | FACES may be either a single face or a list of faces. | |
522fb950 | 471 | \[This is an internal function.]" |
c7f814cb MB |
472 | (cond ((not (face-attribute-relative-p attribute value)) |
473 | value) | |
474 | ((null faces) | |
475 | value) | |
476 | ((consp faces) | |
477 | (face-attribute-merged-with | |
478 | attribute | |
479 | (face-attribute-merged-with attribute value (car faces) frame) | |
480 | (cdr faces) | |
481 | frame)) | |
482 | (t | |
483 | (merge-face-attribute attribute | |
484 | value | |
485 | (face-attribute faces attribute frame t))))) | |
486 | ||
487 | ||
488 | (defmacro face-attribute-specified-or (value &rest body) | |
489 | "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result." | |
490 | (let ((temp (make-symbol "value"))) | |
491 | `(let ((,temp ,value)) | |
492 | (if (not (eq ,temp 'unspecified)) | |
493 | ,temp | |
494 | ,@body)))) | |
495 | ||
496 | (defun face-foreground (face &optional frame inherit) | |
5f5c8ee5 GM |
497 | "Return the foreground color name of FACE, or nil if unspecified. |
498 | If the optional argument FRAME is given, report on face FACE in that frame. | |
499 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
c7f814cb | 500 | If FRAME is omitted or nil, use the selected frame. |
5f5c8ee5 | 501 | |
c7f814cb MB |
502 | If INHERIT is nil, only a foreground color directly defined by FACE is |
503 | considered, so the return value may be nil. | |
504 | If INHERIT is t, and FACE doesn't define a foreground color, then any | |
505 | foreground color that FACE inherits through its `:inherit' attribute | |
506 | is considered as well; however the return value may still be nil. | |
507 | If INHERIT is a face or a list of faces, then it is used to try to | |
508 | resolve an unspecified foreground color. | |
509 | ||
510 | To ensure that a valid color is always returned, use a value of | |
511 | `default' for INHERIT; this will resolve any unspecified values by | |
512 | merging with the `default' face (which is always completely specified)." | |
513 | (face-attribute-specified-or (face-attribute face :foreground frame inherit) | |
514 | nil)) | |
515 | ||
516 | (defun face-background (face &optional frame inherit) | |
5f5c8ee5 GM |
517 | "Return the background color name of FACE, or nil if unspecified. |
518 | If the optional argument FRAME is given, report on face FACE in that frame. | |
519 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
c7f814cb | 520 | If FRAME is omitted or nil, use the selected frame. |
5f5c8ee5 | 521 | |
c7f814cb MB |
522 | If INHERIT is nil, only a background color directly defined by FACE is |
523 | considered, so the return value may be nil. | |
524 | If INHERIT is t, and FACE doesn't define a background color, then any | |
525 | background color that FACE inherits through its `:inherit' attribute | |
526 | is considered as well; however the return value may still be nil. | |
527 | If INHERIT is a face or a list of faces, then it is used to try to | |
528 | resolve an unspecified background color. | |
529 | ||
530 | To ensure that a valid color is always returned, use a value of | |
531 | `default' for INHERIT; this will resolve any unspecified values by | |
532 | merging with the `default' face (which is always completely specified)." | |
533 | (face-attribute-specified-or (face-attribute face :background frame inherit) | |
534 | nil)) | |
535 | ||
536 | (defun face-stipple (face &optional frame inherit) | |
5f5c8ee5 GM |
537 | "Return the stipple pixmap name of FACE, or nil if unspecified. |
538 | If the optional argument FRAME is given, report on face FACE in that frame. | |
539 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
c7f814cb MB |
540 | If FRAME is omitted or nil, use the selected frame. |
541 | ||
542 | If INHERIT is nil, only a stipple directly defined by FACE is | |
543 | considered, so the return value may be nil. | |
544 | If INHERIT is t, and FACE doesn't define a stipple, then any stipple | |
545 | that FACE inherits through its `:inherit' attribute is considered as | |
546 | well; however the return value may still be nil. | |
547 | If INHERIT is a face or a list of faces, then it is used to try to | |
548 | resolve an unspecified stipple. | |
549 | ||
550 | To ensure that a valid stipple or nil is always returned, use a value of | |
551 | `default' for INHERIT; this will resolve any unspecified values by merging | |
552 | with the `default' face (which is always completely specified)." | |
553 | (face-attribute-specified-or (face-attribute face :stipple frame inherit) | |
554 | nil)) | |
5f5c8ee5 GM |
555 | |
556 | ||
557 | (defalias 'face-background-pixmap 'face-stipple) | |
558 | ||
559 | ||
560 | (defun face-underline-p (face &optional frame) | |
561 | "Return non-nil if FACE is underlined. | |
562 | If the optional argument FRAME is given, report on face FACE in that frame. | |
563 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
564 | If FRAME is omitted or nil, use the selected frame." | |
565 | (eq (face-attribute face :underline frame) t)) | |
566 | ||
567 | ||
568 | (defun face-inverse-video-p (face &optional frame) | |
569 | "Return non-nil if FACE is in inverse video on FRAME. | |
570 | If the optional argument FRAME is given, report on face FACE in that frame. | |
571 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
572 | If FRAME is omitted or nil, use the selected frame." | |
573 | (eq (face-attribute face :inverse-video frame) t)) | |
574 | ||
575 | ||
576 | (defun face-bold-p (face &optional frame) | |
577 | "Return non-nil if the font of FACE is bold on FRAME. | |
578 | If the optional argument FRAME is given, report on face FACE in that frame. | |
579 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
580 | If FRAME is omitted or nil, use the selected frame. | |
581 | Use `face-attribute' for finer control." | |
582 | (let ((bold (face-attribute face :weight frame))) | |
da2c7b8c | 583 | (memq bold '(semi-bold bold extra-bold ultra-bold)))) |
5f5c8ee5 GM |
584 | |
585 | ||
586 | (defun face-italic-p (face &optional frame) | |
587 | "Return non-nil if the font of FACE is italic on FRAME. | |
588 | If the optional argument FRAME is given, report on face FACE in that frame. | |
589 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
590 | If FRAME is omitted or nil, use the selected frame. | |
591 | Use `face-attribute' for finer control." | |
592 | (let ((italic (face-attribute face :slant frame))) | |
a48f6020 | 593 | (memq italic '(italic oblique)))) |
00f51890 | 594 | |
5f5c8ee5 | 595 | |
5f5c8ee5 GM |
596 | \f |
597 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
598 | ;;; Face documentation. | |
599 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
600 | ||
601 | (defun face-documentation (face) | |
9a558a07 GM |
602 | "Get the documentation string for FACE. |
603 | If FACE is a face-alias, get the documentation for the target face." | |
604 | (let ((alias (get face 'face-alias)) | |
605 | doc) | |
606 | (if alias | |
607 | (progn | |
608 | (setq doc (get alias 'face-documentation)) | |
609 | (format "%s is an alias for the face `%s'.%s" face alias | |
610 | (if doc (format "\n%s" doc) | |
611 | ""))) | |
612 | (get face 'face-documentation)))) | |
5f5c8ee5 GM |
613 | |
614 | ||
615 | (defun set-face-documentation (face string) | |
616 | "Set the documentation string for FACE to STRING." | |
291cfb96 | 617 | ;; Perhaps the text should go in DOC. |
49435801 | 618 | (put face 'face-documentation (purecopy string))) |
5f5c8ee5 GM |
619 | |
620 | ||
621 | (defalias 'face-doc-string 'face-documentation) | |
622 | (defalias 'set-face-doc-string 'set-face-documentation) | |
623 | ||
624 | ||
625 | \f | |
626 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
627 | ;; Setting face attributes. | |
628 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
629 | ||
630 | ||
1df64254 RS |
631 | (defvar inhibit-face-set-after-frame-default nil |
632 | "If non-nil, that tells `face-set-after-frame-default' to do nothing.") | |
633 | ||
5f5c8ee5 GM |
634 | (defun set-face-attribute (face frame &rest args) |
635 | "Set attributes of FACE on FRAME from ARGS. | |
636 | ||
637 | FRAME nil means change attributes on all frames. FRAME t means change | |
638 | the default for new frames (this is done automatically each time an | |
639 | attribute is changed on all frames). | |
640 | ||
641 | ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a valid | |
a7b0a0e3 | 642 | face attribute name. All attributes can be set to `unspecified'; |
5f5c8ee5 GM |
643 | this fact is not further mentioned below. |
644 | ||
645 | The following attributes are recognized: | |
646 | ||
647 | `:family' | |
648 | ||
649 | VALUE must be a string specifying the font family, e.g. ``courier'', | |
650 | or a fontset alias name. If a font family is specified, wild-cards `*' | |
651 | and `?' are allowed. | |
652 | ||
653 | `:width' | |
654 | ||
655 | VALUE specifies the relative proportionate width of the font to use. | |
656 | It must be one of the symbols `ultra-condensed', `extra-condensed', | |
657 | `condensed', `semi-condensed', `normal', `semi-expanded', `expanded', | |
658 | `extra-expanded', or `ultra-expanded'. | |
659 | ||
660 | `:height' | |
661 | ||
19feb949 MB |
662 | VALUE must be either an integer specifying the height of the font to use |
663 | in 1/10 pt, a floating point number specifying the amount by which to | |
664 | scale any underlying face, or a function, which is called with the old | |
665 | height (from the underlying face), and should return the new height. | |
5f5c8ee5 GM |
666 | |
667 | `:weight' | |
668 | ||
669 | VALUE specifies the weight of the font to use. It must be one of the | |
670 | symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal', | |
671 | `semi-light', `light', `extra-light', `ultra-light'. | |
672 | ||
673 | `:slant' | |
674 | ||
675 | VALUE specifies the slant of the font to use. It must be one of the | |
676 | symbols `italic', `oblique', `normal', `reverse-italic', or | |
677 | `reverse-oblique'. | |
678 | ||
679 | `:foreground', `:background' | |
680 | ||
681 | VALUE must be a color name, a string. | |
682 | ||
683 | `:underline' | |
684 | ||
685 | VALUE specifies whether characters in FACE should be underlined. If | |
686 | VALUE is t, underline with foreground color of the face. If VALUE is | |
687 | a string, underline with that color. If VALUE is nil, explicitly | |
688 | don't underline. | |
689 | ||
690 | `:overline' | |
691 | ||
692 | VALUE specifies whether characters in FACE should be overlined. If | |
693 | VALUE is t, overline with foreground color of the face. If VALUE is a | |
694 | string, overline with that color. If VALUE is nil, explicitly don't | |
695 | overline. | |
696 | ||
697 | `:strike-through' | |
698 | ||
699 | VALUE specifies whether characters in FACE should be drawn with a line | |
700 | striking through them. If VALUE is t, use the foreground color of the | |
701 | face. If VALUE is a string, strike-through with that color. If VALUE | |
702 | is nil, explicitly don't strike through. | |
703 | ||
704 | `:box' | |
705 | ||
706 | VALUE specifies whether characters in FACE should have a box drawn | |
707 | around them. If VALUE is nil, explicitly don't draw boxes. If | |
708 | VALUE is t, draw a box with lines of width 1 in the foreground color | |
709 | of the face. If VALUE is a string, the string must be a color name, | |
710 | and the box is drawn in that color with a line width of 1. Otherwise, | |
711 | VALUE must be a property list of the form `(:line-width WIDTH | |
712 | :color COLOR :style STYLE)'. If a keyword/value pair is missing from | |
713 | the property list, a default value will be used for the value, as | |
714 | specified below. WIDTH specifies the width of the lines to draw; it | |
0f937ebd KH |
715 | defaults to 1. If WIDTH is negative, the absolute value is the width |
716 | of the lines, and draw top/bottom lines inside the characters area, | |
717 | not around it. COLOR is the name of the color to draw in, default is | |
5f5c8ee5 GM |
718 | the foreground color of the face for simple boxes, and the background |
719 | color of the face for 3D boxes. STYLE specifies whether a 3D box | |
720 | should be draw. If STYLE is `released-button', draw a box looking | |
721 | like a released 3D button. If STYLE is `pressed-button' draw a box | |
722 | that appears like a pressed button. If STYLE is nil, the default if | |
723 | the property list doesn't contain a style specification, draw a 2D | |
724 | box. | |
725 | ||
726 | `:inverse-video' | |
727 | ||
728 | VALUE specifies whether characters in FACE should be displayed in | |
70d0c3b0 | 729 | inverse video. VALUE must be one of t or nil. |
5f5c8ee5 GM |
730 | |
731 | `:stipple' | |
732 | ||
733 | If VALUE is a string, it must be the name of a file of pixmap data. | |
734 | The directories listed in the `x-bitmap-file-path' variable are | |
735 | searched. Alternatively, VALUE may be a list of the form (WIDTH | |
736 | HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA | |
737 | is a string containing the raw bits of the bitmap. VALUE nil means | |
738 | explicitly don't use a stipple pattern. | |
739 | ||
740 | For convenience, attributes `:family', `:width', `:height', `:weight', | |
741 | and `:slant' may also be set in one step from an X font name: | |
742 | ||
743 | `:font' | |
744 | ||
745 | Set font-related face attributes from VALUE. VALUE must be a valid | |
746 | XLFD font name. If it is a font name pattern, the first matching font | |
747 | will be used. | |
748 | ||
749 | For compatibility with Emacs 20, keywords `:bold' and `:italic' can | |
750 | be used to specify that a bold or italic font should be used. VALUE | |
19feb949 MB |
751 | must be t or nil in that case. A value of `unspecified' is not allowed. |
752 | ||
753 | `:inherit' | |
754 | ||
755 | VALUE is the name of a face from which to inherit attributes, or a list | |
756 | of face names. Attributes from inherited faces are merged into the face | |
757 | like an underlying face would be, with higher priority than underlying faces." | |
70a267c9 GM |
758 | (let ((where (if (null frame) 0 frame))) |
759 | (setq args (purecopy args)) | |
680da3f8 RS |
760 | ;; If we set the new-frame defaults, this face is modified outside Custom. |
761 | (if (memq where '(0 t)) | |
9a558a07 | 762 | (put (or (get face 'face-alias) face) 'face-modified t)) |
70a267c9 | 763 | (while args |
1df64254 RS |
764 | ;; Don't recursively set the attributes from the frame's font param |
765 | ;; when we update the frame's font param fro the attributes. | |
766 | (let ((inhibit-face-set-after-frame-default t)) | |
767 | (internal-set-lisp-face-attribute face (car args) | |
768 | (purecopy (cadr args)) | |
769 | where)) | |
70a267c9 | 770 | (setq args (cdr (cdr args)))))) |
5f5c8ee5 GM |
771 | |
772 | ||
39cac3e7 | 773 | (defun make-face-bold (face &optional frame noerror) |
5f5c8ee5 GM |
774 | "Make the font of FACE be bold, if possible. |
775 | FRAME nil or not specified means change face on all frames. | |
39cac3e7 | 776 | Argument NOERROR is ignored and retained for compatibility. |
5f5c8ee5 | 777 | Use `set-face-attribute' for finer control of the font weight." |
95125512 | 778 | (interactive (list (read-face-name "Make which face bold"))) |
5f5c8ee5 GM |
779 | (set-face-attribute face frame :weight 'bold)) |
780 | ||
781 | ||
39cac3e7 | 782 | (defun make-face-unbold (face &optional frame noerror) |
5f5c8ee5 | 783 | "Make the font of FACE be non-bold, if possible. |
39cac3e7 GM |
784 | FRAME nil or not specified means change face on all frames. |
785 | Argument NOERROR is ignored and retained for compatibility." | |
95125512 | 786 | (interactive (list (read-face-name "Make which face non-bold"))) |
5f5c8ee5 GM |
787 | (set-face-attribute face frame :weight 'normal)) |
788 | ||
00f51890 | 789 | |
39cac3e7 | 790 | (defun make-face-italic (face &optional frame noerror) |
5f5c8ee5 GM |
791 | "Make the font of FACE be italic, if possible. |
792 | FRAME nil or not specified means change face on all frames. | |
39cac3e7 | 793 | Argument NOERROR is ignored and retained for compatibility. |
5f5c8ee5 | 794 | Use `set-face-attribute' for finer control of the font slant." |
95125512 | 795 | (interactive (list (read-face-name "Make which face italic"))) |
5f5c8ee5 GM |
796 | (set-face-attribute face frame :slant 'italic)) |
797 | ||
798 | ||
39cac3e7 | 799 | (defun make-face-unitalic (face &optional frame noerror) |
5f5c8ee5 | 800 | "Make the font of FACE be non-italic, if possible. |
70d0c3b0 DL |
801 | FRAME nil or not specified means change face on all frames. |
802 | Argument NOERROR is ignored and retained for compatibility." | |
95125512 | 803 | (interactive (list (read-face-name "Make which face non-italic"))) |
5f5c8ee5 GM |
804 | (set-face-attribute face frame :slant 'normal)) |
805 | ||
00f51890 | 806 | |
39cac3e7 | 807 | (defun make-face-bold-italic (face &optional frame noerror) |
5f5c8ee5 GM |
808 | "Make the font of FACE be bold and italic, if possible. |
809 | FRAME nil or not specified means change face on all frames. | |
39cac3e7 | 810 | Argument NOERROR is ignored and retained for compatibility. |
5f5c8ee5 | 811 | Use `set-face-attribute' for finer control of font weight and slant." |
95125512 | 812 | (interactive (list (read-face-name "Make which face bold-italic"))) |
5f5c8ee5 GM |
813 | (set-face-attribute face frame :weight 'bold :slant 'italic)) |
814 | ||
815 | ||
816 | (defun set-face-font (face font &optional frame) | |
817 | "Change font-related attributes of FACE to those of FONT (a string). | |
818 | FRAME nil or not specified means change face on all frames. | |
819 | This sets the attributes `:family', `:width', `:height', `:weight', | |
820 | and `:slant'. When called interactively, prompt for the face and font." | |
821 | (interactive (read-face-and-attribute :font)) | |
822 | (set-face-attribute face frame :font font)) | |
823 | ||
824 | ||
825 | ;; Implementation note: Emulating gray background colors with a | |
826 | ;; stipple pattern is now part of the face realization process, and is | |
827 | ;; done in C depending on the frame on which the face is realized. | |
828 | ||
829 | (defun set-face-background (face color &optional frame) | |
830 | "Change the background color of face FACE to COLOR (a string). | |
831 | FRAME nil or not specified means change face on all frames. | |
72e6f142 RS |
832 | COLOR can be a system-defined color name (see `list-colors-display') |
833 | or a hex spec of the form #RRGGBB. | |
834 | When called interactively, prompts for the face and color." | |
5f5c8ee5 | 835 | (interactive (read-face-and-attribute :background)) |
78ad1cd5 | 836 | (set-face-attribute face frame :background (or color 'unspecified))) |
5f5c8ee5 GM |
837 | |
838 | ||
839 | (defun set-face-foreground (face color &optional frame) | |
840 | "Change the foreground color of face FACE to COLOR (a string). | |
841 | FRAME nil or not specified means change face on all frames. | |
72e6f142 RS |
842 | COLOR can be a system-defined color name (see `list-colors-display') |
843 | or a hex spec of the form #RRGGBB. | |
844 | When called interactively, prompts for the face and color." | |
5f5c8ee5 | 845 | (interactive (read-face-and-attribute :foreground)) |
78ad1cd5 | 846 | (set-face-attribute face frame :foreground (or color 'unspecified))) |
5f5c8ee5 GM |
847 | |
848 | ||
849 | (defun set-face-stipple (face stipple &optional frame) | |
850 | "Change the stipple pixmap of face FACE to STIPPLE. | |
851 | FRAME nil or not specified means change face on all frames. | |
70d0c3b0 | 852 | STIPPLE should be a string, the name of a file of pixmap data. |
5f5c8ee5 GM |
853 | The directories listed in the `x-bitmap-file-path' variable are searched. |
854 | ||
855 | Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA) | |
856 | where WIDTH and HEIGHT are the size in pixels, | |
857 | and DATA is a string, containing the raw bits of the bitmap." | |
858 | (interactive (read-face-and-attribute :stipple)) | |
78ad1cd5 | 859 | (set-face-attribute face frame :stipple (or stipple 'unspecified))) |
5f5c8ee5 GM |
860 | |
861 | ||
a61afeac | 862 | (defun set-face-underline-p (face underline &optional frame) |
5f5c8ee5 GM |
863 | "Specify whether face FACE is underlined. |
864 | UNDERLINE nil means FACE explicitly doesn't underline. | |
865 | UNDERLINE non-nil means FACE explicitly does underlining | |
866 | with the same of the foreground color. | |
867 | If UNDERLINE is a string, underline with the color named UNDERLINE. | |
868 | FRAME nil or not specified means change face on all frames. | |
5f5c8ee5 GM |
869 | Use `set-face-attribute' to ``unspecify'' underlining." |
870 | (interactive | |
871 | (let ((list (read-face-and-attribute :underline))) | |
872 | (list (car list) (eq (car (cdr list)) t)))) | |
a61afeac | 873 | (set-face-attribute face frame :underline underline)) |
5f5c8ee5 | 874 | |
9b82fc01 JL |
875 | (define-obsolete-function-alias 'set-face-underline |
876 | 'set-face-underline-p "22.1") | |
877 | ||
5f5c8ee5 GM |
878 | |
879 | (defun set-face-inverse-video-p (face inverse-video-p &optional frame) | |
880 | "Specify whether face FACE is in inverse video. | |
881 | INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video. | |
882 | INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video. | |
883 | FRAME nil or not specified means change face on all frames. | |
884 | Use `set-face-attribute' to ``unspecify'' the inverse video attribute." | |
885 | (interactive | |
886 | (let ((list (read-face-and-attribute :inverse-video))) | |
887 | (list (car list) (eq (car (cdr list)) t)))) | |
888 | (set-face-attribute face frame :inverse-video inverse-video-p)) | |
889 | ||
890 | ||
891 | (defun set-face-bold-p (face bold-p &optional frame) | |
892 | "Specify whether face FACE is bold. | |
893 | BOLD-P non-nil means FACE should explicitly display bold. | |
894 | BOLD-P nil means FACE should explicitly display non-bold. | |
895 | FRAME nil or not specified means change face on all frames. | |
896 | Use `set-face-attribute' or `modify-face' for finer control." | |
897 | (if (null bold-p) | |
898 | (make-face-unbold face frame) | |
899 | (make-face-bold face frame))) | |
900 | ||
901 | ||
902 | (defun set-face-italic-p (face italic-p &optional frame) | |
903 | "Specify whether face FACE is italic. | |
904 | ITALIC-P non-nil means FACE should explicitly display italic. | |
905 | ITALIC-P nil means FACE should explicitly display non-italic. | |
906 | FRAME nil or not specified means change face on all frames. | |
907 | Use `set-face-attribute' or `modify-face' for finer control." | |
908 | (if (null italic-p) | |
909 | (make-face-unitalic face frame) | |
910 | (make-face-italic face frame))) | |
911 | ||
912 | ||
913 | (defalias 'set-face-background-pixmap 'set-face-stipple) | |
914 | ||
915 | ||
916 | (defun invert-face (face &optional frame) | |
917 | "Swap the foreground and background colors of FACE. | |
e458cb49 | 918 | If FRAME is omitted or nil, it means change face on all frames. |
5f5c8ee5 GM |
919 | If FACE specifies neither foreground nor background color, |
920 | set its foreground and background to the background and foreground | |
921 | of the default face. Value is FACE." | |
95125512 | 922 | (interactive (list (read-face-name "Invert face"))) |
5f5c8ee5 GM |
923 | (let ((fg (face-attribute face :foreground frame)) |
924 | (bg (face-attribute face :background frame))) | |
e458cb49 | 925 | (if (not (and (eq fg 'unspecified) (eq bg 'unspecified))) |
5f5c8ee5 GM |
926 | (set-face-attribute face frame :foreground bg :background fg) |
927 | (set-face-attribute face frame | |
928 | :foreground | |
929 | (face-attribute 'default :background frame) | |
930 | :background | |
931 | (face-attribute 'default :foreground frame)))) | |
932 | face) | |
933 | ||
934 | \f | |
935 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
936 | ;;; Interactively modifying faces. | |
937 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
938 | ||
a482f364 RS |
939 | (defun read-face-name (prompt &optional string-describing-default multiple) |
940 | "Read a face, defaulting to the face or faces on the char after point. | |
c7b93b44 | 941 | If it has the property `read-face-name', that overrides the `face' property. |
3748d13d RS |
942 | PROMPT should be a string that describes what the caller will do with the face; |
943 | it should not end in a space. | |
944 | STRING-DESCRIBING-DEFAULT should describe what default the caller will use if | |
945 | the user just types RET; you can omit it. | |
a482f364 RS |
946 | If MULTIPLE is non-nil, return a list of faces (possibly only one). |
947 | Otherwise, return a single face." | |
948 | (let ((faceprop (or (get-char-property (point) 'read-face-name) | |
949 | (get-char-property (point) 'face))) | |
e3b5b35b SM |
950 | (aliasfaces nil) |
951 | (nonaliasfaces nil) | |
a482f364 | 952 | faces) |
224d108e JL |
953 | ;; Try to get a face name from the buffer. |
954 | (if (memq (intern-soft (thing-at-point 'symbol)) (face-list)) | |
955 | (setq faces (list (intern-soft (thing-at-point 'symbol))))) | |
956 | ;; Add the named faces that the `face' property uses. | |
1bd59f82 RS |
957 | (if (and (listp faceprop) |
958 | ;; Don't treat an attribute spec as a list of faces. | |
959 | (not (keywordp (car faceprop))) | |
960 | (not (memq (car faceprop) '(foreground-color background-color)))) | |
a482f364 RS |
961 | (dolist (f faceprop) |
962 | (if (symbolp f) | |
963 | (push f faces))) | |
964 | (if (symbolp faceprop) | |
1bd59f82 | 965 | (push faceprop faces))) |
81435dc4 | 966 | (delete-dups faces) |
a482f364 | 967 | |
e3b5b35b SM |
968 | ;; Build up the completion tables. |
969 | (mapatoms (lambda (s) | |
970 | (if (custom-facep s) | |
971 | (if (get s 'face-alias) | |
972 | (push (symbol-name s) aliasfaces) | |
973 | (push (symbol-name s) nonaliasfaces))))) | |
974 | ||
a482f364 RS |
975 | ;; If we only want one, and the default is more than one, |
976 | ;; discard the unwanted ones now. | |
977 | (unless multiple | |
978 | (if faces | |
979 | (setq faces (list (car faces))))) | |
224d108e | 980 | (require 'crm) |
a482f364 RS |
981 | (let* ((input |
982 | ;; Read the input. | |
224d108e | 983 | (completing-read-multiple |
a482f364 RS |
984 | (if (or faces string-describing-default) |
985 | (format "%s (default %s): " prompt | |
224d108e | 986 | (if faces (mapconcat 'symbol-name faces ",") |
a482f364 | 987 | string-describing-default)) |
3b4ef34b | 988 | (format "%s: " prompt)) |
45555ebe | 989 | (completion-table-in-turn nonaliasfaces aliasfaces) |
224d108e JL |
990 | nil t nil nil |
991 | (if faces (mapconcat 'symbol-name faces ",")))) | |
a482f364 RS |
992 | ;; Canonicalize the output. |
993 | (output | |
224d108e JL |
994 | (cond ((or (equal input "") (equal input '(""))) |
995 | faces) | |
996 | ((stringp input) | |
997 | (mapcar 'intern (split-string input ", *" t))) | |
998 | ((listp input) | |
999 | (mapcar 'intern input)) | |
1000 | (input)))) | |
a482f364 RS |
1001 | ;; Return either a list of faces or just one face. |
1002 | (if multiple | |
1003 | output | |
1004 | (car output))))) | |
1005 | ||
1006 | ||
5f5c8ee5 GM |
1007 | (defun face-valid-attribute-values (attribute &optional frame) |
1008 | "Return valid values for face attribute ATTRIBUTE. | |
1009 | The optional argument FRAME is used to determine available fonts | |
1010 | and colors. If it is nil or not specified, the selected frame is | |
1011 | used. Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value | |
1012 | out of a set of discrete values. Value is `integerp' if ATTRIBUTE expects | |
1013 | an integer value." | |
00f51890 SS |
1014 | (let ((valid |
1015 | (case attribute | |
1016 | (:family | |
428a555e | 1017 | (if (window-system frame) |
00f51890 SS |
1018 | (mapcar #'(lambda (x) (cons (car x) (car x))) |
1019 | (x-font-family-list)) | |
1020 | ;; Only one font on TTYs. | |
1021 | (list (cons "default" "default")))) | |
1022 | ((:width :weight :slant :inverse-video) | |
1023 | (mapcar #'(lambda (x) (cons (symbol-name x) x)) | |
1024 | (internal-lisp-face-attribute-values attribute))) | |
1025 | ((:underline :overline :strike-through :box) | |
428a555e | 1026 | (if (window-system frame) |
00f51890 SS |
1027 | (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x)) |
1028 | (internal-lisp-face-attribute-values attribute)) | |
1029 | (mapcar #'(lambda (c) (cons c c)) | |
b533d0ae | 1030 | (defined-colors frame))) |
00f51890 SS |
1031 | (mapcar #'(lambda (x) (cons (symbol-name x) x)) |
1032 | (internal-lisp-face-attribute-values attribute)))) | |
1033 | ((:foreground :background) | |
1034 | (mapcar #'(lambda (c) (cons c c)) | |
1035 | (defined-colors frame))) | |
1036 | ((:height) | |
1037 | 'integerp) | |
1038 | (:stipple | |
428a555e | 1039 | (and (memq (window-system frame) '(x w32 mac)) |
00f51890 SS |
1040 | (mapcar #'list |
1041 | (apply #'nconc | |
1042 | (mapcar (lambda (dir) | |
1043 | (and (file-readable-p dir) | |
1044 | (file-directory-p dir) | |
1045 | (directory-files dir))) | |
1046 | x-bitmap-file-path))))) | |
1047 | (:inherit | |
1048 | (cons '("none" . nil) | |
1049 | (mapcar #'(lambda (c) (cons (symbol-name c) c)) | |
1050 | (face-list)))) | |
1051 | (t | |
1052 | (error "Internal error"))))) | |
19feb949 | 1053 | (if (and (listp valid) (not (memq attribute '(:inherit)))) |
fbd5f1cc GM |
1054 | (nconc (list (cons "unspecified" 'unspecified)) valid) |
1055 | valid))) | |
5f5c8ee5 GM |
1056 | |
1057 | ||
1058 | (defvar face-attribute-name-alist | |
1059 | '((:family . "font family") | |
1060 | (:width . "character set width") | |
1061 | (:height . "height in 1/10 pt") | |
1062 | (:weight . "weight") | |
1063 | (:slant . "slant") | |
1064 | (:underline . "underline") | |
1065 | (:overline . "overline") | |
1066 | (:strike-through . "strike-through") | |
1067 | (:box . "box") | |
1068 | (:inverse-video . "inverse-video display") | |
1069 | (:foreground . "foreground color") | |
1070 | (:background . "background color") | |
19feb949 MB |
1071 | (:stipple . "background stipple") |
1072 | (:inherit . "inheritance")) | |
5f5c8ee5 GM |
1073 | "An alist of descriptive names for face attributes. |
1074 | Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where | |
1075 | ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and | |
1076 | DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.") | |
1077 | ||
1078 | ||
1079 | (defun face-descriptive-attribute-name (attribute) | |
1080 | "Return a descriptive name for ATTRIBUTE." | |
1081 | (cdr (assq attribute face-attribute-name-alist))) | |
1082 | ||
1083 | ||
1084 | (defun face-read-string (face default name &optional completion-alist) | |
1085 | "Interactively read a face attribute string value. | |
19feb949 MB |
1086 | FACE is the face whose attribute is read. If non-nil, DEFAULT is the |
1087 | default string to return if no new value is entered. NAME is a | |
1088 | descriptive name of the attribute for prompting. COMPLETION-ALIST is an | |
1089 | alist of valid values, if non-nil. | |
5f5c8ee5 | 1090 | |
19feb949 | 1091 | Entering nothing accepts the default string DEFAULT. |
5f5c8ee5 | 1092 | Value is the new attribute value." |
19feb949 MB |
1093 | ;; Capitalize NAME (we don't use `capitalize' because that capitalizes |
1094 | ;; each word in a string separately). | |
1095 | (setq name (concat (upcase (substring name 0 1)) (substring name 1))) | |
5f5c8ee5 GM |
1096 | (let* ((completion-ignore-case t) |
1097 | (value (completing-read | |
1098 | (if default | |
19feb949 MB |
1099 | (format "%s for face `%s' (default %s): " |
1100 | name face default) | |
1101 | (format "%s for face `%s': " name face)) | |
d69ab4ba | 1102 | completion-alist nil nil nil nil default))) |
fbd5f1cc | 1103 | (if (equal value "") default value))) |
5f5c8ee5 GM |
1104 | |
1105 | ||
1106 | (defun face-read-integer (face default name) | |
1107 | "Interactively read an integer face attribute value. | |
1108 | FACE is the face whose attribute is read. DEFAULT is the default | |
1109 | value to return if no new value is entered. NAME is a descriptive | |
1110 | name of the attribute for prompting. Value is the new attribute value." | |
fbd5f1cc GM |
1111 | (let ((new-value |
1112 | (face-read-string face | |
19feb949 | 1113 | (format "%s" default) |
fbd5f1cc GM |
1114 | name |
1115 | (list (cons "unspecified" 'unspecified))))) | |
19feb949 MB |
1116 | (cond ((equal new-value "unspecified") |
1117 | 'unspecified) | |
1118 | ((member new-value '("unspecified-fg" "unspecified-bg")) | |
1119 | new-value) | |
1120 | (t | |
027a4b6b | 1121 | (string-to-number new-value))))) |
5f5c8ee5 GM |
1122 | |
1123 | ||
1124 | (defun read-face-attribute (face attribute &optional frame) | |
1125 | "Interactively read a new value for FACE's ATTRIBUTE. | |
1126 | Optional argument FRAME nil or unspecified means read an attribute value | |
1127 | of a global face. Value is the new attribute value." | |
1128 | (let* ((old-value (face-attribute face attribute frame)) | |
1129 | (attribute-name (face-descriptive-attribute-name attribute)) | |
1130 | (valid (face-valid-attribute-values attribute frame)) | |
1131 | new-value) | |
1132 | ;; Represent complex attribute values as strings by printing them | |
1133 | ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be | |
1134 | ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow | |
1135 | ;; SHADOW)'. | |
1136 | (when (and (or (eq attribute :stipple) | |
1137 | (eq attribute :box)) | |
1138 | (or (consp old-value) | |
1139 | (vectorp old-value))) | |
1140 | (setq old-value (prin1-to-string old-value))) | |
1141 | (cond ((listp valid) | |
19feb949 MB |
1142 | (let ((default |
1143 | (or (car (rassoc old-value valid)) | |
1144 | (format "%s" old-value)))) | |
1145 | (setq new-value | |
1146 | (face-read-string face default attribute-name valid)) | |
1147 | (if (equal new-value default) | |
1148 | ;; Nothing changed, so don't bother with all the stuff | |
1149 | ;; below. In particular, this avoids a non-tty color | |
1150 | ;; from being canonicalized for a tty when the user | |
1151 | ;; just uses the default. | |
1152 | (setq new-value old-value) | |
1153 | ;; Terminal frames can support colors that don't appear | |
1154 | ;; explicitly in VALID, using color approximation code | |
1155 | ;; in tty-colors.el. | |
f9056dd9 | 1156 | (when (and (memq attribute '(:foreground :background)) |
428a555e | 1157 | (not (memq (window-system frame) '(x w32 mac))) |
f9056dd9 MB |
1158 | (not (member new-value |
1159 | '("unspecified" | |
1160 | "unspecified-fg" "unspecified-bg")))) | |
4385f1b0 | 1161 | (setq new-value (car (tty-color-desc new-value frame)))) |
f9056dd9 MB |
1162 | (when (assoc new-value valid) |
1163 | (setq new-value (cdr (assoc new-value valid))))))) | |
5f5c8ee5 GM |
1164 | ((eq valid 'integerp) |
1165 | (setq new-value (face-read-integer face old-value attribute-name))) | |
1166 | (t (error "Internal error"))) | |
1167 | ;; Convert stipple and box value text we read back to a list or | |
1168 | ;; vector if it looks like one. This makes the assumption that a | |
1169 | ;; pixmap file name won't start with an open-paren. | |
1170 | (when (and (or (eq attribute :stipple) | |
1171 | (eq attribute :box)) | |
1172 | (stringp new-value) | |
1173 | (string-match "^[[(]" new-value)) | |
1174 | (setq new-value (read new-value))) | |
1175 | new-value)) | |
1176 | ||
1177 | ||
1178 | (defun read-face-font (face &optional frame) | |
1179 | "Read the name of a font for FACE on FRAME. | |
522fb950 | 1180 | If optional argument FRAME is nil or omitted, use the selected frame." |
5f5c8ee5 | 1181 | (let ((completion-ignore-case t)) |
48ec9939 | 1182 | (completing-read (format "Set font attributes of face `%s' from font: " face) |
6b61353c | 1183 | (append (fontset-list) (x-list-fonts "*" nil frame))))) |
5f5c8ee5 GM |
1184 | |
1185 | ||
1186 | (defun read-all-face-attributes (face &optional frame) | |
1187 | "Interactively read all attributes for FACE. | |
522fb950 | 1188 | If optional argument FRAME is nil or omitted, use the selected frame. |
5f5c8ee5 GM |
1189 | Value is a property list of attribute names and new values." |
1190 | (let (result) | |
1191 | (dolist (attribute face-attribute-name-alist result) | |
1192 | (setq result (cons (car attribute) | |
1193 | (cons (read-face-attribute face (car attribute) frame) | |
1194 | result)))))) | |
1195 | ||
7cd512f2 | 1196 | (defun modify-face (&optional face foreground background stipple |
a61afeac | 1197 | bold-p italic-p underline inverse-p frame) |
5f5c8ee5 GM |
1198 | "Modify attributes of faces interactively. |
1199 | If optional argument FRAME is nil or omitted, modify the face used | |
7cd512f2 SM |
1200 | for newly created frame, i.e. the global face. |
1201 | For non-interactive use, `set-face-attribute' is preferred. | |
522fb950 | 1202 | When called from Lisp, if FACE is nil, all arguments but FRAME are ignored |
7cd512f2 | 1203 | and the face and its settings are obtained by querying the user." |
5f5c8ee5 | 1204 | (interactive) |
7cd512f2 SM |
1205 | (if face |
1206 | (set-face-attribute face frame | |
1207 | :foreground (or foreground 'unspecified) | |
1208 | :background (or background 'unspecified) | |
1209 | :stipple stipple | |
1210 | :bold bold-p | |
1211 | :italic italic-p | |
a61afeac | 1212 | :underline underline |
7cd512f2 SM |
1213 | :inverse-video inverse-p) |
1214 | (setq face (read-face-name "Modify face")) | |
5f5c8ee5 GM |
1215 | (apply #'set-face-attribute face frame |
1216 | (read-all-face-attributes face frame)))) | |
1217 | ||
5f5c8ee5 GM |
1218 | (defun read-face-and-attribute (attribute &optional frame) |
1219 | "Read face name and face attribute value. | |
1220 | ATTRIBUTE is the attribute whose new value is read. | |
1221 | FRAME nil or unspecified means read attribute value of global face. | |
1222 | Value is a list (FACE NEW-VALUE) where FACE is the face read | |
7cd512f2 | 1223 | \(a symbol), and NEW-VALUE is value read." |
5f5c8ee5 | 1224 | (cond ((eq attribute :font) |
48ec9939 | 1225 | (let* ((prompt "Set font-related attributes of face") |
5f5c8ee5 GM |
1226 | (face (read-face-name prompt)) |
1227 | (font (read-face-font face frame))) | |
1228 | (list face font))) | |
1229 | (t | |
1230 | (let* ((attribute-name (face-descriptive-attribute-name attribute)) | |
19feb949 | 1231 | (prompt (format "Set %s of face" attribute-name)) |
5f5c8ee5 GM |
1232 | (face (read-face-name prompt)) |
1233 | (new-value (read-face-attribute face attribute frame))) | |
1234 | (list face new-value))))) | |
1235 | ||
1236 | ||
1237 | \f | |
1238 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1239 | ;;; Listing faces. | |
1240 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1241 | ||
1242 | (defvar list-faces-sample-text | |
1243 | "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
1244 | "*Text string to display as the sample text for `list-faces-display'.") | |
1245 | ||
1246 | ||
1247 | ;; The name list-faces would be more consistent, but let's avoid a | |
1248 | ;; conflict with Lucid, which uses that name differently. | |
1249 | ||
645a1038 | 1250 | (defvar help-xref-stack) |
e2c11e3b | 1251 | (defun list-faces-display (&optional regexp) |
5f5c8ee5 GM |
1252 | "List all faces, using the same sample text in each. |
1253 | The sample text is a string that comes from the variable | |
e2c11e3b RS |
1254 | `list-faces-sample-text'. |
1255 | ||
1256 | If REGEXP is non-nil, list only those faces with names matching | |
1257 | this regular expression. When called interactively with a prefix | |
1258 | arg, prompt for a regular expression." | |
1259 | (interactive (list (and current-prefix-arg | |
1260 | (read-string "List faces matching regexp: ")))) | |
011131fd | 1261 | (let ((all-faces (zerop (length regexp))) |
5f5c8ee5 | 1262 | (frame (selected-frame)) |
011131fd JB |
1263 | (max-length 0) |
1264 | faces line-format | |
84fe35f0 | 1265 | disp-frame window face-name) |
011131fd JB |
1266 | ;; We filter and take the max length in one pass |
1267 | (setq faces | |
1268 | (delq nil | |
1269 | (mapcar (lambda (f) | |
1270 | (let ((s (symbol-name f))) | |
1271 | (when (or all-faces (string-match regexp s)) | |
1272 | (setq max-length (max (length s) max-length)) | |
1273 | f))) | |
1274 | (sort (face-list) #'string-lessp)))) | |
1275 | (unless faces | |
1276 | (error "No faces matching \"%s\"" regexp)) | |
1277 | (setq max-length (1+ max-length) | |
1278 | line-format (format "%%-%ds" max-length)) | |
b766be6a | 1279 | (with-help-window "*Faces*" |
5f5c8ee5 GM |
1280 | (save-excursion |
1281 | (set-buffer standard-output) | |
1282 | (setq truncate-lines t) | |
84fe35f0 DL |
1283 | (insert |
1284 | (substitute-command-keys | |
1285 | (concat | |
1286 | "Use " | |
53c80cf6 | 1287 | (if (display-mouse-p) "\\[help-follow-mouse] or ") |
32e33f60 | 1288 | "\\[help-follow] on a face name to customize it\n" |
46057f5f | 1289 | "or on its sample text for a description of the face.\n\n"))) |
84fe35f0 | 1290 | (setq help-xref-stack nil) |
e2c11e3b | 1291 | (dolist (face faces) |
84fe35f0 | 1292 | (setq face-name (symbol-name face)) |
011131fd | 1293 | (insert (format line-format face-name)) |
84fe35f0 DL |
1294 | ;; Hyperlink to a customization buffer for the face. Using |
1295 | ;; the help xref mechanism may not be the best way. | |
1296 | (save-excursion | |
1297 | (save-match-data | |
1298 | (search-backward face-name) | |
35a0a8aa | 1299 | (setq help-xref-stack-item `(list-faces-display ,regexp)) |
a482f364 RS |
1300 | (help-xref-button 0 'help-customize-face face))) |
1301 | (let ((beg (point)) | |
1302 | (line-beg (line-beginning-position))) | |
5f5c8ee5 | 1303 | (insert list-faces-sample-text) |
84fe35f0 DL |
1304 | ;; Hyperlink to a help buffer for the face. |
1305 | (save-excursion | |
1306 | (save-match-data | |
1307 | (search-backward list-faces-sample-text) | |
8940232b | 1308 | (help-xref-button 0 'help-face face))) |
5f5c8ee5 GM |
1309 | (insert "\n") |
1310 | (put-text-property beg (1- (point)) 'face face) | |
a482f364 RS |
1311 | ;; Make all face commands default to the proper face |
1312 | ;; anywhere in the line. | |
1313 | (put-text-property line-beg (1- (point)) 'read-face-name face) | |
5f5c8ee5 GM |
1314 | ;; If the sample text has multiple lines, line up all of them. |
1315 | (goto-char beg) | |
1316 | (forward-line 1) | |
1317 | (while (not (eobp)) | |
011131fd | 1318 | (insert-char ?\s max-length) |
5f5c8ee5 | 1319 | (forward-line 1)))) |
b766be6a | 1320 | (goto-char (point-min)))) |
5f5c8ee5 GM |
1321 | ;; If the *Faces* buffer appears in a different frame, |
1322 | ;; copy all the face definitions from FRAME, | |
1323 | ;; so that the display will reflect the frame that was selected. | |
1324 | (setq window (get-buffer-window (get-buffer "*Faces*") t)) | |
1325 | (setq disp-frame (if window (window-frame window) | |
1326 | (car (frame-list)))) | |
1327 | (or (eq frame disp-frame) | |
1328 | (let ((faces (face-list))) | |
1329 | (while faces | |
1330 | (copy-face (car faces) (car faces) frame disp-frame) | |
1331 | (setq faces (cdr faces))))))) | |
1332 | ||
e2c11e3b | 1333 | |
5f5c8ee5 GM |
1334 | (defun describe-face (face &optional frame) |
1335 | "Display the properties of face FACE on FRAME. | |
6afa5404 | 1336 | Interactively, FACE defaults to the faces of the character after point |
a482f364 RS |
1337 | and FRAME defaults to the selected frame. |
1338 | ||
5f5c8ee5 GM |
1339 | If the optional argument FRAME is given, report on face FACE in that frame. |
1340 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
1341 | If FRAME is omitted or nil, use the selected frame." | |
a482f364 | 1342 | (interactive (list (read-face-name "Describe face" "= `default' face" t))) |
5f5c8ee5 GM |
1343 | (let* ((attrs '((:family . "Family") |
1344 | (:width . "Width") | |
1345 | (:height . "Height") | |
1346 | (:weight . "Weight") | |
1347 | (:slant . "Slant") | |
1348 | (:foreground . "Foreground") | |
1349 | (:background . "Background") | |
1350 | (:underline . "Underline") | |
1351 | (:overline . "Overline") | |
1352 | (:strike-through . "Strike-through") | |
1353 | (:box . "Box") | |
1354 | (:inverse-video . "Inverse") | |
b32631c8 | 1355 | (:stipple . "Stipple") |
0540dc5e KH |
1356 | (:font . "Font") |
1357 | (:fontset . "Fontset") | |
25ac7b52 | 1358 | (:inherit . "Inherit"))) |
5f5c8ee5 GM |
1359 | (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x))) |
1360 | attrs)))) | |
2cb95d1b | 1361 | (help-setup-xref (list #'describe-face face) (interactive-p)) |
a482f364 RS |
1362 | (unless face |
1363 | (setq face 'default)) | |
1364 | (if (not (listp face)) | |
1365 | (setq face (list face))) | |
b766be6a | 1366 | (with-help-window (help-buffer) |
5f5c8ee5 GM |
1367 | (save-excursion |
1368 | (set-buffer standard-output) | |
a482f364 | 1369 | (dolist (f face) |
faa3d27b | 1370 | (if (stringp f) (setq f (intern f))) |
a482f364 RS |
1371 | (insert "Face: " (symbol-name f)) |
1372 | (if (not (facep f)) | |
1373 | (insert " undefined face.\n") | |
19941ff5 RS |
1374 | (let ((customize-label "customize this face") |
1375 | file-name) | |
1b2b8998 | 1376 | (insert (concat " (" (propertize "sample" 'font-lock-face f) ")")) |
a482f364 RS |
1377 | (princ (concat " (" customize-label ")\n")) |
1378 | (insert "Documentation: " | |
1379 | (or (face-documentation f) | |
f79f9fb2 | 1380 | "Not documented as a face.") |
19941ff5 | 1381 | "\n") |
a482f364 RS |
1382 | (with-current-buffer standard-output |
1383 | (save-excursion | |
1384 | (re-search-backward | |
1385 | (concat "\\(" customize-label "\\)") nil t) | |
1386 | (help-xref-button 1 'help-customize-face f))) | |
19941ff5 RS |
1387 | ;; The next 4 sexps are copied from describe-function-1 |
1388 | ;; and simplified. | |
1389 | (setq file-name (symbol-file f 'defface)) | |
d1a74d58 | 1390 | (setq file-name (describe-simplify-lib-file-name file-name)) |
19941ff5 RS |
1391 | (when file-name |
1392 | (princ "Defined in `") | |
1393 | (princ file-name) | |
1394 | (princ "'") | |
1395 | ;; Make a hyperlink to the library. | |
1396 | (save-excursion | |
1397 | (re-search-backward "`\\([^`']+\\)'" nil t) | |
1398 | (help-xref-button 1 'help-face-def f file-name)) | |
1399 | (princ ".") | |
1400 | (terpri) | |
1401 | (terpri)) | |
a482f364 RS |
1402 | (dolist (a attrs) |
1403 | (let ((attr (face-attribute f (car a) frame))) | |
522fb950 | 1404 | (insert (make-string (- max-width (length (cdr a))) ?\s) |
9b82fc01 JL |
1405 | (cdr a) ": " (format "%s" attr)) |
1406 | (if (and (eq (car a) :inherit) | |
1407 | (not (eq attr 'unspecified))) | |
1408 | ;; Make a hyperlink to the parent face. | |
1409 | (save-excursion | |
1410 | (re-search-backward ": \\([^:]+\\)" nil t) | |
1411 | (help-xref-button 1 'help-face attr))) | |
1412 | (insert "\n"))))) | |
b766be6a | 1413 | (terpri)))))) |
8940232b | 1414 | |
5f5c8ee5 GM |
1415 | \f |
1416 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1417 | ;;; Face specifications (defface). | |
1418 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1419 | ||
1420 | ;; Parameter FRAME Is kept for call compatibility to with previous | |
1421 | ;; face implementation. | |
1422 | ||
1423 | (defun face-attr-construct (face &optional frame) | |
522fb950 | 1424 | "Return a `defface'-style attribute list for FACE on FRAME. |
5f5c8ee5 GM |
1425 | Value is a property list of pairs ATTRIBUTE VALUE for all specified |
1426 | face attributes of FACE where ATTRIBUTE is the attribute name and | |
1427 | VALUE is the specified value of that attribute." | |
1428 | (let (result) | |
1429 | (dolist (entry face-attribute-name-alist result) | |
1430 | (let* ((attribute (car entry)) | |
1431 | (value (face-attribute face attribute))) | |
1432 | (unless (eq value 'unspecified) | |
1433 | (setq result (nconc (list attribute value) result))))))) | |
00f51890 | 1434 | |
5f5c8ee5 GM |
1435 | |
1436 | (defun face-spec-set-match-display (display frame) | |
1437 | "Non-nil if DISPLAY matches FRAME. | |
1438 | DISPLAY is part of a spec such as can be used in `defface'. | |
1439 | If FRAME is nil, the current FRAME is used." | |
1440 | (let* ((conjuncts display) | |
1441 | conjunct req options | |
1442 | ;; t means we have succeeded against all the conjuncts in | |
1443 | ;; DISPLAY that have been tested so far. | |
1444 | (match t)) | |
1445 | (if (eq conjuncts t) | |
1446 | (setq conjuncts nil)) | |
1447 | (while (and conjuncts match) | |
1448 | (setq conjunct (car conjuncts) | |
1449 | conjuncts (cdr conjuncts) | |
1450 | req (car conjunct) | |
1451 | options (cdr conjunct) | |
1452 | match (cond ((eq req 'type) | |
428a555e | 1453 | (or (memq (window-system frame) options) |
1695ca2b EZ |
1454 | ;; FIXME: This should be revisited to use |
1455 | ;; display-graphic-p, provided that the | |
1456 | ;; color selection depends on the number | |
1457 | ;; of supported colors, and all defface's | |
1458 | ;; are changed to look at number of colors | |
1459 | ;; instead of (type graphic) etc. | |
428a555e | 1460 | (and (null (window-system frame)) |
1695ca2b | 1461 | (memq 'tty options)) |
ee716db5 GM |
1462 | (and (memq 'motif options) |
1463 | (featurep 'motif)) | |
9b44aa8b JD |
1464 | (and (memq 'gtk options) |
1465 | (featurep 'gtk)) | |
ee716db5 GM |
1466 | (and (memq 'lucid options) |
1467 | (featurep 'x-toolkit) | |
9b44aa8b JD |
1468 | (not (featurep 'motif)) |
1469 | (not (featurep 'gtk))) | |
ee716db5 GM |
1470 | (and (memq 'x-toolkit options) |
1471 | (featurep 'x-toolkit)))) | |
6b61353c KH |
1472 | ((eq req 'min-colors) |
1473 | (>= (display-color-cells frame) (car options))) | |
5f5c8ee5 GM |
1474 | ((eq req 'class) |
1475 | (memq (frame-parameter frame 'display-type) options)) | |
1476 | ((eq req 'background) | |
1477 | (memq (frame-parameter frame 'background-mode) | |
1478 | options)) | |
16320ac7 MB |
1479 | ((eq req 'supports) |
1480 | (display-supports-face-attributes-p options frame)) | |
70d0c3b0 | 1481 | (t (error "Unknown req `%S' with options `%S'" |
5f5c8ee5 GM |
1482 | req options))))) |
1483 | match)) | |
1484 | ||
1485 | ||
1486 | (defun face-spec-choose (spec &optional frame) | |
96c2938f MB |
1487 | "Choose the proper attributes for FRAME, out of SPEC. |
1488 | If SPEC is nil, return nil." | |
5f5c8ee5 GM |
1489 | (unless frame |
1490 | (setq frame (selected-frame))) | |
1491 | (let ((tail spec) | |
cf459bb7 | 1492 | result defaults) |
5f5c8ee5 | 1493 | (while tail |
073f69e6 MB |
1494 | (let* ((entry (pop tail)) |
1495 | (display (car entry)) | |
cf459bb7 RS |
1496 | (attrs (cdr entry)) |
1497 | thisval) | |
1498 | ;; Get the attributes as actually specified by this alternative. | |
1499 | (setq thisval | |
1500 | (if (null (cdr attrs)) ;; was (listp (car attrs)) | |
1501 | ;; Old-style entry, the attribute list is the | |
1502 | ;; first element. | |
1503 | (car attrs) | |
1504 | attrs)) | |
1505 | ||
1506 | ;; If the condition is `default', that sets the default | |
1507 | ;; for following conditions. | |
1508 | (if (eq display 'default) | |
1509 | (setq defaults thisval) | |
1510 | ;; Otherwise, if it matches, use it. | |
1511 | (when (face-spec-set-match-display display frame) | |
1512 | (setq result thisval) | |
b6b90dfc | 1513 | (setq tail nil))))) |
cf459bb7 | 1514 | (if defaults (append result defaults) result))) |
5f5c8ee5 GM |
1515 | |
1516 | ||
1517 | (defun face-spec-reset-face (face &optional frame) | |
1518 | "Reset all attributes of FACE on FRAME to unspecified." | |
bfe27647 | 1519 | (let ((attrs face-attribute-name-alist)) |
5f5c8ee5 GM |
1520 | (while attrs |
1521 | (let ((attr-and-name (car attrs))) | |
bfe27647 GM |
1522 | (set-face-attribute face frame (car attr-and-name) 'unspecified)) |
1523 | (setq attrs (cdr attrs))))) | |
5f5c8ee5 GM |
1524 | |
1525 | ||
24837f13 | 1526 | (defun face-spec-set (face spec &optional for-defface) |
a1792b9b | 1527 | "Set FACE's face spec, which controls its appearance, to SPEC. |
24837f13 RS |
1528 | If FOR-DEFFACE is t, set the base spec, the one that `defface' |
1529 | and Custom set. (In that case, the caller must put it in the | |
1530 | appropriate property, because that depends on the caller.) | |
1531 | If FOR-DEFFACE is nil, set the overriding spec (and store it | |
1532 | in the `face-override-spec' property of FACE). | |
1533 | ||
1534 | The appearance of FACE is controlled by the base spec, | |
1535 | by any custom theme specs on top of that, and by the | |
a1792b9b | 1536 | overriding spec on top of all the rest. |
24837f13 RS |
1537 | |
1538 | FOR-DEFFACE can also be a frame, in which case we set the | |
1539 | frame-specific attributes of FACE for that frame based on SPEC. | |
1540 | That usage is deprecated. | |
1541 | ||
1542 | See `defface' for information about the format and meaning of SPEC." | |
1543 | (if (framep for-defface) | |
1544 | ;; Handle the deprecated case where third arg is a frame. | |
1545 | (face-spec-set-2 face for-defface spec) | |
1546 | (if for-defface | |
1547 | ;; When we reset the face based on its custom spec, then it is | |
1548 | ;; unmodified as far as Custom is concerned. | |
1549 | (put (or (get face 'face-alias) face) 'face-modified nil) | |
1550 | ;; When we change a face based on a spec from outside custom, | |
1551 | ;; record it for future frames. | |
1552 | (put (or (get face 'face-alias) face) 'face-override-spec spec)) | |
1553 | ;;; RMS 29 dec 2007: Perhaps this code should be reinstated. | |
1554 | ;;; That depends on whether the overriding spec | |
1555 | ;;; or the default face attributes | |
1556 | ;;; should take priority. | |
1557 | ;;; ;; Clear all the new-frame default attributes for this face. | |
26c07a69 RS |
1558 | ;;; ;; face-spec-reset-face won't do it right. |
1559 | ;;; (let ((facevec (cdr (assq face face-new-frame-defaults)))) | |
1560 | ;;; (dotimes (i (length facevec)) | |
1561 | ;;; (unless (= i 0) | |
1562 | ;;; (aset facevec i 'unspecified)))) | |
24837f13 | 1563 | ;; Reset each frame according to the rules implied by all its specs. |
01d2eac8 | 1564 | (dolist (frame (frame-list)) |
24837f13 RS |
1565 | (face-spec-recalc face frame)))) |
1566 | ||
1567 | (defun face-spec-recalc (face frame) | |
1568 | "Reset the face attributes of FACE on FRAME according to its specs. | |
1569 | This applies the defface/custom spec first, then the custom theme specs, | |
1570 | then the override spec." | |
1571 | (face-spec-reset-face face frame) | |
1572 | (let ((face-sym (or (get face 'face-alias) face))) | |
1573 | (face-spec-set-2 face frame | |
1574 | (face-user-default-spec face)) | |
1575 | (let ((theme-faces (reverse (get face-sym 'theme-face)))) | |
1576 | (dolist (spec theme-faces) | |
1577 | (face-spec-set-2 face frame (cadr spec)))) | |
1578 | (face-spec-set-2 face frame (get face-sym 'face-override-spec)))) | |
1579 | ||
1580 | (defun face-spec-set-2 (face frame spec) | |
1581 | "Set the face attributes of FACE on FRAME according to SPEC." | |
1582 | (let* ((attrs (face-spec-choose spec frame))) | |
1583 | (while attrs | |
1584 | (let ((attribute (car attrs)) | |
1585 | (value (car (cdr attrs)))) | |
1586 | ;; Support some old-style attribute names and values. | |
1587 | (case attribute | |
1588 | (:bold (setq attribute :weight value (if value 'bold 'normal))) | |
1589 | (:italic (setq attribute :slant value (if value 'italic 'normal))) | |
1590 | ((:foreground :background) | |
1591 | ;; Compatibility with 20.x. Some bogus face specs seem to | |
1592 | ;; exist containing things like `:foreground nil'. | |
1593 | (if (null value) (setq value 'unspecified))) | |
1594 | (t (unless (assq attribute face-x-resources) | |
1595 | (setq attribute nil)))) | |
1596 | (when attribute | |
1597 | (set-face-attribute face frame attribute value))) | |
1598 | (setq attrs (cdr (cdr attrs)))))) | |
5f5c8ee5 GM |
1599 | |
1600 | (defun face-attr-match-p (face attrs &optional frame) | |
a9de7d29 | 1601 | "Return t if attributes of FACE match values in plist ATTRS. |
5f5c8ee5 GM |
1602 | Optional parameter FRAME is the frame whose definition of FACE |
1603 | is used. If nil or omitted, use the selected frame." | |
1604 | (unless frame | |
1605 | (setq frame (selected-frame))) | |
1606 | (let ((list face-attribute-name-alist) | |
1607 | (match t)) | |
1608 | (while (and match (not (null list))) | |
1609 | (let* ((attr (car (car list))) | |
a9de7d29 MB |
1610 | (specified-value |
1611 | (if (plist-member attrs attr) | |
1612 | (plist-get attrs attr) | |
1613 | 'unspecified)) | |
5f5c8ee5 | 1614 | (value-now (face-attribute face attr frame))) |
a9de7d29 | 1615 | (setq match (equal specified-value value-now)) |
5f5c8ee5 GM |
1616 | (setq list (cdr list)))) |
1617 | match)) | |
1618 | ||
5f5c8ee5 GM |
1619 | (defun face-spec-match-p (face spec &optional frame) |
1620 | "Return t if FACE, on FRAME, matches what SPEC says it should look like." | |
1621 | (face-attr-match-p face (face-spec-choose spec frame) frame)) | |
1622 | ||
94fe8a31 | 1623 | (defsubst face-default-spec (face) |
96c2938f MB |
1624 | "Return the default face-spec for FACE, ignoring any user customization. |
1625 | If there is no default for FACE, return nil." | |
1626 | (get face 'face-defface-spec)) | |
5f5c8ee5 | 1627 | |
94fe8a31 MB |
1628 | (defsubst face-user-default-spec (face) |
1629 | "Return the user's customized face-spec for FACE, or the default if none. | |
7cd512f2 | 1630 | If there is neither a user setting nor a default for FACE, return nil." |
e44d251c JL |
1631 | (or (get face 'customized-face) |
1632 | (get face 'saved-face) | |
94fe8a31 MB |
1633 | (face-default-spec face))) |
1634 | ||
5f5c8ee5 | 1635 | \f |
f795f633 EZ |
1636 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1637 | ;;; Frame-type independent color support. | |
1638 | ;;; We keep the old x-* names as aliases for back-compatibility. | |
1639 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1640 | ||
1641 | (defun defined-colors (&optional frame) | |
1642 | "Return a list of colors supported for a particular frame. | |
1643 | The argument FRAME specifies which frame to try. | |
1644 | The value may be different for frames on different display types. | |
43c58260 RS |
1645 | If FRAME doesn't support colors, the value is nil. |
1646 | If FRAME is nil, that stands for the selected frame." | |
1a578e9b | 1647 | (if (memq (framep (or frame (selected-frame))) '(x w32 mac)) |
f795f633 | 1648 | (xw-defined-colors frame) |
37462f4c | 1649 | (mapcar 'car (tty-color-alist frame)))) |
f795f633 EZ |
1650 | (defalias 'x-defined-colors 'defined-colors) |
1651 | ||
1652 | (defun color-defined-p (color &optional frame) | |
1653 | "Return non-nil if color COLOR is supported on frame FRAME. | |
1654 | If FRAME is omitted or nil, use the selected frame. | |
293b4814 EZ |
1655 | If COLOR is the symbol `unspecified' or one of the strings |
1656 | \"unspecified-fg\" or \"unspecified-bg\", the value is nil." | |
1e221c16 | 1657 | (if (member color '(unspecified "unspecified-bg" "unspecified-fg")) |
f795f633 | 1658 | nil |
1a578e9b | 1659 | (if (member (framep (or frame (selected-frame))) '(x w32 mac)) |
f795f633 | 1660 | (xw-color-defined-p color frame) |
37462f4c | 1661 | (numberp (tty-color-translate color frame))))) |
f795f633 EZ |
1662 | (defalias 'x-color-defined-p 'color-defined-p) |
1663 | ||
1664 | (defun color-values (color &optional frame) | |
1665 | "Return a description of the color named COLOR on frame FRAME. | |
22bbca61 JB |
1666 | The value is a list of integer RGB values--(RED GREEN BLUE). |
1667 | These values appear to range from 0 to 65280 or 65535, depending | |
1668 | on the system; white is \(65280 65280 65280\) or \(65535 65535 65535\). | |
f795f633 EZ |
1669 | If FRAME is omitted or nil, use the selected frame. |
1670 | If FRAME cannot display COLOR, the value is nil. | |
293b4814 EZ |
1671 | If COLOR is the symbol `unspecified' or one of the strings |
1672 | \"unspecified-fg\" or \"unspecified-bg\", the value is nil." | |
1e221c16 | 1673 | (if (member color '(unspecified "unspecified-fg" "unspecified-bg")) |
f795f633 | 1674 | nil |
1a578e9b | 1675 | (if (memq (framep (or frame (selected-frame))) '(x w32 mac)) |
f795f633 EZ |
1676 | (xw-color-values color frame) |
1677 | (tty-color-values color frame)))) | |
1678 | (defalias 'x-color-values 'color-values) | |
1679 | ||
1680 | (defun display-color-p (&optional display) | |
1681 | "Return t if DISPLAY supports color. | |
1682 | The optional argument DISPLAY specifies which display to ask about. | |
1683 | DISPLAY should be either a frame or a display name (a string). | |
1684 | If omitted or nil, that stands for the selected frame's display." | |
1a578e9b | 1685 | (if (memq (framep-on-display display) '(x w32 mac)) |
d5179a01 EZ |
1686 | (xw-display-color-p display) |
1687 | (tty-display-color-p display))) | |
f795f633 EZ |
1688 | (defalias 'x-display-color-p 'display-color-p) |
1689 | ||
d5179a01 EZ |
1690 | (defun display-grayscale-p (&optional display) |
1691 | "Return non-nil if frames on DISPLAY can display shades of gray." | |
1692 | (let ((frame-type (framep-on-display display))) | |
1693 | (cond | |
1694 | ((memq frame-type '(x w32 mac)) | |
1695 | (x-display-grayscale-p display)) | |
1696 | (t | |
1697 | (> (tty-color-gray-shades display) 2))))) | |
1698 | ||
26c07a69 RS |
1699 | (defun read-color (&optional prompt convert-to-RGB-p allow-empty-name-p msg-p) |
1700 | "Read a color name or RGB hex value: #RRRRGGGGBBBB. | |
1701 | Completion is available for color names, but not for RGB hex strings. | |
1702 | If the user inputs an RGB hex string, it must have the form | |
1703 | #XXXXXXXXXXXX or XXXXXXXXXXXX, where each X is a hex digit. The | |
1704 | number of Xs must be a multiple of 3, with the same number of Xs for | |
1705 | each of red, green, and blue. The order is red, green, blue. | |
1706 | ||
1707 | In addition to standard color names and RGB hex values, the following | |
1708 | are available as color candidates. In each case, the corresponding | |
1709 | color is used. | |
1710 | ||
1711 | * `foreground at point' - foreground under the cursor | |
1712 | * `background at point' - background under the cursor | |
1713 | ||
1714 | Checks input to be sure it represents a valid color. If not, raises | |
1715 | an error (but see exception for empty input with non-nil | |
1716 | ALLOW-EMPTY-NAME-P). | |
1717 | ||
1718 | Optional arg PROMPT is the prompt; if nil, uses a default prompt. | |
1719 | ||
1720 | Interactively, or with optional arg CONVERT-TO-RGB-P non-nil, converts | |
1721 | an input color name to an RGB hex string. Returns the RGB hex string. | |
1722 | ||
1723 | Optional arg ALLOW-EMPTY-NAME-P controls what happens if the user | |
1724 | enters an empty color name (that is, just hits `RET'). If non-nil, | |
1725 | then returns an empty color name, \"\". If nil, then raises an error. | |
1726 | Programs must test for \"\" if ALLOW-EMPTY-NAME-P is non-nil. They | |
1727 | can then perform an appropriate action in case of empty input. | |
1728 | ||
1729 | Interactively, or with optional arg MSG-P non-nil, echoes the color in | |
1730 | a message." | |
1731 | (interactive "i\np\ni\np") ; Always convert to RGB interactively. | |
1732 | (let* ((completion-ignore-case t) | |
1733 | (colors (append '("foreground at point" "background at point") | |
1734 | (defined-colors))) | |
1735 | (color (completing-read (or prompt "Color (name or #R+G+B+): ") | |
1736 | colors)) | |
1737 | hex-string) | |
1738 | (cond ((string= "foreground at point" color) | |
1739 | (setq color (foreground-color-at-point))) | |
1740 | ((string= "background at point" color) | |
1741 | (setq color (background-color-at-point)))) | |
1742 | (unless color | |
1743 | (setq color "")) | |
1744 | (setq hex-string | |
1745 | (string-match "^#?\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color)) | |
1746 | (if (and allow-empty-name-p (string= "" color)) | |
1747 | "" | |
1748 | (when (and hex-string (not (eq (aref color 0) ?#))) | |
1749 | (setq color (concat "#" color))) ; No #; add it. | |
1750 | (unless hex-string | |
1751 | (when (or (string= "" color) (not (test-completion color colors))) | |
1752 | (error "No such color: %S" color)) | |
1753 | (when convert-to-RGB-p | |
1754 | (let ((components (x-color-values color))) | |
1755 | (unless components (error "No such color: %S" color)) | |
1756 | (unless (string-match "^#\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color) | |
1757 | (setq color (format "#%04X%04X%04X" | |
1758 | (logand 65535 (nth 0 components)) | |
1759 | (logand 65535 (nth 1 components)) | |
1760 | (logand 65535 (nth 2 components)))))))) | |
1761 | (when msg-p (message "Color: `%s'" color)) | |
1762 | color))) | |
1763 | ||
1764 | ;; Commented out because I decided it is better to include the | |
1765 | ;; duplicates in read-color's completion list. | |
1766 | ||
1767 | ;; (defun defined-colors-without-duplicates () | |
1768 | ;; "Return the list of defined colors, without the no-space versions. | |
1769 | ;; For each color name, we keep the variant that DOES have spaces." | |
1770 | ;; (let ((result (copy-sequence (defined-colors))) | |
1771 | ;; to-be-rejected) | |
1772 | ;; (save-match-data | |
1773 | ;; (dolist (this result) | |
1774 | ;; (if (string-match " " this) | |
986845af | 1775 | ;; (push (replace-regexp-in-string " " "" |
26c07a69 RS |
1776 | ;; this) |
1777 | ;; to-be-rejected))) | |
1778 | ;; (dolist (elt to-be-rejected) | |
1779 | ;; (let ((as-found (car (member-ignore-case elt result)))) | |
1780 | ;; (setq result (delete as-found result))))) | |
1781 | ;; result)) | |
1782 | ||
1783 | (defun face-at-point () | |
1784 | "Return the face of the character after point. | |
1785 | If it has more than one face, return the first one. | |
1786 | Return nil if it has no specified face." | |
1787 | (let* ((faceprop (or (get-char-property (point) 'read-face-name) | |
1788 | (get-char-property (point) 'face) | |
1789 | 'default)) | |
1790 | (face (cond ((symbolp faceprop) faceprop) | |
1791 | ;; List of faces (don't treat an attribute spec). | |
1792 | ;; Just use the first face. | |
1793 | ((and (consp faceprop) (not (keywordp (car faceprop))) | |
1794 | (not (memq (car faceprop) | |
1795 | '(foreground-color background-color)))) | |
1796 | (car faceprop)) | |
1797 | (t nil)))) ; Invalid face value. | |
1798 | (if (facep face) face nil))) | |
1799 | ||
1800 | (defun foreground-color-at-point () | |
1801 | "Return the foreground color of the character after point." | |
1802 | ;; `face-at-point' alone is not sufficient. It only gets named faces. | |
1803 | ;; Need also pick up any face properties that are not associated with named faces. | |
1804 | (let ((face (or (face-at-point) | |
1805 | (get-char-property (point) 'read-face-name) | |
1806 | (get-char-property (point) 'face)))) | |
1807 | (cond ((and face (symbolp face)) | |
1808 | (let ((value (face-foreground face nil 'default))) | |
1809 | (if (member value '("unspecified-fg" "unspecified-bg")) | |
1810 | nil | |
1811 | value))) | |
1812 | ((consp face) | |
1813 | (cond ((memq 'foreground-color face) (cdr (memq 'foreground-color face))) | |
1814 | ((memq ':foreground face) (cadr (memq ':foreground face))))) | |
1815 | (t nil)))) ; Invalid face value. | |
1816 | ||
1817 | (defun background-color-at-point () | |
1818 | "Return the background color of the character after point." | |
1819 | ;; `face-at-point' alone is not sufficient. It only gets named faces. | |
1820 | ;; Need also pick up any face properties that are not associated with named faces. | |
1821 | (let ((face (or (face-at-point) | |
1822 | (get-char-property (point) 'read-face-name) | |
1823 | (get-char-property (point) 'face)))) | |
1824 | (cond ((and face (symbolp face)) | |
1825 | (let ((value (face-background face nil 'default))) | |
1826 | (if (member value '("unspecified-fg" "unspecified-bg")) | |
1827 | nil | |
1828 | value))) | |
1829 | ((consp face) | |
1830 | (cond ((memq 'background-color face) (cdr (memq 'background-color face))) | |
1831 | ((memq ':background face) (cadr (memq ':background face))))) | |
1832 | (t nil)))) ; Invalid face value. | |
f795f633 | 1833 | \f |
5f5c8ee5 GM |
1834 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1835 | ;;; Background mode. | |
1836 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1837 | ||
1838 | (defcustom frame-background-mode nil | |
1839 | "*The brightness of the background. | |
e44d251c | 1840 | Set this to the symbol `dark' if your background color is dark, |
d4c6530f JL |
1841 | `light' if your background is light, or nil (automatic by default) |
1842 | if you want Emacs to examine the brightness for you. Don't set this | |
1843 | variable with `setq'; this won't have the expected effect." | |
5f5c8ee5 GM |
1844 | :group 'faces |
1845 | :set #'(lambda (var value) | |
c20d5073 | 1846 | (set-default var value) |
b5325e78 | 1847 | (mapc 'frame-set-background-mode (frame-list))) |
5f5c8ee5 | 1848 | :initialize 'custom-initialize-changed |
d4c6530f JL |
1849 | :type '(choice (const dark) |
1850 | (const light) | |
1851 | (const :tag "automatic" nil))) | |
5f5c8ee5 GM |
1852 | |
1853 | ||
1854 | (defun frame-set-background-mode (frame) | |
d8abcd91 MB |
1855 | "Set up display-dependent faces on FRAME. |
1856 | Display-dependent faces are those which have different definitions | |
1857 | according to the `background-mode' and `display-type' frame parameters." | |
5f5c8ee5 | 1858 | (let* ((bg-resource |
428a555e | 1859 | (and (window-system frame) |
30aa9e51 | 1860 | (x-get-resource "backgroundMode" "BackgroundMode"))) |
772139c0 | 1861 | (bg-color (frame-parameter frame 'background-color)) |
8cbd7bed KL |
1862 | (terminal-bg-mode (terminal-parameter frame 'background-mode)) |
1863 | (tty-type (tty-type frame)) | |
f161d539 MB |
1864 | (bg-mode |
1865 | (cond (frame-background-mode) | |
f161d539 MB |
1866 | (bg-resource |
1867 | (intern (downcase bg-resource))) | |
8cbd7bed | 1868 | (terminal-bg-mode) |
2666355c KL |
1869 | ((and (null (window-system frame)) |
1870 | ;; Unspecified frame background color can only | |
1871 | ;; happen on tty's. | |
1872 | (member bg-color '(nil unspecified "unspecified-bg"))) | |
1873 | ;; There is no way to determine the background mode | |
1874 | ;; automatically, so we make a guess based on the | |
1875 | ;; terminal type. | |
1876 | (if (and tty-type | |
1877 | (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)" | |
1878 | tty-type)) | |
1879 | 'light | |
1880 | 'dark)) | |
1e221c16 | 1881 | ((equal bg-color "unspecified-fg") ; inverted colors |
2666355c KL |
1882 | (if (and tty-type |
1883 | (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)" | |
1884 | tty-type)) | |
1885 | 'dark | |
1886 | 'light)) | |
ff52c940 | 1887 | ((>= (apply '+ (color-values bg-color frame)) |
f161d539 MB |
1888 | ;; Just looking at the screen, colors whose |
1889 | ;; values add up to .6 of the white total | |
1890 | ;; still look dark to me. | |
ff52c940 | 1891 | (* (apply '+ (color-values "white" frame)) .6)) |
772139c0 EZ |
1892 | 'light) |
1893 | (t 'dark))) | |
f161d539 | 1894 | (display-type |
428a555e | 1895 | (cond ((null (window-system frame)) |
f161d539 | 1896 | (if (tty-display-color-p frame) 'color 'mono)) |
ff52c940 | 1897 | ((display-color-p frame) |
f161d539 MB |
1898 | 'color) |
1899 | ((x-display-grayscale-p frame) | |
1900 | 'grayscale) | |
1901 | (t 'mono))) | |
1902 | (old-bg-mode | |
1903 | (frame-parameter frame 'background-mode)) | |
1904 | (old-display-type | |
1905 | (frame-parameter frame 'display-type))) | |
1906 | ||
1907 | (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type)) | |
6e424019 MB |
1908 | (let ((locally-modified-faces nil)) |
1909 | ;; Before modifying the frame parameters, we collect a list of | |
1910 | ;; faces that don't match what their face-spec says they should | |
24837f13 RS |
1911 | ;; look like; we then avoid changing these faces below. |
1912 | ;; These are the faces whose attributes were modified on FRAME. | |
1913 | ;; We use a negative list on the assumption that most faces will | |
6e424019 MB |
1914 | ;; be unmodified, so we can avoid consing in the common case. |
1915 | (dolist (face (face-list)) | |
24837f13 RS |
1916 | (and (not (get face 'face-override-spec)) |
1917 | (not (face-spec-match-p face | |
1918 | (face-user-default-spec face) | |
1919 | (selected-frame))) | |
1920 | (push face locally-modified-faces))) | |
6e424019 MB |
1921 | ;; Now change to the new frame parameters |
1922 | (modify-frame-parameters frame | |
1923 | (list (cons 'background-mode bg-mode) | |
1924 | (cons 'display-type display-type))) | |
1925 | ;; For all named faces, choose face specs matching the new frame | |
1926 | ;; parameters, unless they have been locally modified. | |
1927 | (dolist (face (face-list)) | |
1928 | (unless (memq face locally-modified-faces) | |
24837f13 | 1929 | (face-spec-recalc face frame))))))) |
5f5c8ee5 | 1930 | |
5f5c8ee5 GM |
1931 | \f |
1932 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1933 | ;;; Frame creation. | |
1934 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1935 | ||
1936 | (defun x-handle-named-frame-geometry (parameters) | |
1937 | "Add geometry parameters for a named frame to parameter list PARAMETERS. | |
1938 | Value is the new parameter list." | |
1939 | (let* ((name (or (cdr (assq 'name parameters)) | |
1940 | (cdr (assq 'name default-frame-alist)))) | |
1941 | (x-resource-name name) | |
1942 | (res-geometry (if name (x-get-resource "geometry" "Geometry")))) | |
1943 | (when res-geometry | |
1944 | (let ((parsed (x-parse-geometry res-geometry))) | |
1945 | ;; If the resource specifies a position, call the position | |
1946 | ;; and size "user-specified". | |
1947 | (when (or (assq 'top parsed) | |
1948 | (assq 'left parsed)) | |
1949 | (setq parsed (append '((user-position . t) (user-size . t)) parsed))) | |
1950 | ;; Put the geometry parameters at the end. Copy | |
1951 | ;; default-frame-alist so that they go after it. | |
1952 | (setq parameters (append parameters default-frame-alist parsed)))) | |
1953 | parameters)) | |
1954 | ||
1955 | ||
1956 | (defun x-handle-reverse-video (frame parameters) | |
1957 | "Handle the reverse-video frame parameter and X resource. | |
1958 | `x-create-frame' does not handle this one." | |
1959 | (when (cdr (or (assq 'reverse parameters) | |
1960 | (assq 'reverse default-frame-alist) | |
1961 | (let ((resource (x-get-resource "reverseVideo" | |
1962 | "ReverseVideo"))) | |
1963 | (if resource | |
1964 | (cons nil (member (downcase resource) | |
1965 | '("on" "true"))))))) | |
1966 | (let* ((params (frame-parameters frame)) | |
1967 | (bg (cdr (assq 'foreground-color params))) | |
1968 | (fg (cdr (assq 'background-color params)))) | |
1969 | (modify-frame-parameters frame | |
1970 | (list (cons 'foreground-color fg) | |
1971 | (cons 'background-color bg))) | |
1972 | (if (equal bg (cdr (assq 'border-color params))) | |
1973 | (modify-frame-parameters frame | |
1974 | (list (cons 'border-color fg)))) | |
1975 | (if (equal bg (cdr (assq 'mouse-color params))) | |
1976 | (modify-frame-parameters frame | |
1977 | (list (cons 'mouse-color fg)))) | |
1978 | (if (equal bg (cdr (assq 'cursor-color params))) | |
1979 | (modify-frame-parameters frame | |
1980 | (list (cons 'cursor-color fg))))))) | |
1981 | ||
1982 | ||
1983 | (defun x-create-frame-with-faces (&optional parameters) | |
1984 | "Create a frame from optional frame parameters PARAMETERS. | |
1985 | Parameters not specified by PARAMETERS are taken from | |
1986 | `default-frame-alist'. If PARAMETERS specify a frame name, | |
1987 | handle X geometry resources for that name. If either PARAMETERS | |
1988 | or `default-frame-alist' contains a `reverse' parameter, or | |
1989 | the X resource ``reverseVideo'' is present, handle that. | |
1990 | Value is the new frame created." | |
1991 | (setq parameters (x-handle-named-frame-geometry parameters)) | |
1992 | (let ((visibility-spec (assq 'visibility parameters)) | |
7f19e125 | 1993 | (frame (x-create-frame `((visibility . nil) . ,parameters))) |
5f5c8ee5 GM |
1994 | success) |
1995 | (unwind-protect | |
1996 | (progn | |
2bb819d5 | 1997 | (x-setup-function-keys frame) |
5f5c8ee5 GM |
1998 | (x-handle-reverse-video frame parameters) |
1999 | (frame-set-background-mode frame) | |
448bcb40 | 2000 | (face-set-after-frame-default frame) |
095fe281 KL |
2001 | ;; Make sure the tool-bar is ready to be enabled. The |
2002 | ;; `tool-bar-lines' frame parameter will not take effect | |
2003 | ;; without this call. | |
2004 | (tool-bar-setup frame) | |
2005 | (if (null visibility-spec) | |
5f5c8ee5 GM |
2006 | (make-frame-visible frame) |
2007 | (modify-frame-parameters frame (list visibility-spec))) | |
2008 | (setq success t)) | |
2009 | (unless success | |
2010 | (delete-frame frame))) | |
2011 | frame)) | |
2012 | ||
5f5c8ee5 | 2013 | (defun face-set-after-frame-default (frame) |
f1cae29e GM |
2014 | "Set frame-local faces of FRAME from face specs and resources. |
2015 | Initialize colors of certain faces from frame parameters." | |
1df64254 RS |
2016 | (unless inhibit-face-set-after-frame-default |
2017 | (if (face-attribute 'default :font t) | |
2018 | (set-face-attribute 'default frame :font | |
2019 | (face-attribute 'default :font t)) | |
2020 | (set-face-attribute 'default frame :family | |
2021 | (face-attribute 'default :family t)) | |
2022 | (set-face-attribute 'default frame :height | |
2023 | (face-attribute 'default :height t)) | |
2024 | (set-face-attribute 'default frame :slant | |
2025 | (face-attribute 'default :slant t)) | |
2026 | (set-face-attribute 'default frame :weight | |
2027 | (face-attribute 'default :weight t)) | |
2028 | (set-face-attribute 'default frame :width | |
2029 | (face-attribute 'default :width t)))) | |
8db9c5ee CY |
2030 | ;; Find attributes that should be initialized from frame parameters. |
2031 | (let ((face-params '((foreground-color default :foreground) | |
2032 | (background-color default :background) | |
2033 | (border-color border :background) | |
2034 | (cursor-color cursor :background) | |
2035 | (scroll-bar-foreground scroll-bar :foreground) | |
2036 | (scroll-bar-background scroll-bar :background) | |
2037 | (mouse-color mouse :background))) | |
2038 | apply-params) | |
2039 | (dolist (param face-params) | |
2040 | (let* ((value (frame-parameter frame (nth 0 param))) | |
2041 | (face (nth 1 param)) | |
2042 | (attr (nth 2 param)) | |
2043 | (default-value (face-attribute face attr t))) | |
2044 | ;; Compile a list of face attributes to set, but don't set | |
2045 | ;; them yet. The call to make-face-x-resource-internal, | |
2046 | ;; below, can change frame parameters, and the final set of | |
2047 | ;; frame parameters should be the ones acquired at this step. | |
2048 | (if (eq default-value 'unspecified) | |
2049 | ;; The face spec does not specify a new-frame value for | |
2050 | ;; this attribute. Check if the existing frame parameter | |
2051 | ;; specifies it. | |
2052 | (if value | |
2053 | (push (list face frame attr value) apply-params)) | |
2054 | ;; The face spec specifies a value for this attribute, to be | |
2055 | ;; applied to the face on all new frames. | |
2056 | (push (list face frame attr default-value) apply-params)))) | |
2057 | ;; Initialize faces from face specs and X resources. The | |
2058 | ;; condition-case prevents invalid specs from causing frame | |
2059 | ;; creation to fail. | |
2060 | (dolist (face (delq 'default (face-list))) | |
2061 | (condition-case () | |
2062 | (progn | |
24837f13 | 2063 | (face-spec-recalc face frame) |
f65f7603 | 2064 | (if (memq (window-system frame) '(x w32 mac)) |
87a0fbbe | 2065 | (make-face-x-resource-internal face frame)) |
6aa2269d | 2066 | (internal-merge-in-global-face face frame)) |
8db9c5ee CY |
2067 | (error nil))) |
2068 | ;; Apply the attributes specified by frame parameters. This | |
2069 | ;; rewrites parameters changed by make-face-x-resource-internal | |
2070 | (dolist (param apply-params) | |
2071 | (apply 'set-face-attribute param)))) | |
5f5c8ee5 | 2072 | |
53990c84 EZ |
2073 | (defun tty-handle-reverse-video (frame parameters) |
2074 | "Handle the reverse-video frame parameter for terminal frames." | |
2075 | (when (cdr (or (assq 'reverse parameters) | |
2076 | (assq 'reverse default-frame-alist))) | |
53990c84 EZ |
2077 | (let* ((params (frame-parameters frame)) |
2078 | (bg (cdr (assq 'foreground-color params))) | |
2079 | (fg (cdr (assq 'background-color params)))) | |
2080 | (modify-frame-parameters frame | |
2081 | (list (cons 'foreground-color fg) | |
2082 | (cons 'background-color bg))) | |
2083 | (if (equal bg (cdr (assq 'mouse-color params))) | |
2084 | (modify-frame-parameters frame | |
2085 | (list (cons 'mouse-color fg)))) | |
2086 | (if (equal bg (cdr (assq 'cursor-color params))) | |
2087 | (modify-frame-parameters frame | |
2088 | (list (cons 'cursor-color fg))))))) | |
2089 | ||
5f5c8ee5 GM |
2090 | |
2091 | (defun tty-create-frame-with-faces (&optional parameters) | |
2092 | "Create a frame from optional frame parameters PARAMETERS. | |
2093 | Parameters not specified by PARAMETERS are taken from | |
2094 | `default-frame-alist'. If either PARAMETERS or `default-frame-alist' | |
2095 | contains a `reverse' parameter, handle that. Value is the new frame | |
2096 | created." | |
2097 | (let ((frame (make-terminal-frame parameters)) | |
2098 | success) | |
2099 | (unwind-protect | |
061e4e7f | 2100 | (with-selected-frame frame |
53990c84 | 2101 | (tty-handle-reverse-video frame (frame-parameters frame)) |
cd85984a | 2102 | |
8782c744 SM |
2103 | (unless (terminal-parameter frame 'terminal-initted) |
2104 | (set-terminal-parameter frame 'terminal-initted t) | |
2105 | (set-locale-environment nil frame) | |
2106 | (tty-run-terminal-initialization frame)) | |
5f5c8ee5 GM |
2107 | (frame-set-background-mode frame) |
2108 | (face-set-after-frame-default frame) | |
2109 | (setq success t)) | |
2110 | (unless success | |
2111 | (delete-frame frame))) | |
2112 | frame)) | |
465fceed | 2113 | |
b34c34da KL |
2114 | (defun tty-find-type (pred type) |
2115 | "Return the longest prefix of TYPE to which PRED returns non-nil. | |
2116 | TYPE should be a tty type name such as \"xterm-16color\". | |
2117 | ||
2118 | The function tries only those prefixes that are followed by a | |
2119 | dash or underscore in the original type name, like \"xterm\" in | |
2120 | the above example." | |
2121 | (let (hyphend) | |
2122 | (while (and type | |
2123 | (not (funcall pred type))) | |
2124 | ;; Strip off last hyphen and what follows, then try again | |
2125 | (setq type | |
2126 | (if (setq hyphend (string-match "[-_][^-_]+$" type)) | |
2127 | (substring type 0 hyphend) | |
2128 | nil)))) | |
2129 | type) | |
2130 | ||
8cbd7bed KL |
2131 | (defun tty-run-terminal-initialization (frame &optional type) |
2132 | "Run the special initialization code for the terminal type of FRAME. | |
2133 | The optional TYPE parameter may be used to override the autodetected | |
2134 | terminal type to a different value." | |
2135 | (setq type (or type (tty-type frame))) | |
cd85984a KL |
2136 | ;; Load library for our terminal type. |
2137 | ;; User init file can set term-file-prefix to nil to prevent this. | |
2138 | (with-selected-frame frame | |
8782c744 | 2139 | (unless (null term-file-prefix) |
b34c34da KL |
2140 | (let* (term-init-func) |
2141 | ;; First, load the terminal initialization file, if it is | |
2142 | ;; available and it hasn't been loaded already. | |
2143 | (tty-find-type #'(lambda (type) | |
2144 | (let ((file (locate-library (concat term-file-prefix type)))) | |
2145 | (and file | |
2146 | (or (assoc file load-history) | |
2147 | (load file t t))))) | |
8cbd7bed | 2148 | type) |
b34c34da KL |
2149 | ;; Next, try to find a matching initialization function, and call it. |
2150 | (tty-find-type #'(lambda (type) | |
2151 | (fboundp (setq term-init-func | |
2152 | (intern (concat "terminal-init-" type))))) | |
8cbd7bed | 2153 | type) |
567c8878 | 2154 | (when (fboundp term-init-func) |
b34c34da KL |
2155 | (funcall term-init-func)) |
2156 | (set-terminal-parameter frame 'terminal-initted term-init-func))))) | |
465fceed | 2157 | |
5f5c8ee5 GM |
2158 | ;; Called from C function init_display to initialize faces of the |
2159 | ;; dumped terminal frame on startup. | |
465fceed | 2160 | |
5f5c8ee5 GM |
2161 | (defun tty-set-up-initial-frame-faces () |
2162 | (let ((frame (selected-frame))) | |
2163 | (frame-set-background-mode frame) | |
2164 | (face-set-after-frame-default frame))) | |
00f51890 | 2165 | |
465fceed | 2166 | |
465fceed | 2167 | |
5f5c8ee5 GM |
2168 | \f |
2169 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
2170 | ;;; Compatiblity with 20.2 | |
2171 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
72418504 | 2172 | |
5f5c8ee5 | 2173 | ;; Update a frame's faces when we change its default font. |
465fceed | 2174 | |
e16e7eac | 2175 | (defalias 'frame-update-faces 'ignore "") |
4b22f844 | 2176 | (make-obsolete 'frame-update-faces "no longer necessary." "21.1") |
e8e4cda0 | 2177 | |
5f5c8ee5 GM |
2178 | ;; Update the colors of FACE, after FRAME's own colors have been |
2179 | ;; changed. | |
1bcb155c | 2180 | |
522fb950 JB |
2181 | (define-obsolete-function-alias 'frame-update-face-colors |
2182 | 'frame-set-background-mode "21.1") | |
d11fba25 | 2183 | |
bdda3754 | 2184 | \f |
5f5c8ee5 GM |
2185 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2186 | ;;; Standard faces. | |
2187 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
465fceed | 2188 | |
5f5c8ee5 GM |
2189 | (defgroup basic-faces nil |
2190 | "The standard faces of Emacs." | |
2191 | :group 'faces) | |
ef436392 | 2192 | |
bacbbe8f CY |
2193 | (defface default |
2194 | '((t nil)) ; If this were nil, face-defface-spec would not be set. | |
5f5c8ee5 GM |
2195 | "Basic default face." |
2196 | :group 'basic-faces) | |
465fceed | 2197 | |
51d44a36 JL |
2198 | (defface bold |
2199 | '((t :weight bold)) | |
2200 | "Basic bold face." | |
2201 | :group 'basic-faces) | |
2202 | ||
2203 | (defface italic | |
2204 | '((((supports :slant italic)) | |
2205 | :slant italic) | |
2206 | (((supports :underline t)) | |
2207 | :underline t) | |
2208 | (t | |
2209 | ;; default to italic, even it doesn't appear to be supported, | |
2210 | ;; because in some cases the display engine will do it's own | |
2211 | ;; workaround (to `dim' on ttys) | |
2212 | :slant italic)) | |
2213 | "Basic italic face." | |
2214 | :group 'basic-faces) | |
2215 | ||
2216 | (defface bold-italic | |
2217 | '((t :weight bold :slant italic)) | |
2218 | "Basic bold-italic face." | |
2219 | :group 'basic-faces) | |
2220 | ||
2221 | (defface underline | |
2222 | '((((supports :underline t)) | |
2223 | :underline t) | |
2224 | (((supports :weight bold)) | |
2225 | :weight bold) | |
2226 | (t :underline t)) | |
2227 | "Basic underlined face." | |
2228 | :group 'basic-faces) | |
2229 | ||
2230 | (defface fixed-pitch | |
2231 | '((t :family "courier")) | |
2232 | "The basic fixed-pitch face." | |
2233 | :group 'basic-faces) | |
2234 | ||
2235 | (defface variable-pitch | |
2236 | '((t :family "helv")) | |
2237 | "The basic variable-pitch face." | |
2238 | :group 'basic-faces) | |
2239 | ||
2240 | (defface shadow | |
2241 | '((((class color grayscale) (min-colors 88) (background light)) | |
2242 | :foreground "grey50") | |
2243 | (((class color grayscale) (min-colors 88) (background dark)) | |
2244 | :foreground "grey70") | |
2245 | (((class color) (min-colors 8) (background light)) | |
2246 | :foreground "green") | |
2247 | (((class color) (min-colors 8) (background dark)) | |
2248 | :foreground "yellow")) | |
2249 | "Basic face for shadowed text." | |
2250 | :group 'basic-faces | |
2251 | :version "22.1") | |
2252 | ||
59746720 JL |
2253 | (defface link |
2254 | '((((class color) (min-colors 88) (background light)) | |
2255 | :foreground "blue1" :underline t) | |
2256 | (((class color) (background light)) | |
2257 | :foreground "blue" :underline t) | |
2258 | (((class color) (min-colors 88) (background dark)) | |
2259 | :foreground "cyan1" :underline t) | |
2260 | (((class color) (background dark)) | |
2261 | :foreground "cyan" :underline t) | |
2262 | (t :inherit underline)) | |
2263 | "Basic face for unvisited links." | |
2264 | :group 'basic-faces | |
2265 | :version "22.1") | |
2266 | ||
2267 | (defface link-visited | |
2268 | '((default :inherit link) | |
2269 | (((class color) (background light)) :foreground "magenta4") | |
2270 | (((class color) (background dark)) :foreground "violet")) | |
2271 | "Basic face for visited links." | |
2272 | :group 'basic-faces | |
2273 | :version "22.1") | |
2274 | ||
51d44a36 JL |
2275 | (defface highlight |
2276 | '((((class color) (min-colors 88) (background light)) | |
2277 | :background "darkseagreen2") | |
2278 | (((class color) (min-colors 88) (background dark)) | |
2279 | :background "darkolivegreen") | |
2280 | (((class color) (min-colors 16) (background light)) | |
2281 | :background "darkseagreen2") | |
2282 | (((class color) (min-colors 16) (background dark)) | |
2283 | :background "darkolivegreen") | |
2284 | (((class color) (min-colors 8)) | |
2285 | :background "green" :foreground "black") | |
2286 | (t :inverse-video t)) | |
2287 | "Basic face for highlighting." | |
2288 | :group 'basic-faces) | |
2289 | ||
51d44a36 JL |
2290 | (defface region |
2291 | '((((class color) (min-colors 88) (background dark)) | |
2292 | :background "blue3") | |
2293 | (((class color) (min-colors 88) (background light)) | |
2294 | :background "lightgoldenrod2") | |
2295 | (((class color) (min-colors 16) (background dark)) | |
2296 | :background "blue3") | |
2297 | (((class color) (min-colors 16) (background light)) | |
2298 | :background "lightgoldenrod2") | |
2299 | (((class color) (min-colors 8)) | |
2300 | :background "blue" :foreground "white") | |
2301 | (((type tty) (class mono)) | |
2302 | :inverse-video t) | |
2303 | (t :background "gray")) | |
2304 | "Basic face for highlighting the region." | |
2305 | :version "21.1" | |
2306 | :group 'basic-faces) | |
2307 | ||
2308 | (defface secondary-selection | |
2309 | '((((class color) (min-colors 88) (background light)) | |
2310 | :background "yellow1") | |
2311 | (((class color) (min-colors 88) (background dark)) | |
2312 | :background "SkyBlue4") | |
2313 | (((class color) (min-colors 16) (background light)) | |
2314 | :background "yellow") | |
2315 | (((class color) (min-colors 16) (background dark)) | |
2316 | :background "SkyBlue4") | |
2317 | (((class color) (min-colors 8)) | |
2318 | :background "cyan" :foreground "black") | |
2319 | (t :inverse-video t)) | |
2320 | "Basic face for displaying the secondary selection." | |
2321 | :group 'basic-faces) | |
2322 | ||
2323 | (defface trailing-whitespace | |
2324 | '((((class color) (background light)) | |
2325 | :background "red1") | |
2326 | (((class color) (background dark)) | |
2327 | :background "red1") | |
2328 | (t :inverse-video t)) | |
2329 | "Basic face for highlighting trailing whitespace." | |
2330 | :version "21.1" | |
d4c6530f | 2331 | :group 'whitespace-faces ; like `show-trailing-whitespace' |
51d44a36 JL |
2332 | :group 'basic-faces) |
2333 | ||
2334 | (defface escape-glyph | |
2335 | '((((background dark)) :foreground "cyan") | |
2336 | ;; See the comment in minibuffer-prompt for | |
2337 | ;; the reason not to use blue on MS-DOS. | |
2338 | (((type pc)) :foreground "magenta") | |
2339 | ;; red4 is too dark, but some say blue is too loud. | |
2340 | ;; brown seems to work ok. -- rms. | |
2341 | (t :foreground "brown")) | |
1a77c985 | 2342 | "Face for characters displayed as sequences using `^' or `\\'." |
51d44a36 JL |
2343 | :group 'basic-faces |
2344 | :version "22.1") | |
2345 | ||
2346 | (defface nobreak-space | |
2347 | '((((class color) (min-colors 88)) :inherit escape-glyph :underline t) | |
2348 | (((class color) (min-colors 8)) :background "magenta") | |
2349 | (t :inverse-video t)) | |
2350 | "Face for displaying nobreak space." | |
2351 | :group 'basic-faces | |
2352 | :version "22.1") | |
72418504 | 2353 | |
97bca259 JL |
2354 | (defgroup mode-line-faces nil |
2355 | "Faces used in the mode line." | |
6d968826 | 2356 | :group 'mode-line |
97bca259 JL |
2357 | :group 'faces |
2358 | :version "22.1") | |
2359 | ||
3759f14b | 2360 | (defface mode-line |
11c2175c | 2361 | '((((class color) (min-colors 88)) |
b6b90dfc SM |
2362 | :box (:line-width -1 :style released-button) |
2363 | :background "grey75" :foreground "black") | |
5f5c8ee5 | 2364 | (t |
b6b90dfc | 2365 | :inverse-video t)) |
c5752dcb | 2366 | "Basic mode line face for selected window." |
a4391cf1 | 2367 | :version "21.1" |
97bca259 | 2368 | :group 'mode-line-faces |
5f5c8ee5 | 2369 | :group 'basic-faces) |
465fceed | 2370 | |
c5752dcb | 2371 | (defface mode-line-inactive |
cf459bb7 | 2372 | '((default |
b6b90dfc | 2373 | :inherit mode-line) |
11c2175c | 2374 | (((class color) (min-colors 88) (background light)) |
c5752dcb KS |
2375 | :weight light |
2376 | :box (:line-width -1 :color "grey75" :style nil) | |
2377 | :foreground "grey20" :background "grey90") | |
11c2175c | 2378 | (((class color) (min-colors 88) (background dark) ) |
53a2f6e1 MB |
2379 | :weight light |
2380 | :box (:line-width -1 :color "grey40" :style nil) | |
b6b90dfc | 2381 | :foreground "grey80" :background "grey30")) |
c5752dcb | 2382 | "Basic mode line face for non-selected windows." |
bf247b6e | 2383 | :version "22.1" |
97bca259 JL |
2384 | :group 'mode-line-faces |
2385 | :group 'basic-faces) | |
2386 | ||
2387 | (defface mode-line-highlight | |
2388 | '((((class color) (min-colors 88)) | |
2389 | :box (:line-width 2 :color "grey40" :style released-button)) | |
2390 | (t | |
2391 | :inherit highlight)) | |
2392 | "Basic mode line face for highlighting." | |
2393 | :version "22.1" | |
2394 | :group 'mode-line-faces | |
2395 | :group 'basic-faces) | |
2396 | ||
313e2fc4 GM |
2397 | (defface mode-line-emphasis |
2398 | '((t (:weight bold))) | |
2399 | "Face used to emphasize certain mode line features. | |
2400 | Use the face `mode-line-highlight' for features that can be selected." | |
2401 | :version "23.1" | |
2402 | :group 'mode-line-faces | |
2403 | :group 'basic-faces) | |
2404 | ||
97bca259 JL |
2405 | (defface mode-line-buffer-id |
2406 | '((t (:weight bold))) | |
2407 | "Face used for buffer identification parts of the mode line." | |
2408 | :version "22.1" | |
2409 | :group 'mode-line-faces | |
c5752dcb KS |
2410 | :group 'basic-faces) |
2411 | ||
3759f14b GM |
2412 | ;; Make `modeline' an alias for `mode-line', for compatibility. |
2413 | (put 'modeline 'face-alias 'mode-line) | |
c5752dcb | 2414 | (put 'modeline-inactive 'face-alias 'mode-line-inactive) |
e0dcaa3f | 2415 | (put 'modeline-highlight 'face-alias 'mode-line-highlight) |
97bca259 | 2416 | (put 'modeline-buffer-id 'face-alias 'mode-line-buffer-id) |
d11fba25 | 2417 | |
e5e7779f | 2418 | (defface header-line |
cf459bb7 | 2419 | '((default |
6b61353c KH |
2420 | :inherit mode-line) |
2421 | (((type tty)) | |
1cb4393e MB |
2422 | ;; This used to be `:inverse-video t', but that doesn't look very |
2423 | ;; good when combined with inverse-video mode-lines and multiple | |
2424 | ;; windows. Underlining looks better, and is more consistent with | |
2425 | ;; the window-system face variants, which deemphasize the | |
2426 | ;; header-line in relation to the mode-line face. If a terminal | |
2427 | ;; can't underline, then the header-line will end up without any | |
2428 | ;; highlighting; this may be too confusing in general, although it | |
2429 | ;; happens to look good with the only current use of header-lines, | |
2430 | ;; the info browser. XXX | |
6b61353c | 2431 | :inverse-video nil ;Override the value inherited from mode-line. |
a7ac92b6 | 2432 | :underline t) |
98490598 | 2433 | (((class color grayscale) (background light)) |
bdab1d43 | 2434 | :background "grey90" :foreground "grey20" |
6b61353c | 2435 | :box nil) |
98490598 | 2436 | (((class color grayscale) (background dark)) |
bdab1d43 | 2437 | :background "grey20" :foreground "grey90" |
6b61353c | 2438 | :box nil) |
98490598 | 2439 | (((class mono) (background light)) |
bdab1d43 MB |
2440 | :background "white" :foreground "black" |
2441 | :inverse-video nil | |
2442 | :box nil | |
6b61353c | 2443 | :underline t) |
98490598 | 2444 | (((class mono) (background dark)) |
bdab1d43 MB |
2445 | :background "black" :foreground "white" |
2446 | :inverse-video nil | |
2447 | :box nil | |
6b61353c | 2448 | :underline t)) |
e5e7779f | 2449 | "Basic header-line face." |
a4391cf1 | 2450 | :version "21.1" |
5f5c8ee5 | 2451 | :group 'basic-faces) |
e8e4cda0 | 2452 | |
51d44a36 JL |
2453 | (defface vertical-border |
2454 | '((((type tty)) :inherit mode-line-inactive)) | |
2455 | "Face used for vertical window dividers on ttys." | |
2456 | :version "22.1" | |
5f5c8ee5 | 2457 | :group 'basic-faces) |
d11fba25 | 2458 | |
9ed779e8 JL |
2459 | (defface minibuffer-prompt |
2460 | '((((background dark)) :foreground "cyan") | |
2461 | ;; Don't use blue because many users of the MS-DOS port customize | |
2462 | ;; their foreground color to be blue. | |
2463 | (((type pc)) :foreground "magenta") | |
c57a1dc6 | 2464 | (t :foreground "medium blue")) |
9ed779e8 JL |
2465 | "Face for minibuffer prompts. |
2466 | By default, Emacs automatically adds this face to the value of | |
2467 | `minibuffer-prompt-properties', which is a list of text properties | |
2468 | used to display the prompt text." | |
bf247b6e | 2469 | :version "22.1" |
31cf46d3 RS |
2470 | :group 'basic-faces) |
2471 | ||
2472 | (setq minibuffer-prompt-properties | |
2473 | (append minibuffer-prompt-properties (list 'face 'minibuffer-prompt))) | |
2474 | ||
f1cae29e | 2475 | (defface fringe |
d6d59057 | 2476 | '((((class color) (background light)) |
b6b90dfc SM |
2477 | :background "grey95") |
2478 | (((class color) (background dark)) | |
2479 | :background "grey10") | |
2480 | (t | |
2481 | :background "gray")) | |
f1cae29e GM |
2482 | "Basic face for the fringes to the left and right of windows under X." |
2483 | :version "21.1" | |
84fe35f0 | 2484 | :group 'frames |
f1cae29e GM |
2485 | :group 'basic-faces) |
2486 | ||
d390b4d2 | 2487 | (defface scroll-bar '((t nil)) |
f1cae29e GM |
2488 | "Basic face for the scroll bar colors under X." |
2489 | :version "21.1" | |
84fe35f0 | 2490 | :group 'frames |
f1cae29e GM |
2491 | :group 'basic-faces) |
2492 | ||
d390b4d2 | 2493 | (defface border '((t nil)) |
f1cae29e GM |
2494 | "Basic face for the frame border under X." |
2495 | :version "21.1" | |
84fe35f0 | 2496 | :group 'frames |
f1cae29e GM |
2497 | :group 'basic-faces) |
2498 | ||
d390b4d2 | 2499 | (defface cursor '((t nil)) |
8d413c2b KS |
2500 | "Basic face for the cursor color under X. |
2501 | Note: Other faces cannot inherit from the cursor face." | |
f1cae29e | 2502 | :version "21.1" |
84fe35f0 | 2503 | :group 'cursor |
f1cae29e GM |
2504 | :group 'basic-faces) |
2505 | ||
8d413c2b | 2506 | (put 'cursor 'face-no-inherit t) |
f1cae29e | 2507 | |
d390b4d2 | 2508 | (defface mouse '((t nil)) |
f1cae29e | 2509 | "Basic face for the mouse color under X." |
e59176e2 | 2510 | :version "21.1" |
84fe35f0 | 2511 | :group 'mouse |
5f5c8ee5 | 2512 | :group 'basic-faces) |
bdda3754 | 2513 | |
51d44a36 JL |
2514 | (defface tool-bar |
2515 | '((default | |
2516 | :box (:line-width 1 :style released-button) | |
2517 | :foreground "black") | |
2518 | (((type x w32 mac) (class color)) | |
2519 | :background "grey75") | |
2520 | (((type x) (class mono)) | |
2521 | :background "grey")) | |
2522 | "Basic tool-bar face." | |
2523 | :version "21.1" | |
5f5c8ee5 | 2524 | :group 'basic-faces) |
bdda3754 | 2525 | |
51d44a36 JL |
2526 | (defface menu |
2527 | '((((type tty)) | |
2528 | :inverse-video t) | |
2529 | (((type x-toolkit)) | |
2530 | ) | |
16320ac7 | 2531 | (t |
51d44a36 JL |
2532 | :inverse-video t)) |
2533 | "Basic face for the font and colors of the menu bar and popup menus." | |
a4391cf1 | 2534 | :version "21.1" |
51d44a36 | 2535 | :group 'menu |
a4391cf1 | 2536 | :group 'basic-faces) |
465fceed | 2537 | |
465fceed | 2538 | \f |
5f5c8ee5 GM |
2539 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2540 | ;;; Manipulating font names. | |
2541 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
2542 | ||
2543 | ;; This is here for compatibilty with Emacs 20.2. For example, | |
07f27947 DL |
2544 | ;; international/fontset.el uses x-resolve-font-name. The following |
2545 | ;; functions are not used in the face implementation itself. | |
465fceed | 2546 | |
d7fa5aa2 RS |
2547 | (defvar x-font-regexp nil) |
2548 | (defvar x-font-regexp-head nil) | |
2549 | (defvar x-font-regexp-weight nil) | |
2550 | (defvar x-font-regexp-slant nil) | |
465fceed | 2551 | |
021ca129 KH |
2552 | (defconst x-font-regexp-weight-subnum 1) |
2553 | (defconst x-font-regexp-slant-subnum 2) | |
2554 | (defconst x-font-regexp-swidth-subnum 3) | |
2555 | (defconst x-font-regexp-adstyle-subnum 4) | |
2556 | ||
465fceed ER |
2557 | ;;; Regexps matching font names in "Host Portable Character Representation." |
2558 | ;;; | |
2559 | (let ((- "[-?]") | |
2560 | (foundry "[^-]+") | |
2561 | (family "[^-]+") | |
2562 | (weight "\\(bold\\|demibold\\|medium\\)") ; 1 | |
2563 | ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1 | |
2564 | (weight\? "\\([^-]*\\)") ; 1 | |
2565 | (slant "\\([ior]\\)") ; 2 | |
2566 | ; (slant\? "\\([ior?*]?\\)") ; 2 | |
2567 | (slant\? "\\([^-]?\\)") ; 2 | |
2568 | ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3 | |
2569 | (swidth "\\([^-]*\\)") ; 3 | |
2570 | ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4 | |
c8787b81 | 2571 | (adstyle "\\([^-]*\\)") ; 4 |
465fceed ER |
2572 | (pixelsize "[0-9]+") |
2573 | (pointsize "[0-9][0-9]+") | |
2574 | (resx "[0-9][0-9]+") | |
2575 | (resy "[0-9][0-9]+") | |
2576 | (spacing "[cmp?*]") | |
2577 | (avgwidth "[0-9]+") | |
2578 | (registry "[^-]+") | |
2579 | (encoding "[^-]+") | |
2580 | ) | |
2581 | (setq x-font-regexp | |
2582 | (concat "\\`\\*?[-?*]" | |
2583 | foundry - family - weight\? - slant\? - swidth - adstyle - | |
e20d641f RS |
2584 | pixelsize - pointsize - resx - resy - spacing - avgwidth - |
2585 | registry - encoding "\\*?\\'" | |
465fceed ER |
2586 | )) |
2587 | (setq x-font-regexp-head | |
2588 | (concat "\\`[-?*]" foundry - family - weight\? - slant\? | |
2589 | "\\([-*?]\\|\\'\\)")) | |
2590 | (setq x-font-regexp-slant (concat - slant -)) | |
2591 | (setq x-font-regexp-weight (concat - weight -)) | |
70d0c3b0 | 2592 | nil) |
465fceed | 2593 | |
5f5c8ee5 | 2594 | |
281dc1c2 JB |
2595 | (defun x-resolve-font-name (pattern &optional face frame) |
2596 | "Return a font name matching PATTERN. | |
ac4c2e6b | 2597 | All wildcards in PATTERN are instantiated. |
10d89673 JB |
2598 | If PATTERN is nil, return the name of the frame's base font, which never |
2599 | contains wildcards. | |
e17dbede RS |
2600 | Given optional arguments FACE and FRAME, return a font which is |
2601 | also the same size as FACE on FRAME, or fail." | |
14e6867c RS |
2602 | (or (symbolp face) |
2603 | (setq face (face-name face))) | |
2604 | (and (eq frame t) | |
2605 | (setq frame nil)) | |
10d89673 | 2606 | (if pattern |
8db93e45 | 2607 | ;; Note that x-list-fonts has code to handle a face with nil as its font. |
abd89b80 | 2608 | (let ((fonts (x-list-fonts pattern face frame 1))) |
10d89673 JB |
2609 | (or fonts |
2610 | (if face | |
962a60aa RS |
2611 | (if (string-match "\\*" pattern) |
2612 | (if (null (face-font face)) | |
2613 | (error "No matching fonts are the same height as the frame default font") | |
2614 | (error "No matching fonts are the same height as face `%s'" face)) | |
2615 | (if (null (face-font face)) | |
2616 | (error "Height of font `%s' doesn't match the frame default font" | |
2617 | pattern) | |
2618 | (error "Height of font `%s' doesn't match face `%s'" | |
2619 | pattern face))) | |
7cf6fac1 | 2620 | (error "No fonts match `%s'" pattern))) |
10d89673 JB |
2621 | (car fonts)) |
2622 | (cdr (assq 'font (frame-parameters (selected-frame)))))) | |
281dc1c2 | 2623 | |
5f5c8ee5 | 2624 | |
465fceed | 2625 | (defun x-frob-font-weight (font which) |
b7ffee5f SM |
2626 | (let ((case-fold-search t)) |
2627 | (cond ((string-match x-font-regexp font) | |
2628 | (concat (substring font 0 | |
2629 | (match-beginning x-font-regexp-weight-subnum)) | |
2630 | which | |
2631 | (substring font (match-end x-font-regexp-weight-subnum) | |
2632 | (match-beginning x-font-regexp-adstyle-subnum)) | |
2633 | ;; Replace the ADD_STYLE_NAME field with * | |
2634 | ;; because the info in it may not be the same | |
2635 | ;; for related fonts. | |
2636 | "*" | |
2637 | (substring font (match-end x-font-regexp-adstyle-subnum)))) | |
528fbf51 RS |
2638 | ((string-match x-font-regexp-head font) |
2639 | (concat (substring font 0 (match-beginning 1)) which | |
2640 | (substring font (match-end 1)))) | |
2641 | ((string-match x-font-regexp-weight font) | |
b7ffee5f SM |
2642 | (concat (substring font 0 (match-beginning 1)) which |
2643 | (substring font (match-end 1))))))) | |
2598a293 | 2644 | (make-obsolete 'x-frob-font-weight 'make-face-... "21.1") |
5f5c8ee5 | 2645 | |
465fceed | 2646 | (defun x-frob-font-slant (font which) |
b7ffee5f SM |
2647 | (let ((case-fold-search t)) |
2648 | (cond ((string-match x-font-regexp font) | |
2649 | (concat (substring font 0 | |
2650 | (match-beginning x-font-regexp-slant-subnum)) | |
2651 | which | |
2652 | (substring font (match-end x-font-regexp-slant-subnum) | |
2653 | (match-beginning x-font-regexp-adstyle-subnum)) | |
2654 | ;; Replace the ADD_STYLE_NAME field with * | |
2655 | ;; because the info in it may not be the same | |
2656 | ;; for related fonts. | |
2657 | "*" | |
2658 | (substring font (match-end x-font-regexp-adstyle-subnum)))) | |
528fbf51 RS |
2659 | ((string-match x-font-regexp-head font) |
2660 | (concat (substring font 0 (match-beginning 2)) which | |
2661 | (substring font (match-end 2)))) | |
2662 | ((string-match x-font-regexp-slant font) | |
b7ffee5f SM |
2663 | (concat (substring font 0 (match-beginning 1)) which |
2664 | (substring font (match-end 1))))))) | |
2598a293 | 2665 | (make-obsolete 'x-frob-font-slant 'make-face-... "21.1") |
5f5c8ee5 | 2666 | |
3fc67165 EZ |
2667 | ;; These aliases are here so that we don't get warnings about obsolete |
2668 | ;; functions from the byte compiler. | |
2669 | (defalias 'internal-frob-font-weight 'x-frob-font-weight) | |
2670 | (defalias 'internal-frob-font-slant 'x-frob-font-slant) | |
2671 | ||
465fceed | 2672 | (defun x-make-font-bold (font) |
f3f31ccf RS |
2673 | "Given an X font specification, make a bold version of it. |
2674 | If that can't be done, return nil." | |
3fc67165 | 2675 | (internal-frob-font-weight font "bold")) |
2598a293 | 2676 | (make-obsolete 'x-make-font-bold 'make-face-bold "21.1") |
5f5c8ee5 | 2677 | |
465fceed | 2678 | (defun x-make-font-demibold (font) |
f3f31ccf RS |
2679 | "Given an X font specification, make a demibold version of it. |
2680 | If that can't be done, return nil." | |
3fc67165 | 2681 | (internal-frob-font-weight font "demibold")) |
2598a293 | 2682 | (make-obsolete 'x-make-font-demibold 'make-face-bold "21.1") |
5f5c8ee5 | 2683 | |
465fceed | 2684 | (defun x-make-font-unbold (font) |
f3f31ccf RS |
2685 | "Given an X font specification, make a non-bold version of it. |
2686 | If that can't be done, return nil." | |
3fc67165 | 2687 | (internal-frob-font-weight font "medium")) |
2598a293 | 2688 | (make-obsolete 'x-make-font-unbold 'make-face-unbold "21.1") |
5f5c8ee5 | 2689 | |
465fceed | 2690 | (defun x-make-font-italic (font) |
f3f31ccf RS |
2691 | "Given an X font specification, make an italic version of it. |
2692 | If that can't be done, return nil." | |
3fc67165 | 2693 | (internal-frob-font-slant font "i")) |
2598a293 | 2694 | (make-obsolete 'x-make-font-italic 'make-face-italic "21.1") |
5f5c8ee5 | 2695 | |
465fceed | 2696 | (defun x-make-font-oblique (font) ; you say tomayto... |
f3f31ccf RS |
2697 | "Given an X font specification, make an oblique version of it. |
2698 | If that can't be done, return nil." | |
3fc67165 | 2699 | (internal-frob-font-slant font "o")) |
2598a293 | 2700 | (make-obsolete 'x-make-font-oblique 'make-face-italic "21.1") |
5f5c8ee5 | 2701 | |
465fceed | 2702 | (defun x-make-font-unitalic (font) |
f3f31ccf RS |
2703 | "Given an X font specification, make a non-italic version of it. |
2704 | If that can't be done, return nil." | |
3fc67165 | 2705 | (internal-frob-font-slant font "r")) |
2598a293 | 2706 | (make-obsolete 'x-make-font-unitalic 'make-face-unitalic "21.1") |
5f5c8ee5 | 2707 | |
b7d7285c KH |
2708 | (defun x-make-font-bold-italic (font) |
2709 | "Given an X font specification, make a bold and italic version of it. | |
2710 | If that can't be done, return nil." | |
3fc67165 EZ |
2711 | (and (setq font (internal-frob-font-weight font "bold")) |
2712 | (internal-frob-font-slant font "i"))) | |
2598a293 | 2713 | (make-obsolete 'x-make-font-bold-italic 'make-face-bold-italic "21.1") |
113ab303 | 2714 | |
f0138172 JB |
2715 | (provide 'faces) |
2716 | ||
e3b5b35b | 2717 | ;; arch-tag: 19a4759f-2963-445f-b004-425b9aadd7d6 |
70d0c3b0 | 2718 | ;;; faces.el ends here |