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