Mercurial > vim
view runtime/syntax/dircolors.vim @ 34194:a522c6c0127b v9.1.0047
patch 9.1.0047: issues with temp curwin/buf while cmdwin is open
Commit: https://github.com/vim/vim/commit/988f74311c26ea9917e84fbae608de226dba7e5f
Author: Sean Dewar <seandewar@users.noreply.github.com>
Date: Wed Aug 16 14:17:36 2023 +0100
patch 9.1.0047: issues with temp curwin/buf while cmdwin is open
Problem: Things that temporarily change/restore curwin/buf (e.g:
win_execute, some autocmds) may break assumptions that
curwin/buf is the cmdwin when "cmdwin_type != 0", causing
issues.
Solution: Expose the cmdwin's real win/buf and check that instead. Also
try to ensure these variables are NULL if "cmdwin_type == 0",
allowing them to be used directly in most cases without
checking cmdwin_type. (Sean Dewar)
Alternatively, we could ban win_execute in the cmdwin and audit all places that
temporarily change/restore curwin/buf, but I didn't notice any problems arising
from allowing this (standard cmdwin restrictions still apply, so things that may
actually break the cmdwin are still forbidden).
closes: #12819
Signed-off-by: Sean Dewar <seandewar@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 23 Jan 2024 23:00:04 +0100 |
parents | acd7eaa13d2b |
children |
line wrap: on
line source
" Vim syntax file " Language: dircolors(1) input file " Maintainer: Jan Larres <jan@majutsushi.net> " Previous Maintainer: Nikolai Weibull <now@bitwi.se> " Latest Revision: 2018-02-19 if exists("b:current_syntax") finish endif let s:cpo_save = &cpo set cpo&vim syntax keyword dircolorsTodo FIXME TODO XXX NOTE contained syntax region dircolorsComment start='#' end='$' contains=dircolorsTodo,@Spell syntax keyword dircolorsKeyword TERM LEFT LEFTCODE RIGHT RIGHTCODE END ENDCODE syntax keyword dircolorsKeyword NORMAL NORM FILE RESET DIR LNK LINK SYMLINK \ MULTIHARDLINK FIFO SOCK DOOR BLK CHR ORPHAN \ MISSING PIPE BLOCK CHR EXEC SETUID SETGID \ CAPABILITY STICKY_OTHER_WRITABLE \ OTHER_WRITABLE STICKY " Slackware only, ignored by GNU dircolors. syntax keyword dircolorsKeyword COLOR OPTIONS EIGHTBIT syntax match dircolorsExtension '^\s*\zs[.*]\S\+' syntax match dircolorsEscape '\\[abefnrtv?_\\^#]' syntax match dircolorsEscape '\\[0-9]\{3}' syntax match dircolorsEscape '\\x[0-9a-f]\{3}' if !has('gui_running') && &t_Co == '' syntax match dircolorsNumber '\<\d\+\>' highlight default link dircolorsNumber Number endif highlight default link dircolorsTodo Todo highlight default link dircolorsComment Comment highlight default link dircolorsKeyword Keyword highlight default link dircolorsExtension Identifier highlight default link dircolorsEscape Special function! s:set_guicolors() abort let s:termguicolors = {} let s:termguicolors[0] = "Black" let s:termguicolors[1] = "DarkRed" let s:termguicolors[2] = "DarkGreen" let s:termguicolors[3] = "DarkYellow" let s:termguicolors[4] = "DarkBlue" let s:termguicolors[5] = "DarkMagenta" let s:termguicolors[6] = "DarkCyan" let s:termguicolors[7] = "Gray" let s:termguicolors[8] = "DarkGray" let s:termguicolors[9] = "Red" let s:termguicolors[10] = "Green" let s:termguicolors[11] = "Yellow" let s:termguicolors[12] = "Blue" let s:termguicolors[13] = "Magenta" let s:termguicolors[14] = "Cyan" let s:termguicolors[15] = "White" let xterm_palette = ["00", "5f", "87", "af", "d7", "ff"] let cur_col = 16 for r in xterm_palette for g in xterm_palette for b in xterm_palette let s:termguicolors[cur_col] = '#' . r . g . b let cur_col += 1 endfor endfor endfor for i in range(24) let g = i * 0xa + 8 let s:termguicolors[i + 232] = '#' . g . g . g endfor endfunction function! s:get_hi_str(color, place) abort if a:color >= 0 && a:color <= 255 if has('gui_running') return ' gui' . a:place . '=' . s:termguicolors[a:color] elseif a:color <= 7 || &t_Co == 256 || &t_Co == 88 return ' cterm' . a:place . '=' . a:color endif endif return '' endfunction function! s:get_256color(colors) abort if len(a:colors) >= 2 " May be fewer while editing let [_five, color] = remove(a:colors, 0, 1) if _five != '5' || color == '' return -1 else return str2nr(color) endif else return -1 endif endfunction function! s:preview_color(linenr) abort let line = getline(a:linenr) let defline = matchlist(line, '^\v([A-Z_]+|[*.]\S+)\s+([0-9;]+)') if empty(defline) return endif let colordef = defline[2] let colors = split(colordef, ';') let hi_str = '' let hi_attrs = [] while len(colors) > 0 let item = str2nr(remove(colors, 0)) if item == 1 call add(hi_attrs, 'bold') elseif item == 3 call add(hi_attrs, 'italic') elseif item == 4 call add(hi_attrs, 'underline') elseif item == 7 call add(hi_attrs, 'inverse') elseif item >= 30 && item <= 37 " ANSI SGR foreground color let hi_str .= s:get_hi_str(item - 30, 'fg') elseif item >= 40 && item <= 47 " ANSI SGR background color let hi_str .= s:get_hi_str(item - 40, 'bg') elseif item >= 90 && item <= 97 " ANSI SGR+8 foreground color (xterm 16-color support) let hi_str .= s:get_hi_str(item - 82, 'fg') elseif item >= 100 && item <= 107 " ANSI SGR+8 background color (xterm 16-color support) let hi_str .= s:get_hi_str(item - 92, 'bg') elseif item == 38 " Foreground for terminals with 88/256 color support let color = s:get_256color(colors) if color == -1 break endif let hi_str .= s:get_hi_str(color, 'fg') elseif item == 48 " Background for terminals with 88/256 color support let color = s:get_256color(colors) if color == -1 break endif let hi_str .= s:get_hi_str(color, 'bg') endif endwhile if hi_str == '' && empty(hi_attrs) return endif " Check whether we have already defined this color redir => s:currentmatch silent! execute 'syntax list' redir END if s:currentmatch !~# '\/\\_s\\zs' . colordef . '\\ze\\_s\/' " Append the buffer number to avoid problems with other dircolors " buffers interfering let bufnr = bufnr('%') execute 'syntax match dircolorsColor' . b:dc_next_index . '_' . bufnr . \ ' "\_s\zs' . colordef . '\ze\_s"' let hi_attrs_str = '' if !empty(hi_attrs) if has('gui_running') let hi_attrs_str = ' gui=' . join(hi_attrs, ',') else let hi_attrs_str = ' cterm=' . join(hi_attrs, ',') endif endif execute 'highlight default dircolorsColor' . b:dc_next_index . '_' . \ bufnr . hi_str . hi_attrs_str let b:dc_next_index += 1 endif endfunction " Avoid accumulating too many definitions while editing function! s:reset_colors() abort if b:dc_next_index > 0 let bufnr = bufnr('%') for i in range(b:dc_next_index) execute 'syntax clear dircolorsColor' . i . '_' . bufnr execute 'highlight clear dircolorsColor' . i . '_' . bufnr endfor let b:dc_next_index = 0 endif for linenr in range(1, line('$')) call s:preview_color(linenr) endfor endfunction let b:dc_next_index = 0 if has('gui_running') call s:set_guicolors() endif if has('gui_running') || &t_Co != '' call s:reset_colors() autocmd CursorMoved,CursorMovedI <buffer> call s:preview_color('.') autocmd CursorHold,CursorHoldI <buffer> call s:reset_colors() endif let b:current_syntax = "dircolors" let &cpo = s:cpo_save unlet s:cpo_save