mirror of
https://github.com/osyo-manga/vim-brightest.git
synced 2025-11-17 16:03:41 -05:00
Add g:brightest#enable_highlight_all_window.
This commit is contained in:
@@ -3,6 +3,7 @@ let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
|
||||
function! s:_vital_loaded(V)
|
||||
let s:V = a:V
|
||||
let s:Buffer = s:V.import("Coaster.Buffer")
|
||||
@@ -27,22 +28,48 @@ function! s:region_pair(fist, last, ...)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:pattern_in_range(wise, first, last, pattern)
|
||||
function! s:pattern_in_region_char(first, last, pattern)
|
||||
if a:first == a:last
|
||||
return printf('\%%%dl\%%%dc', a:first[0], a:first[1])
|
||||
elseif a:first[0] == a:last[0]
|
||||
return printf('\%%%dl\%%>%dc%s\%%<%dc', a:first[0], a:first[1]-1, a:pattern, a:last[1]+1)
|
||||
return printf('\%%%dl\%%>%dc\%%(%s\M\)\%%<%dc', a:first[0], a:first[1]-1, a:pattern, a:last[1]+1)
|
||||
elseif a:last[0] - a:first[0] == 1
|
||||
return printf('\%%%dl%s\%%>%dc', a:first[0], a:pattern, a:first[1]-1)
|
||||
\ . "\\|" . printf('\%%%dl%s\%%<%dc', a:last[0], a:pattern, a:last[1]+1)
|
||||
return printf('\%%%dl\%%(%s\M\)\%%>%dc', a:first[0], a:pattern, a:first[1]-1)
|
||||
\ . "\\|" . printf('\%%%dl\%%(%s\M\)\%%<%dc', a:last[0], a:pattern, a:last[1]+1)
|
||||
else
|
||||
return printf('\%%%dl%s\%%>%dc', a:first[0], a:pattern, a:first[1]-1)
|
||||
\ . "\\|" . printf('\%%>%dl%s\%%<%dl', a:first[0], a:pattern, a:last[0])
|
||||
\ . "\\|" . printf('\%%%dl%s\%%<%dc', a:last[0], a:pattern, a:last[1]+1)
|
||||
return printf('\%%%dl\%%(%s\M\)\%%>%dc', a:first[0], a:pattern, a:first[1]-1)
|
||||
\ . "\\|" . printf('\%%>%dl\%%(%s\M\)\%%<%dl', a:first[0], a:pattern, a:last[0])
|
||||
\ . >"\\|" . printf('\%%%dl\%%(%s\M\)\%%<%dc', a:last[0], a:pattern, a:last[1]+1)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:pattern_in_region_line(first, last, pattern)
|
||||
return printf('\%%>%dl\%%(%s\M\)\%%<%dl', a:first[0]-1, a:pattern, a:last[0]+1)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:pattern_in_region_block(first, last, pattern)
|
||||
return join(map(range(a:first[0], a:last[0]), "s:pattern_in_region_char([v:val, a:first[1]], [v:val, a:last[1]], a:pattern)"), '\|')
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:pattern_in_region(wise, first, last, ...)
|
||||
let pattern = get(a:, 1, "")
|
||||
if a:wise ==# "v"
|
||||
return s:pattern_in_region_char(a:first, a:last, pattern)
|
||||
elseif a:wise ==# "V"
|
||||
return s:pattern_in_region_line(a:first, a:last, pattern)
|
||||
elseif a:wise ==# "\<C-v>"
|
||||
return s:pattern_in_region_block(a:first, a:last, pattern)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:pattern_in_range(...)
|
||||
return call("s:pattern_in_region", a:000)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:pattern_by_range(wise, first, last)
|
||||
return s:pattern_in_range(a:wise, a:first, a:last, '.\{-}')
|
||||
endfunction
|
||||
@@ -58,5 +85,36 @@ function! s:text_by_pattern(pattern, ...)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:_syntax_name(pos)
|
||||
return synIDattr(synIDtrans(synID(a:pos[0], a:pos[1], 1)), 'name')
|
||||
endfunction
|
||||
|
||||
|
||||
" log : http://lingr.com/room/vim/archives/2014/08/15#message-19938628
|
||||
function! s:pos_ignore_syntaxes(pattern, syntaxes, ...)
|
||||
let old_pos = getpos(".")
|
||||
let old_view = winsaveview()
|
||||
let flag = substitute(get(a:, 1, ""), 'n', "", "g")
|
||||
try
|
||||
while 1
|
||||
let pos = searchpos(a:pattern, flag . "W")
|
||||
if pos == [0, 0] || index(a:syntaxes, s:_syntax_name(pos)) == -1
|
||||
return pos
|
||||
endif
|
||||
endwhile
|
||||
finally
|
||||
if get(a:, 1, "") =~# "n"
|
||||
call setpos(".", old_pos)
|
||||
call winrestview(old_view)
|
||||
endif
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:count(pattern)
|
||||
return matchstr(s:M.capture('%s/' . a:pattern . '//n'), '\d\+\ze')
|
||||
endfunction
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
Reference in New Issue
Block a user