update vital

This commit is contained in:
haya14busa 2015-06-28 23:01:55 +09:00
parent 15fc017ed1
commit b11864a467
12 changed files with 321 additions and 220 deletions

View File

@ -5,6 +5,12 @@ let s:self_file = expand('<sfile>')
let s:globpath_third_arg = v:version > 702 || v:version == 702 && has('patch51') let s:globpath_third_arg = v:version > 702 || v:version == 702 && has('patch51')
let s:loaded = {} let s:loaded = {}
let s:cache_module_path = {}
let s:cache_sid = {}
let s:_vital_files_cache_runtimepath = ''
let s:_vital_files_cache = []
let s:_unify_path_cache = {}
function! s:import(name, ...) abort function! s:import(name, ...) abort
let target = {} let target = {}
@ -35,12 +41,13 @@ function! s:load(...) dict abort
let [name; as] = type(arg) == type([]) ? arg[: 1] : [arg, arg] let [name; as] = type(arg) == type([]) ? arg[: 1] : [arg, arg]
let target = split(join(as, ''), '\W\+') let target = split(join(as, ''), '\W\+')
let dict = self let dict = self
while 1 <= len(target) let dict_type = type({})
while !empty(target)
let ns = remove(target, 0) let ns = remove(target, 0)
if !has_key(dict, ns) if !has_key(dict, ns)
let dict[ns] = {} let dict[ns] = {}
endif endif
if type(dict[ns]) == type({}) if type(dict[ns]) == dict_type
let dict = dict[ns] let dict = dict[ns]
else else
unlet dict unlet dict
@ -58,6 +65,8 @@ endfunction
function! s:unload() abort function! s:unload() abort
let s:loaded = {} let s:loaded = {}
let s:cache_sid = {}
let s:cache_module_path = {}
endfunction endfunction
function! s:exists(name) abort function! s:exists(name) abort
@ -118,6 +127,10 @@ function! s:_import(name) abort
endfunction endfunction
function! s:_get_module_path(name) abort function! s:_get_module_path(name) abort
let key = a:name . '_'
if has_key(s:cache_module_path, key)
return s:cache_module_path[key]
endif
if s:_is_absolute_path(a:name) && filereadable(a:name) if s:_is_absolute_path(a:name) && filereadable(a:name)
return a:name return a:name
endif endif
@ -131,30 +144,35 @@ function! s:_get_module_path(name) abort
call filter(paths, 'filereadable(expand(v:val, 1))') call filter(paths, 'filereadable(expand(v:val, 1))')
let path = get(paths, 0, '') let path = get(paths, 0, '')
return path !=# '' ? path : '' let s:cache_module_path[key] = path
return path
endfunction endfunction
function! s:_get_sid_by_script(path) abort function! s:_get_sid_by_script(path) abort
if has_key(s:cache_sid, a:path)
return s:cache_sid[a:path]
endif
let path = s:_unify_path(a:path) let path = s:_unify_path(a:path)
for line in filter(split(s:_redir('scriptnames'), "\n"), for line in filter(split(s:_redir('scriptnames'), "\n"),
\ 'stridx(v:val, s:self_version) > 0') \ 'stridx(v:val, s:self_version) > 0')
let list = matchlist(line, '^\s*\(\d\+\):\s\+\(.\+\)\s*$') let list = matchlist(line, '^\s*\(\d\+\):\s\+\(.\+\)\s*$')
if !empty(list) && s:_unify_path(list[2]) ==# path if !empty(list) && s:_unify_path(list[2]) ==# path
return list[1] - 0 let s:cache_sid[a:path] = list[1] - 0
return s:cache_sid[a:path]
endif endif
endfor endfor
return 0 return 0
endfunction endfunction
function! s:_file2module(file) abort function! s:_file2module(file) abort
let filename = fnamemodify(a:file, ':p:gs?[\\/]\+?/?') let filename = fnamemodify(a:file, ':p:gs?[\\/]?/?')
let tail = matchstr(filename, 'autoload/vital/_\w\+/\zs.*\ze\.vim$') let tail = matchstr(filename, 'autoload/vital/_\w\+/\zs.*\ze\.vim$')
return join(split(tail, '[\\/]\+'), '.') return join(split(tail, '[\\/]\+'), '.')
endfunction endfunction
if filereadable(expand('<sfile>:r') . '.VIM') if filereadable(expand('<sfile>:r') . '.VIM')
" resolve() is slow, so we cache results. " resolve() is slow, so we cache results.
let s:_unify_path_cache = {}
" Note: On windows, vim can't expand path names from 8.3 formats. " 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, " So if getting full path via <sfile> and $HOME was set as 8.3 format,
" vital load duplicated scripts. Below's :~ avoid this issue. " vital load duplicated scripts. Below's :~ avoid this issue.
@ -163,13 +181,13 @@ if filereadable(expand('<sfile>:r') . '.VIM')
return s:_unify_path_cache[a:path] return s:_unify_path_cache[a:path]
endif endif
let value = tolower(fnamemodify(resolve(fnamemodify( let value = tolower(fnamemodify(resolve(fnamemodify(
\ a:path, ':p')), ':~:gs?[\\/]\+?/?')) \ a:path, ':p')), ':~:gs?[\\/]?/?'))
let s:_unify_path_cache[a:path] = value let s:_unify_path_cache[a:path] = value
return value return value
endfunction endfunction
else else
function! s:_unify_path(path) abort function! s:_unify_path(path) abort
return resolve(fnamemodify(a:path, ':p:gs?[\\/]\+?/?')) return resolve(fnamemodify(a:path, ':p:gs?[\\/]?/?'))
endfunction endfunction
endif endif
@ -183,8 +201,6 @@ else
endfunction endfunction
endif endif
let s:_vital_files_cache_runtimepath = ''
let s:_vital_files_cache = []
function! s:_vital_files(pattern) abort function! s:_vital_files(pattern) abort
if s:_vital_files_cache_runtimepath !=# &runtimepath if s:_vital_files_cache_runtimepath !=# &runtimepath
let path = printf('autoload/vital/%s/**/*.vim', s:self_version) let path = printf('autoload/vital/%s/**/*.vim', s:self_version)

View File

@ -268,7 +268,6 @@ function! s:with_index(list, ...) abort
endfunction endfunction
" similar to Ruby's detect or Haskell's find. " similar to Ruby's detect or Haskell's find.
" TODO spec and doc
function! s:find(list, default, f) abort function! s:find(list, default, f) abort
for x in a:list for x in a:list
if eval(substitute(a:f, 'v:val', string(x), 'g')) if eval(substitute(a:f, 'v:val', string(x), 'g'))
@ -332,6 +331,17 @@ function! s:has_common_items(list1, list2) abort
return !empty(filter(copy(a:list1), 'index(a:list2, v:val) isnot -1')) return !empty(filter(copy(a:list1), 'index(a:list2, v:val) isnot -1'))
endfunction endfunction
function! s:intersect(list1, list2) abort
let items = []
" for funcref
for X in a:list1
if index(a:list2, X) != -1 && index(items, X) == -1
let items += [X]
endif
endfor
return items
endfunction
" similar to Ruby's group_by. " similar to Ruby's group_by.
function! s:group_by(xs, f) abort function! s:group_by(xs, f) abort
let result = {} let result = {}

View File

@ -128,8 +128,8 @@ endfunction
function! s:base.is_input(key, ...) function! s:base.is_input(key, ...)
let prekey = get(a:, 1, "") let prekey = get(a:, 1, "")
return self.get_tap_key() == prekey return self.get_tap_key() ==# prekey
\ && self.char() == a:key \ && self.char() ==# a:key
" \ && self.char() == (prekey . a:key) " \ && self.char() == (prekey . a:key)
endfunction endfunction
@ -238,14 +238,18 @@ endfunction
function! s:base.keymapping() function! s:base.keymapping()
return self.__keymapping__()
endfunction
function! s:base.__keymapping__()
return {} return {}
endfunction endfunction
function! s:base.execute(...) function! s:base.execute(...)
let command = get(a:, 1, self.getline()) let command = get(a:, 1, self.getline())
call self._execute(command) call self.__execute(command)
" execute self.getline()
endfunction endfunction
@ -277,7 +281,7 @@ endfunction
" function! s:base.cancel() " function! s:base.cancel()
" call self.exit(1) " call self.exit(1)
" call self._on_cancel() " call self.__on_cancel()
" endfunction " endfunction
@ -313,7 +317,7 @@ endfunction
function! s:base.start(...) function! s:base.start(...)
let exit_code = call(self._main, a:000, self) let exit_code = call(self.__main, a:000, self)
return exit_code return exit_code
endfunction endfunction
@ -353,7 +357,20 @@ function! s:base.set_input_key_stack(stack)
endfunction endfunction
function! s:base._init_variables() function! s:base.input_key_stack_pop()
return remove(self.input_key_stack(), 0)
endfunction
function! s:base.getchar(...)
if empty(self.input_key_stack())
return call(s:Input.getchar, a:000, s:Input)
endif
return self.input_key_stack_pop()
endfunction
function! s:base.__init_variables()
let self.variables.tap_key = "" let self.variables.tap_key = ""
let self.variables.char = "" let self.variables.char = ""
let self.variables.input = "" let self.variables.input = ""
@ -381,8 +398,8 @@ function! s:_is_valid_highlight(name)
endfunction endfunction
function! s:base._init() function! s:base.__init()
call self._init_variables() call self.__init_variables()
call self.hl_cursor_off() call self.hl_cursor_off()
if !hlexists(self.highlights.cursor) if !hlexists(self.highlights.cursor)
if s:_is_valid_highlight("Cursor") if s:_is_valid_highlight("Cursor")
@ -403,10 +420,10 @@ function! s:base._init()
endfunction endfunction
function! s:base._execute(command) function! s:base.__execute(command)
call self.callevent("on_execute_pre") call self.callevent("on_execute_pre")
try try
execute a:command call self.__execute__(a:command)
catch catch
echohl ErrorMsg echohl ErrorMsg
echom matchstr(v:exception, 'Vim\((\w*)\)\?:\zs.*\ze') echom matchstr(v:exception, 'Vim\((\w*)\)\?:\zs.*\ze')
@ -418,7 +435,12 @@ function! s:base._execute(command)
endfunction endfunction
function! s:base._input_char(char) function! s:base.__execute__(cmd)
execute a:cmd
endfunction
function! s:base.__input_char(char)
let char = a:char let char = a:char
let self.variables.input_key = char let self.variables.input_key = char
let self.variables.char = char let self.variables.char = char
@ -430,14 +452,14 @@ function! s:base._input_char(char)
endfunction endfunction
function! s:base._input(input, ...) function! s:base.__input(input, ...)
if a:input == "" if a:input == ""
return return
endif endif
let self.variables.input_key = a:input let self.variables.input_key = a:input
if a:0 == 0 if a:0 == 0
let keymapping = self._get_keymapping() let keymapping = self.__get_keymapping()
else else
let keymapping = a:1 let keymapping = a:1
endif endif
@ -451,8 +473,8 @@ function! s:base._input(input, ...)
endif endif
call self.set_input_key_stack(s:String.split_by_keys(key)) call self.set_input_key_stack(s:String.split_by_keys(key))
while !(empty(self.input_key_stack()) || self._is_exit()) while !(empty(self.input_key_stack()) || self.is_exit())
call self._input_char(remove(self.input_key_stack(), 0)) call self.__input_char(self.input_key_stack_pop())
endwhile endwhile
endfunction endfunction
@ -463,22 +485,21 @@ function! s:is_input_waiting(keymapping, input)
endfunction endfunction
function! s:base._inputting() function! s:base.__inputting()
if !self.is_enable_keymapping() if !self.is_enable_keymapping()
return self._input(s:Input.getchar()) return self.__input(s:Input.getchar())
endif endif
let input = s:Input.getchar() let input = s:Input.getchar()
let old_line = self.getline() let old_line = self.getline()
let old_pos = self.getpos() let old_pos = self.getpos()
let old_forward = self.forward() let keymapping = self.__get_keymapping()
let old_backward = self.backward()
let keymapping = self._get_keymapping()
try try
let t = reltime() let t = reltime()
while s:is_input_waiting(keymapping, input) while s:is_input_waiting(keymapping, input)
\ && str2nr(reltimestr(reltime(t))) * 1000 < &timeoutlen \ && str2nr(reltimestr(reltime(t))) * 1000 < &timeoutlen
call self.setline(old_backward . input . old_forward) call self.setline(old_line)
call self.insert(input)
call self.setpos(old_pos) call self.setpos(old_pos)
call self.draw() call self.draw()
let input .= s:Input.getchar(0) let input .= s:Input.getchar(0)
@ -487,39 +508,39 @@ function! s:base._inputting()
call self.setline(old_line) call self.setline(old_line)
call self.setpos(old_pos) call self.setpos(old_pos)
endtry endtry
call self._input(input, keymapping) call self.__input(input, keymapping)
endfunction endfunction
function! s:base._update() function! s:base.__update()
" call self.callevent("on_update") " call self.callevent("on_update")
" if !getchar(1) " if !getchar(1)
" continue " continue
" endif " endif
" "
" call self._input(s:getchar(0)) " call self.__input(s:getchar(0))
" call self.draw() " call self.draw()
call self.callevent("on_update") call self.callevent("on_update")
call self._inputting() call self.__inputting()
" call self._input(s:Input.getchar()) " call self.__input(s:Input.getchar())
if self._is_exit() if self.is_exit()
return -1 return -1
endif endif
call self.draw() call self.draw()
endfunction endfunction
function! s:base._main(...) function! s:base.__main(...)
try try
call self._init() call self.__init()
call self.callevent("on_enter") call self.callevent("on_enter")
call self._input(get(a:, 1, "")) call self.__input(get(a:, 1, ""))
call self.draw() call self.draw()
while !self._is_exit() while !self.is_exit()
try try
if self._update() if self.__update()
break break
endif endif
catch catch
@ -530,24 +551,29 @@ function! s:base._main(...)
echohl ErrorMsg | echom v:throwpoint . " " . v:exception | echohl None echohl ErrorMsg | echom v:throwpoint . " " . v:exception | echohl None
let self.variables.exit_code = -1 let self.variables.exit_code = -1
finally finally
call self._finish() call self.__finish()
call self.callevent("on_leave") call self.callevent("on_leave")
endtry endtry
return self.exit_code() return self.exit_code()
endfunction endfunction
function! s:base._finish() function! s:base.__finish()
call self.hl_cursor_on() call self.hl_cursor_on()
endfunction endfunction
function! s:base._is_exit() function! s:base.__is_exit()
return self.is_exit()
endfunction
function! s:base.is_exit()
return self.variables.exit return self.variables.exit
endfunction endfunction
function! s:base._get_keymapping() function! s:base.__get_keymapping()
let result = {} let result = {}
" for module in values(self.variables.modules) " for module in values(self.variables.modules)
for module in self.variables.modules.slots() for module in self.variables.modules.slots()

View File

@ -3,23 +3,41 @@ let s:save_cpo = &cpo
set cpo&vim set cpo&vim
function! s:_vital_loaded(V)
let s:V = a:V
let s:E = s:V.import("Over.Exception")
endfunction
function! s:_vital_depends()
return [
\ "Over.Exception",
\ ]
endfunction
let s:cache_command = {} let s:cache_command = {}
function! s:doautocmd_user(prefix, command) function! s:doautocmd_user(prefix, command)
let group = a:prefix . "-vital-over-commandline-doautocmd-dummy" let group = a:prefix . "-vital-over-commandline-doautocmd-dummy"
if !has_key(s:cache_command, a:command) if !has_key(s:cache_command, a:prefix)
let s:cache_command[a:prefix] = {}
endif
if !has_key(s:cache_command[a:prefix], a:command)
execute "autocmd " . group execute "autocmd " . group
\ . " User " . a:command." silent! execute ''" \ . " User " . a:command." silent! execute ''"
if v:version > 703 || v:version == 703 && has("patch438") if v:version > 703 || v:version == 703 && has("patch438")
let s:cache_command[a:command] = "doautocmd <nomodeline> User " . a:command let s:cache_command[a:prefix][a:command] = "doautocmd <nomodeline> User " . a:command
else else
let s:cache_command[a:command] = "doautocmd User " . a:command let s:cache_command[a:prefix][a:command] = "doautocmd User " . a:command
endif endif
endif endif
execute s:cache_command[a:command] execute s:cache_command[a:prefix][a:command]
endfunction endfunction
let s:hooks = [ let s:hooks = [
\ "enter", \ "enter",
\ "leave", \ "leave",
@ -54,14 +72,26 @@ let s:module = {
for s:i in range(len(s:hooks)) for s:i in range(len(s:hooks))
execute join([ execute join([
\ "function! s:module.on_" . s:hooks[s:i] . "(...)", \ "function! s:module.on_" . s:hooks[s:i] . "(cmdline, ...)",
\ " let s:cmdline = a:cmdline",
\ " call s:doautocmd_user(self.prefix, self.prefix . " . string(s:hooks_camel[s:i]) . ")", \ " call s:doautocmd_user(self.prefix, self.prefix . " . string(s:hooks_camel[s:i]) . ")",
\ "endfunction", \ "endfunction",
\ ], "\n") \ ], "\n")
endfor endfor
function! s:get_cmdline()
if !exists("s:cmdline")
execute s:E.throw_cmd("Undefined cmdline object.", "Over.Commandline.Modules.Doautocmd")
endif
return s:cmdline
endfunction
function! s:make(prefix) function! s:make(prefix)
if has_key(s:cache_command, a:prefix)
unlet! s:cache_command[a:prefix]
endif
execute "augroup " a:prefix . "-vital-over-commandline-doautocmd-dummy" execute "augroup " a:prefix . "-vital-over-commandline-doautocmd-dummy"
autocmd! autocmd!
augroup END augroup END

View File

@ -2,6 +2,10 @@ scriptencoding utf-8
let s:save_cpo = &cpo let s:save_cpo = &cpo
set cpo&vim set cpo&vim
let s:vname = expand("<sfile>:h:h:h:h:t")
let s:module = { let s:module = {
\ "name" : "ExceptionMessage", \ "name" : "ExceptionMessage",
\} \}
@ -22,7 +26,7 @@ endfunction
function! s:module.message(...) function! s:module.message(...)
echohl ErrorMsg echohl ErrorMsg
execute self.command string(self.prefix . self.throwpoint . " " . self.exception) execute self.command string(self.prefix . " : " . self.throwpoint . " " . self.exception)
echohl None echohl None
endfunction endfunction
@ -34,12 +38,14 @@ function! s:module.on_leave(cmdline)
endif endif
endfunction endfunction
function! s:make(...) function! s:make(...)
let result = deepcopy(s:module) let result = deepcopy(s:module)
let result.prefix = get(a:, 1, "vital-over:") let result.prefix = get(a:, 1, "vital-over(".s:vname.") Exception")
let result.command = get(a:, 2, "echo") let result.command = get(a:, 2, "echom")
return result return result
endfunction endfunction
let &cpo = s:save_cpo let &cpo = s:save_cpo
unlet s:save_cpo unlet s:save_cpo

View File

@ -85,6 +85,10 @@ let s:vim_cmdline_mapping = {
\ "_cmaps" : {} \ "_cmaps" : {}
\} \}
function! s:_convert_sid(rhs, sid) abort
return substitute(a:rhs, '<SID>', '<SNR>' . a:sid . '_', 'g')
endfunction
function! s:_auto_cmap() function! s:_auto_cmap()
let cmaps = {} let cmaps = {}
let cmap_info = s:Keymapping.rhs_key_list("c", 0, 1) let cmap_info = s:Keymapping.rhs_key_list("c", 0, 1)
@ -92,7 +96,7 @@ function! s:_auto_cmap()
for c in filter(cmap_info, "v:val['buffer'] ==# 0") for c in filter(cmap_info, "v:val['buffer'] ==# 0")
let cmaps[s:Keymapping.escape_special_key(c['lhs'])] = { let cmaps[s:Keymapping.escape_special_key(c['lhs'])] = {
\ 'noremap' : c['noremap'], \ 'noremap' : c['noremap'],
\ 'key' : s:Keymapping.escape_special_key(c['rhs']), \ 'key' : s:Keymapping.escape_special_key(s:_convert_sid(c['rhs'], c['sid'])),
\ 'expr' : s:Keymapping.escape_special_key(c['expr']), \ 'expr' : s:Keymapping.escape_special_key(c['expr']),
\ } \ }
endfor endfor

View File

@ -0,0 +1,31 @@
scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim
let s:vname = expand("<sfile>:h:h:t")
let s:prefix = printf("vital-over(%s) Exception", s:vname)
function! s:set_prefix(prefix)
let s:prefix = a:prefix
endfunction
function! s:throw_cmd(exp, where)
return 'throw ' . string(s:prefix . " : " . a:exp . " in " . a:where)
endfunction
function! s:throw(exp, where)
execute s:throw_cmd(a:exp, a:where)
endfunction
function! s:error(text, where)
echohl ErrorMsg
echom s:prefix . " : " . a:text . " in " . a:where
echohl None
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -80,13 +80,14 @@ endfunction
function! s:base.remove(index) function! s:base.remove(index)
if a:index < 0 || self.length() <= a:index if a:index < 0 || self.length() <= a:index
return self return ""
endif endif
let result = self.list[a:index]
unlet self.list[a:index] unlet self.list[a:index]
if a:index < self.col if a:index < self.col
call self.set(self.col - 1) call self.set(self.col - 1)
endif endif
return self return result
endfunction endfunction
function! s:base.remove_pos() function! s:base.remove_pos()
@ -109,158 +110,24 @@ function! s:make(...)
return result return result
endfunction endfunction
" NOTE: old regexpengine has a bug with string which contains binary
function! s:_split(str, pat) " :echo "\x80" =~ "\\%#=1\x80" | " => 0
let pat = (exists("+regexpengine") ? '\%#=2' : '') . a:pat " But it matches correctly with :h /collection
let list = split(a:str, pat . '\zs') " :echo "\x80" =~ "\\%#=1[\x80]" | " => 1
return s:List.flatten(map(list, 'v:val == a:pat ? a:pat : v:val =~ pat . ''$'' ? split(v:val, pat) + [a:pat] : v:val')) " http://lingr.com/room/vim/archives/2015/02/13#message-21261450
let s:_engine = exists("+regexpengine") ? '\%#=2' : ''
" \<A-]> => Û\xfdQ
" \<A-@> => À\xfeX
let s:_regex = exists("+regexpengine")
\ ? "\\%(Û\xfdQ\\|À\xfeX\\|\x80\xfc.\\%(\x80..\\|.\\)\\|\x80..\\|.\\)\\zs"
\ : "\\%(Û[\xfd]Q\\|À[\xfe]X\\|[\x80][\xfc].\\%([\x80]..\\|.\\)\\|[\x80]..\\|.\\)\\zs"
function! s:_split_keystring(str, ...)
return split(a:str, s:_engine . '\m\%(' . get(a:, 1, '') . s:_regex . '\)')
endfunction endfunction
function! s:split_by_keys(str)
function! s:_split_keystring(str, pats, ...)
if a:str =~ '^<Over>(.\{-})$'
\ || a:str =~ "^\<Plug>(.\\{-})$"
return [a:str]
endif
let pats = a:pats
let index = get(a:, 1, 0)
if !exists("+regexpengine")
\ || index > len(pats)
\ || len(filter(copy(pats), 'a:str =~ ''\%#=2'' . v:val')) == 0
if len(filter(copy(pats), 'a:str ==# v:val')) == 0
return split(a:str, '\zs')
else
return [a:str]
endif
endif
if len(filter(copy(pats), 'a:str == v:val')) == 1
return [a:str]
endif
let result = []
let pat = pats[index]
let list = s:_split(a:str, pat)
let result += eval(join(map(list, "s:_split_keystring(v:val, pats, index+1)"), "+"))
return result
endfunction
let s:special_keys = [
\ "\<BS>",
\ "\<Down>",
\ "\<Up>",
\ "\<Left>",
\ "\<Right>",
\ "\<Home>",
\ "\<End>",
\ "\<Insert>",
\ "\<Delete>",
\ "\<PageUp>",
\ "\<PageDown>",
\ "\<F1>",
\ "\<F2>",
\ "\<F3>",
\ "\<F4>",
\ "\<F5>",
\ "\<F6>",
\ "\<F7>",
\ "\<F8>",
\ "\<F9>",
\ "\<F10>",
\ "\<F11>",
\ "\<F12>",
\ "\<A-BS>",
\ "\<A-Down>",
\ "\<A-Up>",
\ "\<A-Left>",
\ "\<A-Right>",
\ "\<A-Home>",
\ "\<A-End>",
\ "\<A-Insert>",
\ "\<A-Delete>",
\ "\<A-PageUp>",
\ "\<A-PageDown>",
\ "\<A-F1>",
\ "\<A-F2>",
\ "\<A-F3>",
\ "\<A-F4>",
\ "\<A-F5>",
\ "\<A-F6>",
\ "\<A-F7>",
\ "\<A-F8>",
\ "\<A-F9>",
\ "\<A-F10>",
\ "\<A-F11>",
\ "\<A-F12>",
\ "\<A-Tab>",
\ "\<C-BS>",
\ "\<C-Down>",
\ "\<C-Up>",
\ "\<C-Left>",
\ "\<C-Right>",
\ "\<C-Home>",
\ "\<C-End>",
\ "\<C-Insert>",
\ "\<C-Delete>",
\ "\<C-PageUp>",
\ "\<C-PageDown>",
\ "\<C-Tab>",
\ "\<C-F1>",
\ "\<C-F2>",
\ "\<C-F3>",
\ "\<C-F4>",
\ "\<C-F5>",
\ "\<C-F6>",
\ "\<C-F7>",
\ "\<C-F8>",
\ "\<C-F9>",
\ "\<C-F10>",
\ "\<C-F11>",
\ "\<C-F12>",
\ "\<S-Down>",
\ "\<S-Up>",
\ "\<S-Left>",
\ "\<S-Right>",
\ "\<S-Home>",
\ "\<S-Insert>",
\ "\<S-PageUp>",
\ "\<S-PageDown>",
\ "\<S-F1>",
\ "\<S-F2>",
\ "\<S-F3>",
\ "\<S-F4>",
\ "\<S-F5>",
\ "\<S-F6>",
\ "\<S-F7>",
\ "\<S-F8>",
\ "\<S-F9>",
\ "\<S-F10>",
\ "\<S-F11>",
\ "\<S-F12>",
\ "\<S-Tab>",
\]
" Issues #45
" \ "\<S-End>",
" \ "\<S-Delete>",
" Workaround
" https://github.com/osyo-manga/vital-over/pull/63
" http://lingr.com/room/vim/archives/2014/10/29#message-20492403
if exists("+regexpengine")
function! s:_split_keystring(str, ...)
return split(a:str, '\%#=2' . "\\m\\%(" . get(a:, 1, '') . "\x80\xfc.\\%(\x80..\\|.\\)\\zs\\|\x80..\\zs\\|.\\zs\\)")
endfunction
function! s:split_by_keys(str)
return s:_split_keystring(a:str, "\\%(\<Plug>\\|<Over>\\)(.\\{-})\\zs\\|") return s:_split_keystring(a:str, "\\%(\<Plug>\\|<Over>\\)(.\\{-})\\zs\\|")
endfunction endfunction
else
function! s:split_by_keys(str)
return s:_split_keystring(a:str, s:special_keys)
endfunction
endif
function! s:index(haystack, needle, ...) function! s:index(haystack, needle, ...)
let start = get(a:, 1, 0) let start = get(a:, 1, 0)

View File

@ -0,0 +1,59 @@
scriptencoding utf-8
let s:save_cpo = &cpo
set cpo&vim
let s:verbosefiles = []
function! s:_verbosefile_push(file)
call add(s:verbosefiles, &verbosefile)
let &verbosefile = a:file
return a:file
endfunction
function! s:_verbosefile_pop()
let filename = &verbosefile
let &verbosefile = get(s:verbosefiles, -1)
call remove(s:verbosefiles, -1)
return filename
endfunction
function! s:_reset()
let s:verbosefiles = []
endfunction
function! s:extend(dict, src)
for [key, value] in items(a:src)
let a:dict[key] = value
unlet value
endfor
endfunction
function! s:command(cmd, ...)
" Workaround : Vim 7.3.xxx in Travis and Ubuntu
" https://github.com/osyo-manga/vital-palette/issues/5
" call extend(l:, get(a:, 1, {}))
if a:0 > 0
call s:extend(l:, a:1)
endif
call s:_verbosefile_push(tempname())
try
redir =>result
silent execute a:cmd
finally
redir END
endtry
call s:_verbosefile_pop()
" let result = substitute(result, "<SRN>", "\<SNR>", "g")
" let result = substitute(result, "<SID>", "\<SID>", "g")
return result
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -16,6 +16,11 @@ function! s:_vital_depends()
endfunction endfunction
function! s:_execute(cmd)
execute a:cmd
endfunction
function! s:capture(name) function! s:capture(name)
if hlexists(a:name) == 0 if hlexists(a:name) == 0
return "" return ""
@ -42,7 +47,7 @@ function! s:parse(highlight)
endif endif
let name = s:parse_to_name(a:highlight) let name = s:parse_to_name(a:highlight)
let result = { "name " : name } let result = { "_name" : name }
if highlight =~# '^\w\+\s\+xxx cleared' if highlight =~# '^\w\+\s\+xxx cleared'
let result.cleared = 1 let result.cleared = 1
@ -89,6 +94,20 @@ function! s:get(name, ...)
endfunction endfunction
function! s:set(name, config)
if type(a:config) == type("")
return s:set(a:config, s:get(a:config))
endif
if has_key(a:config, "cleared")
return s:_execute("highlight clear " . a:name)
endif
if has_key(a:config, "link")
return s:_execute("highlight link " . a:name . " " . a:config.link)
endif
return s:_execute("highlight " . a:name . " " . join(map(items(filter(a:config, "v:key !=# '_name'")), "v:val[0] . '=' . v:val[1]"), " "))
endfunction
function! s:group_list() function! s:group_list()
let highlights = split(s:Message.capture("highlight"), "\n") let highlights = split(s:Message.capture("highlight"), "\n")
return filter(map(highlights, "s:parse_to_name(v:val)"), "v:val != ''") return filter(map(highlights, "s:parse_to_name(v:val)"), "v:val != ''")

View File

@ -3,30 +3,42 @@ let s:save_cpo = &cpo
set cpo&vim set cpo&vim
let s:modep = "[nvoicsxl]"
function! s:_vital_loaded(V) function! s:_vital_loaded(V)
let s:V = a:V let s:V = a:V
let s:Message = s:V.import("Vim.Message") let s:Capture = s:V.import("Palette.Capture")
endfunction endfunction
function! s:_vital_depends() function! s:_vital_depends()
return [ return [
\ "Vim.Message", \ "Palette.Capture",
\ ] \ ]
endfunction endfunction
function! s:_capture(mode)
let cmd = "map"
if a:mode ==# "!"
let cmd = cmd . "!"
elseif a:mode =~# "[nvoicsxl]"
let cmd = a:mode . cmd
endif
return s:Capture.command(cmd)
endfunction
function! s:capture(...) function! s:capture(...)
let mode = get(a:, 1, "") let mode = get(a:, 1, "")
if mode != "" && mode !~# "[nvoicsxl]" let modes = split(mode, '\zs')
return "" return join(map(modes, "s:_capture(v:val)"), "\n")
endif
return s:Message.capture(mode . "map")
endfunction endfunction
function! s:_keymapping(str) function! s:_keymapping(str)
return a:str =~# '^[nvoicsxl]\s' return a:str =~ '^[!nvoicsxl]\s'
endfunction endfunction
@ -37,14 +49,22 @@ endfunction
function! s:escape_special_key(key) function! s:escape_special_key(key)
" Workaround : <C-?> https://github.com/osyo-manga/vital-palette/issues/5
if a:key ==# "<^?>"
return "\<C-?>"
endif
execute 'let result = "' . substitute(escape(a:key, '\"'), '\(<.\{-}>\)', '\\\1', 'g') . '"' execute 'let result = "' . substitute(escape(a:key, '\"'), '\(<.\{-}>\)', '\\\1', 'g') . '"'
return result return result
endfunction endfunction
function! s:parse_lhs(text, ...) function! s:parse_lhs(text, ...)
let mode = get(a:, 1, '[nvoicsxl]') let mode = get(a:, 1, '[!nvoicsxl]')
return matchstr(a:text, mode . '\s\+\zs\S\{-}\ze\s\+') " NOTE: :map! Surpport : https://github.com/osyo-manga/vital-palette/issues/4
if get(a:, 1, "") =~# '[!ci]'
let mode = '[!ci]'
endif
return matchstr(a:text, mode . '\{1,3\}\s*\zs\S\{-}\ze\s\+')
endfunction endfunction
@ -60,12 +80,25 @@ function! s:lhs_key_list(...)
endfunction endfunction
function! s:_maparg(name, mode, abbr, dict)
" Workaround : <C-?> https://github.com/osyo-manga/vital-palette/issues/5
if a:name ==# "<^?>"
return maparg("\<C-?>", a:mode, a:abbr, a:dict)
endif
return maparg(a:name, a:mode, a:abbr, a:dict)
endfunction
function! s:rhs_key_list(...) function! s:rhs_key_list(...)
let mode = get(a:, 1, "") let mode = get(a:, 1, "")
let abbr = get(a:, 2, 0) let abbr = get(a:, 2, 0)
let dict = get(a:, 3, 0) let dict = get(a:, 3, 0)
return map(s:parse_lhs_list(mode), "maparg(v:val, mode, abbr, dict)") let result = []
for m in split(mode, '\zs')
let result += map(s:parse_lhs_list(m), "s:_maparg(v:val, m, abbr, dict)")
endfor
return filter(result, "empty(v:val) == 0")
endfunction endfunction

View File

@ -1,5 +1,5 @@
easymotion easymotion
9a8002c 423c2c0
Over.Commandline.Base Over.Commandline.Base
Over.Commandline.Modules.Cancel Over.Commandline.Modules.Cancel