diff options
| author | Richard M. Stallman | 1994-02-12 06:25:56 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-02-12 06:25:56 +0000 |
| commit | 19ae9866c9db33e9e3809c9f14ea19b1958bc285 (patch) | |
| tree | 58a4a4bcf54109e22075ecf690dda1b1fa5c4165 | |
| parent | e1f672f5798d31602ceaf307db47e7003cf82083 (diff) | |
| download | emacs-19ae9866c9db33e9e3809c9f14ea19b1958bc285.tar.gz emacs-19ae9866c9db33e9e3809c9f14ea19b1958bc285.zip | |
(face-initialize): Specify default characteristics
for the standard faces. Use face-fill-in to set up existing frames.
(face-fill-in, face-try-color-list): New subroutines.
Handle underline, foreground and background in the
frame-independent info of a face.
(x-create-frame-with-faces): Use face-fill-in.
(x-initialize-frame-faces): Function deleted.
| -rw-r--r-- | lisp/faces.el | 220 |
1 files changed, 94 insertions, 126 deletions
diff --git a/lisp/faces.el b/lisp/faces.el index 4ecead6a32f..178a07ea3c2 100644 --- a/lisp/faces.el +++ b/lisp/faces.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; faces.el --- Lisp interface to the c "face" structure | 1 | ;;; faces.el --- Lisp interface to the c "face" structure |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; This file is part of GNU Emacs. | 5 | ;; This file is part of GNU Emacs. |
| 6 | 6 | ||
| @@ -28,7 +28,7 @@ | |||
| 28 | ;;;; Functions for manipulating face vectors. | 28 | ;;;; Functions for manipulating face vectors. |
| 29 | 29 | ||
| 30 | ;;; A face vector is a vector of the form: | 30 | ;;; A face vector is a vector of the form: |
| 31 | ;;; [face ID FONT FOREGROUND BACKGROUND BACKGROUND-PIXMAP UNDERLINE] | 31 | ;;; [face NAME ID FONT FOREGROUND BACKGROUND BACKGROUND-PIXMAP UNDERLINE] |
| 32 | 32 | ||
| 33 | ;;; Type checkers. | 33 | ;;; Type checkers. |
| 34 | (defsubst internal-facep (x) | 34 | (defsubst internal-facep (x) |
| @@ -740,17 +740,16 @@ selected frame." | |||
| 740 | (copy-face (car faces) (car faces) frame disp-frame) | 740 | (copy-face (car faces) (car faces) frame disp-frame) |
| 741 | (setq faces (cdr faces))))))) | 741 | (setq faces (cdr faces))))))) |
| 742 | 742 | ||
| 743 | ;;; Make the default and modeline faces; the C code knows these as | 743 | ;;; Make the standard faces. |
| 744 | ;;; faces 0 and 1, respectively, so they must be the first two faces | 744 | ;;; The C code knows the default and modeline faces as faces 0 and 1, |
| 745 | ;;; made. | 745 | ;;; so they must be the first two faces made. |
| 746 | (defun face-initialize () | 746 | (defun face-initialize () |
| 747 | (make-face 'default) | 747 | (make-face 'default) |
| 748 | (make-face 'modeline) | 748 | (make-face 'modeline) |
| 749 | (make-face 'highlight) | 749 | (make-face 'highlight) |
| 750 | ;; | 750 | |
| 751 | ;; These aren't really special in any way, but they're nice to have around. | 751 | ;; These aren't really special in any way, but they're nice to have around. |
| 752 | ;; The X-specific code is clever at them. | 752 | |
| 753 | ;; | ||
| 754 | (make-face 'bold) | 753 | (make-face 'bold) |
| 755 | (make-face 'italic) | 754 | (make-face 'italic) |
| 756 | (make-face 'bold-italic) | 755 | (make-face 'bold-italic) |
| @@ -760,116 +759,35 @@ selected frame." | |||
| 760 | 759 | ||
| 761 | (setq region-face (face-id 'region)) | 760 | (setq region-face (face-id 'region)) |
| 762 | 761 | ||
| 763 | ;; Set up the faces of all existing X Window frames. | 762 | ;; Specify the global properties of these faces |
| 763 | ;; so they will come out right on new frames. | ||
| 764 | |||
| 765 | (make-face-bold 'bold t) | ||
| 766 | (make-face-italic 'italic t) | ||
| 767 | (make-face-bold-italic 'bold-italic t) | ||
| 768 | |||
| 769 | (set-face-background 'highlight '("darkseagreen2" "green" t) t) | ||
| 770 | (set-face-background 'region '("gray" t) t) | ||
| 771 | (set-face-background 'secondary-selection '("paleturquoise" "green" t) t) | ||
| 772 | (set-face-background 'modeline '(t) t) | ||
| 773 | (set-face-underline-p 'underline t t) | ||
| 774 | |||
| 775 | ;; Set up the faces of all existing X Window frames | ||
| 776 | ;; from those global properties, unless already set in a given frame. | ||
| 777 | |||
| 764 | (let ((frames (frame-list))) | 778 | (let ((frames (frame-list))) |
| 765 | (while frames | 779 | (while frames |
| 766 | (if (eq (framep (car frames)) 'x) | 780 | (if (eq (framep (car frames)) 'x) |
| 767 | (x-initialize-frame-faces (car frames))) | 781 | (let ((frame (car frames)) |
| 782 | (rest global-face-data)) | ||
| 783 | (while rest | ||
| 784 | (let ((face (car (car rest)))) | ||
| 785 | (or (face-differs-from-default-p face) | ||
| 786 | (face-fill-in face (cdr (car rest)) frame))) | ||
| 787 | (setq rest (cdr rest))))) | ||
| 768 | (setq frames (cdr frames))))) | 788 | (setq frames (cdr frames))))) |
| 769 | 789 | ||
| 770 | 790 | ||
| 771 | ;;; This really belongs in setting a frame's own font. | ||
| 772 | ;;; ;; | ||
| 773 | ;;; ;; No font specified in the resource database; try to cope. | ||
| 774 | ;;; ;; | ||
| 775 | ;;; (internal-try-face-font default "-*-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-*" | ||
| 776 | ;;; frame) | ||
| 777 | ;;; (internal-try-face-font default "-*-courier-*-r-*-*-*-120-*-*-*-*-iso8859-*" | ||
| 778 | ;;; frame) | ||
| 779 | ;;; (internal-try-face-font default "-*-*-medium-r-*-*-*-120-*-*-m-*-iso8859-*" frame) | ||
| 780 | ;;; (internal-try-face-font default "-*-*-medium-r-*-*-*-120-*-*-c-*-iso8859-*" frame) | ||
| 781 | ;;; (internal-try-face-font default "-*-*-*-r-*-*-*-120-*-*-m-*-iso8859-*" frame) | ||
| 782 | ;;; (internal-try-face-font default "-*-*-*-r-*-*-*-120-*-*-c-*-iso8859-*" frame) | ||
| 783 | ;;; (internal-try-face-font default "-*-*-*-r-*-*-*-120-*-*-*-*-iso8859-*" frame) | ||
| 784 | |||
| 785 | |||
| 786 | ;;; This is called from make-screen-initial-faces to make sure that the | ||
| 787 | ;;; "default" and "modeline" faces for this screen have enough attributes | ||
| 788 | ;;; specified for emacs to be able to display anything on it. This had | ||
| 789 | ;;; better not signal an error. | ||
| 790 | ;;; | ||
| 791 | (defun x-initialize-frame-faces (frame) | ||
| 792 | (or (face-differs-from-default-p 'bold frame) | ||
| 793 | (make-face-bold 'bold frame t) | ||
| 794 | ;; if default font is bold, then make the `bold' face be unbold. | ||
| 795 | (make-face-unbold 'bold frame t) | ||
| 796 | ;; otherwise the luser specified one of the bogus font names | ||
| 797 | (internal-x-complain-about-font 'bold frame) | ||
| 798 | ) | ||
| 799 | |||
| 800 | (or (face-differs-from-default-p 'italic frame) | ||
| 801 | (make-face-italic 'italic frame t) | ||
| 802 | (progn | ||
| 803 | (make-face-bold 'italic frame t) | ||
| 804 | (internal-x-complain-about-font 'italic frame)) | ||
| 805 | ) | ||
| 806 | |||
| 807 | (or (face-differs-from-default-p 'bold-italic frame) | ||
| 808 | (make-face-bold-italic 'bold-italic frame t) | ||
| 809 | ;; if we couldn't get a bold-italic version, try just bold. | ||
| 810 | (make-face-bold 'bold-italic frame t) | ||
| 811 | ;; if we couldn't get bold or bold-italic, then that's probably because | ||
| 812 | ;; the default font is bold, so make the `bold-italic' face be unbold. | ||
| 813 | (and (make-face-unbold 'bold-italic frame t) | ||
| 814 | (make-face-italic 'bold-italic frame t)) | ||
| 815 | ;; if that didn't work, try italic (can this ever happen? what the hell.) | ||
| 816 | (progn | ||
| 817 | (make-face-italic 'bold-italic frame t) | ||
| 818 | ;; then bitch and moan. | ||
| 819 | (internal-x-complain-about-font 'bold-italic frame)) | ||
| 820 | ) | ||
| 821 | |||
| 822 | (or (face-differs-from-default-p 'highlight frame) | ||
| 823 | (if (or (not (x-display-color-p)) | ||
| 824 | (= (x-display-planes) 1)) | ||
| 825 | (invert-face 'highlight frame) | ||
| 826 | (condition-case () | ||
| 827 | (condition-case () | ||
| 828 | (set-face-background 'highlight "darkseagreen2" frame) | ||
| 829 | (error (set-face-background 'highlight "green" frame))) | ||
| 830 | ;;; (set-face-background-pixmap 'highlight "gray1" frame) | ||
| 831 | (error (invert-face 'highlight frame))))) | ||
| 832 | |||
| 833 | (or (face-differs-from-default-p 'region frame) | ||
| 834 | (if (= (x-display-planes) 1) | ||
| 835 | (invert-face 'region frame) | ||
| 836 | (condition-case () | ||
| 837 | (set-face-background 'region "gray" frame) | ||
| 838 | (error (invert-face 'region frame))))) | ||
| 839 | |||
| 840 | (or (face-differs-from-default-p 'modeline frame) | ||
| 841 | (invert-face 'modeline frame)) | ||
| 842 | |||
| 843 | (or (face-differs-from-default-p 'underline frame) | ||
| 844 | (set-face-underline-p 'underline t frame)) | ||
| 845 | |||
| 846 | (or (face-differs-from-default-p 'secondary-selection frame) | ||
| 847 | (if (or (not (x-display-color-p)) | ||
| 848 | (= (x-display-planes) 1)) | ||
| 849 | (invert-face 'secondary-selection frame) | ||
| 850 | (condition-case () | ||
| 851 | (condition-case () | ||
| 852 | ;; some older X servers don't have this one. | ||
| 853 | (set-face-background 'secondary-selection "paleturquoise" | ||
| 854 | frame) | ||
| 855 | (error | ||
| 856 | (set-face-background 'secondary-selection "green" frame))) | ||
| 857 | ;;; (set-face-background-pixmap 'secondary-selection "gray1" frame) | ||
| 858 | (error (invert-face 'secondary-selection frame))))) | ||
| 859 | ) | ||
| 860 | |||
| 861 | (defun internal-x-complain-about-font (face frame) | ||
| 862 | ;;; It's annoying to bother the user about this, | ||
| 863 | ;;; since it happens under normal circumstances. | ||
| 864 | ;;; (message "No %s version of %S" | ||
| 865 | ;;; face | ||
| 866 | ;;; (or (face-font face frame) | ||
| 867 | ;;; (face-font face t) | ||
| 868 | ;;; (face-font 'default frame) | ||
| 869 | ;;; (cdr (assq 'font (frame-parameters frame))))) | ||
| 870 | ;;; (sit-for 1) | ||
| 871 | ) | ||
| 872 | |||
| 873 | ;; Like x-create-frame but also set up the faces. | 791 | ;; Like x-create-frame but also set up the faces. |
| 874 | 792 | ||
| 875 | (defun x-create-frame-with-faces (&optional parameters) | 793 | (defun x-create-frame-with-faces (&optional parameters) |
| @@ -897,24 +815,74 @@ selected frame." | |||
| 897 | ;; Copy the vectors that represent the faces. | 815 | ;; Copy the vectors that represent the faces. |
| 898 | ;; Also fill them in from X resources. | 816 | ;; Also fill them in from X resources. |
| 899 | (while rest | 817 | (while rest |
| 900 | (setcdr (car rest) (copy-sequence (cdr (car rest)))) | 818 | (let ((global (cdr (car rest)))) |
| 901 | (condition-case nil | 819 | (setcdr (car rest) (vector 'face |
| 902 | (if (listp (face-font (cdr (car rest)))) | 820 | (face-name (cdr (car rest))) |
| 903 | (let ((bold (memq 'bold (face-font (cdr (car rest))))) | 821 | (face-id (cdr (car rest))) |
| 904 | (italic (memq 'italic (face-font (cdr (car rest)))))) | 822 | nil nil nil nil nil)) |
| 905 | (if (and bold italic) | 823 | (face-fill-in (car (car rest)) global frame)) |
| 906 | (make-face-bold-italic (car (car rest)) frame) | ||
| 907 | (if bold | ||
| 908 | (make-face-bold (car (car rest)) frame) | ||
| 909 | (if italic | ||
| 910 | (make-face-italic (car (car rest)) frame)))))) | ||
| 911 | (error nil)) | ||
| 912 | (make-face-x-resource-internal (cdr (car rest)) frame t) | 824 | (make-face-x-resource-internal (cdr (car rest)) frame t) |
| 913 | (setq rest (cdr rest))) | 825 | (setq rest (cdr rest))) |
| 826 | frame))) | ||
| 914 | 827 | ||
| 915 | (x-initialize-frame-faces frame) | 828 | ;; Fill in the face FACE from frame-independent face data DATA. |
| 829 | ;; DATA should be the non-frame-specific ("global") face vector | ||
| 830 | ;; for the face. FACE should be a face name or face object. | ||
| 831 | ;; FRAME is the frame to act on; it must be an actual frame, not nil or t. | ||
| 832 | (defun face-fill-in (face data frame) | ||
| 833 | (condition-case nil | ||
| 834 | (let ((foreground (face-foreground data)) | ||
| 835 | (background (face-background data)) | ||
| 836 | (font (face-font data))) | ||
| 837 | (set-face-underline-p face (face-underline-p data) frame) | ||
| 838 | (if foreground | ||
| 839 | (face-try-color-list 'set-face-foreground | ||
| 840 | face foreground frame)) | ||
| 841 | (if background | ||
| 842 | (face-try-color-list 'set-face-background | ||
| 843 | face background frame)) | ||
| 844 | (if (listp font) | ||
| 845 | (let ((bold (memq 'bold font)) | ||
| 846 | (italic (memq 'italic font))) | ||
| 847 | (cond ((and bold italic) | ||
| 848 | (make-face-bold-italic face frame)) | ||
| 849 | (bold | ||
| 850 | (make-face-bold face frame)) | ||
| 851 | (italic | ||
| 852 | (make-face-italic face frame)))) | ||
| 853 | (if font | ||
| 854 | (set-face-font face font frame)))) | ||
| 855 | (error nil))) | ||
| 916 | 856 | ||
| 917 | frame))) | 857 | ;; Use FUNCTION to store a color in FACE on FRAME. |
| 858 | ;; COLORS is either a single color or a list of colors. | ||
| 859 | ;; If it is a list, try the colors one by one until one of them | ||
| 860 | ;; succeeds. We signal an error only if all the colors failed. | ||
| 861 | ;; t as COLORS or as an element of COLORS means to invert the face. | ||
| 862 | ;; That can't fail, so any subsequent elements after the t are ignored. | ||
| 863 | (defun face-try-color-list (function face colors frame) | ||
| 864 | (if (stringp colors) | ||
| 865 | (funcall function face colors frame) | ||
| 866 | (if (eq colors t) | ||
| 867 | (invert-face face frame) | ||
| 868 | (let (done) | ||
| 869 | (while (and colors (not done)) | ||
| 870 | (if (cdr colors) | ||
| 871 | ;; If there are more colors to try, catch errors | ||
| 872 | ;; and set `done' if we succeed. | ||
| 873 | (condition-case nil | ||
| 874 | (progn | ||
| 875 | (if (eq (car colors) t) | ||
| 876 | (invert-face face frame) | ||
| 877 | (funcall function face (car colors) frame)) | ||
| 878 | (setq done t)) | ||
| 879 | (error nil)) | ||
| 880 | ;; If this is the last color, let the error get out if it fails. | ||
| 881 | ;; If it succeeds, we will exit anyway after this iteration. | ||
| 882 | (if (eq (car colors) t) | ||
| 883 | (invert-face face frame) | ||
| 884 | (funcall function face (car colors) frame))) | ||
| 885 | (setq colors (cdr colors))))))) | ||
| 918 | 886 | ||
| 919 | ;; If we are already using x-window frames, initialize faces for them. | 887 | ;; If we are already using x-window frames, initialize faces for them. |
| 920 | (if (eq (framep (selected-frame)) 'x) | 888 | (if (eq (framep (selected-frame)) 'x) |