robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Judit Novakfix(runtime): "E121 Undefined variable s:termguicolors" #32209cb924764a4

master
7.0 KiB225 linesraw
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")
8    finish
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 == ''
36    syntax match dircolorsNumber '\<\d\+\>'
37    highlight 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
47    let s:termguicolors = {}
48
49    let s:termguicolors[0]  = "Black"
50    let s:termguicolors[1]  = "DarkRed"
51    let s:termguicolors[2]  = "DarkGreen"
52    let s:termguicolors[3]  = "DarkYellow"
53    let s:termguicolors[4]  = "DarkBlue"
54    let s:termguicolors[5]  = "DarkMagenta"
55    let s:termguicolors[6]  = "DarkCyan"
56    let s:termguicolors[7]  = "Gray"
57    let s:termguicolors[8]  = "DarkGray"
58    let s:termguicolors[9]  = "Red"
59    let s:termguicolors[10] = "Green"
60    let s:termguicolors[11] = "Yellow"
61    let s:termguicolors[12] = "Blue"
62    let s:termguicolors[13] = "Magenta"
63    let s:termguicolors[14] = "Cyan"
64    let s:termguicolors[15] = "White"
65
66    let xterm_palette = ["00", "5f", "87", "af", "d7", "ff"]
67
68    let cur_col = 16
69
70    for r in xterm_palette
71        for g in xterm_palette
72            for b in xterm_palette
73                let s:termguicolors[cur_col] = '#' . r . g . b
74                let cur_col += 1
75            endfor
76        endfor
77    endfor
78
79    for i in range(24)
80        let g = i * 0xa + 8
81        let s:termguicolors[i + 232] = '#' . g . g . g
82    endfor
83endfunction
84
85function! s:get_hi_str(color, place) abort
86    if a:color >= 0 && a:color <= 255
87        if has('gui_running') || &termguicolors
88            if ! exists("s:termguicolors")
89              call s:set_guicolors()
90            endif
91            return ' gui' . a:place . '=' . s:termguicolors[a:color]
92        elseif a:color <= 7 || &t_Co == 256 || &t_Co == 88
93            return ' cterm' . a:place . '=' . a:color
94        endif
95    endif
96    return ''
97endfunction
98
99function! s:get_256color(colors) abort
100    if len(a:colors) >= 2 " May be fewer while editing
101        let [_five, color] = remove(a:colors, 0, 1)
102        if _five != '5' || color == ''
103            return -1
104        else
105            return str2nr(color)
106        endif
107    else
108        return -1
109    endif
110endfunction
111
112function! s:preview_color(linenr) abort
113    let line = getline(a:linenr)
114    let defline = matchlist(line, '^\v([A-Z_]+|[*.]\S+)\s+([0-9;]+)')
115    if empty(defline)
116        return
117    endif
118
119    let colordef = defline[2]
120
121    let colors = split(colordef, ';')
122
123    let hi_str = ''
124    let hi_attrs = []
125    while len(colors) > 0
126        let item = str2nr(remove(colors, 0))
127        if item == 1
128            call add(hi_attrs, 'bold')
129        elseif item == 3
130            call add(hi_attrs, 'italic')
131        elseif item == 4
132            call add(hi_attrs, 'underline')
133        elseif item == 7
134            call add(hi_attrs, 'inverse')
135        elseif item >= 30 && item <= 37
136            " ANSI SGR foreground color
137            let hi_str .= s:get_hi_str(item - 30, 'fg')
138        elseif item >= 40 && item <= 47
139            " ANSI SGR background color
140            let hi_str .= s:get_hi_str(item - 40, 'bg')
141        elseif item >= 90 && item <= 97
142            " ANSI SGR+8 foreground color (xterm 16-color support)
143            let hi_str .= s:get_hi_str(item - 82, 'fg')
144        elseif item >= 100 && item <= 107
145            " ANSI SGR+8 background color (xterm 16-color support)
146            let hi_str .= s:get_hi_str(item - 92, 'bg')
147        elseif item == 38
148            " Foreground for terminals with 88/256 color support
149            let color = s:get_256color(colors)
150            if color == -1
151                break
152            endif
153            let hi_str .= s:get_hi_str(color, 'fg')
154        elseif item == 48
155            " Background for terminals with 88/256 color support
156            let color = s:get_256color(colors)
157            if color == -1
158                break
159            endif
160            let hi_str .= s:get_hi_str(color, 'bg')
161        endif
162    endwhile
163
164    if hi_str == '' && empty(hi_attrs)
165        return
166    endif
167
168    " Check whether we have already defined this color
169    redir => s:currentmatch
170    silent! execute 'syntax list'
171    redir END
172
173    if s:currentmatch !~# '\/\\_s\\zs' . colordef . '\\ze\\_s\/'
174        " Append the buffer number to avoid problems with other dircolors
175        " buffers interfering
176        let bufnr = bufnr('%')
177        execute 'syntax match dircolorsColor' . b:dc_next_index . '_' . bufnr .
178              \ ' "\_s\zs' . colordef . '\ze\_s"'
179        let hi_attrs_str = ''
180        if !empty(hi_attrs)
181            if has('gui_running') || &termguicolors
182                let hi_attrs_str = ' gui=' . join(hi_attrs, ',')
183            else
184                let hi_attrs_str = ' cterm=' . join(hi_attrs, ',')
185            endif
186        endif
187        execute 'highlight default dircolorsColor' . b:dc_next_index . '_' .
188              \ bufnr . hi_str . hi_attrs_str
189        let b:dc_next_index += 1
190    endif
191endfunction
192
193" Avoid accumulating too many definitions while editing
194function! s:reset_colors() abort
195    if b:dc_next_index > 0
196        let bufnr = bufnr('%')
197        for i in range(b:dc_next_index)
198            execute 'syntax clear dircolorsColor' . i . '_' . bufnr
199            execute 'highlight clear dircolorsColor' . i . '_' . bufnr
200        endfor
201        let b:dc_next_index = 0
202    endif
203
204    for linenr in range(1, line('$'))
205        call s:preview_color(linenr)
206    endfor
207endfunction
208
209let b:dc_next_index = 0
210
211if has('gui_running') || &termguicolors
212    call s:set_guicolors()
213endif
214
215if has('gui_running') || &termguicolors || &t_Co != ''
216    call s:reset_colors()
217
218    autocmd CursorMoved,CursorMovedI <buffer> call s:preview_color('.')
219    autocmd CursorHold,CursorHoldI   <buffer> call s:reset_colors()
220endif
221
222let b:current_syntax = "dircolors"
223
224let &cpo = s:cpo_save
225unlet s:cpo_save