mirrored from git://git.sv.gnu.org/emacs.git
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathfaces.el
3232 lines (2827 loc) · 125 KB
/
faces.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; faces.el --- Lisp faces -*- lexical-binding: t -*-
;; Copyright (C) 1992-2025 Free Software Foundation, Inc.
;; Maintainer: emacs-devel@gnu.org
;; Keywords: internal
;; Package: emacs
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(defcustom term-file-prefix "term/"
"If non-nil, Emacs startup performs terminal-specific initialization.
It does this by: (load (concat term-file-prefix (getenv \"TERM\")))
You may set this variable to nil in your init file if you do not wish
the terminal-initialization file to be loaded."
:type '(choice (const :tag "No terminal-specific initialization" nil)
(string :tag "Name of directory with term files"))
:group 'terminals)
(defcustom term-file-aliases
'(("apollo" . "vt100")
("vt102" . "vt100")
("vt125" . "vt100")
("vt201" . "vt200")
("vt220" . "vt200")
("vt240" . "vt200")
("vt300" . "vt200")
("vt320" . "vt200")
("vt400" . "vt200")
("vt420" . "vt200")
("alacritty" . "xterm")
("foot" . "xterm")
("contour" . "xterm"))
"Alist of terminal type aliases.
Entries are of the form (TYPE . ALIAS), where both elements are strings.
This means to treat a terminal of type TYPE as if it were of type ALIAS."
:type '(alist :key-type (string :tag "Terminal")
:value-type (string :tag "Alias"))
:group 'terminals
:version "25.1")
(declare-function display-graphic-p "frame" (&optional display))
(declare-function xw-defined-colors "term/common-win" (&optional frame))
(defvar help-xref-stack-item)
(defvar face-name-history nil
"History list for some commands that read face names.
Maximum length of the history list is determined by the value
of `history-length', which see.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Font selection.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defgroup font-selection nil
"Influencing face font selection."
:group 'faces)
(defcustom face-font-selection-order
'(:width :height :weight :slant)
"A list specifying how face font selection chooses fonts.
Each of the four symbols `:width', `:height', `:weight', and `:slant'
must appear once in the list, and the list must not contain any other
elements. Font selection first tries to find a best matching font
for those face attributes that appear before in the list. For
example, if `:slant' appears before `:height', font selection first
tries to find a font with a suitable slant, even if this results in
a font height that isn't optimal."
:tag "Font selection order"
:type '(list symbol symbol symbol symbol)
:group 'font-selection
:set (lambda (symbol value)
(set-default symbol value)
(internal-set-font-selection-order value)))
;; In the absence of Fontconfig support, Monospace and Sans Serif are
;; unavailable, and we fall back on the courier and helv families,
;; which are generally available.
(defcustom face-font-family-alternatives
'(("Monospace" "Cascadia Code" "Lucida Console" "courier" "fixed")
;; Monospace Serif is an Emacs invention, intended to work around
;; portability problems when using Courier. It should work well
;; when combined with Monospaced and with other standard fonts.
;; One of its uses is for 'tex-verbatim' and 'Info-quoted' faces,
;; so the result must be different from the default face's font,
;; and must be monospaced. For 'tex-verbatim', it is desirable
;; that the font really is a Serif font, so as to look like
;; TeX's 'verbatim'.
("Monospace Serif"
;; This looks good on GNU/Linux.
"Courier 10 Pitch"
;; This looks good on MS-Windows and OS X. Note that this is
;; actually a sans-serif font, but it's here for lack of a better
;; alternative.
"Consolas"
;; This looks good on macOS. "Courier" looks good too, but is
;; jagged on GNU/Linux and so is listed later as "courier".
"Courier Std"
;; Although these are anti-aliased, they are a bit faint compared
;; to the above.
"FreeMono" "Nimbus Mono L"
;; These are aliased and look jagged.
"courier" "fixed"
;; Omit Courier New, as it is the default MS-Windows font and so
;; would look no different, and is pretty faint on other platforms.
)
;; This is present for backward compatibility.
("courier" "CMU Typewriter Text" "fixed")
("Sans Serif"
;; https://en.wikipedia.org/wiki/List_of_typefaces_included_with_Microsoft_Windows
"Calibri" "Tahoma" "Lucida Sans Unicode"
"helv" "helvetica" "arial" "fixed")
("helv" "helvetica" "arial" "fixed"))
"Alist of alternative font family names.
Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...).
If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then
ALTERNATIVE2 etc."
:tag "Alternative font families to try"
:type '(repeat (repeat string))
:group 'font-selection
:set (lambda (symbol value)
(set-default symbol value)
(internal-set-alternative-font-family-alist value)))
;; This is defined originally in xfaces.c.
(defcustom face-font-registry-alternatives
(if (featurep 'w32)
'(("iso8859-1" "ms-oemlatin")
("gb2312.1980" "gb2312" "gbk" "gb18030")
("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
("muletibetan-2" "muletibetan-0"))
'(("gb2312.1980" "gb2312.80&gb8565.88" "gbk" "gb18030")
("jisx0208.1990" "jisx0208.1983" "jisx0208.1978")
("ksc5601.1989" "ksx1001.1992" "ksc5601.1987")
("muletibetan-2" "muletibetan-0")))
"Alist of alternative font registry names.
Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...).
If fonts of registry REGISTRY can be loaded, font selection
tries to find a best matching font among all fonts of registry
REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc."
:tag "Alternative font registries to try"
:type '(repeat (repeat string))
:version "21.1"
:group 'font-selection
:set (lambda (symbol value)
(set-default symbol value)
(internal-set-alternative-font-registry-alist value)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Creation, copying.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(make-obsolete-variable 'face-new-frame-defaults
"use `face--new-frame-defaults' or `face-alist' instead." "28.1")
(defun frame-face-alist (&optional frame)
"Return an alist of frame-local faces defined on FRAME.
This alist is a copy of the contents of `frame--face-hash-table'.
For internal use only."
(declare (obsolete frame--face-hash-table "28.1"))
(let (faces)
(maphash (lambda (face spec)
(let ((face-id (car (gethash face face--new-frame-defaults))))
(push `(,face-id ,face . ,spec) faces)))
(frame--face-hash-table frame))
(mapcar #'cdr (sort faces (lambda (f1 f2) (> (car f1) (car f2)))))))
(defun face-list ()
"Return a list of all defined faces."
(let (faces)
(maphash (lambda (face spec)
(push `(,(car spec) . ,face) faces))
face--new-frame-defaults)
(mapcar #'cdr (sort faces (lambda (f1 f2) (> (car f1) (car f2)))))))
(defun make-face (face)
"Define a new face with name FACE, a symbol.
Do not call this directly from Lisp code; use `defface' instead.
If FACE is already known as a face, leave it unmodified. Return FACE."
(interactive (list (read-from-minibuffer
"Make face: " nil nil t 'face-name-history)))
(unless (facep face)
;; Make frame-local faces (this also makes the global one).
(dolist (frame (frame-list))
(internal-make-lisp-face face frame))
;; Add the face to the face menu.
(when (fboundp 'facemenu-add-new-face)
(facemenu-add-new-face face))
;; Define frame-local faces for all frames from X resources.
(make-face-x-resource-internal face))
face)
(defun make-empty-face (face)
"Define a new, empty face with name FACE.
Do not call this directly from Lisp code; use `defface' instead."
(interactive (list (read-from-minibuffer
"Make empty face: " nil nil t 'face-name-history)))
(make-face face))
(defun copy-face (old-face new-face &optional frame new-frame)
"Define a face named NEW-FACE, which is a copy of OLD-FACE.
This function does not copy face customization data, so NEW-FACE
will not be made customizable. Most Lisp code should not call
this function; use `defface' with :inherit instead.
If NEW-FACE already exists as a face, modify it to be like
OLD-FACE. If NEW-FACE doesn't already exist, create it.
If the optional argument FRAME is a frame, change NEW-FACE on
FRAME only. If FRAME is t, copy the frame-independent default
specification for OLD-FACE to NEW-FACE. If FRAME is nil, copy
the defaults as well as the faces on each existing frame.
If the optional fourth argument NEW-FRAME is given, copy the
information from face OLD-FACE on frame FRAME to NEW-FACE on
frame NEW-FRAME. In this case, FRAME must not be nil."
(let ((inhibit-quit t))
(if (null frame)
(progn
(when new-frame
(error "Copying face %s from all frames to one frame"
old-face))
(make-empty-face new-face)
(dolist (frame (frame-list))
(copy-face old-face new-face frame))
(copy-face old-face new-face t))
(make-empty-face new-face)
(internal-copy-lisp-face old-face new-face frame new-frame))
new-face))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Predicates, type checks.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun facep (face)
"Return non-nil if FACE is a face name; nil otherwise.
A face name can be a string or a symbol."
(internal-lisp-face-p face))
(defun check-face (face)
"Signal an error if FACE doesn't name a face.
Value is FACE."
(unless (facep face)
(error "Not a face: %s" face))
face)
;; The ID returned is not to be confused with the internally used IDs
;; of realized faces. The ID assigned to Lisp faces is used to
;; support faces in display table entries.
(defun face-id (face &optional _frame)
"Return the internal ID of face with name FACE.
If FACE is a face-alias, return the ID of the target face.
The optional argument FRAME is ignored, since the internal face ID
of a face name is the same for all frames."
(check-face face)
(or (get face 'face)
(face-id (get face 'face-alias))))
(defun face-equal (face1 face2 &optional frame)
"Non-nil if faces FACE1 and FACE2 are equal.
Faces are considered equal if all their attributes are equal.
If optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
If FRAME is omitted or nil, use the selected frame."
(internal-lisp-face-equal-p face1 face2 frame))
(defun face-differs-from-default-p (face &optional frame)
"Return non-nil if FACE displays differently from the default face.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame."
(let ((attrs
;; The _value_ of :inherit teaches us nothing about how FACE
;; looks compared to the default face. Instead, we will ask
;; `face-attribute' to take inheritance into account when
;; examining other attributes.
(delq :inherit
;; A difference in extension past EOL only matters when
;; relevant attributes (such as :background) also
;; differ from the default; otherwise this difference
;; is a false positive.
(delq :extend (mapcar 'car face-attribute-name-alist))))
(differs nil))
(while (and attrs (not differs))
(let* ((attr (pop attrs))
(attr-val (face-attribute face attr frame t)))
(when (and
(not (eq attr-val 'unspecified))
(display-supports-face-attributes-p (list attr attr-val)
frame))
(setq differs attr))))
differs))
(defun face-nontrivial-p (face &optional frame)
"True if face FACE has some non-nil attribute.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame."
(not (internal-lisp-face-empty-p face frame)))
(defun face-list-p (face-or-list)
"True if FACE-OR-LIST is a list of faces.
Return nil if FACE-OR-LIST is a non-nil atom, or a cons cell whose car
is either `foreground-color', `background-color', or a keyword."
;; The logic of merge_face_ref (xfaces.c) is recreated here.
(and (listp face-or-list)
(not (memq (car face-or-list)
'(foreground-color background-color)))
(not (keywordp (car face-or-list)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Setting face attributes from X resources.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defcustom face-x-resources
'((:family (".attributeFamily" . "Face.AttributeFamily"))
(:foundry (".attributeFoundry" . "Face.AttributeFoundry"))
(:width (".attributeWidth" . "Face.AttributeWidth"))
(:height (".attributeHeight" . "Face.AttributeHeight"))
(:weight (".attributeWeight" . "Face.AttributeWeight"))
(:slant (".attributeSlant" . "Face.AttributeSlant"))
(:foreground (".attributeForeground" . "Face.AttributeForeground"))
(:distant-foreground
(".attributeDistantForeground" . "Face.AttributeDistantForeground"))
(:background (".attributeBackground" . "Face.AttributeBackground"))
(:overline (".attributeOverline" . "Face.AttributeOverline"))
(:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough"))
(:box (".attributeBox" . "Face.AttributeBox"))
(:underline (".attributeUnderline" . "Face.AttributeUnderline"))
(:inverse-video (".attributeInverse" . "Face.AttributeInverse"))
(:extend (".attributeExtend" . "Face.AttributeExtend"))
(:stipple
(".attributeStipple" . "Face.AttributeStipple")
(".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap"))
(:bold (".attributeBold" . "Face.AttributeBold"))
(:italic (".attributeItalic" . "Face.AttributeItalic"))
(:font (".attributeFont" . "Face.AttributeFont"))
(:inherit (".attributeInherit" . "Face.AttributeInherit")))
"List of X resources and classes for face attributes.
Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is
the name of a face attribute, and each ENTRY is a cons of the form
\(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the
X resource class for the attribute."
:type '(repeat (cons symbol (repeat (cons string string))))
:group 'faces)
(declare-function internal-face-x-get-resource "xfaces.c"
(resource class &optional frame))
(declare-function internal-set-lisp-face-attribute-from-resource "xfaces.c"
(face attr value &optional frame))
(defun set-face-attribute-from-resource (face attribute resource class frame)
"Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME.
Value is the attribute value specified by the resource, or nil
if not present. This function displays a message if the resource
specifies an invalid attribute."
(let* ((face-name (face-name face))
(value (internal-face-x-get-resource (concat face-name resource)
class frame)))
(when value
(condition-case ()
(internal-set-lisp-face-attribute-from-resource
face attribute (downcase value) frame)
(error
(message "Face %s, frame %s: invalid attribute %s %s from X resource"
face-name frame attribute value))))
value))
(defun set-face-attributes-from-resources (face frame)
"Set attributes of FACE from X resources for FRAME."
(when (memq (framep frame) '(x w32))
(dolist (definition face-x-resources)
(let ((attribute (car definition)))
(dolist (entry (cdr definition))
(set-face-attribute-from-resource face attribute (car entry)
(cdr entry) frame))))))
(defun make-face-x-resource-internal (face &optional frame)
"Fill frame-local FACE on FRAME from X resources.
FRAME nil or not specified means do it for all frames.
If `inhibit-x-resources' is non-nil, this function does nothing."
(unless inhibit-x-resources
(dolist (frame (if (null frame) (frame-list) (list frame)))
;; `x-create-frame' already took care of correctly handling
;; the reverse video case-- do _not_ touch the default face
(unless (and (eq face 'default)
(frame-parameter frame 'reverse))
(set-face-attributes-from-resources face frame)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Retrieving face attributes.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun face-name (face)
"Return the name of face FACE."
(symbol-name (check-face face)))
(defun face-all-attributes (face &optional frame)
"Return an alist stating the attributes of FACE.
Each element of the result has the form (ATTR-NAME . ATTR-VALUE).
If FRAME is omitted or nil the value describes the default attributes,
but if you specify FRAME, the value describes the attributes
of FACE on FRAME."
(mapcar (lambda (pair)
(let ((attr (car pair)))
(cons attr (face-attribute face attr (or frame t)))))
face-attribute-name-alist))
(defun face-attribute (face attribute &optional frame inherit)
"Return the value of FACE's ATTRIBUTE on FRAME.
See `set-face-attribute' for the list of supported attributes
and their meanings and allowed values.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame.
If INHERIT is nil, only attributes directly defined by FACE are considered,
so the return value may be `unspecified', or a relative value.
If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the
faces specified by its `:inherit' attribute; however the return value
may still be `unspecified' or relative.
If INHERIT is a face or a list of faces, then the result is further merged
with that face (or faces), until it becomes specified and absolute.
To ensure that the return value is always specified and absolute, use a
value of `default' for INHERIT; this will resolve any unspecified or
relative values by merging with the `default' face (which is always
completely specified)."
(let ((value (internal-get-lisp-face-attribute face attribute frame)))
(when (and inherit (face-attribute-relative-p attribute value))
;; VALUE is relative, so merge with inherited faces
(let ((inh-from (face-attribute face :inherit frame)))
(unless (or (null inh-from) (eq inh-from 'unspecified))
(condition-case nil
(setq value
(face-attribute-merged-with attribute value inh-from frame))
;; The `inherit' attribute may point to non existent faces.
(error nil)))))
(when (and inherit
(not (eq inherit t))
(face-attribute-relative-p attribute value))
;; We should merge with INHERIT as well
(setq value (face-attribute-merged-with attribute value inherit frame)))
value))
(defun face-attribute-merged-with (attribute value faces &optional frame)
"Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
FACES may be either a single face or a list of faces.
[This is an internal function.]"
(cond ((not (face-attribute-relative-p attribute value))
value)
((null faces)
value)
((consp faces)
(face-attribute-merged-with
attribute
(face-attribute-merged-with attribute value (car faces) frame)
(cdr faces)
frame))
(t
(merge-face-attribute attribute
value
(face-attribute faces attribute frame t)))))
(defmacro face-attribute-specified-or (value &rest body)
"Return VALUE or, if it's `unspecified', the result of evaluating BODY."
(let ((temp (make-symbol "value")))
`(let ((,temp ,value))
(if (not (eq ,temp 'unspecified))
,temp
,@body))))
(defun face-foreground (face &optional frame inherit)
"Return the foreground color name of FACE, or nil if unspecified.
On TTY frames, the returned color name can be \"unspecified-fg\",
which stands for the unknown default foreground color of the display
where the frame is displayed.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame.
If INHERIT is nil, only a foreground color directly defined by FACE is
considered, so the return value may be nil.
If INHERIT is t, and FACE doesn't define a foreground color, then any
foreground color that FACE inherits through its `:inherit' attribute
is considered as well; however the return value may still be nil.
If INHERIT is a face or a list of faces, then it is used to try to
resolve an unspecified foreground color, in addition to using any
inherited color.
To ensure that a valid color is always returned, use a value of
`default' for INHERIT; this will resolve any unspecified values by
merging with the `default' face (which is always completely specified)."
(face-attribute-specified-or (face-attribute face :foreground frame inherit)
nil))
(defun face-background (face &optional frame inherit)
"Return the background color name of FACE, or nil if unspecified.
On TTY frames, the returned color name can be \"unspecified-bg\",
which stands for the unknown default background color of the display
where the frame is displayed.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame.
If INHERIT is nil, only a background color directly defined by FACE is
considered, so the return value may be nil.
If INHERIT is t, and FACE doesn't define a background color, then any
background color that FACE inherits through its `:inherit' attribute
is considered as well; however the return value may still be nil.
If INHERIT is a face or a list of faces, then it is used to try to
resolve an unspecified background color, in addition to using any
inherited color.
To ensure that a valid color is always returned, use a value of
`default' for INHERIT; this will resolve any unspecified values by
merging with the `default' face (which is always completely specified)."
(face-attribute-specified-or (face-attribute face :background frame inherit)
nil))
(defun face-stipple (face &optional frame inherit)
"Return the stipple pixmap name of FACE, or nil if unspecified.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame.
If INHERIT is nil, only a stipple directly defined by FACE is
considered, so the return value may be nil.
If INHERIT is t, and FACE doesn't define a stipple, then any stipple
that FACE inherits through its `:inherit' attribute is considered as
well; however the return value may still be nil.
If INHERIT is a face or a list of faces, then it is used to try to
resolve an unspecified stipple.
To ensure that a valid stipple or nil is always returned, use a value of
`default' for INHERIT; this will resolve any unspecified values by merging
with the `default' face (which is always completely specified)."
(face-attribute-specified-or (face-attribute face :stipple frame inherit)
nil))
(defun face-underline-p (face &optional frame inherit)
"Return non-nil if FACE specifies a non-nil underlining.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame.
Optional argument INHERIT is passed to `face-attribute'."
(face-attribute-specified-or
(face-attribute face :underline frame inherit) nil))
(defun face-inverse-video-p (face &optional frame inherit)
"Return non-nil if FACE specifies a non-nil inverse-video.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame.
Optional argument INHERIT is passed to `face-attribute'."
(eq (face-attribute face :inverse-video frame inherit) t))
(defun face-bold-p (face &optional frame inherit)
"Return non-nil if the font of FACE is bold on FRAME.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame.
Optional argument INHERIT is passed to `face-attribute'.
Use `face-attribute' for finer control."
(let ((bold (face-attribute face :weight frame inherit)))
(memq bold '(semi-bold bold extra-bold ultra-bold))))
(defun face-italic-p (face &optional frame inherit)
"Return non-nil if the font of FACE is italic on FRAME.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame.
Optional argument INHERIT is passed to `face-attribute'.
Use `face-attribute' for finer control."
(let ((italic (face-attribute face :slant frame inherit)))
(memq italic '(italic oblique))))
(defun face-extend-p (face &optional frame inherit)
"Return non-nil if FACE specifies a non-nil extend.
If the optional argument FRAME is given, report on face FACE in that frame.
If FRAME is t, report on the defaults for face FACE (for new frames).
If FRAME is omitted or nil, use the selected frame.
Optional argument INHERIT is passed to `face-attribute'."
(eq (face-attribute face :extend frame inherit) t))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Face documentation.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun face-documentation (face)
"Get the documentation string for FACE.
If FACE is a face-alias, get the documentation for the target face."
(let ((alias (get face 'face-alias)))
(if alias
(let ((doc (documentation-property alias 'face-documentation)))
(format "%s is an alias for the face `%s'.%s" face alias
(if doc (format "\n%s" doc)
"")))
(documentation-property face 'face-documentation))))
(defun set-face-documentation (face string)
"Set the documentation string for FACE to STRING."
;; Perhaps the text should go in DOC.
(put face 'face-documentation string))
(define-obsolete-function-alias 'face-doc-string #'face-documentation "29.1")
(define-obsolete-function-alias 'set-face-doc-string #'set-face-documentation "29.1")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Setting face attributes.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun set-face-attribute (face frame &rest args)
"Set attributes of FACE on FRAME from ARGS.
This function overrides the face attributes specified by FACE's face spec.
It is mostly intended for internal use.
If FRAME is a frame, set the FACE's attributes only for that frame. If
FRAME is nil, set attribute values for all existing frames, as well as
the default for new frames. If FRAME is t, change the default values
of attributes for new frames.
ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a valid face
attribute name and VALUE must be a value that is valid for ATTRIBUTE,
as described below for each attribute.
In addition to the attribute values listed below, all attributes can
also be set to the special value `unspecified', which means the face
doesn't by itself specify a value for the attribute.
When a new frame is created, attribute values in the FACE's `defface'
spec normally override the `unspecified' values in the FACE's
default attributes. To avoid that, i.e. to cause ATTRIBUTE's value
be reset to `unspecified' when creating new frames, disregarding
what the FACE's face spec says, call this function with FRAME set to
t and the ATTRIBUTE's value set to `unspecified'.
Note that the ATTRIBUTE VALUE pairs are evaluated in the order
they are specified, except that the `:family' and `:foundry'
attributes are evaluated first.
The following attributes are recognized:
`:family'
VALUE must be a string specifying the font family
\(e.g. \"Monospace\").
`:foundry'
VALUE must be a string specifying the font foundry,
e.g., \"adobe\". If a font foundry is specified, wild-cards `*'
and `?' are allowed.
`:width'
VALUE specifies the relative proportionate width of the font to use.
It must be one of the symbols `ultra-condensed', `extra-condensed',
`condensed' (a.k.a. `compressed', a.k.a. `narrow'),
`semi-condensed' (a.k.a. `demi-condensed'), `normal' (a.k.a. `medium',
a.k.a. `regular'), `semi-expanded' (a.k.a. `demi-expanded'),
`expanded', `extra-expanded', or `ultra-expanded' (a.k.a. `wide').
`:height'
VALUE specifies the relative or absolute font size (height of the
font). An absolute height is an integer, and specifies font height in
units of 1/10 pt. A relative height is either a floating point
number, which specifies a scaling factor for the underlying face
height; or a function that takes a single argument (the underlying
face height) and returns the new height. Note that for the `default'
face, you must specify an absolute height (since there is nothing for
it to be relative to).
`:weight'
VALUE specifies the weight of the font to use. It must be one of
the symbols `ultra-heavy', `heavy' (a.k.a. `black'),
`ultra-bold' (a.k.a. `extra-bold'), `bold',
`semi-bold' (a.k.a. `demi-bold'), `medium', `normal' (a.k.a. `regular',
a.k.a. `book'), `semi-light' (a.k.a. `demi-light'),
`light', `extra-light' (a.k.a. `ultra-light'), or `thin'.
`:slant'
VALUE specifies the slant of the font to use. It must be one of the
symbols `italic', `oblique', `normal', `reverse-italic', or
`reverse-oblique'.
`:foreground', `:background'
VALUE must be a color name, a string.
`:underline'
VALUE specifies whether characters in FACE should be underlined.
If VALUE is t, underline with foreground color of the face.
If VALUE is a string, underline with that color.
If VALUE is nil, explicitly don't underline.
Otherwise, VALUE must be a property list of the form:
`(:color COLOR :style STYLE)'.
COLOR can be either a color name string or `foreground-color'.
STYLE can be either `line' or `wave'.
If a keyword/value pair is missing from the property list, a
default value will be used for the value.
The default value of COLOR is the foreground color of the face.
The default value of STYLE is `line'.
`:overline'
VALUE specifies whether characters in FACE should be overlined. If
VALUE is t, overline with foreground color of the face. If VALUE is a
string, overline with that color. If VALUE is nil, explicitly don't
overline.
`:strike-through'
VALUE specifies whether characters in FACE should be drawn with a line
striking through them. If VALUE is t, use the foreground color of the
face. If VALUE is a string, strike-through with that color. If VALUE
is nil, explicitly don't strike through.
`:box'
VALUE specifies whether characters in FACE should have a box drawn
around them. If VALUE is nil, explicitly don't draw boxes. If
VALUE is t, draw a box with lines of width 1 in the foreground color
of the face. If VALUE is a string, the string must be a color name,
and the box is drawn in that color with a line width of 1. Otherwise,
VALUE must be a property list of the following form:
(:line-width WIDTH :color COLOR :style STYLE)
If a keyword/value pair is missing from the property list, a default
value will be used for the value, as specified below.
WIDTH specifies the width of the lines to draw; it defaults to 1.
If WIDTH is negative, the absolute value is the width of the lines,
and draw top/bottom lines inside the characters area, not around it.
WIDTH can also be a cons (VWIDTH . HWIDTH), which specifies different
values for the vertical and the horizontal line width.
COLOR is the name of the color to use for the box lines, default is
the background color of the face for 3D and `flat-button' boxes, and
the foreground color of the face for the other boxes.
STYLE specifies whether a 3D box should be drawn. If STYLE
is `released-button', draw a box looking like a released 3D button.
If STYLE is `pressed-button', draw a box that looks like a pressed
button. If STYLE is nil, `flat-button', or omitted, draw a 2D box.
`:inverse-video'
VALUE specifies whether characters in FACE should be displayed in
inverse video. VALUE must be one of t or nil.
`:stipple'
If VALUE is a string, it must be the name of a file of pixmap data.
The directories listed in the `x-bitmap-file-path' variable are
searched. Alternatively, VALUE may be a list of the form (WIDTH
HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA
is a string containing the raw bits of the bitmap. VALUE nil means
explicitly don't use a stipple pattern.
For convenience, attributes `:family', `:foundry', `:width',
`:height', `:weight', and `:slant' may also be set in one step
from an X font name:
`:extend'
VALUE specifies whether the FACE should be extended after EOL.
VALUE must be one of t or nil.
`:font'
Set font-related face attributes from VALUE.
VALUE must be a valid font name or font object. It can also
be a fontset name. Setting this attribute will also set
the `:family', `:foundry', `:width', `:height', `:weight',
and `:slant' attributes.
`:inherit'
VALUE is the name of a face from which to inherit attributes, or
a list of face names. Attributes from inherited faces are merged
into the face like an underlying face would be, with higher
priority than underlying faces.
For backward compatibility, the keywords `:bold' and `:italic'
can be used to specify weight and slant respectively. This usage
is considered obsolete. For these two keywords, the VALUE must
be either t or nil. A value of t for `:bold' is equivalent to
setting `:weight' to `bold', and a value of t for `:italic' is
equivalent to setting `:slant' to `italic'. But if `:weight' is
specified in the face spec, `:bold' is ignored, and if `:slant'
is specified, `:italic' is ignored."
(let ((where (if (null frame) 0 frame))
(spec args)
family foundry orig-family orig-foundry)
;; If we set the new-frame defaults, this face is modified outside Custom.
(if (memq where '(0 t))
(put (or (get face 'face-alias) face) 'face-modified t))
;; If family and/or foundry are specified, set it first. Certain
;; face attributes, e.g. :weight semi-condensed, are not supported
;; in every font. See bug#1127.
(while spec
(cond ((eq (car spec) :family)
(setq family (cadr spec)))
((eq (car spec) :foundry)
(setq foundry (cadr spec))))
(setq spec (cddr spec)))
(when (or family foundry)
(when (and (stringp family)
(string-match "\\([^-]*\\)-\\([^-]*\\)" family))
(setq orig-foundry foundry
orig-family family)
(unless foundry
(setq foundry (match-string 1 family)))
(setq family (match-string 2 family))
;; Reject bogus "families" that are all-digits -- those are some
;; weird font names, like Foobar-12, that end in a number.
(when (string-match "\\`[0-9]*\\'" family)
(setq family orig-family)
(setq foundry orig-foundry)))
(when (or (stringp family) (eq family 'unspecified))
(internal-set-lisp-face-attribute face :family family where))
(when (or (stringp foundry) (eq foundry 'unspecified))
(internal-set-lisp-face-attribute face :foundry foundry where)))
(while args
(unless (memq (car args) '(:family :foundry))
(internal-set-lisp-face-attribute face (car args)
(cadr args)
where))
(setq args (cddr args)))))
(defun make-face-bold (face &optional frame _noerror)
"Make the font of FACE be bold, if possible.
FRAME nil or not specified means change face on all frames.
Use `set-face-attribute' for finer control of the font weight."
(declare (advertised-calling-convention (face &optional frame) "29.1"))
(interactive (list (read-face-name "Make which face bold"
(face-at-point t))))
(set-face-attribute face frame :weight 'bold))
(defun make-face-unbold (face &optional frame _noerror)
"Make the font of FACE be non-bold, if possible.
FRAME nil or not specified means change face on all frames."
(declare (advertised-calling-convention (face &optional frame) "29.1"))
(interactive (list (read-face-name "Make which face non-bold"
(face-at-point t))))
(set-face-attribute face frame :weight 'normal))
(defun make-face-italic (face &optional frame _noerror)
"Make the font of FACE be italic, if possible.
FRAME nil or not specified means change face on all frames.
Use `set-face-attribute' for finer control of the font slant."
(declare (advertised-calling-convention (face &optional frame) "29.1"))
(interactive (list (read-face-name "Make which face italic"
(face-at-point t))))
(set-face-attribute face frame :slant 'italic))
(defun make-face-unitalic (face &optional frame _noerror)
"Make the font of FACE be non-italic, if possible.
FRAME nil or not specified means change face on all frames."
(declare (advertised-calling-convention (face &optional frame) "29.1"))
(interactive (list (read-face-name "Make which face non-italic"
(face-at-point t))))
(set-face-attribute face frame :slant 'normal))
(defun make-face-bold-italic (face &optional frame _noerror)
"Make the font of FACE be bold and italic, if possible.
FRAME nil or not specified means change face on all frames.
Use `set-face-attribute' for finer control of font weight and slant."
(declare (advertised-calling-convention (face &optional frame) "29.1"))
(interactive (list (read-face-name "Make which face bold-italic"
(face-at-point t))))
(set-face-attribute face frame :weight 'bold :slant 'italic))
(defun set-face-font (face font &optional frame)
"Change font-related attributes of FACE to those of FONT.
FONT can be a string, a font spec, a font entity, a font object,
or a fontset. However, interactively, only strings are accepted.
The format of the font string specification varies based on the font
system in use, but it can commonly be an X Logical Font
Description (XLFD) string, or a simpler string like \"Courier-10\"
or \"courier:size=10\".
FRAME nil or not specified means change face on all frames.
This sets the attributes `:family', `:foundry', `:width',
`:height', `:weight', and `:slant'. When called interactively,
prompt for the face and font."
(interactive (read-face-and-attribute :font))
(set-face-attribute face frame :font font))
;; Implementation note: Emulating gray background colors with a
;; stipple pattern is now part of the face realization process, and is
;; done in C depending on the frame on which the face is realized.
(defun set-face-background (face color &optional frame)
"Change the background color of face FACE to COLOR (a string).
FRAME nil or not specified means change face on all frames.
COLOR can be a system-defined color name (see `list-colors-display')
or a hex spec of the form #RRGGBB.
When called interactively, prompts for the face and color."
(interactive (read-face-and-attribute :background))
(set-face-attribute face frame :background (or color 'unspecified)))
(defun set-face-foreground (face color &optional frame)
"Change the foreground color of face FACE to COLOR (a string).
FRAME nil or not specified means change face on all frames.
COLOR can be a system-defined color name (see `list-colors-display')
or a hex spec of the form #RRGGBB.
When called interactively, prompts for the face and color."
(interactive (read-face-and-attribute :foreground))
(set-face-attribute face frame :foreground (or color 'unspecified)))
(defun set-face-stipple (face stipple &optional frame)
"Change the stipple pixmap of face FACE to STIPPLE.
FRAME nil or not specified means change face on all frames.
STIPPLE should be a string, the name of a file of pixmap data.
The directories listed in the `x-bitmap-file-path' variable are searched.
Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA)
where WIDTH and HEIGHT are the size in pixels,
and DATA is a string, containing the raw bits of the bitmap."
(interactive (read-face-and-attribute :stipple))
(set-face-attribute face frame :stipple (or stipple 'unspecified)))
(defun set-face-underline (face underline &optional frame)