diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Make_cyg_ming.mak | 1 | ||||
-rw-r--r-- | src/Make_morph.mak | 1 | ||||
-rw-r--r-- | src/Make_mvc.mak | 4 | ||||
-rw-r--r-- | src/Make_vms.mms | 33 | ||||
-rw-r--r-- | src/Makefile | 10 | ||||
-rw-r--r-- | src/README.md | 1 | ||||
-rw-r--r-- | src/globals.h | 10 | ||||
-rw-r--r-- | src/highlight.c | 3575 | ||||
-rw-r--r-- | src/proto.h | 1 | ||||
-rw-r--r-- | src/proto/highlight.pro | 43 | ||||
-rw-r--r-- | src/proto/syntax.pro | 40 | ||||
-rw-r--r-- | src/structs.h | 52 | ||||
-rw-r--r-- | src/syntax.c | 3637 | ||||
-rw-r--r-- | src/version.c | 2 |
14 files changed, 3719 insertions, 3691 deletions
diff --git a/src/Make_cyg_ming.mak b/src/Make_cyg_ming.mak index e689bad40c..a54730b796 100644 --- a/src/Make_cyg_ming.mak +++ b/src/Make_cyg_ming.mak @@ -730,6 +730,7 @@ OBJ = \ $(OUTDIR)/getchar.o \ $(OUTDIR)/hardcopy.o \ $(OUTDIR)/hashtab.o \ + $(OUTDIR)/highlight.o \ $(OUTDIR)/indent.o \ $(OUTDIR)/insexpand.o \ $(OUTDIR)/json.o \ diff --git a/src/Make_morph.mak b/src/Make_morph.mak index 2565df54ee..6990a04274 100644 --- a/src/Make_morph.mak +++ b/src/Make_morph.mak @@ -50,6 +50,7 @@ SRC = arabic.c \ getchar.c \ hardcopy.c \ hashtab.c \ + highlight.c \ indent.c \ insexpand.c \ json.c \ diff --git a/src/Make_mvc.mak b/src/Make_mvc.mak index 7ce8d3d0e9..8901a7c311 100644 --- a/src/Make_mvc.mak +++ b/src/Make_mvc.mak @@ -739,6 +739,7 @@ OBJ = \ $(OUTDIR)\getchar.obj \ $(OUTDIR)\hardcopy.obj \ $(OUTDIR)\hashtab.obj \ + $(OUTDIR)\highlight.obj \ $(OUTDIR)\indent.obj \ $(OUTDIR)\insexpand.obj \ $(OUTDIR)\json.obj \ @@ -1487,6 +1488,8 @@ $(OUTDIR)/hardcopy.obj: $(OUTDIR) hardcopy.c $(INCL) $(OUTDIR)/hashtab.obj: $(OUTDIR) hashtab.c $(INCL) +$(OUTDIR)/highlight.obj: $(OUTDIR) highlight.c $(INCL) + $(OUTDIR)/indent.obj: $(OUTDIR) indent.c $(INCL) $(OUTDIR)/insexpand.obj: $(OUTDIR) insexpand.c $(INCL) @@ -1747,6 +1750,7 @@ proto.h: \ proto/getchar.pro \ proto/hardcopy.pro \ proto/hashtab.pro \ + proto/highlight.pro \ proto/indent.pro \ proto/insexpand.pro \ proto/json.pro \ diff --git a/src/Make_vms.mms b/src/Make_vms.mms index 2b1d5c6245..92c078b822 100644 --- a/src/Make_vms.mms +++ b/src/Make_vms.mms @@ -311,12 +311,13 @@ SRC = arabic.c autocmd.c beval.c blob.c blowfish.c buffer.c change.c charset.c \ crypt.c crypt_zip.c debugger.c dict.c diff.c digraph.c edit.c eval.c \ evalfunc.c ex_cmds.c ex_cmds2.c ex_docmd.c ex_eval.c ex_getln.c \ if_cscope.c if_xcmdsrv.c fileio.c findfile.c fold.c getchar.c \ - hardcopy.c hashtab.c indent.c insexpand.c json.c list.c main.c mark.c \ - menu.c mbyte.c memfile.c memline.c message.c misc1.c misc2.c move.c \ - normal.c ops.c option.c popupmnu.c popupwin.c profiler.c quickfix.c \ - regexp.c search.c sha256.c sign.c spell.c spellfile.c syntax.c tag.c \ - term.c termlib.c testing.c textprop.c ui.c undo.c usercmd.c userfunc.c \ - version.c screen.c window.c os_unix.c os_vms.c pathdef.c \ + hardcopy.c hashtab.c highlight.c indent.c insexpand.c json.c list.c \ + main.c mark.c menu.c mbyte.c memfile.c memline.c message.c misc1.c \ + misc2.c move.c normal.c ops.c option.c popupmnu.c popupwin.c \ + profiler.c quickfix.c regexp.c search.c sha256.c sign.c spell.c \ + spellfile.c syntax.c tag.c term.c termlib.c testing.c textprop.c ui.c \ + undo.c usercmd.c userfunc.c version.c screen.c window.c os_unix.c \ + os_vms.c pathdef.c \ $(GUI_SRC) $(PERL_SRC) $(PYTHON_SRC) $(TCL_SRC) \ $(RUBY_SRC) $(HANGULIN_SRC) $(MZSCH_SRC) $(XDIFF_SRC) @@ -325,14 +326,14 @@ OBJ = arabic.obj autocmd.obj beval.obj blob.obj blowfish.obj buffer.obj change. digraph.obj edit.obj eval.obj evalfunc.obj ex_cmds.obj ex_cmds2.obj \ ex_docmd.obj ex_eval.obj ex_getln.obj if_cscope.obj if_xcmdsrv.obj \ fileio.obj findfile.obj fold.obj getchar.obj hardcopy.obj hashtab.obj \ - indent.obj insexpand.obj json.obj list.obj main.obj mark.obj \ - menu.obj memfile.obj memline.obj message.obj misc1.obj misc2.obj \ - move.obj mbyte.obj normal.obj ops.obj option.obj popupmnu.obj \ - popupwin.obj profiler.obj quickfix.obj regexp.obj search.obj \ - sha256.obj sign.obj spell.obj spellfile.obj syntax.obj tag.obj \ - term.obj termlib.obj testing.obj textprop.obj ui.obj undo.obj usercmd.obj \ - userfunc.obj screen.obj version.obj window.obj os_unix.obj os_vms.obj \ - pathdef.obj if_mzsch.obj \ + highlight.obj indent.obj insexpand.obj json.obj list.obj main.obj \ + mark.obj menu.obj memfile.obj memline.obj message.obj misc1.obj \ + misc2.obj move.obj mbyte.obj normal.obj ops.obj option.obj \ + popupmnu.obj popupwin.obj profiler.obj quickfix.obj regexp.obj \ + search.obj sha256.obj sign.obj spell.obj spellfile.obj syntax.obj \ + tag.obj term.obj termlib.obj testing.obj textprop.obj ui.obj undo.obj \ + usercmd.obj userfunc.obj screen.obj version.obj window.obj \ + os_unix.obj os_vms.obj pathdef.obj if_mzsch.obj \ $(GUI_OBJ) $(PERL_OBJ) $(PYTHON_OBJ) $(TCL_OBJ) \ $(RUBY_OBJ) $(HANGULIN_OBJ) $(MZSCH_OBJ) $(XDIFF_OBJ) @@ -599,6 +600,10 @@ hashtab.obj : hashtab.c vim.h [.auto]config.h feature.h os_unix.h \ ascii.h keymap.h term.h macros.h structs.h regexp.h \ gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ globals.h +highlight.obj : highlight.c vim.h [.auto]config.h feature.h os_unix.h \ + ascii.h keymap.h term.h macros.h structs.h regexp.h \ + gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ + globals.h if_cscope.obj : if_cscope.c vim.h [.auto]config.h feature.h os_unix.h \ ascii.h keymap.h term.h macros.h structs.h regexp.h \ gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ diff --git a/src/Makefile b/src/Makefile index 10d2b39385..f4f8cc31da 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1604,6 +1604,7 @@ BASIC_SRC = \ getchar.c \ hardcopy.c \ hashtab.c \ + highlight.c \ if_cscope.c \ if_xcmdsrv.c \ indent.c \ @@ -1725,6 +1726,7 @@ OBJ_COMMON = \ objects/getchar.o \ objects/hardcopy.o \ objects/hashtab.o \ + objects/highlight.o \ $(HANGULIN_OBJ) \ objects/if_cscope.o \ objects/if_xcmdsrv.o \ @@ -1860,6 +1862,7 @@ PRO_AUTO = \ hardcopy.pro \ hashtab.pro \ hangulin.pro \ + highlight.pro \ if_cscope.pro \ if_lua.pro \ if_mzsch.pro \ @@ -3103,6 +3106,9 @@ objects/gui_mac.o: gui_mac.c objects/hangulin.o: hangulin.c $(CCC) -o $@ hangulin.c +objects/highlight.o: highlight.c + $(CCC) -o $@ highlight.c + objects/if_cscope.o: if_cscope.c $(CCC) -o $@ if_cscope.c @@ -3554,6 +3560,10 @@ objects/hashtab.o: hashtab.c vim.h protodef.h auto/config.h feature.h os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ proto.h globals.h +objects/highlight.o: highlight.c vim.h protodef.h auto/config.h feature.h os_unix.h \ + auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ + proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ + proto.h globals.h objects/if_cscope.o: if_cscope.c vim.h protodef.h auto/config.h feature.h \ os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ diff --git a/src/README.md b/src/README.md index 61fbcf281b..5293ed3796 100644 --- a/src/README.md +++ b/src/README.md @@ -34,6 +34,7 @@ fileio.c | reading and writing files findfile.c | search for files in 'path' fold.c | folding getchar.c | getting characters and key mapping +highlight.c | syntax highlighting indent.c | C and Lisp indentation insexpand.c | Insert mode completion mark.c | marks diff --git a/src/globals.h b/src/globals.h index 0c2df36b8e..bef5c30bf0 100644 --- a/src/globals.h +++ b/src/globals.h @@ -355,6 +355,16 @@ EXTERN char_u hash_removed; EXTERN int scroll_region INIT(= FALSE); /* term supports scroll region */ EXTERN int t_colors INIT(= 0); /* int value of T_CCO */ +// highlight groups for 'highlight' option +EXTERN garray_T highlight_ga INIT(= {0 COMMA 0 COMMA sizeof(hl_group_T) COMMA 10 COMMA NULL}); + +#ifdef FEAT_CMDL_COMPL +// Flags to indicate an additional string for highlight name completion. +EXTERN int include_none INIT(= 0); // when 1 include "None" +EXTERN int include_default INIT(= 0); // when 1 include "default" +EXTERN int include_link INIT(= 0); // when 2 include "link" and "clear" +#endif + /* * When highlight_match is TRUE, highlight a match, starting at the cursor * position. Search_match_lines is the number of lines after the match (0 for diff --git a/src/highlight.c b/src/highlight.c new file mode 100644 index 0000000000..2ae265ce72 --- /dev/null +++ b/src/highlight.c @@ -0,0 +1,3575 @@ +/* vi:set ts=8 sts=4 sw=4 noet: + * + * VIM - Vi IMproved by Bram Moolenaar + * + * Do ":help uganda" in Vim to read copying and usage conditions. + * Do ":help credits" in Vim to see a list of people who contributed. + * See README.txt for an overview of the Vim source code. + */ + +/* + * Highlighting stuff + */ + +#include "vim.h" + +#define SG_TERM 1 // term has been set +#define SG_CTERM 2 // cterm has been set +#define SG_GUI 4 // gui has been set +#define SG_LINK 8 // link has been set + +/* + * The "term", "cterm" and "gui" arguments can be any combination of the + * following names, separated by commas (but no spaces!). + */ +static char *(hl_name_table[]) = + {"bold", "standout", "underline", "undercurl", + "italic", "reverse", "inverse", "nocombine", "strikethrough", "NONE"}; +static int hl_attr_table[] = + {HL_BOLD, HL_STANDOUT, HL_UNDERLINE, HL_UNDERCURL, HL_ITALIC, HL_INVERSE, HL_INVERSE, HL_NOCOMBINE, HL_STRIKETHROUGH, 0}; +#define ATTR_COMBINE(attr_a, attr_b) ((((attr_b) & HL_NOCOMBINE) ? attr_b : (attr_a)) | (attr_b)) + +static void syn_unadd_group(void); +static void set_hl_attr(int idx); +static void highlight_list_one(int id); +static int highlight_list_arg(int id, int didh, int type, int iarg, char_u *sarg, char *name); +static int syn_add_group(char_u *name); +static int hl_has_settings(int idx, int check_link); +static void highlight_clear(int idx); + +#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) +static void gui_do_one_color(int idx, int do_menu, int do_tooltip); +#endif +#ifdef FEAT_GUI +static int set_group_colors(char_u *name, guicolor_T *fgp, guicolor_T *bgp, int do_menu, int use_norm, int do_tooltip); +static void hl_do_font(int idx, char_u *arg, int do_normal, int do_menu, int do_tooltip, int free_font); +#endif + +/* + * An attribute number is the index in attr_table plus ATTR_OFF. + */ +#define ATTR_OFF (HL_ALL + 1) + +/* + * The default highlight groups. These are compiled-in for fast startup and + * they still work when the runtime files can't be found. + * When making changes here, also change runtime/colors/default.vim! + * The #ifdefs are needed to reduce the amount of static data. Helps to make + * the 16 bit DOS (museum) version compile. + */ +#if defined(FEAT_GUI) || defined(FEAT_EVAL) +# define CENT(a, b) b +#else +# define CENT(a, b) a +#endif +static char *(highlight_init_both[]) = { + CENT("ErrorMsg term=standout ctermbg=DarkRed ctermfg=White", + "ErrorMsg term=standout ctermbg=DarkRed ctermfg=White guibg=Red guifg=White"), + CENT("IncSearch term=reverse cterm=reverse", + "IncSearch term=reverse cterm=reverse gui=reverse"), + CENT("ModeMsg term=bold cterm=bold", + "ModeMsg term=bold cterm=bold gui=bold"), + CENT("NonText term=bold ctermfg=Blue", + "NonText term=bold ctermfg=Blue gui=bold guifg=Blue"), + CENT("StatusLine term=reverse,bold cterm=reverse,bold", + "StatusLine term=reverse,bold cterm=reverse,bold gui=reverse,bold"), + CENT("StatusLineNC term=reverse cterm=reverse", + "StatusLineNC term=reverse cterm=reverse gui=reverse"), + "default link EndOfBuffer NonText", + CENT("VertSplit term=reverse cterm=reverse", + "VertSplit term=reverse cterm=reverse gui=reverse"), +#ifdef FEAT_CLIPBOARD + CENT("VisualNOS term=underline,bold cterm=underline,bold", + "VisualNOS term=underline,bold cterm=underline,bold gui=underline,bold"), +#endif +#ifdef FEAT_DIFF + CENT("DiffText term=reverse cterm=bold ctermbg=Red", + "DiffText term=reverse cterm=bold ctermbg=Red gui=bold guibg=Red"), +#endif +#ifdef FEAT_INS_EXPAND + CENT("PmenuSbar ctermbg=Grey", + "PmenuSbar ctermbg=Grey guibg=Grey"), +#endif + CENT("TabLineSel term=bold cterm=bold", + "TabLineSel term=bold cterm=bold gui=bold"), + CENT("TabLineFill term=reverse cterm=reverse", + "TabLineFill term=reverse cterm=reverse gui=reverse"), +#ifdef FEAT_GUI + "Cursor guibg=fg guifg=bg", + "lCursor guibg=fg guifg=bg", // should be different, but what? +#endif + "default link QuickFixLine Search", + CENT("Normal cterm=NONE", "Normal gui=NONE"), + NULL +}; + +/* Default colors only used with a light background. */ +static char *(highlight_init_light[]) = { + CENT("Directory term=bold ctermfg=DarkBlue", + "Directory term=bold ctermfg=DarkBlue guifg=Blue"), + CENT("LineNr term=underline ctermfg=Brown", + "LineNr term=underline ctermfg=Brown guifg=Brown"), + CENT("CursorLineNr term=bold ctermfg=Brown", + "CursorLineNr term=bold ctermfg=Brown gui=bold guifg=Brown"), + CENT("MoreMsg term=bold ctermfg=DarkGreen", + "MoreMsg term=bold ctermfg=DarkGreen gui=bold guifg=SeaGreen"), + CENT("Question term=standout ctermfg=DarkGreen", + "Question term=standout ctermfg=DarkGreen gui=bold guifg=SeaGreen"), + CENT("Search term=reverse ctermbg=Yellow ctermfg=NONE", + "Search term=reverse ctermbg=Yellow ctermfg=NONE guibg=Yellow guifg=NONE"), +#ifdef FEAT_SPELL + CENT("SpellBad term=reverse ctermbg=LightRed", + "SpellBad term=reverse ctermbg=LightRed guisp=Red gui=undercurl"), + CENT("SpellCap term=reverse ctermbg=LightBlue", + "SpellCap term=reverse ctermbg=LightBlue guisp=Blue gui=undercurl"), + CENT("SpellRare term=reverse ctermbg=LightMagenta", + "SpellRare term=reverse ctermbg=LightMagenta guisp=Magenta gui=undercurl"), + CENT("SpellLocal term=underline ctermbg=Cyan", + "SpellLocal term=underline ctermbg=Cyan guisp=DarkCyan gui=undercurl"), +#endif +#ifdef FEAT_INS_EXPAND + CENT("PmenuThumb ctermbg=Black", + "PmenuThumb ctermbg=Black guibg=Black"), + CENT("Pmenu ctermbg=LightMagenta ctermfg=Black", + "Pmenu ctermbg=LightMagenta ctermfg=Black guibg=LightMagenta"), + CENT("PmenuSel ctermbg=LightGrey ctermfg=Black", + "PmenuSel ctermbg=LightGrey ctermfg=Black guibg=Grey"), +#endif + CENT("SpecialKey term=bold ctermfg=DarkBlue", + "SpecialKey term=bold ctermfg=DarkBlue guifg=Blue"), + CENT("Title term=bold ctermfg=DarkMagenta", + "Title term=bold ctermfg=DarkMagenta gui=bold guifg=Magenta"), + CENT("WarningMsg term=standout ctermfg=DarkRed", + "WarningMsg term=standout ctermfg=DarkRed guifg=Red"), +#ifdef FEAT_WILDMENU + CENT("WildMenu term=standout ctermbg=Yellow ctermfg=Black", + "WildMenu term=standout ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), +#endif +#ifdef FEAT_FOLDING + CENT("Folded term=standout ctermbg=Grey ctermfg=DarkBlue", + "Folded term=standout ctermbg=Grey ctermfg=DarkBlue guibg=LightGrey guifg=DarkBlue"), + CENT("FoldColumn term=standout ctermbg=Grey ctermfg=DarkBlue", + "FoldColumn term=standout ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue"), +#endif +#ifdef FEAT_SIGNS + CENT("SignColumn term=standout ctermbg=Grey ctermfg=DarkBlue", + "SignColumn term=standout ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue"), +#endif + CENT("Visual term=reverse", + "Visual term=reverse guibg=LightGrey"), +#ifdef FEAT_DIFF + CENT("DiffAdd term=bold ctermbg=LightBlue", + "DiffAdd term=bold ctermbg=LightBlue guibg=LightBlue"), + CENT("DiffChange term=bold ctermbg=LightMagenta", + "DiffChange term=bold ctermbg=LightMagenta guibg=LightMagenta"), + CENT("DiffDelete term=bold ctermfg=Blue ctermbg=LightCyan", + "DiffDelete term=bold ctermfg=Blue ctermbg=LightCyan gui=bold guifg=Blue guibg=LightCyan"), +#endif + CENT("TabLine term=underline cterm=underline ctermfg=black ctermbg=LightGrey", + "TabLine term=underline cterm=underline ctermfg=black ctermbg=LightGrey gui=underline guibg=LightGrey"), +#ifdef FEAT_SYN_HL + CENT("CursorColumn term=reverse ctermbg=LightGrey", + "CursorColumn term=reverse ctermbg=LightGrey guibg=Grey90"), + CENT("CursorLine term=underline cterm=underline", + "CursorLine term=underline cterm=underline guibg=Grey90"), + CENT("ColorColumn term=reverse ctermbg=LightRed", + "ColorColumn term=reverse ctermbg=LightRed guibg=LightRed"), +#endif +#ifdef FEAT_CONCEAL + CENT("Conceal ctermbg=DarkGrey ctermfg=LightGrey", + "Conceal ctermbg=DarkGrey ctermfg=LightGrey guibg=DarkGrey guifg=LightGrey"), +#endif + CENT("MatchParen term=reverse ctermbg=Cyan", + "MatchParen term=reverse ctermbg=Cyan guibg=Cyan"), +#ifdef FEAT_TERMINAL + CENT("StatusLineTerm term=reverse,bold cterm=bold ctermfg=White ctermbg=DarkGreen", + "StatusLineTerm term=reverse,bold cterm=bold ctermfg=White ctermbg=DarkGreen gui=bold guifg=bg guibg=DarkGreen"), + CENT("StatusLineTermNC term=reverse ctermfg=White ctermbg=DarkGreen", + "StatusLineTermNC term=reverse ctermfg=White ctermbg=DarkGreen guifg=bg guibg=DarkGreen"), +#endif +#ifdef FEAT_MENU + CENT("ToolbarLine term=underline ctermbg=LightGrey", + "ToolbarLine term=underline ctermbg=LightGrey guibg=LightGrey"), + CENT("ToolbarButton cterm=bold ctermfg=White ctermbg=DarkGrey", + "ToolbarButton cterm=bold ctermfg=White ctermbg=DarkGrey gui=bold guifg=White guibg=Grey40"), +#endif + NULL +}; + +/* Default colors only used with a dark background. */ +static char *(highlight_init_dark[]) = { + CENT("Directory term=bold ctermfg=LightCyan", + "Directory term=bold ctermfg=LightCyan guifg=Cyan"), + CENT("LineNr term=underline ctermfg=Yellow", + "LineNr term=underline ctermfg=Yellow guifg=Yellow"), + CENT("CursorLineNr term=bold ctermfg=Yellow", + "CursorLineNr term=bold ctermfg=Yellow gui=bold guifg=Yellow"), + CENT("MoreMsg term=bold ctermfg=LightGreen", + "MoreMsg term=bold ctermfg=LightGreen gui=bold guifg=SeaGreen"), + CENT("Question term=standout ctermfg=LightGreen", + "Question term=standout ctermfg=LightGreen gui=bold guifg=Green"), + CENT("Search term=reverse ctermbg=Yellow ctermfg=Black", + "Search term=reverse ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), + CENT("SpecialKey term=bold ctermfg=LightBlue", + "SpecialKey term=bold ctermfg=LightBlue guifg=Cyan"), +#ifdef FEAT_SPELL + CENT("SpellBad term=reverse ctermbg=Red", + "SpellBad term=reverse ctermbg=Red guisp=Red gui=undercurl"), + CENT("SpellCap term=reverse ctermbg=Blue", + "SpellCap term=reverse ctermbg=Blue guisp=Blue gui=undercurl"), + CENT("SpellRare term=reverse ctermbg=Magenta", + "SpellRare term=reverse ctermbg=Magenta guisp=Magenta gui=undercurl"), + CENT("SpellLocal term=underline ctermbg=Cyan", + "SpellLocal term=underline ctermbg=Cyan guisp=Cyan gui=undercurl"), +#endif +#ifdef FEAT_INS_EXPAND + CENT("PmenuThumb ctermbg=White", + "PmenuThumb ctermbg=White guibg=White"), + CENT("Pmenu ctermbg=Magenta ctermfg=Black", + "Pmenu ctermbg=Magenta ctermfg=Black guibg=Magenta"), + CENT("PmenuSel ctermbg=Black ctermfg=DarkGrey", + "PmenuSel ctermbg=Black ctermfg=DarkGrey guibg=DarkGrey"), +#endif + CENT("Title term=bold ctermfg=LightMagenta", + "Title term=bold ctermfg=LightMagenta gui=bold guifg=Magenta"), + CENT("WarningMsg term=standout ctermfg=LightRed", + "WarningMsg term=standout ctermfg=LightRed guifg=Red"), +#ifdef FEAT_WILDMENU + CENT("WildMenu term=standout ctermbg=Yellow ctermfg=Black", + "WildMenu term=standout ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), +#endif +#ifdef FEAT_FOLDING + CENT("Folded term=standout ctermbg=DarkGrey ctermfg=Cyan", + "Folded term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=DarkGrey guifg=Cyan"), + CENT("FoldColumn term=standout ctermbg=DarkGrey ctermfg=Cyan", + "FoldColumn term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan"), +#endif +#ifdef FEAT_SIGNS + CENT("SignColumn term=standout ctermbg=DarkGrey ctermfg=Cyan", + "SignColumn term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan"), +#endif + CENT("Visual term=reverse", + "Visual term=reverse guibg=DarkGrey"), +#ifdef FEAT_DIFF + CENT("DiffAdd term=bold ctermbg=DarkBlue", + "DiffAdd term=bold ctermbg=DarkBlue guibg=DarkBlue"), + CENT("DiffChange term=bold ctermbg=DarkMagenta", + "DiffChange term=bold ctermbg=DarkMagenta guibg=DarkMagenta"), + CENT("DiffDelete term=bold ctermfg=Blue ctermbg=DarkCyan", + "DiffDelete term=bold ctermfg=Blue ctermbg=DarkCyan gui=bold guifg=Blue guibg=DarkCyan"), +#endif + CENT("TabLine term=underline cterm=underline ctermfg=white ctermbg=DarkGrey", + "TabLine term=underline cterm=underline ctermfg=white ctermbg=DarkGrey gui=underline guibg=DarkGrey"), +#ifdef FEAT_SYN_HL + CENT("CursorColumn term=reverse ctermbg=DarkGrey", + "CursorColumn term=reverse ctermbg=DarkGrey guibg=Grey40"), + CENT("CursorLine term=underline cterm=underline", + "CursorLine term=underline cterm=underline guibg=Grey40"), + CENT("ColorColumn term=reverse ctermbg=DarkRed", + "ColorColumn term=reverse ctermbg=DarkRed guibg=DarkRed"), +#endif + CENT("MatchParen term=reverse ctermbg=DarkCyan", + "MatchParen term=reverse ctermbg=DarkCyan guibg=DarkCyan"), +#ifdef FEAT_CONCEAL + CENT("Conceal ctermbg=DarkGrey ctermfg=LightGrey", + "Conceal ctermbg=DarkGrey ctermfg=LightGrey guibg=DarkGrey guifg=LightGrey"), +#endif +#ifdef FEAT_TERMINAL + CENT("StatusLineTerm term=reverse,bold cterm=bold ctermfg=Black ctermbg=LightGreen", + "StatusLineTerm term=reverse,bold cterm=bold ctermfg=Black ctermbg=LightGreen gui=bold guifg=bg guibg=LightGreen"), + CENT("StatusLineTermNC term=reverse ctermfg=Black ctermbg=LightGreen", + "StatusLineTermNC term=reverse ctermfg=Black ctermbg=LightGreen guifg=bg guibg=LightGreen"), +#endif +#ifdef FEAT_MENU + CENT("ToolbarLine term=underline ctermbg=DarkGrey", + "ToolbarLine term=underline ctermbg=DarkGrey guibg=Grey50"), + CENT("ToolbarButton cterm=bold ctermfg=Black ctermbg=LightGrey", + "ToolbarButton cterm=bold ctermfg=Black ctermbg=LightGrey gui=bold guifg=Black guibg=LightGrey"), +#endif + NULL +}; + + void +init_highlight( + int both, // include groups where 'bg' doesn't matter + int reset) // clear group first +{ + int i; + char **pp; + static int had_both = FALSE; +#ifdef FEAT_EVAL + char_u *p; + + /* + * Try finding the color scheme file. Used when a color file was loaded + * and 'background' or 't_Co' is changed. + */ + p = get_var_value((char_u *)"g:colors_name"); + if (p != NULL) + { + // The value of g:colors_name could be freed when sourcing the script, + // making "p" invalid, so copy it. + char_u *copy_p = vim_strsave(p); + int r; + + if (copy_p != NULL) + { + r = load_colors(copy_p); + vim_free(copy_p); + if (r == OK) + return; + } + } + +#endif + + /* + * Didn't use a color file, use the compiled-in colors. + */ + if (both) + { + had_both = TRUE; + pp = highlight_init_both; + for (i = 0; pp[i] != NULL; ++i) + do_highlight((char_u *)pp[i], reset, TRUE); + } + else if (!had_both) + // Don't do anything before the call with both == TRUE from main(). + // Not everything has been setup then, and that call will overrule + // everything anyway. + return; + + if (*p_bg == 'l') + pp = highlight_init_light; + else + pp = highlight_init_dark; + for (i = 0; pp[i] != NULL; ++i) + do_highlight((char_u *)pp[i], reset, TRUE); + + // Reverse looks ugly, but grey may not work for 8 colors. Thus let it + // depend on the number of colors available. + // With 8 colors brown is equal to yellow, need to use black for Search fg + // to avoid Statement highlighted text disappears. + // Clear the attributes, needed when changing the t_Co value. + if (t_colors > 8) + do_highlight((char_u *)(*p_bg == 'l' + ? "Visual cterm=NONE ctermbg=LightGrey" + : "Visual cterm=NONE ctermbg=DarkGrey"), FALSE, TRUE); + else + { + do_highlight((char_u *)"Visual cterm=reverse ctermbg=NONE", + FALSE, TRUE); + if (*p_bg == 'l') + do_highlight((char_u *)"Search ctermfg=black", FALSE, TRUE); + } + +#ifdef FEAT_SYN_HL + /* + * If syntax highlighting is enabled load the highlighting for it. + */ + if (get_var_value((char_u *)"g:syntax_on") != NULL) + { + static int recursive = 0; + + if (recursive >= 5) + emsg(_("E679: recursive loop loading syncolor.vim")); + else + { + ++recursive; + (void)source_runtime((char_u *)"syntax/syncolor.vim", DIP_ALL); + --recursive; + } + } +#endif +} + +/* + * Load color file "name". + * Return OK for success, FAIL for failure. + */ + int +load_colors(char_u *name) +{ + char_u *buf; + int retval = FAIL; + static int recursive = FALSE; + + // When being called recursively, this is probably because setting + // 'background' caused the highlighting to be reloaded. This means it is + // working, thus we should return OK. + if (recursive) + return OK; + + recursive = TRUE; + buf = alloc(STRLEN(name) + 12); + if (buf != NULL) + { + apply_autocmds(EVENT_COLORSCHEMEPRE, name, + curbuf->b_fname, FALSE, curbuf); + sprintf((char *)buf, "colors/%s.vim", name); + retval = source_runtime(buf, DIP_START + DIP_OPT); + vim_free(buf); + apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname, FALSE, curbuf); + } + recursive = FALSE; + + return retval; +} + +static char *(color_names[28]) = { + "Black", "DarkBlue", "DarkGreen", "DarkCyan", + "DarkRed", "DarkMagenta", "Brown", "DarkYellow", + "Gray", "Grey", "LightGray", "LightGrey", + "DarkGray", "DarkGrey", + "Blue", "LightBlue", "Green", "LightGreen", + "Cyan", "LightCyan", "Red", "LightRed", "Magenta", + "LightMagenta", "Yellow", "LightYellow", "White", "NONE"}; + // indices: + // 0, 1, 2, 3, + // 4, 5, 6, 7, + // 8, 9, 10, 11, + // 12, 13, + // 14, 15, 16, 17, + // 18, 19, 20, 21, 22, + // 23, 24, 25, 26, 27 +static int color_numbers_16[28] = {0, 1, 2, 3, + 4, 5, 6, 6, + 7, 7, 7, 7, + 8, 8, + 9, 9, 10, 10, + 11, 11, 12, 12, 13, + 13, 14, 14, 15, -1}; +// for xterm with 88 colors... +static int color_numbers_88[28] = {0, 4, 2, 6, + 1, 5, 32, 72, + 84, 84, 7, 7, + 82, 82, + 12, 43, 10, 61, + 14, 63, 9, 74, 13, + 75, 11, 78, 15, -1}; +// for xterm with 256 colors... +static int color_numbers_256[28] = {0, 4, 2, 6, + 1, 5, 130, 130, + 248, 248, 7, 7, + 242, 242, + 12, 81, 10, 121, + 14, 159, 9, 224, 13, + 225, 11, 229, 15, -1}; +// for terminals with less than 16 colors... +static int color_numbers_8[28] = {0, 4, 2, 6, + 1, 5, 3, 3, + 7, 7, 7, 7, + 0+8, 0+8, + 4+8, 4+8, 2+8, 2+8, + 6+8, 6+8, 1+8, 1+8, 5+8, + 5+8, 3+8, 3+8, 7+8, -1}; + +/* + * Lookup the "cterm" value to be used for color with index "idx" in + * color_names[]. + * "boldp" will be set to TRUE or FALSE for a foreground color when using 8 + * colors, otherwise it will be unchanged. + */ + int +lookup_color(int idx, int foreground, int *boldp) +{ + int color = color_numbers_16[idx]; + char_u *p; + + // Use the _16 table to check if it's a valid color name. + if (color < 0) + return -1; + + if (t_colors == 8) + { + // t_Co is 8: use the 8 colors table +#if defined(__QNXNTO__) + color = color_numbers_8_qansi[idx]; +#else + color = color_numbers_8[idx]; +#endif + if (foreground) + { + // set/reset bold attribute to get light foreground + // colors (on some terminals, e.g. "linux") + if (color & 8) + *boldp = TRUE; + else + *boldp = FALSE; + } + color &= 7; // truncate to 8 colors + } + else if (t_colors == 16 || t_colors == 88 + || t_colors >= 256) + { + /* + * Guess: if the termcap entry ends in 'm', it is + * probably an xterm-like terminal. Use the changed + * order for colors. + */ + if (*T_CAF != NUL) + p = T_CAF; + else + p = T_CSF; + if (*p != NUL && (t_colors > 256 + || *(p + STRLEN(p) - 1) == 'm')) + { + if (t_colors == 88) + color = color_numbers_88[idx]; + else if (t_colors >= 256) + color = color_numbers_256[idx]; + else + color = color_numbers_8[idx]; + } +#ifdef FEAT_TERMRESPONSE + if (t_colors >= 256 && color == 15 && is_mac_terminal) + // Terminal.app has a bug: 15 is light grey. Use white + // from the color cube instead. + color = 231; +#endif + } + return color; +} + +/* + * Handle the ":highlight .." command. + * When using ":hi clear" this is called recursively for each group with + * "forceit" and "init" both TRUE. + */ + void +do_highlight( + char_u *line, + int forceit, + int init) // TRUE when called for initializing +{ + char_u *name_end; + char_u *p; + char_u *linep; + char_u *key_start; + char_u *arg_start; + char_u *key = NULL, *arg = NULL; + long i; + int off; + int len; + int attr; + int id; + int idx; + hl_group_T item_before; + int did_change = FALSE; + int dodefault = FALSE; + int doclear = FALSE; + int dolink = FALSE; + int error = FALSE; + int color; + int is_normal_group = FALSE; // "Normal" group +#ifdef FEAT_TERMINAL + int is_terminal_group = FALSE; // "Terminal" group +#endif +#ifdef FEAT_GUI_X11 + int is_menu_group = FALSE; // "Menu" group + int is_scrollbar_group = FALSE; // "Scrollbar" group + int is_tooltip_group = FALSE; // "Tooltip" group + int do_colors = FALSE; // need to update colors? +#else +# define is_menu_group 0 +# define is_tooltip_group 0 +#endif +#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) + int did_highlight_changed = FALSE; +#endif + + /* + * If no argument, list current highlighting. + */ + if (ends_excmd(*line)) + { + for (i = 1; i <= highlight_ga.ga_len && !got_int; ++i) + // TODO: only call when the group has attributes set + highlight_list_one((int)i); + return; + } + + /* + * Isolate the name. + */ + name_end = skiptowhite(line); + linep = skipwhite(name_end); + + /* + * Check for "default" argument. + */ + if (STRNCMP(line, "default", name_end - line) == 0) + { + dodefault = TRUE; + line = linep; + name_end = skiptowhite(line); + linep = skipwhite(name_end); + } + + /* + * Check for "clear" or "link" argument. + */ + if (STRNCMP(line, "clear", name_end - line) == 0) + doclear = TRUE; + if (STRNCMP(line, "link", name_end - line) == 0) + dolink = TRUE; + + /* + * ":highlight {group-name}": list highlighting for one group. + */ + if (!doclear && !dolink && ends_excmd(*linep)) + { + id = syn_namen2id(line, (int)(name_end - line)); + if (id == 0) + semsg(_("E411: highlight group not found: %s"), line); + else + highlight_list_one(id); + return; + } + + /* + * Handle ":highlight link {from} {to}" command. + */ + if (dolink) + { + char_u *from_start = linep; + char_u *from_end; + char_u *to_start; + char_u *to_end; + int from_id; + int to_id; + + from_end = skiptowhite(from_start); + to_start = skipwhite(from_end); + to_end = skiptowhite(to_start); + + if (ends_excmd(*from_start) || ends_excmd(*to_start)) + { + semsg(_("E412: Not enough arguments: \":highlight link %s\""), + from_start); + return; + } + + if (!ends_excmd(*skipwhite(to_end))) + { + semsg(_("E413: Too many arguments: \":highlight link %s\""), from_start); + return; + } + + from_id = syn_check_group(from_start, (int)(from_end - from_start)); + if (STRNCMP(to_start, "NONE", 4) == 0) + to_id = 0; + else + to_id = syn_check_group(to_start, (int)(to_end - to_start)); + + if (from_id > 0 && (!init || HL_TABLE()[from_id - 1].sg_set == 0)) + { + /* + * Don't allow a link when there already is some highlighting + * for the group, unless '!' is used + */ + if (to_id > 0 && !forceit && !init + && hl_has_settings(from_id - 1, dodefault)) + { + if (sourcing_name == NULL && !dodefault) + emsg(_("E414: group has settings, highlight link ignored")); + } + else if (HL_TABLE()[from_id - 1].sg_link != to_id +#ifdef FEAT_EVAL + || HL_TABLE()[from_id - 1].sg_script_ctx.sc_sid + != current_sctx.sc_sid +#endif + || HL_TABLE()[from_id - 1].sg_cleared) + { + if (!init) + HL_TABLE()[from_id - 1].sg_set |= SG_LINK; + HL_TABLE()[from_id - 1].sg_link = to_id; +#ifdef FEAT_EVAL + HL_TABLE()[from_id - 1].sg_script_ctx = current_sctx; + HL_TABLE()[from_id - 1].sg_script_ctx.sc_lnum += sourcing_lnum; +#endif + HL_TABLE()[from_id - 1].sg_cleared = FALSE; + redraw_all_later(SOME_VALID); + + // Only call highlight_changed() once after multiple changes. + need_highlight_changed = TRUE; + } + } + + return; + } + + if (doclear) + { + /* + * ":highlight clear [group]" command. + */ + line = linep; + if (ends_excmd(*line)) + { +#ifdef FEAT_GUI + // First, we do not destroy the old values, but allocate the new + // ones and update the display. THEN we destroy the old values. + // If we destroy the old values first, then the old values + // (such as GuiFont's or GuiFontset's) will still be displayed but + // invalid because they were free'd. + if (gui.in_use) + { +# ifdef FEAT_BEVAL_TIP + gui_init_tooltip_font(); +# endif +# if defined(FEAT_MENU) && (defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MOTIF)) + gui_init_menu_font(); +# endif + } +# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_X11) + gui_mch_def_colors(); +# endif +# ifdef FEAT_GUI_X11 +# ifdef FEAT_MENU + + // This only needs to be done when there is no Menu highlight + // group defined by default, which IS currently the case. + gui_mch_new_menu_colors(); +# endif |