1
0
forked from aniani/vim

Allow synIDattr() getting GUI attributes when build without GUI.

(Matt Wozniski)
This commit is contained in:
Bram Moolenaar
2010-07-14 22:04:22 +02:00
parent 865242e121
commit 61623362be
3 changed files with 51 additions and 40 deletions

View File

@@ -1091,12 +1091,6 @@ Before (beta) release 7.3:
Vim 7.3: Vim 7.3:
Patches to possibly include: Patches to possibly include:
- Add different highlighting for a fold line depending on the fold level.
Patch. (Noel Henson, 2009 Sep 13)
- Patch to make synIDattr() work for GUI attributes in Vim without GUI
feature. (Matt Wozniski, 2009 Apr 15)
Patch go make gui highlight settings work in Vim without +gui feature.
(Matt Wozniski, 2009 Mar 27)
- Replace ccomplete.vim by cppcomplete.vim from www.vim.org? script 1520 by - Replace ccomplete.vim by cppcomplete.vim from www.vim.org? script 1520 by
Vissale Neang. (Martin Stubenschrott) Vissale Neang. (Martin Stubenschrott)
Asked Vissale to make the scripts more friendly for the Vim distribution. Asked Vissale to make the scripts more friendly for the Vim distribution.

View File

@@ -16953,11 +16953,7 @@ f_synIDattr(argvars, rettv)
{ {
mode = get_tv_string_buf(&argvars[2], modebuf); mode = get_tv_string_buf(&argvars[2], modebuf);
modec = TOLOWER_ASC(mode[0]); modec = TOLOWER_ASC(mode[0]);
if (modec != 't' && modec != 'c' if (modec != 't' && modec != 'c' && modec != 'g')
#ifdef FEAT_GUI
&& modec != 'g'
#endif
)
modec = 0; /* replace invalid with current */ modec = 0; /* replace invalid with current */
} }
else else

View File

@@ -35,19 +35,22 @@ struct hl_group
int sg_cterm_attr; /* Screen attr for color term mode */ int sg_cterm_attr; /* Screen attr for color term mode */
#ifdef FEAT_GUI #ifdef FEAT_GUI
/* for when using the GUI */ /* for when using the GUI */
int sg_gui; /* "gui=" highlighting attributes */
guicolor_T sg_gui_fg; /* GUI foreground color handle */ guicolor_T sg_gui_fg; /* GUI foreground color handle */
char_u *sg_gui_fg_name;/* GUI foreground color name */
guicolor_T sg_gui_bg; /* GUI background color handle */ guicolor_T sg_gui_bg; /* GUI background color handle */
char_u *sg_gui_bg_name;/* GUI background color name */
guicolor_T sg_gui_sp; /* GUI special color handle */ guicolor_T sg_gui_sp; /* GUI special color handle */
char_u *sg_gui_sp_name;/* GUI special color name */
GuiFont sg_font; /* GUI font handle */ GuiFont sg_font; /* GUI font handle */
#ifdef FEAT_XFONTSET #ifdef FEAT_XFONTSET
GuiFontset sg_fontset; /* GUI fontset handle */ GuiFontset sg_fontset; /* GUI fontset handle */
#endif #endif
char_u *sg_font_name; /* GUI font or fontset name */ char_u *sg_font_name; /* GUI font or fontset name */
int sg_gui_attr; /* Screen attr for GUI mode */ int sg_gui_attr; /* Screen attr for GUI mode */
#endif
#if defined(FEAT_GUI) || defined(FEAT_EVAL)
/* Store the sp color name for the GUI or synIDattr() */
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_link; /* link to this highlight group ID */
int sg_set; /* combination of SG_* flags */ int sg_set; /* combination of SG_* flags */
@@ -6412,7 +6415,7 @@ syn_get_foldlevel(wp, lnum)
* The #ifdefs are needed to reduce the amount of static data. Helps to make * The #ifdefs are needed to reduce the amount of static data. Helps to make
* the 16 bit DOS (museum) version compile. * the 16 bit DOS (museum) version compile.
*/ */
#ifdef FEAT_GUI #if defined(FEAT_GUI) || defined(FEAT_EVAL)
# define CENT(a, b) b # define CENT(a, b) b
#else #else
# define CENT(a, b) a # define CENT(a, b) a
@@ -7142,7 +7145,7 @@ do_highlight(line, forceit, init)
HL_TABLE()[idx].sg_cterm_bold = FALSE; HL_TABLE()[idx].sg_cterm_bold = FALSE;
} }
} }
#ifdef FEAT_GUI #if defined(FEAT_GUI) || defined(FEAT_EVAL)
else else
{ {
if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI))
@@ -7418,86 +7421,100 @@ do_highlight(line, forceit, init)
} }
else if (STRCMP(key, "GUIFG") == 0) else if (STRCMP(key, "GUIFG") == 0)
{ {
#ifdef FEAT_GUI /* in non-GUI guifg colors are simply ignored */ #if defined(FEAT_GUI) || defined(FEAT_EVAL)
if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI))
{ {
if (!init) if (!init)
HL_TABLE()[idx].sg_set |= SG_GUI; HL_TABLE()[idx].sg_set |= SG_GUI;
# ifdef FEAT_GUI
/* In GUI guifg colors are only used when recognized */
i = color_name2handle(arg); i = color_name2handle(arg);
if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !gui.in_use) if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !gui.in_use)
{ {
HL_TABLE()[idx].sg_gui_fg = i; HL_TABLE()[idx].sg_gui_fg = i;
# endif
vim_free(HL_TABLE()[idx].sg_gui_fg_name); vim_free(HL_TABLE()[idx].sg_gui_fg_name);
if (STRCMP(arg, "NONE")) if (STRCMP(arg, "NONE"))
HL_TABLE()[idx].sg_gui_fg_name = vim_strsave(arg); HL_TABLE()[idx].sg_gui_fg_name = vim_strsave(arg);
else else
HL_TABLE()[idx].sg_gui_fg_name = NULL; HL_TABLE()[idx].sg_gui_fg_name = NULL;
# ifdef FEAT_GUI_X11 # ifdef FEAT_GUI
# ifdef FEAT_GUI_X11
if (is_menu_group) if (is_menu_group)
gui.menu_fg_pixel = i; gui.menu_fg_pixel = i;
if (is_scrollbar_group) if (is_scrollbar_group)
gui.scroll_fg_pixel = i; gui.scroll_fg_pixel = i;
# ifdef FEAT_BEVAL # ifdef FEAT_BEVAL
if (is_tooltip_group) if (is_tooltip_group)
gui.tooltip_fg_pixel = i; gui.tooltip_fg_pixel = i;
# endif # endif
do_colors = TRUE; do_colors = TRUE;
# endif # endif
} }
# endif
} }
#endif #endif
} }
else if (STRCMP(key, "GUIBG") == 0) else if (STRCMP(key, "GUIBG") == 0)
{ {
#ifdef FEAT_GUI /* in non-GUI guibg colors are simply ignored */ #if defined(FEAT_GUI) || defined(FEAT_EVAL)
if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI))
{ {
if (!init) if (!init)
HL_TABLE()[idx].sg_set |= SG_GUI; HL_TABLE()[idx].sg_set |= SG_GUI;
# ifdef FEAT_GUI
/* In GUI guifg colors are only used when recognized */
i = color_name2handle(arg); i = color_name2handle(arg);
if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !gui.in_use) if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !gui.in_use)
{ {
HL_TABLE()[idx].sg_gui_bg = i; HL_TABLE()[idx].sg_gui_bg = i;
# endif
vim_free(HL_TABLE()[idx].sg_gui_bg_name); vim_free(HL_TABLE()[idx].sg_gui_bg_name);
if (STRCMP(arg, "NONE") != 0) if (STRCMP(arg, "NONE") != 0)
HL_TABLE()[idx].sg_gui_bg_name = vim_strsave(arg); HL_TABLE()[idx].sg_gui_bg_name = vim_strsave(arg);
else else
HL_TABLE()[idx].sg_gui_bg_name = NULL; HL_TABLE()[idx].sg_gui_bg_name = NULL;
# ifdef FEAT_GUI_X11 # ifdef FEAT_GUI
# ifdef FEAT_GUI_X11
if (is_menu_group) if (is_menu_group)
gui.menu_bg_pixel = i; gui.menu_bg_pixel = i;
if (is_scrollbar_group) if (is_scrollbar_group)
gui.scroll_bg_pixel = i; gui.scroll_bg_pixel = i;
# ifdef FEAT_BEVAL # ifdef FEAT_BEVAL
if (is_tooltip_group) if (is_tooltip_group)
gui.tooltip_bg_pixel = i; gui.tooltip_bg_pixel = i;
# endif # endif
do_colors = TRUE; do_colors = TRUE;
# endif # endif
} }
# endif
} }
#endif #endif
} }
else if (STRCMP(key, "GUISP") == 0) else if (STRCMP(key, "GUISP") == 0)
{ {
#ifdef FEAT_GUI /* in non-GUI guisp colors are simply ignored */ #if defined(FEAT_GUI) || defined(FEAT_EVAL)
if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI)) if (!init || !(HL_TABLE()[idx].sg_set & SG_GUI))
{ {
if (!init) if (!init)
HL_TABLE()[idx].sg_set |= SG_GUI; HL_TABLE()[idx].sg_set |= SG_GUI;
# ifdef FEAT_GUI
i = color_name2handle(arg); i = color_name2handle(arg);
if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !gui.in_use) if (i != INVALCOLOR || STRCMP(arg, "NONE") == 0 || !gui.in_use)
{ {
HL_TABLE()[idx].sg_gui_sp = i; HL_TABLE()[idx].sg_gui_sp = i;
# endif
vim_free(HL_TABLE()[idx].sg_gui_sp_name); vim_free(HL_TABLE()[idx].sg_gui_sp_name);
if (STRCMP(arg, "NONE") != 0) if (STRCMP(arg, "NONE") != 0)
HL_TABLE()[idx].sg_gui_sp_name = vim_strsave(arg); HL_TABLE()[idx].sg_gui_sp_name = vim_strsave(arg);
else else
HL_TABLE()[idx].sg_gui_sp_name = NULL; HL_TABLE()[idx].sg_gui_sp_name = NULL;
# ifdef FEAT_GUI
} }
# endif
} }
#endif #endif
} }
@@ -7728,17 +7745,19 @@ highlight_clear(idx)
HL_TABLE()[idx].sg_cterm_fg = 0; HL_TABLE()[idx].sg_cterm_fg = 0;
HL_TABLE()[idx].sg_cterm_bg = 0; HL_TABLE()[idx].sg_cterm_bg = 0;
HL_TABLE()[idx].sg_cterm_attr = 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 = 0;
HL_TABLE()[idx].sg_gui_fg = INVALCOLOR;
vim_free(HL_TABLE()[idx].sg_gui_fg_name); vim_free(HL_TABLE()[idx].sg_gui_fg_name);
HL_TABLE()[idx].sg_gui_fg_name = NULL; HL_TABLE()[idx].sg_gui_fg_name = NULL;
HL_TABLE()[idx].sg_gui_bg = INVALCOLOR;
vim_free(HL_TABLE()[idx].sg_gui_bg_name); vim_free(HL_TABLE()[idx].sg_gui_bg_name);
HL_TABLE()[idx].sg_gui_bg_name = NULL; HL_TABLE()[idx].sg_gui_bg_name = NULL;
HL_TABLE()[idx].sg_gui_sp = INVALCOLOR;
vim_free(HL_TABLE()[idx].sg_gui_sp_name); vim_free(HL_TABLE()[idx].sg_gui_sp_name);
HL_TABLE()[idx].sg_gui_sp_name = NULL; 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); gui_mch_free_font(HL_TABLE()[idx].sg_font);
HL_TABLE()[idx].sg_font = NOFONT; HL_TABLE()[idx].sg_font = NOFONT;
# ifdef FEAT_XFONTSET # ifdef FEAT_XFONTSET
@@ -8436,7 +8455,7 @@ highlight_list_one(id)
didh = highlight_list_arg(id, didh, LIST_INT, didh = highlight_list_arg(id, didh, LIST_INT,
sgp->sg_cterm_bg, NULL, "ctermbg"); sgp->sg_cterm_bg, NULL, "ctermbg");
#ifdef FEAT_GUI #if defined(FEAT_GUI) || defined(FEAT_EVAL)
didh = highlight_list_arg(id, didh, LIST_ATTR, didh = highlight_list_arg(id, didh, LIST_ATTR,
sgp->sg_gui, NULL, "gui"); sgp->sg_gui, NULL, "gui");
didh = highlight_list_arg(id, didh, LIST_STRING, didh = highlight_list_arg(id, didh, LIST_STRING,
@@ -8445,6 +8464,8 @@ highlight_list_one(id)
0, sgp->sg_gui_bg_name, "guibg"); 0, sgp->sg_gui_bg_name, "guibg");
didh = highlight_list_arg(id, didh, LIST_STRING, didh = highlight_list_arg(id, didh, LIST_STRING,
0, sgp->sg_gui_sp_name, "guisp"); 0, sgp->sg_gui_sp_name, "guisp");
#endif
#ifdef FEAT_GUI
didh = highlight_list_arg(id, didh, LIST_STRING, didh = highlight_list_arg(id, didh, LIST_STRING,
0, sgp->sg_font_name, "font"); 0, sgp->sg_font_name, "font");
#endif #endif
@@ -8535,7 +8556,7 @@ highlight_has_attr(id, flag, modec)
if (id <= 0 || id > highlight_ga.ga_len) if (id <= 0 || id > highlight_ga.ga_len)
return NULL; return NULL;
#ifdef FEAT_GUI #if defined(FEAT_GUI) || defined(FEAT_EVAL)
if (modec == 'g') if (modec == 'g')
attr = HL_TABLE()[id - 1].sg_gui; attr = HL_TABLE()[id - 1].sg_gui;
else else
@@ -8564,17 +8585,14 @@ highlight_color(id, what, modec)
static char_u name[20]; static char_u name[20];
int n; int n;
int fg = FALSE; int fg = FALSE;
# ifdef FEAT_GUI
int sp = FALSE; int sp = FALSE;
int font = FALSE; int font = FALSE;
# endif
if (id <= 0 || id > highlight_ga.ga_len) if (id <= 0 || id > highlight_ga.ga_len)
return NULL; return NULL;
if (TOLOWER_ASC(what[0]) == 'f' && TOLOWER_ASC(what[1]) == 'g') if (TOLOWER_ASC(what[0]) == 'f' && TOLOWER_ASC(what[1]) == 'g')
fg = TRUE; fg = TRUE;
# ifdef FEAT_GUI
else if (TOLOWER_ASC(what[0]) == 'f' && TOLOWER_ASC(what[1]) == 'o' else if (TOLOWER_ASC(what[0]) == 'f' && TOLOWER_ASC(what[1]) == 'o'
&& TOLOWER_ASC(what[2]) == 'n' && TOLOWER_ASC(what[3]) == 't') && TOLOWER_ASC(what[2]) == 'n' && TOLOWER_ASC(what[3]) == 't')
font = TRUE; font = TRUE;
@@ -8584,6 +8602,7 @@ highlight_color(id, what, modec)
return NULL; return NULL;
if (modec == 'g') if (modec == 'g')
{ {
# ifdef FEAT_GUI
/* return font name */ /* return font name */
if (font) if (font)
return HL_TABLE()[id - 1].sg_font_name; return HL_TABLE()[id - 1].sg_font_name;
@@ -8610,6 +8629,7 @@ highlight_color(id, what, modec)
(unsigned)rgb & 255); (unsigned)rgb & 255);
return buf; return buf;
} }
#endif
if (fg) if (fg)
return (HL_TABLE()[id - 1].sg_gui_fg_name); return (HL_TABLE()[id - 1].sg_gui_fg_name);
if (sp) if (sp)
@@ -8618,7 +8638,6 @@ highlight_color(id, what, modec)
} }
if (font || sp) if (font || sp)
return NULL; return NULL;
# endif
if (modec == 'c') if (modec == 'c')
{ {
if (fg) if (fg)
@@ -9243,7 +9262,7 @@ highlight_changed()
vim_memset(&hlt[hlcnt + i], 0, sizeof(struct hl_group)); vim_memset(&hlt[hlcnt + i], 0, sizeof(struct hl_group));
hlt[hlcnt + i].sg_term = highlight_attr[HLF_SNC]; hlt[hlcnt + i].sg_term = highlight_attr[HLF_SNC];
hlt[hlcnt + i].sg_cterm = 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]; hlt[hlcnt + i].sg_gui = highlight_attr[HLF_SNC];
# endif # endif
} }
@@ -9266,9 +9285,11 @@ highlight_changed()
hlt[hlcnt + i].sg_cterm_fg = hlt[id - 1].sg_cterm_fg; 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) 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; 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[hlcnt + i].sg_gui ^=
hlt[id - 1].sg_gui ^ hlt[id_S - 1].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) 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; 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) if (hlt[id - 1].sg_gui_bg != hlt[id_S - 1].sg_gui_bg)