mirror of
https://github.com/osyo-manga/vim-brightest.git
synced 2025-11-12 13:33:51 -05:00
Add g:brightest#enable_highlight_all_window.
This commit is contained in:
@@ -6,8 +6,8 @@ set cpo&vim
|
||||
let s:V = vital#of("brightest")
|
||||
let s:Prelude = s:V.import("Prelude")
|
||||
let s:Buffer = s:V.import("Coaster.Buffer")
|
||||
let s:Highlight = s:V.import("Coaster.Highlight")
|
||||
let s:Search = s:V.import("Coaster.Search")
|
||||
let s:Highlight = s:V.import("Coaster.Highlight")
|
||||
|
||||
|
||||
let g:brightest#enable_filetypes = get(g:, "brightest#enable_filetypes", {})
|
||||
@@ -51,20 +51,41 @@ function! s:is_ignore(context)
|
||||
endfunction
|
||||
|
||||
|
||||
function! brightest#hl_clear()
|
||||
call s:Highlight.clear_all()
|
||||
" call s:Highlight.clear("cursor_word")
|
||||
" call s:Highlight.clear("cursor_line")
|
||||
" call s:Highlight.clear("current_word")
|
||||
let g:brightest#enable_highlight_all_window = get(g:, "brightest#enable_highlight_all_window", 0)
|
||||
function! s:highlight_on()
|
||||
if g:brightest#enable_highlight_all_window
|
||||
call s:Highlight.as_windo().enable_all()
|
||||
else
|
||||
call s:Highlight.enable_all()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:highlight_off()
|
||||
if g:brightest#enable_highlight_all_window
|
||||
call s:Highlight.as_windo().disable_all()
|
||||
else
|
||||
call s:Highlight.disable_all()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
let s:old_enable_window_all = g:brightest#enable_highlight_all_window
|
||||
function! brightest#hl_clear()
|
||||
if g:brightest#enable_highlight_all_window
|
||||
\ || s:old_enable_window_all
|
||||
call s:Highlight.as_windo().disable_all()
|
||||
endif
|
||||
call s:Highlight.clear_all()
|
||||
let s:old_enable_window_all = g:brightest#enable_highlight_all_window
|
||||
endfunction
|
||||
|
||||
function! s:highlight(name, pattern, hi)
|
||||
if empty(a:hi) || empty(a:pattern) || a:hi.group == ""
|
||||
return
|
||||
endif
|
||||
let pattern = printf(a:hi.format, a:pattern)
|
||||
call s:Highlight.highlight(a:name, a:hi.group, pattern, a:hi.priority)
|
||||
call s:Highlight.add(a:name, a:hi.group, pattern, a:hi.priority)
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -107,6 +128,7 @@ function! s:single_word(pattern, highlight, cursorline)
|
||||
if is_highlight_cursorline
|
||||
call s:highlight("cursor_line", '\%' . line('.') . 'l' . pattern, a:cursorline)
|
||||
endif
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -136,17 +158,20 @@ endfunction
|
||||
|
||||
function! s:highlighting(pattern, highlight, cursorline, ...)
|
||||
call brightest#hl_clear()
|
||||
|
||||
|
||||
let context = s:context()
|
||||
if s:is_ignore(context)
|
||||
return
|
||||
endif
|
||||
|
||||
if get(a:, 1, "") == ""
|
||||
return s:single_word(a:pattern, a:highlight, a:cursorline)
|
||||
if s:single_word(a:pattern, a:highlight, a:cursorline)
|
||||
call s:highlight_on()
|
||||
endif
|
||||
else
|
||||
" return s:with_current(a:1, a:group, a:pattern)
|
||||
endif
|
||||
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -255,3 +280,5 @@ function! brightest#on_CursorMoved()
|
||||
endfunction
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
function! vital#of(name)
|
||||
function! vital#of(name) abort
|
||||
let files = globpath(&runtimepath, 'autoload/vital/' . a:name . '.vital')
|
||||
let file = split(files, "\n")
|
||||
if empty(file)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
let s:self_version = expand('<sfile>:t:r')
|
||||
let s:self_file = expand('<sfile>')
|
||||
|
||||
" Note: The extra argument to globpath() was added in Patch 7.2.051.
|
||||
let s:globpath_third_arg = v:version > 702 || v:version == 702 && has('patch51')
|
||||
|
||||
let s:loaded = {}
|
||||
|
||||
function! s:import(name, ...)
|
||||
function! s:import(name, ...) abort
|
||||
let target = {}
|
||||
let functions = []
|
||||
for a in a:000
|
||||
@@ -29,7 +30,7 @@ function! s:import(name, ...)
|
||||
return target
|
||||
endfunction
|
||||
|
||||
function! s:load(...) dict
|
||||
function! s:load(...) dict abort
|
||||
for arg in a:000
|
||||
let [name; as] = type(arg) == type([]) ? arg[: 1] : [arg, arg]
|
||||
let target = split(join(as, ''), '\W\+')
|
||||
@@ -55,21 +56,21 @@ function! s:load(...) dict
|
||||
return self
|
||||
endfunction
|
||||
|
||||
function! s:unload()
|
||||
function! s:unload() abort
|
||||
let s:loaded = {}
|
||||
endfunction
|
||||
|
||||
function! s:exists(name)
|
||||
function! s:exists(name) abort
|
||||
return s:_get_module_path(a:name) !=# ''
|
||||
endfunction
|
||||
|
||||
function! s:search(pattern)
|
||||
function! s:search(pattern) abort
|
||||
let paths = s:_vital_files(a:pattern)
|
||||
let modules = sort(map(paths, 's:_file2module(v:val)'))
|
||||
return s:_uniq(modules)
|
||||
endfunction
|
||||
|
||||
function! s:expand_modules(entry, all)
|
||||
function! s:expand_modules(entry, all) abort
|
||||
if type(a:entry) == type([])
|
||||
let candidates = s:_concat(map(copy(a:entry), 's:search(v:val)'))
|
||||
if empty(candidates)
|
||||
@@ -93,7 +94,7 @@ function! s:expand_modules(entry, all)
|
||||
return modules
|
||||
endfunction
|
||||
|
||||
function! s:_import(name)
|
||||
function! s:_import(name) abort
|
||||
if type(a:name) == type(0)
|
||||
return s:_build_module(a:name)
|
||||
endif
|
||||
@@ -116,7 +117,7 @@ function! s:_import(name)
|
||||
return s:_build_module(sid)
|
||||
endfunction
|
||||
|
||||
function! s:_get_module_path(name)
|
||||
function! s:_get_module_path(name) abort
|
||||
if s:_is_absolute_path(a:name) && filereadable(a:name)
|
||||
return a:name
|
||||
endif
|
||||
@@ -128,12 +129,12 @@ function! s:_get_module_path(name)
|
||||
throw 'vital: Invalid module name: ' . a:name
|
||||
endif
|
||||
|
||||
call filter(paths, 'filereadable(expand(v:val))')
|
||||
call filter(paths, 'filereadable(expand(v:val, 1))')
|
||||
let path = get(paths, 0, '')
|
||||
return path !=# '' ? path : ''
|
||||
endfunction
|
||||
|
||||
function! s:_get_sid_by_script(path)
|
||||
function! s:_get_sid_by_script(path) abort
|
||||
let path = s:_unify_path(a:path)
|
||||
for line in filter(split(s:_redir('scriptnames'), "\n"),
|
||||
\ 'stridx(v:val, s:self_version) > 0')
|
||||
@@ -145,8 +146,8 @@ function! s:_get_sid_by_script(path)
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:_file2module(file)
|
||||
let filename = fnamemodify(a:file, ':p:gs?[\\/]\+?/?')
|
||||
function! s:_file2module(file) abort
|
||||
let filename = fnamemodify(a:file, ':p:gs?[\\/]?/?')
|
||||
let tail = matchstr(filename, 'autoload/vital/_\w\+/\zs.*\ze\.vim$')
|
||||
return join(split(tail, '[\\/]\+'), '.')
|
||||
endfunction
|
||||
@@ -157,34 +158,34 @@ if filereadable(expand('<sfile>:r') . '.VIM')
|
||||
" Note: On windows, vim can't expand path names from 8.3 formats.
|
||||
" So if getting full path via <sfile> and $HOME was set as 8.3 format,
|
||||
" vital load duplicated scripts. Below's :~ avoid this issue.
|
||||
function! s:_unify_path(path)
|
||||
function! s:_unify_path(path) abort
|
||||
if has_key(s:_unify_path_cache, a:path)
|
||||
return s:_unify_path_cache[a:path]
|
||||
endif
|
||||
let value = tolower(fnamemodify(resolve(fnamemodify(
|
||||
\ a:path, ':p')), ':~:gs?[\\/]\+?/?'))
|
||||
\ a:path, ':p')), ':~:gs?[\\/]?/?'))
|
||||
let s:_unify_path_cache[a:path] = value
|
||||
return value
|
||||
endfunction
|
||||
else
|
||||
function! s:_unify_path(path)
|
||||
return resolve(fnamemodify(a:path, ':p:gs?[\\/]\+?/?'))
|
||||
function! s:_unify_path(path) abort
|
||||
return resolve(fnamemodify(a:path, ':p:gs?[\\/]?/?'))
|
||||
endfunction
|
||||
endif
|
||||
|
||||
if s:globpath_third_arg
|
||||
function! s:_runtime_files(path)
|
||||
function! s:_runtime_files(path) abort
|
||||
return split(globpath(&runtimepath, a:path, 1), "\n")
|
||||
endfunction
|
||||
else
|
||||
function! s:_runtime_files(path)
|
||||
function! s:_runtime_files(path) abort
|
||||
return split(globpath(&runtimepath, a:path), "\n")
|
||||
endfunction
|
||||
endif
|
||||
|
||||
let s:_vital_files_cache_runtimepath = ''
|
||||
let s:_vital_files_cache = []
|
||||
function! s:_vital_files(pattern)
|
||||
function! s:_vital_files(pattern) abort
|
||||
if s:_vital_files_cache_runtimepath !=# &runtimepath
|
||||
let path = printf('autoload/vital/%s/**/*.vim', s:self_version)
|
||||
let s:_vital_files_cache = s:_runtime_files(path)
|
||||
@@ -200,16 +201,16 @@ endfunction
|
||||
|
||||
" Copy from System.Filepath
|
||||
if has('win16') || has('win32') || has('win64')
|
||||
function! s:_is_absolute_path(path)
|
||||
function! s:_is_absolute_path(path) abort
|
||||
return a:path =~? '^[a-z]:[/\\]'
|
||||
endfunction
|
||||
else
|
||||
function! s:_is_absolute_path(path)
|
||||
function! s:_is_absolute_path(path) abort
|
||||
return a:path[0] ==# '/'
|
||||
endfunction
|
||||
endif
|
||||
|
||||
function! s:_build_module(sid)
|
||||
function! s:_build_module(sid) abort
|
||||
if has_key(s:loaded, a:sid)
|
||||
return copy(s:loaded[a:sid])
|
||||
endif
|
||||
@@ -243,13 +244,13 @@ function! s:_build_module(sid)
|
||||
endfunction
|
||||
|
||||
if exists('+regexpengine')
|
||||
function! s:_get_functions(sid)
|
||||
function! s:_get_functions(sid) abort
|
||||
let funcs = s:_redir(printf("function /\\%%#=2^\<SNR>%d_", a:sid))
|
||||
let map_pat = '<SNR>' . a:sid . '_\zs\w\+'
|
||||
return map(split(funcs, "\n"), 'matchstr(v:val, map_pat)')
|
||||
endfunction
|
||||
else
|
||||
function! s:_get_functions(sid)
|
||||
function! s:_get_functions(sid) abort
|
||||
let prefix = '<SNR>' . a:sid . '_'
|
||||
let funcs = s:_redir('function')
|
||||
let filter_pat = '^\s*function ' . prefix
|
||||
@@ -261,11 +262,11 @@ else
|
||||
endif
|
||||
|
||||
if exists('*uniq')
|
||||
function! s:_uniq(list)
|
||||
function! s:_uniq(list) abort
|
||||
return uniq(a:list)
|
||||
endfunction
|
||||
else
|
||||
function! s:_uniq(list)
|
||||
function! s:_uniq(list) abort
|
||||
let i = len(a:list) - 1
|
||||
while 0 < i
|
||||
if a:list[i] ==# a:list[i - 1]
|
||||
@@ -279,7 +280,7 @@ else
|
||||
endfunction
|
||||
endif
|
||||
|
||||
function! s:_concat(lists)
|
||||
function! s:_concat(lists) abort
|
||||
let result_list = []
|
||||
for list in a:lists
|
||||
let result_list += list
|
||||
@@ -287,7 +288,7 @@ function! s:_concat(lists)
|
||||
return result_list
|
||||
endfunction
|
||||
|
||||
function! s:_redir(cmd)
|
||||
function! s:_redir(cmd) abort
|
||||
let [save_verbose, save_verbosefile] = [&verbose, &verbosefile]
|
||||
set verbose=0 verbosefile=
|
||||
redir => res
|
||||
@@ -297,8 +298,6 @@ function! s:_redir(cmd)
|
||||
return res
|
||||
endfunction
|
||||
|
||||
function! vital#{s:self_version}#new()
|
||||
function! vital#{s:self_version}#new() abort
|
||||
return s:_import('')
|
||||
endfunction
|
||||
|
||||
let s:self_file = s:_unify_path(expand('<sfile>'))
|
||||
|
||||
@@ -3,6 +3,13 @@ let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
function! s:_vital_depends()
|
||||
return [
|
||||
\ "Coaster.Buffer",
|
||||
\ "Coaster.Search",
|
||||
\ "Coaster.Highlight"
|
||||
\ ]
|
||||
endfunction
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
|
||||
@@ -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
|
||||
150
autoload/vital/_brightest/Gift.vim
Normal file
150
autoload/vital/_brightest/Gift.vim
Normal file
@@ -0,0 +1,150 @@
|
||||
scriptencoding utf-8
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
function! s:_vital_loaded(V)
|
||||
let s:V = a:V
|
||||
let s:Window = s:V.import("Gift.Window")
|
||||
let s:Tabpage = s:V.import("Gift.Tabpage")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:_vital_depends()
|
||||
return [
|
||||
\ "Gift.Window",
|
||||
\ "Gift.Tabpage",
|
||||
\ ]
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:to_fullpath(filename)
|
||||
let name = substitute(fnamemodify(a:filename, ":p"), '\', '/', "g")
|
||||
if filereadable(name)
|
||||
return name
|
||||
else
|
||||
return a:filename
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:flatten(list)
|
||||
return eval(join(a:list, "+"))
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:bufnr(expr)
|
||||
return type(a:expr) == type([])
|
||||
\ ? s:bufnr(s:uniq_winnr(a:expr[1], a:expr[0]))
|
||||
\ : s:Window.bufnr(a:expr)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:openable_bufnr_list()
|
||||
return map(s:tabpagewinnr_list(), "s:bufnr([v:val[0], v:val[1]])")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tabpagewinnr(...)
|
||||
return a:0 == 0 ? s:tabpagewinnr(s:uniq_winnr())
|
||||
\ : s:Window.tabpagewinnr(a:1)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tabpagewinnr_list()
|
||||
return s:Window.tabpagewinnr_list()
|
||||
" return s:flatten(map(range(1, tabpagenr("$")), "map(range(1, tabpagewinnr(v:val, '$')), '['.v:val.', v:val]')"))
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
function! s:uniq_winnr(...)
|
||||
return call(s:Window.uniq_nr, a:000, s:Window)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:winnr(uniqnr)
|
||||
let [tabnr, winnr] = s:Window.tabpagewinnr(a:uniqnr)
|
||||
return winnr
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:uniq_winnr_list(...)
|
||||
return map(s:tabpagewinnr_list(), "s:uniq_winnr(v:val[1], v:val[0])")
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
function! s:find(expr)
|
||||
let gift_find_result = []
|
||||
for [tabnr, winnr] in s:tabpagewinnr_list()
|
||||
let bufnr = s:bufnr([tabnr, winnr])
|
||||
if eval(a:expr)
|
||||
call add(gift_find_result, [tabnr, winnr])
|
||||
endif
|
||||
endfor
|
||||
return gift_find_result
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:find_by(expr)
|
||||
if type(a:expr) == type(function("tr"))
|
||||
return filter(s:tabpagewinnr_list(), "a:expr(s:bufnr([v:val[0], v:val[1]]), v:val[0], v:val[1])")
|
||||
else
|
||||
return s:find(a:expr)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:jump_window(expr)
|
||||
return type(a:expr) == type([])
|
||||
\ ? s:jump_window(s:uniq_winnr(a:expr[1], a:expr[0]))
|
||||
\ : s:Window.jump(a:expr)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:set_current_window(expr)
|
||||
return s:jump_window(a:expr)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:close_window(expr, ...)
|
||||
let close_cmd = get(a:, 1, "close")
|
||||
return type(a:expr) == type([])
|
||||
\ ? s:close_window(s:uniq_winnr(a:expr[1], a:expr[0]), close_cmd)
|
||||
\ : s:Window.close(a:expr, close_cmd)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:close_window_by(expr, ...)
|
||||
let close_cmd = get(a:, 1, "close")
|
||||
return map(map(s:find(a:expr), "s:uniq_winnr(v:val[1], v:val[0])"), 's:close_window(v:val, close_cmd)')
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:execute(expr, execute)
|
||||
return type(a:expr) == type([])
|
||||
\ ? s:execute(s:uniq_winnr(a:expr[1], a:expr[0]), a:execute)
|
||||
\ : s:Window.execute(a:expr, a:execute)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:getwinvar(uniq_winnr, varname, ...)
|
||||
let def = get(a:, 1, "")
|
||||
return s:Window.getvar(a:uniq_winnr, a:varname, def)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:setwinvar(uniq_winnr, varname, val)
|
||||
return s:Window.setvar(a:uniq_winnr, a:varname, a:val)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:uniq_tabpagenr(...)
|
||||
return call(s:Tabpage.uniq_nr, a:000, s:Tabpage)
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
38
autoload/vital/_brightest/Gift/Tabpage.vim
Normal file
38
autoload/vital/_brightest/Gift/Tabpage.vim
Normal file
@@ -0,0 +1,38 @@
|
||||
scriptencoding utf-8
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
let s:prefix = expand("<sfile>:p:h:h:t")
|
||||
function! s:set_prefix(prefix)
|
||||
let s:prefix = a:prefix
|
||||
endfunction
|
||||
|
||||
|
||||
let s:uniq_counter = 0
|
||||
function! s:make_uniq_nr()
|
||||
let s:uniq_counter += 1
|
||||
return s:uniq_counter
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:numbering(...)
|
||||
let tabnr = get(a:, 1, tabpagenr())
|
||||
let uniq_nr = s:make_uniq_nr()
|
||||
call settabvar(tabnr, s:prefix . "_gift_uniq_tabpagenr", uniq_nr)
|
||||
return uniq_nr
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:uniq_nr(...)
|
||||
let tabnr = get(a:, 1, tabpagenr())
|
||||
let uniq_nr = gettabvar(tabnr, s:prefix . "_gift_uniq_tabpagenr", -1)
|
||||
if uniq_nr == -1
|
||||
let uniq_nr = s:numbering(tabnr)
|
||||
endif
|
||||
return uniq_nr
|
||||
endfunction
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
145
autoload/vital/_brightest/Gift/Window.vim
Normal file
145
autoload/vital/_brightest/Gift/Window.vim
Normal file
@@ -0,0 +1,145 @@
|
||||
scriptencoding utf-8
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
function! s:_vital_loaded(V)
|
||||
let s:V = a:V
|
||||
let s:Tabpage = s:V.import("Gift.Tabpage")
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:_vital_depends()
|
||||
return [
|
||||
\ "Gift.Tabpage",
|
||||
\ ]
|
||||
endfunction
|
||||
|
||||
|
||||
let s:prefix = expand("<sfile>:p:h:h:t")
|
||||
function! s:set_prefix(prefix)
|
||||
let s:prefix = a:prefix
|
||||
endfunction
|
||||
|
||||
function! s:flatten(list)
|
||||
return eval(join(a:list, "+"))
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
function! s:tabpagewinnr_list()
|
||||
return s:flatten(map(range(1, tabpagenr("$")), "map(range(1, tabpagewinnr(v:val, '$')), '['.v:val.', v:val]')"))
|
||||
endfunction
|
||||
|
||||
|
||||
if !exists("s:uniq_counter")
|
||||
let s:uniq_counter = 0
|
||||
endif
|
||||
function! s:make_uniq_nr()
|
||||
let s:uniq_counter += 1
|
||||
return s:uniq_counter
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:numbering(...)
|
||||
let winnr = get(a:, 1, winnr())
|
||||
let tabnr = get(a:, 2, tabpagenr())
|
||||
let uniq_nr = s:make_uniq_nr()
|
||||
call settabwinvar(tabnr, winnr, s:prefix . "_gift_uniq_winnr", uniq_nr)
|
||||
return uniq_nr
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:uniq_nr(...)
|
||||
let winnr = get(a:, 1, winnr())
|
||||
let tabnr = get(a:, 2, tabpagenr())
|
||||
let uniq_nr = gettabwinvar(tabnr, winnr, s:prefix . "_gift_uniq_winnr", -1)
|
||||
if uniq_nr == -1
|
||||
let uniq_nr = s:numbering(winnr, tabnr)
|
||||
endif
|
||||
return uniq_nr
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:exists(nr)
|
||||
let [tabnr, winnr] = s:tabpagewinnr(a:nr)
|
||||
return tabnr != 0 && winnr != 0
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tabpagewinnr(nr)
|
||||
if a:nr == 0
|
||||
return s:tabpagewinnr(s:uniq_nr())
|
||||
endif
|
||||
let tabwinnrs = s:tabpagewinnr_list()
|
||||
for [tabnr, winnr] in tabwinnrs
|
||||
if s:uniq_nr(winnr, tabnr) == a:nr
|
||||
return [tabnr, winnr]
|
||||
endif
|
||||
endfor
|
||||
return [0, 0]
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:getvar(nr, varname, ...)
|
||||
let def = get(a:, 1, "")
|
||||
let [tabnr, winnr] = s:tabpagewinnr(a:nr)
|
||||
return gettabwinvar(tabnr, winnr, a:varname, def)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:setvar(nr, varname, val)
|
||||
let [tabnr, winnr] = s:tabpagewinnr(a:nr)
|
||||
if tabnr == 0 || winnr == 0
|
||||
return
|
||||
endif
|
||||
return settabwinvar(tabnr, winnr, a:varname, a:val)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:bufnr(nr)
|
||||
let [tabnr, winnr] = s:tabpagewinnr(a:nr)
|
||||
return winnr >= 1 ? get(tabpagebuflist(tabnr), winnr-1, -1) : -1
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
function! s:jump(nr)
|
||||
let [tabnr, winnr] = s:tabpagewinnr(a:nr)
|
||||
if tabnr == 0 || winnr == 0
|
||||
return -1
|
||||
endif
|
||||
|
||||
execute "tabnext" tabnr
|
||||
execute winnr . "wincmd w"
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:close(nr, close_cmd)
|
||||
call s:execute(a:nr, a:close_cmd)
|
||||
" let current = gift#uniq_winnr()
|
||||
" let result = s:jump(a:nr)
|
||||
" if result == -1
|
||||
" return -1
|
||||
" endif
|
||||
" execute a:close_cmd
|
||||
" return s:jump(current)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:execute(nr, expr)
|
||||
let current = s:uniq_nr()
|
||||
let result = s:jump(a:nr)
|
||||
if result == -1
|
||||
return -1
|
||||
endif
|
||||
execute a:expr
|
||||
return s:jump(current)
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
@@ -3,17 +3,17 @@ set cpo&vim
|
||||
|
||||
if v:version ># 703 ||
|
||||
\ (v:version is 703 && has('patch465'))
|
||||
function! s:glob(expr)
|
||||
function! s:glob(expr) abort
|
||||
return glob(a:expr, 1, 1)
|
||||
endfunction
|
||||
else
|
||||
function! s:glob(expr)
|
||||
function! s:glob(expr) abort
|
||||
let R = glob(a:expr, 1)
|
||||
return split(R, '\n')
|
||||
endfunction
|
||||
endif
|
||||
|
||||
function! s:globpath(path, expr)
|
||||
function! s:globpath(path, expr) abort
|
||||
let R = globpath(a:path, a:expr, 1)
|
||||
return split(R, '\n')
|
||||
endfunction
|
||||
@@ -36,44 +36,44 @@ let [
|
||||
" This doesn't match to anything.
|
||||
|
||||
" Number or Float
|
||||
function! s:is_numeric(Value)
|
||||
function! s:is_numeric(Value) abort
|
||||
let _ = type(a:Value)
|
||||
return _ ==# s:__TYPE_NUMBER
|
||||
\ || _ ==# s:__TYPE_FLOAT
|
||||
endfunction
|
||||
|
||||
" Number
|
||||
function! s:is_number(Value)
|
||||
function! s:is_number(Value) abort
|
||||
return type(a:Value) ==# s:__TYPE_NUMBER
|
||||
endfunction
|
||||
|
||||
" Float
|
||||
function! s:is_float(Value)
|
||||
function! s:is_float(Value) abort
|
||||
return type(a:Value) ==# s:__TYPE_FLOAT
|
||||
endfunction
|
||||
" String
|
||||
function! s:is_string(Value)
|
||||
function! s:is_string(Value) abort
|
||||
return type(a:Value) ==# s:__TYPE_STRING
|
||||
endfunction
|
||||
" Funcref
|
||||
function! s:is_funcref(Value)
|
||||
function! s:is_funcref(Value) abort
|
||||
return type(a:Value) ==# s:__TYPE_FUNCREF
|
||||
endfunction
|
||||
" List
|
||||
function! s:is_list(Value)
|
||||
function! s:is_list(Value) abort
|
||||
return type(a:Value) ==# s:__TYPE_LIST
|
||||
endfunction
|
||||
" Dictionary
|
||||
function! s:is_dict(Value)
|
||||
function! s:is_dict(Value) abort
|
||||
return type(a:Value) ==# s:__TYPE_DICT
|
||||
endfunction
|
||||
|
||||
function! s:truncate_smart(str, max, footer_width, separator)
|
||||
function! s:truncate_smart(str, max, footer_width, separator) abort
|
||||
echoerr 'Prelude.truncate_smart() is obsolete. Use its truncate_skipping() instead; they are equivalent.'
|
||||
return s:truncate_skipping(a:str, a:max, a:footer_width, a:separator)
|
||||
endfunction
|
||||
|
||||
function! s:truncate_skipping(str, max, footer_width, separator)
|
||||
function! s:truncate_skipping(str, max, footer_width, separator) abort
|
||||
let width = s:wcswidth(a:str)
|
||||
if width <= a:max
|
||||
let ret = a:str
|
||||
@@ -86,7 +86,7 @@ function! s:truncate_skipping(str, max, footer_width, separator)
|
||||
return s:truncate(ret, a:max)
|
||||
endfunction
|
||||
|
||||
function! s:truncate(str, width)
|
||||
function! s:truncate(str, width) abort
|
||||
" Original function is from mattn.
|
||||
" http://github.com/mattn/googlereader-vim/tree/master
|
||||
|
||||
@@ -109,7 +109,7 @@ function! s:truncate(str, width)
|
||||
return ret
|
||||
endfunction
|
||||
|
||||
function! s:strwidthpart(str, width)
|
||||
function! s:strwidthpart(str, width) abort
|
||||
if a:width <= 0
|
||||
return ''
|
||||
endif
|
||||
@@ -123,7 +123,7 @@ function! s:strwidthpart(str, width)
|
||||
|
||||
return ret
|
||||
endfunction
|
||||
function! s:strwidthpart_reverse(str, width)
|
||||
function! s:strwidthpart_reverse(str, width) abort
|
||||
if a:width <= 0
|
||||
return ''
|
||||
endif
|
||||
@@ -140,11 +140,11 @@ endfunction
|
||||
|
||||
if v:version >= 703
|
||||
" Use builtin function.
|
||||
function! s:wcswidth(str)
|
||||
function! s:wcswidth(str) abort
|
||||
return strwidth(a:str)
|
||||
endfunction
|
||||
else
|
||||
function! s:wcswidth(str)
|
||||
function! s:wcswidth(str) abort
|
||||
if a:str =~# '^[\x00-\x7f]*$'
|
||||
return strlen(a:str)
|
||||
end
|
||||
@@ -164,7 +164,7 @@ else
|
||||
endfunction
|
||||
|
||||
" UTF-8 only.
|
||||
function! s:_wcwidth(ucs)
|
||||
function! s:_wcwidth(ucs) abort
|
||||
let ucs = a:ucs
|
||||
if (ucs >= 0x1100
|
||||
\ && (ucs <= 0x115f
|
||||
@@ -193,54 +193,54 @@ let s:is_mac = !s:is_windows && !s:is_cygwin
|
||||
\ (!isdirectory('/proc') && executable('sw_vers')))
|
||||
let s:is_unix = has('unix')
|
||||
|
||||
function! s:is_windows()
|
||||
function! s:is_windows() abort
|
||||
return s:is_windows
|
||||
endfunction
|
||||
|
||||
function! s:is_cygwin()
|
||||
function! s:is_cygwin() abort
|
||||
return s:is_cygwin
|
||||
endfunction
|
||||
|
||||
function! s:is_mac()
|
||||
function! s:is_mac() abort
|
||||
return s:is_mac
|
||||
endfunction
|
||||
|
||||
function! s:is_unix()
|
||||
function! s:is_unix() abort
|
||||
return s:is_unix
|
||||
endfunction
|
||||
|
||||
function! s:_deprecated2(fname)
|
||||
function! s:_deprecated2(fname) abort
|
||||
echomsg printf("Vital.Prelude.%s is deprecated!",
|
||||
\ a:fname)
|
||||
endfunction
|
||||
|
||||
function! s:smart_execute_command(action, word)
|
||||
function! s:smart_execute_command(action, word) abort
|
||||
execute a:action . ' ' . (a:word == '' ? '' : '`=a:word`')
|
||||
endfunction
|
||||
|
||||
function! s:escape_file_searching(buffer_name)
|
||||
function! s:escape_file_searching(buffer_name) abort
|
||||
return escape(a:buffer_name, '*[]?{}, ')
|
||||
endfunction
|
||||
|
||||
function! s:escape_pattern(str)
|
||||
function! s:escape_pattern(str) abort
|
||||
return escape(a:str, '~"\.^$[]*')
|
||||
endfunction
|
||||
|
||||
function! s:getchar(...)
|
||||
function! s:getchar(...) abort
|
||||
let c = call('getchar', a:000)
|
||||
return type(c) == type(0) ? nr2char(c) : c
|
||||
endfunction
|
||||
|
||||
function! s:getchar_safe(...)
|
||||
function! s:getchar_safe(...) abort
|
||||
let c = s:input_helper('getchar', a:000)
|
||||
return type(c) == type("") ? c : nr2char(c)
|
||||
endfunction
|
||||
|
||||
function! s:input_safe(...)
|
||||
function! s:input_safe(...) abort
|
||||
return s:input_helper('input', a:000)
|
||||
endfunction
|
||||
|
||||
function! s:input_helper(funcname, args)
|
||||
function! s:input_helper(funcname, args) abort
|
||||
let success = 0
|
||||
if inputsave() !=# success
|
||||
throw 'inputsave() failed'
|
||||
@@ -254,13 +254,13 @@ function! s:input_helper(funcname, args)
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! s:set_default(var, val)
|
||||
function! s:set_default(var, val) abort
|
||||
if !exists(a:var) || type({a:var}) != type(a:val)
|
||||
let {a:var} = a:val
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:set_dictionary_helper(variable, keys, pattern)
|
||||
function! s:set_dictionary_helper(variable, keys, pattern) abort
|
||||
call s:_deprecated2('set_dictionary_helper')
|
||||
|
||||
for key in split(a:keys, '\s*,\s*')
|
||||
@@ -270,15 +270,15 @@ function! s:set_dictionary_helper(variable, keys, pattern)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:substitute_path_separator(path)
|
||||
function! s:substitute_path_separator(path) abort
|
||||
return s:is_windows ? substitute(a:path, '\\', '/', 'g') : a:path
|
||||
endfunction
|
||||
|
||||
function! s:path2directory(path)
|
||||
function! s:path2directory(path) abort
|
||||
return s:substitute_path_separator(isdirectory(a:path) ? a:path : fnamemodify(a:path, ':p:h'))
|
||||
endfunction
|
||||
|
||||
function! s:_path2project_directory_git(path)
|
||||
function! s:_path2project_directory_git(path) abort
|
||||
let parent = a:path
|
||||
|
||||
while 1
|
||||
@@ -294,7 +294,7 @@ function! s:_path2project_directory_git(path)
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! s:_path2project_directory_svn(path)
|
||||
function! s:_path2project_directory_svn(path) abort
|
||||
let search_directory = a:path
|
||||
let directory = ''
|
||||
|
||||
@@ -319,7 +319,7 @@ function! s:_path2project_directory_svn(path)
|
||||
return directory
|
||||
endfunction
|
||||
|
||||
function! s:_path2project_directory_others(vcs, path)
|
||||
function! s:_path2project_directory_others(vcs, path) abort
|
||||
let vcs = a:vcs
|
||||
let search_directory = a:path
|
||||
|
||||
@@ -331,7 +331,7 @@ function! s:_path2project_directory_others(vcs, path)
|
||||
return fnamemodify(d, ':p:h:h')
|
||||
endfunction
|
||||
|
||||
function! s:path2project_directory(path, ...)
|
||||
function! s:path2project_directory(path, ...) abort
|
||||
let is_allow_empty = get(a:000, 0, 0)
|
||||
let search_directory = s:path2directory(a:path)
|
||||
let directory = ''
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
brightest
|
||||
439e6d2
|
||||
e3250cf
|
||||
|
||||
Coaster
|
||||
Prelude
|
||||
|
||||
@@ -177,6 +177,17 @@ g:brightest#enable_insert_mode *g:brightest#enable_insert_mode*
|
||||
Default: >
|
||||
let g:brightest#enable_insert_mode = 0
|
||||
<
|
||||
*g:brightest#enable_highlight_all_window*
|
||||
g:brightest#enable_highlight_all_window
|
||||
0 以外が設定されている場合に表示されているすべてのウィンドウをハイライ
|
||||
トします。
|
||||
Default: >
|
||||
let g:brightest#enable_highlight_all_window = 0
|
||||
<
|
||||
NOTE:この設定を有効にする場合は処理が重くなります
|
||||
気になる場合は |g:brightest#enable_on_CursorHold| と組み合わせて
|
||||
使用してください
|
||||
|
||||
|
||||
==============================================================================
|
||||
ハイライトグループ *brightest-highlight_group*
|
||||
|
||||
Reference in New Issue
Block a user