Currently, in a vim that isn't built with +gui, it's possible to set the
gui, guifg, guibg, and guisp attributes for a highlight group, but not
to retrieve those settings - the command is accepted with no error, but
the settings are silently ignored.  This is unfortunate, since scripts
might want to query what colors would be being used if a gui were
running.  One example is CSApprox.vim, which needs to know what colors
would be being used in the gui in order to pick and set the closest
available terminal colors.

This patch allows synIDattr() to report the gui, guifg, guibg, and guisp
attributes even when vim isn't compiled with +gui.  It should be
uncontroversial; it only changes some #ifdef's around so that things
that were only stored when +gui before are now stored when either +gui
or +eval.  In my testing, it makes CSApprox work perfectly in gui-less
vim versions.

~Matt


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

commit e458c019b0ff0515259aebca8e04ce06b9a2646c
Author: Matt Wozniski <m...@drexel.edu>
Date:   Fri Mar 27 02:15:31 2009 -0400

    Let synIDattr() query guifg/bg/sp without +gui

diff --git a/src/eval.c b/src/eval.c
index 98979b1..ce50aef 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -16629,9 +16629,7 @@ f_synIDattr(argvars, rettv)
 	mode = get_tv_string_buf(&argvars[2], modebuf);
 	modec = TOLOWER_ASC(mode[0]);
 	if (modec != 't' && modec != 'c'
-#ifdef FEAT_GUI
 		&& modec != 'g'
-#endif
 		)
 	    modec = 0;	/* replace invalid with current */
     }
diff --git a/src/syntax.c b/src/syntax.c
index 4b4b0bb..e4d0089 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -48,6 +48,13 @@ struct hl_group
 #endif
     char_u	*sg_font_name;  /* GUI font or fontset name */
     int		sg_gui_attr;    /* Screen attr for GUI mode */
+#else
+# ifdef FEAT_EVAL
+    int		sg_gui;		/* "gui=" highlighting attributes */
+    char_u	*sg_gui_fg_name;/* GUI foreground color name */
+    char_u	*sg_gui_bg_name;/* GUI background color name */
+    char_u	*sg_gui_sp_name;/* GUI special color name */
+# endif
 #endif
     int		sg_link;	/* link to this highlight group ID */
     int		sg_set;		/* combination of SG_* flags */
@@ -6203,7 +6210,7 @@ syn_get_foldlevel(wp, lnum)
  * The #ifdefs are needed to reduce the amount of static data.  Helps to make
  * the 16 bit DOS (museum) version compile.
  */
-#ifdef FEAT_GUI
+#if defined(FEAT_GUI) || defined(FEAT_EVAL)
 # define CENT(a, b) b
 #else
 # define CENT(a, b) a
@@ -6923,7 +6930,7 @@ do_highlight(line, forceit, init)
 		    HL_TABLE()[idx].sg_cterm_bold = FALSE;
 		}
 	    }
-#ifdef FEAT_GUI
+#if defined(FEAT_GUI) || defined(FEAT_EVAL)
 	    else
 	    {
 		if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI))
@@ -7221,6 +7228,20 @@ do_highlight(line, forceit, init)
 # endif
 		}
 	    }
+#else
+# ifdef FEAT_EVAL   /* Store the fg color name for synIDattr() */
+	    if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI))
+	    {
+		if (!init)
+		    HL_TABLE()[idx].sg_set |= SG_GUI;
+
+		vim_free(HL_TABLE()[idx].sg_gui_fg_name);
+		if (STRCMP(arg, "NONE"))
+		    HL_TABLE()[idx].sg_gui_fg_name = vim_strsave(arg);
+		else
+		    HL_TABLE()[idx].sg_gui_fg_name = NULL;
+	    }
+# endif
 #endif
 	}
 	else if (STRCMP(key, "GUIBG") == 0)
@@ -7253,6 +7274,20 @@ do_highlight(line, forceit, init)
 # endif
 		}
 	    }
+#else
+# ifdef FEAT_EVAL   /* Store the bg color name for synIDattr() */
+	    if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI))
+	    {
+		if (!init)
+		    HL_TABLE()[idx].sg_set |= SG_GUI;
+
+		vim_free(HL_TABLE()[idx].sg_gui_bg_name);
+		if (STRCMP(arg, "NONE"))
+		    HL_TABLE()[idx].sg_gui_bg_name = vim_strsave(arg);
+		else
+		    HL_TABLE()[idx].sg_gui_bg_name = NULL;
+	    }
+# endif
 #endif
 	}
 	else if (STRCMP(key, "GUISP") == 0)
@@ -7274,6 +7309,20 @@ do_highlight(line, forceit, init)
 			HL_TABLE()[idx].sg_gui_sp_name = NULL;
 		}
 	    }
+#else
+# ifdef FEAT_EVAL   /* Store the sp color name for synIDattr() */
+	    if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI))
+	    {
+		if (!init)
+		    HL_TABLE()[idx].sg_set |= SG_GUI;
+
+		vim_free(HL_TABLE()[idx].sg_gui_sp_name);
+		if (STRCMP(arg, "NONE"))
+		    HL_TABLE()[idx].sg_gui_sp_name = vim_strsave(arg);
+		else
+		    HL_TABLE()[idx].sg_gui_sp_name = NULL;
+	    }
+# endif
 #endif
 	}
 	else if (STRCMP(key, "START") == 0 || STRCMP(key, "STOP") == 0)
@@ -7503,17 +7552,19 @@ highlight_clear(idx)
     HL_TABLE()[idx].sg_cterm_fg = 0;
     HL_TABLE()[idx].sg_cterm_bg = 0;
     HL_TABLE()[idx].sg_cterm_attr = 0;
-#ifdef FEAT_GUI	    /* in non-GUI fonts are simply ignored */
+#if defined(FEAT_GUI) || defined(FEAT_EVAL)
     HL_TABLE()[idx].sg_gui = 0;
-    HL_TABLE()[idx].sg_gui_fg = INVALCOLOR;
     vim_free(HL_TABLE()[idx].sg_gui_fg_name);
     HL_TABLE()[idx].sg_gui_fg_name = NULL;
-    HL_TABLE()[idx].sg_gui_bg = INVALCOLOR;
     vim_free(HL_TABLE()[idx].sg_gui_bg_name);
     HL_TABLE()[idx].sg_gui_bg_name = NULL;
-    HL_TABLE()[idx].sg_gui_sp = INVALCOLOR;
     vim_free(HL_TABLE()[idx].sg_gui_sp_name);
     HL_TABLE()[idx].sg_gui_sp_name = NULL;
+#endif
+#ifdef FEAT_GUI
+    HL_TABLE()[idx].sg_gui_fg = INVALCOLOR;
+    HL_TABLE()[idx].sg_gui_bg = INVALCOLOR;
+    HL_TABLE()[idx].sg_gui_sp = INVALCOLOR;
     gui_mch_free_font(HL_TABLE()[idx].sg_font);
     HL_TABLE()[idx].sg_font = NOFONT;
 # ifdef FEAT_XFONTSET
@@ -8212,7 +8263,7 @@ highlight_list_one(id)
     didh = highlight_list_arg(id, didh, LIST_INT,
 				    sgp->sg_cterm_bg, NULL, "ctermbg");
 
-#ifdef FEAT_GUI
+#if defined(FEAT_GUI) || defined(FEAT_EVAL)
     didh = highlight_list_arg(id, didh, LIST_ATTR,
 				    sgp->sg_gui, NULL, "gui");
     didh = highlight_list_arg(id, didh, LIST_STRING,
@@ -8221,6 +8272,8 @@ highlight_list_one(id)
 				    0, sgp->sg_gui_bg_name, "guibg");
     didh = highlight_list_arg(id, didh, LIST_STRING,
 				    0, sgp->sg_gui_sp_name, "guisp");
+#endif
+#ifdef FEAT_GUI
     didh = highlight_list_arg(id, didh, LIST_STRING,
 				    0, sgp->sg_font_name, "font");
 #endif
@@ -8311,7 +8364,7 @@ highlight_has_attr(id, flag, modec)
     if (id <= 0 || id > highlight_ga.ga_len)
 	return NULL;
 
-#ifdef FEAT_GUI
+#if defined(FEAT_GUI) || defined(FEAT_EVAL)
     if (modec == 'g')
 	attr = HL_TABLE()[id - 1].sg_gui;
     else
@@ -8340,20 +8393,18 @@ highlight_color(id, what, modec)
     static char_u	name[20];
     int			n;
     int			fg = FALSE;
-# ifdef FEAT_GUI
     int			sp = FALSE;
-# endif
 
     if (id <= 0 || id > highlight_ga.ga_len)
 	return NULL;
 
     if (TOLOWER_ASC(what[0]) == 'f')
 	fg = TRUE;
-# ifdef FEAT_GUI
     else if (TOLOWER_ASC(what[0]) == 's')
 	sp = TRUE;
     if (modec == 'g')
     {
+#ifdef FEAT_GUI
 	/* return #RRGGBB form (only possible when GUI is running) */
 	if (gui.in_use && what[1] && what[2] == '#')
 	{
@@ -8376,13 +8427,13 @@ highlight_color(id, what, modec)
 				      (unsigned)rgb & 255);
 	    return buf;
 	}
+#endif
 	if (fg)
 	    return (HL_TABLE()[id - 1].sg_gui_fg_name);
 	if (sp)
 	    return (HL_TABLE()[id - 1].sg_gui_sp_name);
 	return (HL_TABLE()[id - 1].sg_gui_bg_name);
     }
-# endif
     if (modec == 'c')
     {
 	if (fg)
@@ -9006,7 +9057,7 @@ highlight_changed()
 		memset(&hlt[hlcnt + i], 0, sizeof(struct hl_group));
 		hlt[hlcnt + i].sg_term = highlight_attr[HLF_SNC];
 		hlt[hlcnt + i].sg_cterm = highlight_attr[HLF_SNC];
-#  ifdef FEAT_GUI
+#  if defined(FEAT_GUI) || defined(FEAT_EVAL)
 		hlt[hlcnt + i].sg_gui = highlight_attr[HLF_SNC];
 #  endif
 	    }
@@ -9029,9 +9080,11 @@ highlight_changed()
 		hlt[hlcnt + i].sg_cterm_fg = hlt[id - 1].sg_cterm_fg;
 	    if (hlt[id - 1].sg_cterm_bg != hlt[id_S - 1].sg_cterm_bg)
 		hlt[hlcnt + i].sg_cterm_bg = hlt[id - 1].sg_cterm_bg;
-#  ifdef FEAT_GUI
+#  if defined(FEAT_GUI) || defined(FEAT_EVAL)
 	    hlt[hlcnt + i].sg_gui ^=
 		hlt[id - 1].sg_gui ^ hlt[id_S - 1].sg_gui;
+#  endif
+#  ifdef FEAT_GUI
 	    if (hlt[id - 1].sg_gui_fg != hlt[id_S - 1].sg_gui_fg)
 		hlt[hlcnt + i].sg_gui_fg = hlt[id - 1].sg_gui_fg;
 	    if (hlt[id - 1].sg_gui_bg != hlt[id_S - 1].sg_gui_bg)

Raspunde prin e-mail lui