robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
cb924764a4
master
1" Vim syntax file 2" Language: dircolors(1) input file 3" Maintainer: Jan Larres <jan@majutsushi.net> 4" Previous Maintainer: Nikolai Weibull <now@bitwi.se> 5" Latest Revision: 2018-02-19 6 7if exists ( "b:current_syntax" ) 8finish 9endif 10 11let s: cpo_save = & cpo 12set cpo & vim 13 14syntax keyword dircolorsTodo FIXME TODO XXX NOTE contained 15 16syntax region dircolorsComment start = '# 'end = '$ 'contains = dircolorsTodo , @Spell 17 18syntax keyword dircolorsKeyword TERM LEFT LEFTCODE RIGHT RIGHTCODE END ENDCODE 19 20syntax keyword dircolorsKeyword NORMAL NORM FILE RESET DIR LNK LINK SYMLINK 21 \MULTIHARDLINK FIFO SOCK DOOR BLK CHR ORPHAN 22 \MISSING PIPE BLOCK CHR EXEC SETUID SETGID 23 \CAPABILITY STICKY_OTHER_WRITABLE 24 \OTHER_WRITABLE STICKY 25 26" Slackware only, ignored by GNU dircolors. 27syntax keyword dircolorsKeyword COLOR OPTIONS EIGHTBIT 28 29syntax match dircolorsExtension '^\s * \zs [ .* ] \S\+ ' 30 31syntax match dircolorsEscape '\\ [ abefnrtv?_\\^# ] ' 32syntax match dircolorsEscape '\\ [ 0-9 ] \{3} ' 33syntax match dircolorsEscape '\\x [ 0-9a-f ] \{3} ' 34 35if ! ( has ( 'gui_running' ) || & termguicolors ) && & t_Co == '' 36syntax match dircolorsNumber '\<\d\+\> ' 37highlight default link dircolorsNumber Number 38endif 39 40highlight default link dircolorsTodo Todo 41highlight default link dircolorsComment Comment 42highlight default link dircolorsKeyword Keyword 43highlight default link dircolorsExtension Identifier 44highlight default link dircolorsEscape Special 45 46function ! s: set_guicolors () abort 47let s: termguicolors = {} 48 49let s: termguicolors [ 0 ] = "Black" 50let s: termguicolors [ 1 ] = "DarkRed" 51let s: termguicolors [ 2 ] = "DarkGreen" 52let s: termguicolors [ 3 ] = "DarkYellow" 53let s: termguicolors [ 4 ] = "DarkBlue" 54let s: termguicolors [ 5 ] = "DarkMagenta" 55let s: termguicolors [ 6 ] = "DarkCyan" 56let s: termguicolors [ 7 ] = "Gray" 57let s: termguicolors [ 8 ] = "DarkGray" 58let s: termguicolors [ 9 ] = "Red" 59let s: termguicolors [ 10 ] = "Green" 60let s: termguicolors [ 11 ] = "Yellow" 61let s: termguicolors [ 12 ] = "Blue" 62let s: termguicolors [ 13 ] = "Magenta" 63let s: termguicolors [ 14 ] = "Cyan" 64let s: termguicolors [ 15 ] = "White" 65 66let xterm_palette = [ "00" , "5f" , "87" , "af" , "d7" , "ff" ] 67 68let cur_col = 16 69 70for r in xterm_palette 71for g in xterm_palette 72for b in xterm_palette 73let s: termguicolors [ cur_col ] = '#' . r . g . b 74let cur_col += 1 75endfor 76endfor 77endfor 78 79for i in range ( 24 ) 80let g = i * 0xa + 8 81let s: termguicolors [ i + 232 ] = '#' . g . g . g 82endfor 83endfunction 84 85function ! s: get_hi_str ( color , place ) abort 86if a: color >= 0 && a: color <= 255 87if has ( 'gui_running' ) || & termguicolors 88if ! exists ( "s:termguicolors" ) 89call s: set_guicolors () 90endif 91return ' gui' . a: place . '=' . s: termguicolors [ a: color ] 92elseif a: color <= 7 || & t_Co == 256 || & t_Co == 88 93return ' cterm' . a: place . '=' . a: color 94endif 95endif 96return '' 97endfunction 98 99function ! s: get_256color ( colors ) abort 100if len ( a: colors ) >= 2 " May be fewer while editing 101let [ _five , color ] = remove ( a: colors , 0 , 1 ) 102if _five != '5' || color == '' 103return -1 104else 105return str2nr ( color ) 106endif 107else 108return -1 109endif 110endfunction 111 112function ! s: preview_color ( linenr ) abort 113let line = getline ( a: linenr ) 114let defline = matchlist ( line , '^\v([A-Z_]+|[*.]\S+)\s+([0-9;]+)' ) 115if empty ( defline ) 116return 117endif 118 119let colordef = defline [ 2 ] 120 121let colors = split ( colordef , ';' ) 122 123let hi_str = '' 124let hi_attrs = [] 125while len ( colors ) > 0 126let item = str2nr ( remove ( colors , 0 )) 127if item == 1 128call add ( hi_attrs , 'bold' ) 129elseif item == 3 130call add ( hi_attrs , 'italic' ) 131elseif item == 4 132call add ( hi_attrs , 'underline' ) 133elseif item == 7 134call add ( hi_attrs , 'inverse' ) 135elseif item >= 30 && item <= 37 136" ANSI SGR foreground color 137let hi_str .= s: get_hi_str ( item - 30 , 'fg' ) 138elseif item >= 40 && item <= 47 139" ANSI SGR background color 140let hi_str .= s: get_hi_str ( item - 40 , 'bg' ) 141elseif item >= 90 && item <= 97 142" ANSI SGR+8 foreground color (xterm 16-color support) 143let hi_str .= s: get_hi_str ( item - 82 , 'fg' ) 144elseif item >= 100 && item <= 107 145" ANSI SGR+8 background color (xterm 16-color support) 146let hi_str .= s: get_hi_str ( item - 92 , 'bg' ) 147elseif item == 38 148" Foreground for terminals with 88/256 color support 149let color = s: get_256color ( colors ) 150if color == -1 151break 152endif 153let hi_str .= s: get_hi_str ( color , 'fg' ) 154elseif item == 48 155" Background for terminals with 88/256 color support 156let color = s: get_256color ( colors ) 157if color == -1 158break 159endif 160let hi_str .= s: get_hi_str ( color , 'bg' ) 161endif 162endwhile 163 164if hi_str == '' && empty ( hi_attrs ) 165return 166endif 167 168" Check whether we have already defined this color 169redir => s:currentmatch 170silent ! execute 'syntax list' 171redir END 172 173if s: currentmatch !~# '\/\\_s\\zs' . colordef . '\\ze\\_s\/' 174" Append the buffer number to avoid problems with other dircolors 175" buffers interfering 176let bufnr = bufnr ( '%' ) 177execute 'syntax match dircolorsColor' . b: dc_next_index . '_' . bufnr . 178 \' "\_s\zs' . colordef . '\ze\_s"' 179let hi_attrs_str = '' 180if ! empty ( hi_attrs ) 181if has ( 'gui_running' ) || & termguicolors 182let hi_attrs_str = ' gui=' . join ( hi_attrs , ',' ) 183else 184let hi_attrs_str = ' cterm=' . join ( hi_attrs , ',' ) 185endif 186endif 187execute 'highlight default dircolorsColor' . b: dc_next_index . '_' . 188 \bufnr . hi_str . hi_attrs_str 189let b: dc_next_index += 1 190endif 191endfunction 192 193" Avoid accumulating too many definitions while editing 194function ! s: reset_colors () abort 195if b: dc_next_index > 0 196let bufnr = bufnr ( '%' ) 197for i in range ( b: dc_next_index ) 198execute 'syntax clear dircolorsColor' . i . '_' . bufnr 199execute 'highlight clear dircolorsColor' . i . '_' . bufnr 200endfor 201let b: dc_next_index = 0 202endif 203 204for linenr in range ( 1 , line ( '$' )) 205call s: preview_color ( linenr ) 206endfor 207endfunction 208 209let b: dc_next_index = 0 210 211if has ( 'gui_running' ) || & termguicolors 212call s: set_guicolors () 213endif 214 215if has ( 'gui_running' ) || & termguicolors || & t_Co != '' 216call s: reset_colors () 217 218autocmd CursorMoved , CursorMovedI <buffer> call s: preview_color ( '.' ) 219autocmd CursorHold , CursorHoldI <buffer> call s: reset_colors () 220endif 221 222let b: current_syntax = "dircolors" 223 224let & cpo = s: cpo_save 225unlet s: cpo_save