mirror of
https://github.com/osyo-manga/vim-brightest.git
synced 2025-11-17 07:53:42 -05:00
Add g:brightest#enable_highlight_all_window.
This commit is contained in:
@@ -2,15 +2,19 @@ scriptencoding utf-8
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
|
||||
function! s:_vital_loaded(V)
|
||||
let s:V = a:V
|
||||
let s:Search = a:V.import("Coaster.Search")
|
||||
let s:Object = a:V.import("Coaster.Buffer.Object")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:_vital_depends()
|
||||
return [
|
||||
\ "Coaster.Search"
|
||||
\ "Coaster.Search",
|
||||
\ "Coaster.Buffer.Object"
|
||||
\ ]
|
||||
endfunction
|
||||
|
||||
@@ -78,19 +82,53 @@ function! s:yank(wise, first, last)
|
||||
let old_last = getpos("']")
|
||||
let old_pos = getpos(".")
|
||||
try
|
||||
call setpos("'[", a:first)
|
||||
call setpos("']", a:last)
|
||||
call s:_setpos("'[", a:first)
|
||||
call s:_setpos("']", a:last)
|
||||
execute "normal! `[" . a:wise . "`]y"
|
||||
finally
|
||||
call setpos("'[", old_first)
|
||||
call setpos("']", old_last)
|
||||
call s:_setpos("'[", old_first)
|
||||
call s:_setpos("']", old_last)
|
||||
let &selection = old_selection
|
||||
call winrestview(old_view)
|
||||
call setpos(".", old_pos)
|
||||
call s:_setpos(".", old_pos)
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:delete(wise, first, last)
|
||||
let old_view = winsaveview()
|
||||
let old_selection = &selection
|
||||
let &selection = 'inclusive'
|
||||
let old_first = getpos("'[")
|
||||
let old_last = getpos("']")
|
||||
let old_pos = getpos(".")
|
||||
try
|
||||
call s:_setpos("'[", a:first)
|
||||
call s:_setpos("']", a:last)
|
||||
execute printf('normal! `[%s`]"_d', a:wise)
|
||||
finally
|
||||
call s:_setpos("'[", old_first)
|
||||
call s:_setpos("']", old_last)
|
||||
let &selection = old_selection
|
||||
call winrestview(old_view)
|
||||
call s:_setpos(".", old_pos)
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:_as_pos(pos)
|
||||
return len(a:list) == 2 ? [0] + a:pos + [0] : a:pos
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:_setpos(expr, list)
|
||||
if len(a:list) == 2
|
||||
return s:_setpos(a:expr, [0] + a:list + [0])
|
||||
endif
|
||||
return setpos(a:expr, a:list)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:paste(wise, first, last, register)
|
||||
let old_view = winsaveview()
|
||||
let old_selection = &selection
|
||||
@@ -99,24 +137,36 @@ function! s:paste(wise, first, last, register)
|
||||
let old_last = getpos("']")
|
||||
let old_pos = getpos(".")
|
||||
try
|
||||
call setpos("'[", a:first)
|
||||
call setpos("']", a:last)
|
||||
call s:_setpos("'[", a:first)
|
||||
call s:_setpos("']", a:last)
|
||||
execute printf('normal! `[%s`]"%sp', a:wise, a:register)
|
||||
finally
|
||||
call setpos("'[", old_first)
|
||||
call setpos("']", old_last)
|
||||
call s:_setpos("'[", old_first)
|
||||
call s:_setpos("']", old_last)
|
||||
let &selection = old_selection
|
||||
call winrestview(old_view)
|
||||
call setpos(".", old_pos)
|
||||
call s:_setpos(".", old_pos)
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:paste_for_text(wise, first, last, text)
|
||||
let old = @a
|
||||
try
|
||||
let @a = a:text
|
||||
return s:paste(a:wise, a:first, a:last, "a")
|
||||
finally
|
||||
let @a = old
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
function! s:get_text_line_from_lnum(first, last)
|
||||
return join(getline(a:first, a:last), "\n")
|
||||
endfunction
|
||||
"
|
||||
"
|
||||
|
||||
|
||||
" function! s:get_text_line_from_region(first, last)
|
||||
" " if type(a:first) == type([])
|
||||
" " return s:get_text_line_from_region(a:first[1], a:last)
|
||||
@@ -146,9 +196,7 @@ endfunction
|
||||
function! s:get_block_from_region(first, last)
|
||||
let first = a:first
|
||||
let last = a:last
|
||||
echo join(map(range(a:first[1], a:last[1]), "
|
||||
\ s:get_char_from_region([first[0], v:val, first[2], first[3]], [last[0], v:val, last[2], last[3]])
|
||||
\ "), "\n")
|
||||
return join(map(range(a:first[1], a:last[1]), "s:get_char_from_region([first[0], v:val, first[2], first[3]], [last[0], v:val, last[2], last[3]])"), "\n")
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -161,16 +209,6 @@ function! s:get_text_from_region(first, last, ...)
|
||||
elseif wise ==# "\<C-v>"
|
||||
return s:get_block_from_region(a:first, a:last)
|
||||
endif
|
||||
" let old_first = getpos("'[")
|
||||
" let old_last = getpos("']")
|
||||
" try
|
||||
" call setpos("'[", a:first)
|
||||
" call setpos("']", a:last)
|
||||
" return s:get_text_from_latest_yank(wise)
|
||||
" finally
|
||||
" call setpos("'[", old_first)
|
||||
" call setpos("']", old_last)
|
||||
" endtry
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -245,18 +283,58 @@ function! s:get_region_from_textobj(textobj)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:get(bufnr)
|
||||
return s:Object.make(a:bufnr)
|
||||
endfunction
|
||||
|
||||
|
||||
" function! s:make(expr)
|
||||
" let buffer = s:get(a:expr)
|
||||
" if buffer.is_exists()
|
||||
" return buffer
|
||||
" endif
|
||||
" return s:new("", type(a:expr) == type("") ? a:expr : "")
|
||||
" endfunction
|
||||
|
||||
|
||||
function! s:current()
|
||||
return s:get(bufnr("%"))
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:new(...)
|
||||
let name = get(a:, 1, "")
|
||||
execute "new" name
|
||||
let buffer = s:current()
|
||||
quit
|
||||
return buffer
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:open(cmd)
|
||||
let buffer = s:new()
|
||||
call buffer.open(a:cmd)
|
||||
return buffer
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:execute(expr, cmd)
|
||||
let bufnr = bufnr("%")
|
||||
try
|
||||
noautocmd execute "bufdo if bufnr('%') == " a:expr . ' | ' . a:cmd . ' | endif'
|
||||
finally
|
||||
execute "buffer" bufnr
|
||||
endtry
|
||||
return s:get(a:expr).execute(a:cmd)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:setbufline_if_python(expr, lnum, text)
|
||||
if len(getbufline(a:expr, 1, "$")) < a:lnum - 1
|
||||
return
|
||||
endif
|
||||
let list = type(a:text) == type([]) ? a:text : [a:text]
|
||||
python import vim
|
||||
py vim.buffers[int(vim.eval('a:expr'))][int(vim.eval("a:lnum")) - 1 : int(vim.eval("a:lnum")) - 1 + len(vim.eval("list"))] = vim.eval("list")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:setbufline(expr, lnum, text)
|
||||
return s:execute(a:expr, "call setline(" . a:lnum . "," . string(a:text) . ")")
|
||||
return s:get(a:expr).setline(a:lnum, a:text)
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
225
autoload/vital/_brightest/Coaster/Buffer/Object.vim
Normal file
225
autoload/vital/_brightest/Coaster/Buffer/Object.vim
Normal file
@@ -0,0 +1,225 @@
|
||||
scriptencoding utf-8
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
let s:obj = {
|
||||
\ "__variable" : {}
|
||||
\}
|
||||
|
||||
|
||||
function! s:obj.number()
|
||||
return self.__variable.bufnr
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.invoke(func, ...)
|
||||
let args = get(a:, 1, [])
|
||||
return call(a:func, [self.number()] + args)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.name()
|
||||
return self.invoke("bufname")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.get_variable(...)
|
||||
return self.invoke("getbufvar", a:000)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.set_variable(...)
|
||||
return self.invoke("setbufvar", a:000)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.get_option(name)
|
||||
return self.get_variable("&" . a:name)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.set_option(name, var)
|
||||
return self.set_variable("&" . a:name, a:var)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.winnr()
|
||||
return self.invoke("bufwinnr")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.is_exists()
|
||||
return bufexists(self.number())
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.is_listed()
|
||||
return self.invoke("buflisted")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.is_loaded()
|
||||
return self.invoke("bufloaded")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.is_current()
|
||||
return self.number() == bufnr("%")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.is_modifiable()
|
||||
return self.get_option("modifiable")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.is_opened_in_current_tabpage()
|
||||
return self.winnr() != -1
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.tap()
|
||||
if !self.is_exists() || self.is_tapped()
|
||||
return
|
||||
endif
|
||||
let self.__variable.tap_bufnr = bufnr("%")
|
||||
split
|
||||
execute "b" self.number()
|
||||
return self.number()
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.untap()
|
||||
if !self.is_tapped()
|
||||
return
|
||||
endif
|
||||
quit
|
||||
silent! execute "buffer" self.__variable.tap_bufnr
|
||||
unlet self.__variable.tap_bufnr
|
||||
return self.number()
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.tap_modifiable(...)
|
||||
let force = get(a:, 1, 1)
|
||||
if !(self.is_modifiable() || force)
|
||||
return
|
||||
endif
|
||||
let result = self.tap()
|
||||
if result
|
||||
let self.__variable.modifiable = &modifiable
|
||||
set modifiable
|
||||
endif
|
||||
return result
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.untap_modifiable()
|
||||
if has_key(self.__variable, "modifiable")
|
||||
let &modifiable = self.__variable.modifiable
|
||||
unlet self.__variable.modifiable
|
||||
call self.untap()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.is_tapped()
|
||||
return has_key(self.__variable, "tap_bufnr")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.execute(cmd)
|
||||
if self.is_current()
|
||||
execute a:cmd
|
||||
return
|
||||
endif
|
||||
if self.tap()
|
||||
try
|
||||
execute a:cmd
|
||||
finally
|
||||
call self.untap()
|
||||
endtry
|
||||
endif
|
||||
|
||||
" let view = winsaveview()
|
||||
" try
|
||||
" noautocmd silent! execute "bufdo if bufnr('%') == " a:expr . ' | ' . string(a:cmd) . ' | endif'
|
||||
" finally
|
||||
" noautocmd silent! execute "buffer" bufnr
|
||||
" call winrestview(view)
|
||||
" endtry
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.setline(lnum, text, ...)
|
||||
" if has("python")
|
||||
" return s:setbufline_if_python(a:expr, a:lnum, a:text)
|
||||
" else
|
||||
" return s:execute(bufnr(a:expr), "call setline(" . a:lnum . "," . string(a:text) . ")")
|
||||
" endif
|
||||
|
||||
let force = get(a:, 1, 0)
|
||||
if self.tap_modifiable(force)
|
||||
try
|
||||
call setline(a:lnum, a:text)
|
||||
finally
|
||||
call self.untap_modifiable()
|
||||
endtry
|
||||
endif
|
||||
" return self.execute("call setline(" . a:lnum . "," . string(a:text) . ")")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.clear(...)
|
||||
let force = get(a:, 1, 0)
|
||||
if self.tap_modifiable(force)
|
||||
try
|
||||
silent % delete _
|
||||
finally
|
||||
call self.untap_modifiable()
|
||||
endtry
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.getline(...)
|
||||
return self.invoke("getbufline", a:000)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.open(...)
|
||||
let open_cmd = get(a:, 1, "")
|
||||
execute open_cmd
|
||||
execute "buffer" self.number()
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.delete(...)
|
||||
let force = get(a:, 1, 0)
|
||||
if self.is_exists()
|
||||
try
|
||||
execute "bdelete" . (force ? "! " : " ") . self.number()
|
||||
return 0
|
||||
catch
|
||||
return -1
|
||||
endtry
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:obj.set_name(name)
|
||||
return self.execute(":file " . string(a:name))
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:make(expr)
|
||||
let obj = deepcopy(s:obj)
|
||||
let obj.__variable.bufnr = bufnr(a:expr)
|
||||
return obj
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
@@ -2,6 +2,24 @@ scriptencoding utf-8
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
function! s:_vital_loaded(V)
|
||||
let s:V = a:V
|
||||
let s:Window = a:V.import("Coaster.Window")
|
||||
let s:Gift = a:V.import("Gift")
|
||||
call s:_init()
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:_vital_depends()
|
||||
return [
|
||||
\ "Coaster.Window",
|
||||
\ "Gift",
|
||||
\ ]
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
let s:base = {
|
||||
\ "variables" : {
|
||||
\ "hl_list" : {},
|
||||
@@ -17,6 +35,7 @@ function! s:base.add(name, group, pattern, ...)
|
||||
\ "group" : a:group,
|
||||
\ "pattern" : a:pattern,
|
||||
\ "priority" : priority,
|
||||
\ "name" : a:name,
|
||||
\ }
|
||||
endfunction
|
||||
|
||||
@@ -31,9 +50,28 @@ function! s:base.hl_list()
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.to_list()
|
||||
return values(self.variables.hl_list)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:_is_equal(__expr, __hl)
|
||||
let name = a:__hl.name
|
||||
let group = a:__hl.group
|
||||
let pattern = a:__hl.pattern
|
||||
let priority = a:__hl.priority
|
||||
return eval(a:__expr)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.to_list_by(expr)
|
||||
return filter(values(self.variables.hl_list), "s:_is_equal(a:expr, v:val)")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.enable_list(...)
|
||||
let bufnr = get(a:, 1, bufnr("%"))
|
||||
return keys(get(self.variables.id_list, bufnr, {}))
|
||||
let window = get(a:, 1, s:Gift.uniq_winnr())
|
||||
return keys(get(self.variables.id_list, window, {}))
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -46,14 +84,7 @@ endfunction
|
||||
|
||||
|
||||
function! s:base.delete_by(expr)
|
||||
for [name, _] in items(self.variables.hl_list)
|
||||
let group = _.group
|
||||
let pattern = _.pattern
|
||||
let priority = _.priority
|
||||
if eval(a:expr)
|
||||
call self.delete(name)
|
||||
endif
|
||||
endfor
|
||||
return map(self.to_list_by(a:expr), "self.delete(v:val.name)")
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -65,14 +96,14 @@ endfunction
|
||||
|
||||
|
||||
function! s:base.get_hl_id(name, ...)
|
||||
let bufnr = get(a:, 1, bufnr("%"))
|
||||
return get(get(self.variables.id_list, bufnr, {}), a:name, "")
|
||||
let window = get(a:, 1, s:Gift.uniq_winnr())
|
||||
return get(get(self.variables.id_list, window, {}), a:name, "")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.is_enabled(name, ...)
|
||||
let bufnr = get(a:, 1, bufnr("%"))
|
||||
return self.get_hl_id(a:name, bufnr) != ""
|
||||
let window = get(a:, 1, s:Gift.uniq_winnr())
|
||||
return self.get_hl_id(a:name, window) != ""
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -84,10 +115,11 @@ function! s:base.enable(name)
|
||||
if self.is_enabled(a:name)
|
||||
call self.disable(a:name)
|
||||
endif
|
||||
if !has_key(self.variables.id_list, bufnr("%"))
|
||||
let self.variables.id_list[bufnr("%")] = {}
|
||||
let winnr = s:Gift.uniq_winnr()
|
||||
if !has_key(self.variables.id_list, winnr)
|
||||
let self.variables.id_list[winnr] = {}
|
||||
endif
|
||||
let self.variables.id_list[bufnr("%")][a:name] = matchadd(hl.group, hl.pattern, hl.priority)
|
||||
let self.variables.id_list[winnr][a:name] = matchadd(hl.group, hl.pattern, hl.priority)
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -107,8 +139,8 @@ function! s:base.disable(name)
|
||||
if id == -1
|
||||
return -1
|
||||
endif
|
||||
let bufnr = bufnr("%")
|
||||
unlet! self.variables.id_list[bufnr][a:name]
|
||||
let winnr = get(a:, 1, s:Gift.uniq_winnr())
|
||||
unlet! self.variables.id_list[winnr][a:name]
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -119,6 +151,18 @@ function! s:base.disable_all()
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.update(name)
|
||||
call self.disable(a:name)
|
||||
call self.enable(a:name)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.update_all()
|
||||
call self.disable_all()
|
||||
call self.enable_all()
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.highlight(name, group, pattern, ...)
|
||||
let priority = get(a:, 1, 10)
|
||||
call self.add(a:name, a:group, a:pattern, priority)
|
||||
@@ -138,13 +182,19 @@ function! s:base.clear_all()
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:base.as_windo()
|
||||
return self.windo
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:make()
|
||||
let result = deepcopy(s:base)
|
||||
let result.windo = s:Window.as_windo(result)
|
||||
return result
|
||||
endfunction
|
||||
|
||||
|
||||
let s:global = s:make()
|
||||
let s:global = deepcopy(s:base)
|
||||
let s:funcs = keys(filter(copy(s:global), "type(v:val) == type(function('tr'))"))
|
||||
|
||||
for s:name in s:funcs
|
||||
@@ -156,5 +206,25 @@ endfor
|
||||
unlet s:name
|
||||
|
||||
|
||||
function! s:_init()
|
||||
let s:global.windo = s:Window.as_windo(s:global)
|
||||
endfunction
|
||||
|
||||
" function! s:matchadd(...)
|
||||
" return {
|
||||
" \ "id" : call("matchadd", a:000),
|
||||
" \ "bufnr" : bufnr("%"),
|
||||
" \ }
|
||||
" endfunction
|
||||
"
|
||||
"
|
||||
" function! s:matchdelete(id)
|
||||
" if empty(a:id)
|
||||
" return -1
|
||||
" endif
|
||||
" return s:Buffer.execute(a:id.bufnr, "call matchdelete(" . a:id.id . ")")
|
||||
" endfunction
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
@@ -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
|
||||
|
||||
39
autoload/vital/_brightest/Coaster/Window.vim
Normal file
39
autoload/vital/_brightest/Coaster/Window.vim
Normal file
@@ -0,0 +1,39 @@
|
||||
scriptencoding utf-8
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
function! s:windo(func, args, obj)
|
||||
if len(tabpagebuflist()) <= 1
|
||||
return call(a:func, a:args, a:obj)
|
||||
endif
|
||||
let pre_winnr = winnr()
|
||||
|
||||
noautocmd windo call call(a:func, a:args, a:obj)
|
||||
|
||||
if pre_winnr == winnr()
|
||||
return
|
||||
endif
|
||||
execute pre_winnr . "wincmd w"
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:as_windo(base)
|
||||
let windo = {}
|
||||
let windo.obj = a:base
|
||||
for [key, Value] in items(a:base)
|
||||
if type(function("tr")) == type(Value)
|
||||
execute
|
||||
\ "function! windo.". key. "(...)\n"
|
||||
\ " return s:windo(self.obj." . key . ", a:000, self.obj)\n"
|
||||
\ "endfunction"
|
||||
endif
|
||||
unlet Value
|
||||
endfor
|
||||
return windo
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
Reference in New Issue
Block a user