changeset 26902:264b83a3a688

Changes for separate unspecified foreground and background colors on character terminals: * dispextern.h (FACE_TTY_DEFAULT_FG_COLOR) (FACE_TTY_DEFAULT_BG_COLOR): New macros. * xfaces.c (Qunspecified_fg, Qunspecified_bg): New variables. (syms_of_xfaces): Initialize and staticpro them. (tty_defined_color): If the color name is unspecified-fg or unspecified-bg, return FACE_TTY_DEFAULT_FG_COLOR and FACE_TTY_DEFAULT_BG_COLOR, respectively, as the pixel value. (tty_color_name): If the color pixel value is either FACE_TTY_DEFAULT_FG_COLOR or FACE_TTY_DEFAULT_BG_COLOR, return Qunspecified_fg or Qunspecified_bg, respectively. (Finternal_set_lisp_face_attribute): Allow values Qunspecified_fg and Qunspecified_bg for foreground and background colors. (realize_default_face): If the foreground and background colors are not specified, default to Qunspecified_fg and Qunspecified_bg. (realize_tty_face): By default, set the face colors to FACE_TTY_DEFAULT_FG_COLOR and FACE_TTY_DEFAULT_BG_COLOR. [MSDOS]: Handle FACE_TTY_DEFAULT_FG_COLOR and FACE_TTY_DEFAULT_BG_COLOR when face colors are not defined. Reverse the colors if the default colors were reversed. * dispnew.c (init_display): Initialize the frame pixels of the initial frame to FACE_TTY_DEFAULT_FG_COLOR and FACE_TTY_DEFAULT_BG_COLOR. * term.c (turn_on_face): If the default fore- and background colors are reversed, enter inverse video mode. Don't send color escape sequences for unspecified foreground and background colors. (turn_off_face): Handle unspecified-fg and unspecified-bg colors. * dosfns.c (unspecified_colors): New variable. (msdos_stdcolor_idx): Handle unspecified-fg and unspecified-bg color names, return FACE_TTY_DEFAULT_FG_COLOR and FACE_TTY_DEFAULT_BG_COLOR, respectively. (msdos_stdcolor_name): Handle FACE_TTY_DEFAULT_FG_COLOR and FACE_TTY_DEFAULT_BG_COLOR, return Qunspecified_fg and Qunspecified_bg, respectively. * msdos.c (IT_set_face): Support FACE_TTY_DEFAULT_FG_COLOR and FACE_TTY_DEFAULT_BG_COLOR as pixel values. * faces.el (face-read-integer, read-face-attribute) (color-defined-p, color-values): Allow color values unspecified-fg and unspecified-bg, handle them as unspecified.
author Eli Zaretskii <eliz@gnu.org>
date Wed, 15 Dec 1999 13:14:38 +0000
parents cfaf05bc5ac2
children 02eb743f6ab3
files lisp/ChangeLog lisp/faces.el src/ChangeLog src/dispextern.h src/dispnew.c src/dosfns.c src/msdos.c src/term.c src/xfaces.c
diffstat 9 files changed, 124 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Wed Dec 15 12:49:36 1999 +0000
+++ b/lisp/ChangeLog	Wed Dec 15 13:14:38 1999 +0000
@@ -1,3 +1,9 @@
+1999-12-15  Eli Zaretskii  <eliz@is.elta.co.il>
+
+	* faces.el (face-read-integer, read-face-attribute)
+	(color-defined-p, color-values): Allow color values unspecified-fg
+	and unspecified-bg, handle them as unspecified.
+
 1999-12-15  Kenichi Handa  <handa@etl.go.jp>
 
 	The following changes are for the new composition mechanism.  We
--- a/lisp/faces.el	Wed Dec 15 12:49:36 1999 +0000
+++ b/lisp/faces.el	Wed Dec 15 13:14:38 1999 +0000
@@ -827,12 +827,14 @@
 name of the attribute for prompting.  Value is the new attribute value."
   (let ((new-value
 	 (face-read-string face
-			   (if (eq default 'unspecified)
-			       'unspecified
+			   (if (memq
+				default
+				'(unspecified unspecified-fg unspecified-bg))
+			       default
 			     (int-to-string default))
 			   name
 			   (list (cons "unspecified" 'unspecified)))))
-    (if (eq new-value 'unspecified)
+    (if (memq new-value '(unspecified unspecified-fg unspecified-bg))
 	new-value
       (string-to-int new-value))))
 
@@ -862,7 +864,8 @@
 	   ;; in tty-colors.el.
 	   (if (and (memq attribute '(:foreground :background))
 		    (not (memq window-system '(x w32 mac)))
-		    (not (eq new-value 'unspecified)))
+		    (not (memq new-value
+			       '(unspecified unspecified-fg unspecified-bg))))
 	       (setq new-value (car (tty-color-desc new-value))))
 	   (unless (eq new-value 'unspecified)
 	     (setq new-value (cdr (assoc new-value valid)))))
@@ -1164,8 +1167,9 @@
 (defun color-defined-p (color &optional frame)
   "Return non-nil if color COLOR is supported on frame FRAME.
 If FRAME is omitted or nil, use the selected frame.
-If COLOR is the symbol `unspecified', the value is nil."
-  (if (eq color 'unspecified)
+If COLOR is one of the symbols `unspecified', `unspecified-fg', or
+`unspecified-bg', the value is nil."
+  (if (memq color '(unspecified unspecified-bg unspecified-fg))
       nil
     (if (memq (framep (or frame (selected-frame))) '(x w32))
 	(xw-color-defined-p color frame)
@@ -1179,8 +1183,9 @@
 on the system; white is \(65280 65280 65280\) or \(65535 65535 65535\).
 If FRAME is omitted or nil, use the selected frame.
 If FRAME cannot display COLOR, the value is nil.
-If COLOR is the symbol `unspecified', the value is nil."
-  (if (eq color 'unspecified)
+If COLOR is one of the symbols `unspecified', `unspecified-fg', or
+`unspecified-bg', the value is nil."
+  (if (memq color '(unspecified unspecified-fg unspecified-bg))
       nil
     (if (memq (framep (or frame (selected-frame))) '(x w32))
 	(xw-color-values color frame)
Binary file src/ChangeLog has changed
--- a/src/dispextern.h	Wed Dec 15 12:49:36 1999 +0000
+++ b/src/dispextern.h	Wed Dec 15 13:14:38 1999 +0000
@@ -1268,6 +1268,14 @@
 
 #define FACE_TTY_DEFAULT_COLOR ((unsigned long) -1)
 
+/* Color index indicating that face uses an unknown foreground color.  */
+
+#define FACE_TTY_DEFAULT_FG_COLOR ((unsigned long) -2)
+
+/* Color index indicating that face uses an unsigned background color.  */
+
+#define FACE_TTY_DEFAULT_BG_COLOR ((unsigned long) -3)
+
 /* Non-zero if FACE was realized for unibyte use.  */
 
 #define FACE_UNIBYTE_P(FACE) ((FACE)->charset < 0)
--- a/src/dispnew.c	Wed Dec 15 12:49:36 1999 +0000
+++ b/src/dispnew.c	Wed Dec 15 13:14:38 1999 +0000
@@ -5925,8 +5925,8 @@
 	 are the foreground and background colors of the terminal.  */
       struct frame *sf = SELECTED_FRAME();
 
-      FRAME_FOREGROUND_PIXEL (sf) = -1;
-      FRAME_BACKGROUND_PIXEL (sf) = -1;
+      FRAME_FOREGROUND_PIXEL (sf) = FACE_TTY_DEFAULT_FG_COLOR;
+      FRAME_BACKGROUND_PIXEL (sf) = FACE_TTY_DEFAULT_BG_COLOR;
       call0 (intern ("tty-set-up-initial-frame-faces"));
     }
 }
--- a/src/dosfns.c	Wed Dec 15 12:49:36 1999 +0000
+++ b/src/dosfns.c	Wed Dec 15 13:14:38 1999 +0000
@@ -409,6 +409,10 @@
   "lightred", "lightmagenta", "yellow", "white"
 };
 
+static char *unspecified_colors[] = {
+  "unspecified-fg", "unspecified-bg", "unspecified"
+};
+
 /* Given a color name, return its index, or -1 if not found.  Note
    that this only performs case-insensitive comparison against the
    standard names.  For anything more sophisticated, like matching
@@ -424,17 +428,25 @@
     if (strcasecmp (name, vga_colors[i]) == 0)
       return i;
 
-  return FACE_TTY_DEFAULT_COLOR;
+  return
+    strcmp (name, unspecified_colors[0]) == 0 ? FACE_TTY_DEFAULT_FG_COLOR
+    : strcmp (name, unspecified_colors[1]) == 0 ? FACE_TTY_DEFAULT_BG_COLOR
+    : FACE_TTY_DEFAULT_COLOR;
 }
 
 /* Given a color index, return its standard name.  */
 Lisp_Object
 msdos_stdcolor_name (int idx)
 {
-  extern Lisp_Object Qunspecified;
+  extern Lisp_Object Qunspecified, Qunspecified_fg, Qunspecified_bg;
 
   if (idx < 0 || idx >= sizeof (vga_colors) / sizeof (vga_colors[0]))
-    return Qunspecified;	/* meaning the default */
+    {
+      return
+	idx == FACE_TTY_DEFAULT_FG_COLOR ? Qunspecified_fg
+	: idx == FACE_TTY_DEFAULT_BG_COLOR ? Qunspecified_bg
+	: Qunspecified;	/* meaning the default */
+    }
   return build_string (vga_colors[idx]);
 }
 
--- a/src/msdos.c	Wed Dec 15 12:49:36 1999 +0000
+++ b/src/msdos.c	Wed Dec 15 13:14:38 1999 +0000
@@ -685,12 +685,16 @@
      all 16 colors to be available for the background, since Emacs
      switches on this mode (and loses the blinking attribute) at
      startup.  */
-  if (fg == (unsigned long)-1)
+  if (fg == FACE_TTY_DEFAULT_COLOR || fg == FACE_TTY_DEFAULT_FG_COLOR)
     fg = highlight || fp->tty_reverse_p ? FRAME_BACKGROUND_PIXEL (sf)
 					: FRAME_FOREGROUND_PIXEL (sf);
-  if (bg == (unsigned long)-1)
+  else if (fg == FACE_TTY_DEFAULT_BG_COLOR)
+    fg = highlight ? FRAME_FOREGROUND_PIXEL (sf) : FRAME_BACKGROUND_PIXEL (sf);
+  if (bg == FACE_TTY_DEFAULT_COLOR || fg == FACE_TTY_DEFAULT_BG_COLOR)
     bg = highlight || fp->tty_reverse_p ? FRAME_FOREGROUND_PIXEL (sf)
 					: FRAME_BACKGROUND_PIXEL (sf);
+  else if (bg == FACE_TTY_DEFAULT_FG_COLOR)
+    fg = highlight ? FRAME_BACKGROUND_PIXEL (sf) : FRAME_FOREGROUND_PIXEL (sf);
   if (termscript)
     fprintf (termscript, "<FACE %d%s: %d/%d>",
 	     face, highlight ? "H" : "", fp->foreground, fp->background);
--- a/src/term.c	Wed Dec 15 12:49:36 1999 +0000
+++ b/src/term.c	Wed Dec 15 13:14:38 1999 +0000
@@ -1959,7 +1959,9 @@
       && TN_magic_cookie_glitch_ul <= 0)
     OUTPUT1_IF (TS_enter_underline_mode);
 
-  if (face->tty_reverse_p)
+  if (face->tty_reverse_p
+      || face->foreground == FACE_TTY_DEFAULT_BG_COLOR
+      || face->background == FACE_TTY_DEFAULT_FG_COLOR)
     OUTPUT1_IF (TS_enter_reverse_mode);
 
   if (TN_max_colors > 0)
@@ -1967,6 +1969,8 @@
       char *p;
       
       if (face->foreground != FACE_TTY_DEFAULT_COLOR
+	  && face->foreground != FACE_TTY_DEFAULT_FG_COLOR
+	  && face->foreground != FACE_TTY_DEFAULT_BG_COLOR
 	  && TS_set_foreground)
 	{
 	  p = tparam (TS_set_foreground, NULL, 0, (int) face->foreground);
@@ -1975,6 +1979,8 @@
 	}
 
       if (face->background != FACE_TTY_DEFAULT_COLOR
+	  && face->background != FACE_TTY_DEFAULT_BG_COLOR
+	  && face->background != FACE_TTY_DEFAULT_FG_COLOR
 	  && TS_set_background)
 	{
 	  p = tparam (TS_set_background, NULL, 0, (int) face->background);
@@ -2027,8 +2033,10 @@
 
   /* Switch back to default colors.  */
   if (TN_max_colors > 0
-      && (face->foreground != FACE_TTY_DEFAULT_COLOR
-	  || face->background != FACE_TTY_DEFAULT_COLOR))
+      && ((face->foreground != FACE_TTY_DEFAULT_COLOR
+	   && face->foreground != FACE_TTY_DEFAULT_FG_COLOR)
+	  || (face->background != FACE_TTY_DEFAULT_COLOR
+	      && face->background != FACE_TTY_DEFAULT_BG_COLOR)))
     OUTPUT1_IF (TS_orig_pair);
 }
   
--- a/src/xfaces.c	Wed Dec 15 12:49:36 1999 +0000
+++ b/src/xfaces.c	Wed Dec 15 13:14:38 1999 +0000
@@ -282,7 +282,7 @@
 Lisp_Object Qultra_expanded;
 Lisp_Object Qreleased_button, Qpressed_button;
 Lisp_Object QCstyle, QCcolor, QCline_width;
-Lisp_Object Qunspecified;
+Lisp_Object Qunspecified, Qunspecified_fg, Qunspecified_bg;
 
 /* The symbol `x-charset-registry'.  This property of charsets defines
    the X registry and encoding that fonts should have that are used to
@@ -1108,6 +1108,14 @@
 	   load color" messages in the *Messages* buffer.  */
 	status = 1;
     }
+  if (color_idx == FACE_TTY_DEFAULT_COLOR && *color_name)
+    {
+      if (strcmp (color_name, "unspecified-fg") == 0)
+	color_idx = FACE_TTY_DEFAULT_FG_COLOR;
+      else if (strcmp (color_name, "unspecified-bg") == 0)
+	color_idx = FACE_TTY_DEFAULT_BG_COLOR;
+    }
+
   color_def->pixel = (unsigned long) color_idx;
   color_def->red = red;
   color_def->green = green;
@@ -1179,7 +1187,10 @@
      by index using the default color mapping on a Windows console.  */
 #endif
 
-  return Qunspecified;
+  return
+    idx == FACE_TTY_DEFAULT_FG_COLOR ? Qunspecified_fg
+    : idx == FACE_TTY_DEFAULT_BG_COLOR ? Qunspecified_bg
+    : Qunspecified;
 }
 
 /* Return non-zero if COLOR_NAME is a shade of gray (or white or
@@ -3427,7 +3438,8 @@
     }
   else if (EQ (attr, QCforeground))
     {
-      if (!UNSPECIFIEDP (value))
+      if (!UNSPECIFIEDP (value)
+	  && !EQ (value, Qunspecified_fg) && !EQ (value, Qunspecified_bg))
 	{
 	  /* Don't check for valid color names here because it depends
 	     on the frame (display) whether the color will be valid
@@ -3441,7 +3453,8 @@
     }
   else if (EQ (attr, QCbackground))
     {
-      if (!UNSPECIFIEDP (value))
+      if (!UNSPECIFIEDP (value)
+	  && !EQ (value, Qunspecified_bg) && !EQ (value, Qunspecified_fg))
 	{
 	  /* Don't check for valid color names here because it depends
 	     on the frame (display) whether the color will be valid
@@ -5686,7 +5699,9 @@
 	LFACE_FOREGROUND (lface) = XCDR (color);
       else if (FRAME_X_P (f))
 	return 0;
-      else if (!FRAME_TERMCAP_P (f) && !FRAME_MSDOS_P (f))
+      else if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
+	LFACE_FOREGROUND (lface) = Qunspecified_fg;
+      else
 	abort ();
     }
   
@@ -5699,7 +5714,9 @@
 	LFACE_BACKGROUND (lface) = XCDR (color);
       else if (FRAME_X_P (f))
 	return 0;
-      else if (!FRAME_TERMCAP_P (f) && !FRAME_MSDOS_P (f))
+      else if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
+	LFACE_BACKGROUND (lface) = Qunspecified_bg;
+      else
 	abort ();
     }
   
@@ -6072,7 +6089,8 @@
     face->tty_reverse_p = 1;
 
   /* Map color names to color indices.  */
-  face->foreground = face->background = FACE_TTY_DEFAULT_COLOR;
+  face->foreground = FACE_TTY_DEFAULT_FG_COLOR;
+  face->background = FACE_TTY_DEFAULT_BG_COLOR;
 
   color = attrs[LFACE_FOREGROUND_INDEX];
   if (STRINGP (color)
@@ -6084,7 +6102,7 @@
        (NAME INDEX R G B).  We need the INDEX part.  */
     face->foreground = XINT (XCAR (XCDR (color)));
 
-  if (face->foreground == FACE_TTY_DEFAULT_COLOR
+  if (face->foreground == FACE_TTY_DEFAULT_FG_COLOR
       && STRINGP (attrs[LFACE_FOREGROUND_INDEX]))
     {
       face->foreground = load_color (c->f, face,
@@ -6093,12 +6111,23 @@
 #ifdef MSDOS
       /* If the foreground of the default face is the default color,
 	 use the foreground color defined by the frame.  */
-      if (FRAME_MSDOS_P (c->f) && face->foreground == FACE_TTY_DEFAULT_COLOR)
+      if (FRAME_MSDOS_P (c->f))
 	{
-	  face->foreground = FRAME_FOREGROUND_PIXEL (f);
-	  attrs[LFACE_FOREGROUND_INDEX] =
-	    msdos_stdcolor_name (face->foreground);
-	  face_colors_defaulted = 1;
+	  if (face->foreground == FACE_TTY_DEFAULT_FG_COLOR
+	      || face->foreground == FACE_TTY_DEFAULT_COLOR)
+	    {
+	      face->foreground = FRAME_FOREGROUND_PIXEL (f);
+	      attrs[LFACE_FOREGROUND_INDEX] =
+		msdos_stdcolor_name (face->foreground);
+	      face_colors_defaulted = 1;
+	    }
+	  else if (face->foreground == FACE_TTY_DEFAULT_BG_COLOR)
+	    {
+	      face->foreground = FRAME_BACKGROUND_PIXEL (f);
+	      attrs[LFACE_FOREGROUND_INDEX] =
+		msdos_stdcolor_name (face->foreground);
+	      face_colors_defaulted = 1;
+	    }
 	}
 #endif
     }
@@ -6113,7 +6142,7 @@
        (NAME INDEX R G B).  We need the INDEX part.  */
     face->background = XINT (XCAR (XCDR (color)));
 
-  if (face->background == FACE_TTY_DEFAULT_COLOR
+  if (face->background == FACE_TTY_DEFAULT_BG_COLOR
       && STRINGP (attrs[LFACE_BACKGROUND_INDEX]))
     {
       face->background = load_color (c->f, face,
@@ -6122,12 +6151,23 @@
 #ifdef MSDOS
       /* If the background of the default face is the default color,
 	 use the background color defined by the frame.  */
-      if (FRAME_MSDOS_P (c->f) && face->background == FACE_TTY_DEFAULT_COLOR)
+      if (FRAME_MSDOS_P (c->f))
 	{
-	  face->background = FRAME_BACKGROUND_PIXEL (f);
-	  attrs[LFACE_BACKGROUND_INDEX] =
-	    msdos_stdcolor_name (face->background);
-	  face_colors_defaulted = 1;
+	  if (face->background == FACE_TTY_DEFAULT_BG_COLOR
+	      || face->background == FACE_TTY_DEFAULT_COLOR)
+	    {
+	      face->background = FRAME_BACKGROUND_PIXEL (f);
+	      attrs[LFACE_BACKGROUND_INDEX] =
+		msdos_stdcolor_name (face->background);
+	      face_colors_defaulted = 1;
+	    }
+	  else if (face->background == FACE_TTY_DEFAULT_FG_COLOR)
+	    {
+	      face->background = FRAME_FOREGROUND_PIXEL (f);
+	      attrs[LFACE_BACKGROUND_INDEX] =
+		msdos_stdcolor_name (face->background);
+	      face_colors_defaulted = 1;
+	    }
 	}
 #endif
     }
@@ -6611,6 +6651,10 @@
   staticpro (&Qforeground_color);
   Qunspecified = intern ("unspecified");
   staticpro (&Qunspecified);
+  Qunspecified_fg = intern ("unspecified-fg");
+  staticpro (&Qunspecified_fg);
+  Qunspecified_bg = intern ("unspecified-bg");
+  staticpro (&Qunspecified_bg);
 
   Qx_charset_registry = intern ("x-charset-registry");
   staticpro (&Qx_charset_registry);