Mercurial > hg > xemacs-beta
comparison lisp/x-faces.el @ 4822:0482cdb4e35d
Cosmetic changes in x-faces.e
author | Didier Verna <didier@lrde.epita.fr> |
---|---|
date | Sun, 10 Jan 2010 10:25:57 +0100 |
parents | 49480d838d32 |
children | 8b2f75cecb89 |
comparison
equal
deleted
inserted
replaced
4819:49480d838d32 | 4822:0482cdb4e35d |
---|---|
644 x-color-list-internal-cache))) | 644 x-color-list-internal-cache))) |
645 | 645 |
646 | 646 |
647 ;;; internal routines | 647 ;;; internal routines |
648 | 648 |
649 ;;; x-init-face-from-resources is responsible for initializing a | 649 ;;; x-init-face-from-resources is responsible for initializing a newly-created |
650 ;;; newly-created face from the resource database. | 650 ;;; face from the resource database. |
651 ;;; | 651 ;;; |
652 ;;; When a new frame is created, it is called from `x-init-frame-faces' | 652 ;;; When a new frame is created, it is called from `x-init-frame-faces' called |
653 ;;; called from `init-frame-faces' called from init_frame_faces() | 653 ;;; from `init-frame-faces' called from init_frame_faces() from Fmake_frame(). |
654 ;;; from Fmake_frame(). In this case it is called once for each existing | 654 ;;; In this case it is called once for each existing face, with the |
655 ;;; face, with the newly-created frame as the argument. It then initializes | 655 ;;; newly-created frame as the argument. It then initializes the newly-created |
656 ;;; the newly-created faces on that frame. | 656 ;;; faces on that frame. |
657 ;;; | 657 ;;; |
658 ;;; It's also called from `init-device-faces' and | 658 ;;; It's also called from `init-device-faces' and `init-global-faces'. |
659 ;;; `init-global-faces'. | |
660 ;;; | 659 ;;; |
661 ;;; This had better not signal an error. The frame is in an intermediate | 660 ;;; This had better not signal an error. The frame is in an intermediate state |
662 ;;; state where signalling an error or entering the debugger would likely | 661 ;;; where signalling an error or entering the debugger would likely result in |
663 ;;; result in a crash. | 662 ;;; a crash. |
664 | 663 |
665 ;; When we initialise a face from an X resource, note that we did so. | 664 ;; When we initialise a face from an X resource, note that we did so. Now in |
666 ;; | 665 ;; specifier.el so run-time checks for it on non-X builds don't error. |
667 ;; Now in specifier.el so run-time checks for it on non-X builds don't | 666 ;; (define-specifier-tag 'x-resource) |
668 ;; error. | |
669 | |
670 ; (define-specifier-tag 'x-resource) | |
671 | 667 |
672 (defun x-init-face-from-resources (face &optional locale set-anyway) | 668 (defun x-init-face-from-resources (face &optional locale set-anyway) |
673 | |
674 ;; | |
675 ;; These are things like "attributeForeground" instead of simply | 669 ;; These are things like "attributeForeground" instead of simply |
676 ;; "foreground" because people tend to do things like "*foreground", | 670 ;; "foreground" because people tend to do things like "*foreground", which |
677 ;; which would cause all faces to be fully qualified, making faces | 671 ;; would cause all faces to be fully qualified, making faces inherit |
678 ;; inherit attributes in a non-useful way. So we've made them slightly | 672 ;; attributes in a non-useful way. So we've made them slightly less obvious |
679 ;; less obvious to specify in order to make them work correctly in | 673 ;; to specify in order to make them work correctly in more random |
680 ;; more random environments. | 674 ;; environments. |
681 ;; | 675 |
682 ;; I think these should be called "face.faceForeground" instead of | 676 ;; I think these should be called "face.faceForeground" instead of |
683 ;; "face.attributeForeground", but they're the way they are for | 677 ;; "face.attributeForeground", but they're the way they are for hysterical |
684 ;; hysterical reasons. (jwz) | 678 ;; reasons. (jwz) |
685 | |
686 (let* ((append (if set-anyway nil 'append)) | 679 (let* ((append (if set-anyway nil 'append)) |
687 ;; Some faces are initialized before XEmacs is dumped. | 680 ;; Some faces are initialized before XEmacs is dumped. In order for |
688 ;; In order for the X resources to be able to override | 681 ;; the X resources to be able to override those settings, such |
689 ;; those settings, such initialization always uses the | 682 ;; initialization always uses the `default' tag. We remove all |
690 ;; `default' tag. We remove all specifier specs | 683 ;; specifier specs containing the `default' tag in the locale before |
691 ;; containing the `default' tag in the locale before | |
692 ;; adding new specs. | 684 ;; adding new specs. |
693 (tag-set '(default)) | 685 (tag-set '(default)) |
694 ;; The tag order matters here. The spec removal | 686 ;; The tag order matters here. The spec removal function uses the |
695 ;; function uses the list cdrs. We want to remove (x | 687 ;; list cdrs. We want to remove (x default) and (default) specs, not |
696 ;; default) and (default) specs, not (default x) and (x) | 688 ;; (default x) and (x) specs. |
697 ;; specs. | |
698 (x-tag-set '(x default)) | 689 (x-tag-set '(x default)) |
699 (tty-tag-set '(tty default)) | 690 (tty-tag-set '(tty default)) |
700 (our-tag-set '(x x-resource)) | 691 (our-tag-set '(x x-resource)) |
701 (device-class nil) | 692 (device-class nil) |
702 (face-sym (face-name face)) | 693 (face-sym (face-name face)) |
723 'boolean locale)) | 714 'boolean locale)) |
724 (stp (x-get-resource-and-maybe-bogosity-check | 715 (stp (x-get-resource-and-maybe-bogosity-check |
725 (concat name ".attributeStrikethru") | 716 (concat name ".attributeStrikethru") |
726 "Face.AttributeStrikethru" | 717 "Face.AttributeStrikethru" |
727 'boolean locale)) | 718 'boolean locale)) |
728 ;; we still resource for these TTY-only resources so that | 719 ;; we still resource for these TTY-only resources so that you can |
729 ;; you can specify resources for TTY frames/devices. This is | 720 ;; specify resources for TTY frames/devices. This is useful when you |
730 ;; useful when you start up your XEmacs on an X display and later | 721 ;; start up your XEmacs on an X display and later open some TTY |
731 ;; open some TTY frames. | 722 ;; frames. |
732 (hp (x-get-resource-and-maybe-bogosity-check | 723 (hp (x-get-resource-and-maybe-bogosity-check |
733 (concat name ".attributeHighlight") | 724 (concat name ".attributeHighlight") |
734 "Face.AttributeHighlight" | 725 "Face.AttributeHighlight" |
735 'boolean locale)) | 726 'boolean locale)) |
736 (dp (x-get-resource-and-maybe-bogosity-check | 727 (dp (x-get-resource-and-maybe-bogosity-check |
756 (setq tag-set (cons device-class tag-set) | 747 (setq tag-set (cons device-class tag-set) |
757 x-tag-set (cons device-class x-tag-set) | 748 x-tag-set (cons device-class x-tag-set) |
758 tty-tag-set (cons device-class tty-tag-set) | 749 tty-tag-set (cons device-class tty-tag-set) |
759 our-tag-set (cons device-class our-tag-set))) | 750 our-tag-set (cons device-class our-tag-set))) |
760 | 751 |
761 ;; | 752 ;; For the default and gui-element faces, some unspecified properties |
762 ;; If this is the default face, then any unspecified properties should | 753 ;; should be defaulted from the global properties. Can't do this for |
763 ;; be defaulted from the global properties. Can't do this for | |
764 ;; frames or devices because then, common resource specs like | 754 ;; frames or devices because then, common resource specs like |
765 ;; "*Foreground: black" will have unwanted effects. | 755 ;; "*Foreground: black" will have unwanted effects. |
766 ;; | |
767 (if (and (or (eq (face-name face) 'default) | 756 (if (and (or (eq (face-name face) 'default) |
768 (eq (face-name face) 'gui-element)) | 757 (eq (face-name face) 'gui-element)) |
769 (or (null locale) (eq locale 'global))) | 758 (or (null locale) (eq locale 'global))) |
770 (progn | 759 (progn |
771 (or fn (setq fn (x-get-resource | 760 (or fn (setq fn (x-get-resource |
774 "foreground" "Foreground" 'string locale nil | 763 "foreground" "Foreground" 'string locale nil |
775 'warn))) | 764 'warn))) |
776 (or bg (setq bg (x-get-resource | 765 (or bg (setq bg (x-get-resource |
777 "background" "Background" 'string locale nil | 766 "background" "Background" 'string locale nil |
778 'warn))))) | 767 'warn))))) |
779 ;; | 768 |
780 ;; "*cursorColor: foo" is equivalent to setting the background of the | 769 ;; "*cursorColor: foo" is equivalent to setting the background of the |
781 ;; text-cursor face. | 770 ;; text-cursor face. |
782 ;; | |
783 (if (and (eq (face-name face) 'text-cursor) | 771 (if (and (eq (face-name face) 'text-cursor) |
784 (or (null locale) (eq locale 'global))) | 772 (or (null locale) (eq locale 'global))) |
785 (setq bg (or (x-get-resource | 773 (setq bg (or (x-get-resource |
786 "cursorColor" "CursorColor" 'string locale nil 'warn) | 774 "cursorColor" "CursorColor" 'string locale nil 'warn) |
787 bg))) | 775 bg))) |
788 ;; #### should issue warnings? I think this should be | 776 ;; #### NOTE: should issue warnings? I think this should be done when the |
789 ;; done when the instancing actually happens, but I'm not | 777 ;; instancing actually happens, but I'm not sure how it should actually be |
790 ;; sure how it should actually be dealt with. | 778 ;; dealt with. |
791 (when fn | 779 (when fn |
792 (if device-class | 780 (if device-class |
793 ;; Always use the x-tag-set to remove specs, since we don't | 781 ;; Always use the x-tag-set to remove specs, since we don't know |
794 ;; know whether the predumped face was initialized with an | 782 ;; whether the predumped face was initialized with an 'x tag or not. |
795 ;; 'x tag or not. | |
796 (remove-specifier-specs-matching-tag-set-cdrs (face-font face) | 783 (remove-specifier-specs-matching-tag-set-cdrs (face-font face) |
797 locale | 784 locale |
798 x-tag-set) | 785 x-tag-set) |
799 ;; If there's no device class then we're initializing | 786 ;; If there's no device class then we're initializing globally. This |
800 ;; globally. This means we should override global | 787 ;; means we should override global defaults for all X device classes. |
801 ;; defaults for all X device classes. | |
802 (remove-specifier (face-font face) locale x-tag-set nil)) | 788 (remove-specifier (face-font face) locale x-tag-set nil)) |
803 (set-face-font face fn locale our-tag-set append) | 789 (set-face-font face fn locale our-tag-set append) |
804 | 790 |
805 ;; And retain some of the fallbacks in the generated default face, | 791 ;; And retain some of the fallbacks in the generated default face, since |
806 ;; since we don't want to try andale-mono's ISO-10646-1 encoding for | 792 ;; we don't want to try andale-mono's ISO-10646-1 encoding for Amharic |
807 ;; Amharic or Thai. | 793 ;; or Thai. |
808 (when (and (specifierp (face-font face)) | 794 (when (and (specifierp (face-font face)) |
809 (consp (specifier-fallback (face-font face)))) | 795 (consp (specifier-fallback (face-font face)))) |
810 (loop | 796 (loop |
811 for (tag-set . instantiator) | 797 for (tag-set . instantiator) |
812 in (specifier-fallback (face-font face)) | 798 in (specifier-fallback (face-font face)) |
815 (face-font face) | 801 (face-font face) |
816 (list (cons (or locale 'global) | 802 (list (cons (or locale 'global) |
817 (list (cons tag-set instantiator)))) | 803 (list (cons tag-set instantiator)))) |
818 append)))) | 804 append)))) |
819 | 805 |
820 ;; Kludge-o-rooni. Set the foreground and background resources for | 806 ;; Kludge-o-rooni. Set the foreground and background resources for X |
821 ;; X devices only -- otherwise things tend to get all messed up | 807 ;; devices only -- otherwise things tend to get all messed up if you start |
822 ;; if you start up an X frame and then later create a TTY frame. | 808 ;; up an X frame and then later create a TTY frame. |
823 (when fg | 809 (when fg |
824 (if device-class | 810 (if device-class |
825 (remove-specifier-specs-matching-tag-set-cdrs (face-foreground face) | 811 (remove-specifier-specs-matching-tag-set-cdrs (face-foreground face) |
826 locale | 812 locale |
827 x-tag-set) | 813 x-tag-set) |
903 (defun remove-specifier-specs-matching-tag-set-cdrs (specifier locale tag-set) | 889 (defun remove-specifier-specs-matching-tag-set-cdrs (specifier locale tag-set) |
904 (while tag-set | 890 (while tag-set |
905 (remove-specifier specifier locale tag-set t) | 891 (remove-specifier specifier locale tag-set t) |
906 (setq tag-set (cdr tag-set)))) | 892 (setq tag-set (cdr tag-set)))) |
907 | 893 |
908 ;;; x-init-global-faces is responsible for ensuring that the | 894 ;;; x-init-global-faces is responsible for ensuring that the default face has |
909 ;;; default face has some reasonable fallbacks if nothing else is | 895 ;;; some reasonable fallbacks if nothing else is specified. |
910 ;;; specified. | |
911 ;;; | |
912 (defun x-init-global-faces () | 896 (defun x-init-global-faces () |
913 ;; #### NOTE: this code is probably an oldy: faces.c ensures that we have | 897 ;; #### NOTE: this code is probably an oldy: faces.c ensures that we have |
914 ;; working fallback values so there is no need to initialize anything here. | 898 ;; working fallback values so there is no need to initialize anything here. |
915 ;; -- dvl | 899 ;; -- dvl |
916 ;; (or (face-foreground 'default 'global) | 900 ;; (or (face-foreground 'default 'global) |
917 ;; (set-face-foreground 'default "black" 'global '(x default))) | 901 ;; (set-face-foreground 'default "black" 'global '(x default))) |
918 ;; (or (face-background 'default 'global) | 902 ;; (or (face-background 'default 'global) |
919 ;; (set-face-background 'default "gray80" 'global '(x default)) | 903 ;; (set-face-background 'default "gray80" 'global '(x default)) |
920 ) | 904 ) |
921 | 905 |
922 ;;; x-init-device-faces is responsible for initializing default | 906 ;;; x-init-device-faces is responsible for initializing default values for |
923 ;;; values for faces on a newly created device. | 907 ;;; faces on a newly created device. |
924 ;;; | |
925 (defun x-init-device-faces (device) | 908 (defun x-init-device-faces (device) |
926 ;; | |
927 ;; If the "default" face didn't have a font specified, try to pick one. | 909 ;; If the "default" face didn't have a font specified, try to pick one. |
928 ;; | 910 |
929 ;; (or | 911 ;; (or |
930 ;; (face-font-instance 'default device) | 912 ;; (face-font-instance 'default device) |
931 ;; | 913 |
932 ;; [[ No font specified in the resource database; try to cope. ]] | 914 ;; [[ No font specified in the resource database; try to cope. ]] |
933 ;; | 915 |
934 ;; NOTE: In reality, this will never happen. The fallbacks will always | 916 ;; #### NOTE: In reality, this will never happen. The fallbacks will always |
935 ;; be tried, and the last fallback is "*", which should get any font. No | 917 ;; be tried, and the last fallback is "*", which should get any font. No |
936 ;; need to put the same checks here as in the fallbacks. These comments | 918 ;; need to put the same checks here as in the fallbacks. These comments |
937 ;; appear to be pre-19.12. --ben | 919 ;; appear to be pre-19.12. --ben |
938 | 920 |
939 ;; [[ At first I wanted to do this by just putting a font-spec in the | 921 ;; [[ At first I wanted to do this by just putting a font-spec in the |
940 ;; fallback resources passed to XtAppInitialize(), but that fails | 922 ;; fallback resources passed to XtAppInitialize(), but that fails if there |
941 ;; if there is an Emacs app-defaults file which doesn't specify a | 923 ;; is an Emacs app-defaults file which doesn't specify a font: apparently |
942 ;; font: apparently the fallback resources are not consulted when | 924 ;; the fallback resources are not consulted when there is an app-defaults |
943 ;; there is an app-defaults file, which seems pretty bogus to me. | 925 ;; file, which seems pretty bogus to me. |
944 ;; | 926 |
945 ;; We should also probably try "*xtDefaultFont", but I think that it | 927 ;; We should also probably try "*xtDefaultFont", but I think that it might |
946 ;; might be legal to specify that as "xtDefaultFont:", that is, at | 928 ;; be legal to specify that as "xtDefaultFont:", that is, at top level, |
947 ;; top level, instead of "*xtDefaultFont:", that is, applicable to | 929 ;; instead of "*xtDefaultFont:", that is, applicable to every application. |
948 ;; every application. `x-get-resource' can't handle that right now. | 930 ;; `x-get-resource' can't handle that right now. Anyway, xtDefaultFont is |
949 ;; Anyway, xtDefaultFont is probably variable-width. | 931 ;; probably variable-width. |
950 ;; | 932 |
951 ;; Some who have LucidaTypewriter think it's a better font than Courier, | 933 ;; Some who have LucidaTypewriter think it's a better font than Courier, but |
952 ;; but it has the bug that there are no italic and bold italic versions. | 934 ;; it has the bug that there are no italic and bold italic versions. We |
953 ;; We could hair this code up to try and mix-and-match fonts to get a | 935 ;; could hair this code up to try and mix-and-match fonts to get a full |
954 ;; full complement, but really, why bother. It's just a default. ]] | 936 ;; complement, but really, why bother. It's just a default. ]] |
955 ;; | 937 |
956 ;; [[ We default to looking for iso8859 fonts. Using a wildcard for the | 938 ;; [[ We default to looking for iso8859 fonts. Using a wildcard for the |
957 ;; encoding would be bad, because that can cause English speakers to get | 939 ;; encoding would be bad, because that can cause English speakers to get |
958 ;; Kanji fonts by default. It is safe to assume that people using a | 940 ;; Kanji fonts by default. It is safe to assume that people using a language |
959 ;; language other than English have both set $LANG, and have specified | 941 ;; other than English have both set $LANG, and have specified their `font' |
960 ;; their `font' and `fontList' resources. In any event, it's better to | 942 ;; and `fontList' resources. In any event, it's better to err on the side of |
961 ;; err on the side of the English speaker in this case because they are | 943 ;; the English speaker in this case because they are much less likely to |
962 ;; much less likely to have encountered this problem, and are thus less | 944 ;; have encountered this problem, and are thus less likely to know what to |
963 ;; likely to know what to do about it. ]] | 945 ;; do about it. ]] |
964 | |
965 | 946 |
966 ;; #### NOTE: this code is probably an oldy as well (as per Ben's comment | 947 ;; #### NOTE: this code is probably an oldy as well (as per Ben's comment |
967 ;; above): faces.c ensures that we have working fallback values so there is | 948 ;; above): faces.c ensures that we have working fallback values so there is |
968 ;; no need to initialize anything here. -- dvl | 949 ;; no need to initialize anything here. -- dvl |
969 | 950 |
976 ;; (or fg (set-face-foreground 'default "white" device)) | 957 ;; (or fg (set-face-foreground 'default "white" device)) |
977 ;; (or bg (set-face-background 'default "black" device))) | 958 ;; (or bg (set-face-background 'default "black" device))) |
978 ;; (or fg (set-face-foreground 'default "white" device)) | 959 ;; (or fg (set-face-foreground 'default "white" device)) |
979 ;; (or bg (set-face-background 'default "black" device))))) | 960 ;; (or bg (set-face-background 'default "black" device))))) |
980 | 961 |
981 ;; Don't look at reverseVideo now or initialize the modeline. This | 962 ;; Don't look at reverseVideo now or initialize the modeline. This is done |
982 ;; is done on a per-frame basis at the appropriate time. | 963 ;; on a per-frame basis at the appropriate time. |
983 | 964 |
984 ;; | 965 ;; Now let's try to pick some reasonable defaults for a few other faces. |
985 ;; Now let's try to pick some reasonable defaults for a few other faces. | 966 ;; This kind of stuff should normally go on the create-frame-hook, but this |
986 ;; This kind of stuff should normally go on the create-frame-hook, but | 967 ;; way we won't be in danger of the user screwing things up by not adding |
987 ;; this way we won't be in danger of the user screwing things up by not | 968 ;; hooks in a safe way. |
988 ;; adding hooks in a safe way. | |
989 ;; | |
990 (x-init-pointer-shape device) ; from x-mouse.el | 969 (x-init-pointer-shape device) ; from x-mouse.el |
991 ) | 970 ) |
992 | 971 |
993 ;;; This is called from `init-frame-faces', which is called from | 972 ;;; This is called from `init-frame-faces', which is called from |
994 ;;; init_frame_faces() which is called from Fmake_frame(), to perform | 973 ;;; init_frame_faces() which is called from Fmake_frame(), to perform any |
995 ;;; any device-specific initialization. | 974 ;;; device-specific initialization. |
996 ;;; | |
997 (defun x-init-frame-faces (frame) | 975 (defun x-init-frame-faces (frame) |
998 ;; | 976 ;; The faces already got initialized (by init-frame-faces) from the resource |
999 ;; The faces already got initialized (by init-frame-faces) from | 977 ;; database or global, non-frame faces. The default, bold, bold-italic, and |
1000 ;; the resource database or global, non-frame faces. The default, | 978 ;; italic faces (plus various other random faces) got set up then. But |
1001 ;; bold, bold-italic, and italic faces (plus various other random faces) | 979 ;; modeline didn't so that reverseVideo can be frame-specific. |
1002 ;; got set up then. But modeline didn't so that reverseVideo can be | 980 |
1003 ;; frame-specific. | 981 ;; If reverseVideo was specified, swap the foreground and background of the |
1004 ;; | 982 ;; default and modeline faces. |
1005 | |
1006 ;; | |
1007 ;; If reverseVideo was specified, swap the foreground and background | |
1008 ;; of the default and modeline faces. | |
1009 ;; | |
1010 (cond ((car (x-get-resource "reverseVideo" "ReverseVideo" 'boolean frame | 983 (cond ((car (x-get-resource "reverseVideo" "ReverseVideo" 'boolean frame |
1011 nil 'warn)) | 984 nil 'warn)) |
1012 ;; #### NOTE: again, this is probably yet another oldy: faces.c | 985 ;; #### NOTE: again, this is probably yet another oldy: faces.c |
1013 ;; ensures sane fallbacks for the modeline face. Besides, this face | 986 ;; ensures sane fallbacks for the modeline face. Besides, this face |
1014 ;; does not inherit from the default face, but from the gui-element | 987 ;; does not inherit from the default face, but from the gui-element |
1021 ;; (or (face-background 'modeline frame) | 994 ;; (or (face-background 'modeline frame) |
1022 ;; (set-face-background 'modeline | 995 ;; (set-face-background 'modeline |
1023 ;; (face-background-instance 'default frame) | 996 ;; (face-background-instance 'default frame) |
1024 ;; frame)) | 997 ;; frame)) |
1025 | 998 |
1026 ;; Now invert both of them. If they end up looking the same, | 999 ;; Now invert both of them. If they end up looking the same, |
1027 ;; make-frame-initial-faces will invert the modeline again later. | 1000 ;; make-frame-initial-faces will invert the modeline again later. |
1028 (invert-face 'default frame) | 1001 (invert-face 'default frame) |
1029 (invert-face 'modeline frame) | 1002 (invert-face 'modeline frame) |
1030 ))) | 1003 ))) |
1031 | 1004 |