diff --git a/autoload/vital/_easymotion.vim b/autoload/vital/_easymotion.vim index bfec617..7f81595 100644 --- a/autoload/vital/_easymotion.vim +++ b/autoload/vital/_easymotion.vim @@ -5,6 +5,12 @@ let s:self_file = expand('') let s:globpath_third_arg = v:version > 702 || v:version == 702 && has('patch51') 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 let target = {} @@ -35,12 +41,13 @@ function! s:load(...) dict abort let [name; as] = type(arg) == type([]) ? arg[: 1] : [arg, arg] let target = split(join(as, ''), '\W\+') let dict = self - while 1 <= len(target) + let dict_type = type({}) + while !empty(target) let ns = remove(target, 0) if !has_key(dict, ns) let dict[ns] = {} endif - if type(dict[ns]) == type({}) + if type(dict[ns]) == dict_type let dict = dict[ns] else unlet dict @@ -58,6 +65,8 @@ endfunction function! s:unload() abort let s:loaded = {} + let s:cache_sid = {} + let s:cache_module_path = {} endfunction function! s:exists(name) abort @@ -118,6 +127,10 @@ function! s:_import(name) abort endfunction 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) return a:name endif @@ -131,30 +144,35 @@ function! s:_get_module_path(name) abort call filter(paths, 'filereadable(expand(v:val, 1))') let path = get(paths, 0, '') - return path !=# '' ? path : '' + let s:cache_module_path[key] = path + return path endfunction 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) for line in filter(split(s:_redir('scriptnames'), "\n"), \ 'stridx(v:val, s:self_version) > 0') let list = matchlist(line, '^\s*\(\d\+\):\s\+\(.\+\)\s*$') 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 endfor return 0 endfunction 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$') return join(split(tail, '[\\/]\+'), '.') endfunction if filereadable(expand(':r') . '.VIM') " 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. " So if getting full path via and $HOME was set as 8.3 format, " vital load duplicated scripts. Below's :~ avoid this issue. @@ -163,13 +181,13 @@ if filereadable(expand(':r') . '.VIM') 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) abort - return resolve(fnamemodify(a:path, ':p:gs?[\\/]\+?/?')) + return resolve(fnamemodify(a:path, ':p:gs?[\\/]?/?')) endfunction endif @@ -183,8 +201,6 @@ else endfunction endif -let s:_vital_files_cache_runtimepath = '' -let s:_vital_files_cache = [] function! s:_vital_files(pattern) abort if s:_vital_files_cache_runtimepath !=# &runtimepath let path = printf('autoload/vital/%s/**/*.vim', s:self_version) diff --git a/autoload/vital/_easymotion/Data/List.vim b/autoload/vital/_easymotion/Data/List.vim index 1b42dbf..c8aac65 100644 --- a/autoload/vital/_easymotion/Data/List.vim +++ b/autoload/vital/_easymotion/Data/List.vim @@ -268,7 +268,6 @@ function! s:with_index(list, ...) abort endfunction " similar to Ruby's detect or Haskell's find. -" TODO spec and doc function! s:find(list, default, f) abort for x in a:list 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')) 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. function! s:group_by(xs, f) abort let result = {} diff --git a/autoload/vital/_easymotion/Over/Commandline/Base.vim b/autoload/vital/_easymotion/Over/Commandline/Base.vim index a93c4f2..ddcbd09 100644 --- a/autoload/vital/_easymotion/Over/Commandline/Base.vim +++ b/autoload/vital/_easymotion/Over/Commandline/Base.vim @@ -128,8 +128,8 @@ endfunction function! s:base.is_input(key, ...) let prekey = get(a:, 1, "") - return self.get_tap_key() == prekey -\ && self.char() == a:key + return self.get_tap_key() ==# prekey +\ && self.char() ==# a:key " \ && self.char() == (prekey . a:key) endfunction @@ -238,14 +238,18 @@ endfunction function! s:base.keymapping() + return self.__keymapping__() +endfunction + + +function! s:base.__keymapping__() return {} endfunction function! s:base.execute(...) let command = get(a:, 1, self.getline()) - call self._execute(command) -" execute self.getline() + call self.__execute(command) endfunction @@ -277,7 +281,7 @@ endfunction " function! s:base.cancel() " call self.exit(1) -" call self._on_cancel() +" call self.__on_cancel() " endfunction @@ -313,7 +317,7 @@ endfunction 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 endfunction @@ -353,7 +357,20 @@ function! s:base.set_input_key_stack(stack) 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.char = "" let self.variables.input = "" @@ -381,8 +398,8 @@ function! s:_is_valid_highlight(name) endfunction -function! s:base._init() - call self._init_variables() +function! s:base.__init() + call self.__init_variables() call self.hl_cursor_off() if !hlexists(self.highlights.cursor) if s:_is_valid_highlight("Cursor") @@ -403,10 +420,10 @@ function! s:base._init() endfunction -function! s:base._execute(command) +function! s:base.__execute(command) call self.callevent("on_execute_pre") try - execute a:command + call self.__execute__(a:command) catch echohl ErrorMsg echom matchstr(v:exception, 'Vim\((\w*)\)\?:\zs.*\ze') @@ -418,7 +435,12 @@ function! s:base._execute(command) 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 self.variables.input_key = char let self.variables.char = char @@ -430,14 +452,14 @@ function! s:base._input_char(char) endfunction -function! s:base._input(input, ...) +function! s:base.__input(input, ...) if a:input == "" return endif let self.variables.input_key = a:input if a:0 == 0 - let keymapping = self._get_keymapping() + let keymapping = self.__get_keymapping() else let keymapping = a:1 endif @@ -451,8 +473,8 @@ function! s:base._input(input, ...) endif call self.set_input_key_stack(s:String.split_by_keys(key)) - while !(empty(self.input_key_stack()) || self._is_exit()) - call self._input_char(remove(self.input_key_stack(), 0)) + while !(empty(self.input_key_stack()) || self.is_exit()) + call self.__input_char(self.input_key_stack_pop()) endwhile endfunction @@ -463,22 +485,21 @@ function! s:is_input_waiting(keymapping, input) endfunction -function! s:base._inputting() +function! s:base.__inputting() if !self.is_enable_keymapping() - return self._input(s:Input.getchar()) + return self.__input(s:Input.getchar()) endif let input = s:Input.getchar() let old_line = self.getline() let old_pos = self.getpos() - let old_forward = self.forward() - let old_backward = self.backward() - let keymapping = self._get_keymapping() + let keymapping = self.__get_keymapping() try let t = reltime() while s:is_input_waiting(keymapping, input) \ && 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.draw() let input .= s:Input.getchar(0) @@ -487,39 +508,39 @@ function! s:base._inputting() call self.setline(old_line) call self.setpos(old_pos) endtry - call self._input(input, keymapping) + call self.__input(input, keymapping) endfunction -function! s:base._update() +function! s:base.__update() " call self.callevent("on_update") " if !getchar(1) " continue " endif " -" call self._input(s:getchar(0)) +" call self.__input(s:getchar(0)) " call self.draw() call self.callevent("on_update") - call self._inputting() -" call self._input(s:Input.getchar()) - if self._is_exit() + call self.__inputting() +" call self.__input(s:Input.getchar()) + if self.is_exit() return -1 endif call self.draw() endfunction -function! s:base._main(...) +function! s:base.__main(...) try - call self._init() + call self.__init() call self.callevent("on_enter") - call self._input(get(a:, 1, "")) + call self.__input(get(a:, 1, "")) call self.draw() - while !self._is_exit() + while !self.is_exit() try - if self._update() + if self.__update() break endif catch @@ -530,24 +551,29 @@ function! s:base._main(...) echohl ErrorMsg | echom v:throwpoint . " " . v:exception | echohl None let self.variables.exit_code = -1 finally - call self._finish() + call self.__finish() call self.callevent("on_leave") endtry return self.exit_code() endfunction -function! s:base._finish() +function! s:base.__finish() call self.hl_cursor_on() 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 endfunction -function! s:base._get_keymapping() +function! s:base.__get_keymapping() let result = {} " for module in values(self.variables.modules) for module in self.variables.modules.slots() diff --git a/autoload/vital/_easymotion/Over/Commandline/Modules/Doautocmd.vim b/autoload/vital/_easymotion/Over/Commandline/Modules/Doautocmd.vim index 93ca06f..3c49e78 100644 --- a/autoload/vital/_easymotion/Over/Commandline/Modules/Doautocmd.vim +++ b/autoload/vital/_easymotion/Over/Commandline/Modules/Doautocmd.vim @@ -3,23 +3,41 @@ let s:save_cpo = &cpo 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 = {} function! s:doautocmd_user(prefix, command) 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 \ . " User " . a:command." silent! execute ''" if v:version > 703 || v:version == 703 && has("patch438") - let s:cache_command[a:command] = "doautocmd User " . a:command + let s:cache_command[a:prefix][a:command] = "doautocmd User " . a:command 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 - execute s:cache_command[a:command] + execute s:cache_command[a:prefix][a:command] endfunction + let s:hooks = [ \ "enter", \ "leave", @@ -54,14 +72,26 @@ let s:module = { for s:i in range(len(s:hooks)) 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]) . ")", \ "endfunction", \ ], "\n") 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) + if has_key(s:cache_command, a:prefix) + unlet! s:cache_command[a:prefix] + endif execute "augroup " a:prefix . "-vital-over-commandline-doautocmd-dummy" autocmd! augroup END diff --git a/autoload/vital/_easymotion/Over/Commandline/Modules/ExceptionMessage.vim b/autoload/vital/_easymotion/Over/Commandline/Modules/ExceptionMessage.vim index ed97fbb..082fe31 100644 --- a/autoload/vital/_easymotion/Over/Commandline/Modules/ExceptionMessage.vim +++ b/autoload/vital/_easymotion/Over/Commandline/Modules/ExceptionMessage.vim @@ -2,6 +2,10 @@ scriptencoding utf-8 let s:save_cpo = &cpo set cpo&vim + +let s:vname = expand(":h:h:h:h:t") + + let s:module = { \ "name" : "ExceptionMessage", \} @@ -22,7 +26,7 @@ endfunction function! s:module.message(...) echohl ErrorMsg - execute self.command string(self.prefix . self.throwpoint . " " . self.exception) + execute self.command string(self.prefix . " : " . self.throwpoint . " " . self.exception) echohl None endfunction @@ -34,12 +38,14 @@ function! s:module.on_leave(cmdline) endif endfunction + function! s:make(...) let result = deepcopy(s:module) - let result.prefix = get(a:, 1, "vital-over:") - let result.command = get(a:, 2, "echo") + let result.prefix = get(a:, 1, "vital-over(".s:vname.") Exception") + let result.command = get(a:, 2, "echom") return result endfunction + let &cpo = s:save_cpo unlet s:save_cpo diff --git a/autoload/vital/_easymotion/Over/Commandline/Modules/KeyMapping.vim b/autoload/vital/_easymotion/Over/Commandline/Modules/KeyMapping.vim index 2954e59..41d9de5 100644 --- a/autoload/vital/_easymotion/Over/Commandline/Modules/KeyMapping.vim +++ b/autoload/vital/_easymotion/Over/Commandline/Modules/KeyMapping.vim @@ -85,6 +85,10 @@ let s:vim_cmdline_mapping = { \ "_cmaps" : {} \} +function! s:_convert_sid(rhs, sid) abort + return substitute(a:rhs, '', '' . a:sid . '_', 'g') +endfunction + function! s:_auto_cmap() let cmaps = {} 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") let cmaps[s:Keymapping.escape_special_key(c['lhs'])] = { \ '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']), \ } endfor diff --git a/autoload/vital/_easymotion/Over/Exception.vim b/autoload/vital/_easymotion/Over/Exception.vim new file mode 100644 index 0000000..3dca9c1 --- /dev/null +++ b/autoload/vital/_easymotion/Over/Exception.vim @@ -0,0 +1,31 @@ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let s:vname = expand(":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 diff --git a/autoload/vital/_easymotion/Over/String.vim b/autoload/vital/_easymotion/Over/String.vim index 15a0ad8..d870db2 100644 --- a/autoload/vital/_easymotion/Over/String.vim +++ b/autoload/vital/_easymotion/Over/String.vim @@ -80,13 +80,14 @@ endfunction function! s:base.remove(index) if a:index < 0 || self.length() <= a:index - return self + return "" endif + let result = self.list[a:index] unlet self.list[a:index] if a:index < self.col call self.set(self.col - 1) endif - return self + return result endfunction function! s:base.remove_pos() @@ -109,159 +110,25 @@ function! s:make(...) return result endfunction - -function! s:_split(str, pat) - let pat = (exists("+regexpengine") ? '\%#=2' : '') . a:pat - let list = split(a:str, pat . '\zs') - return s:List.flatten(map(list, 'v:val == a:pat ? a:pat : v:val =~ pat . ''$'' ? split(v:val, pat) + [a:pat] : v:val')) +" NOTE: old regexpengine has a bug with string which contains binary +" :echo "\x80" =~ "\\%#=1\x80" | " => 0 +" But it matches correctly with :h /collection +" :echo "\x80" =~ "\\%#=1[\x80]" | " => 1 +" http://lingr.com/room/vim/archives/2015/02/13#message-21261450 +let s:_engine = exists("+regexpengine") ? '\%#=2' : '' +" \ => Û\xfdQ +" \ => À\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 - -function! s:_split_keystring(str, pats, ...) - if a:str =~ '^(.\{-})$' -\ || a:str =~ "^\(.\\{-})$" - 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 +function! s:split_by_keys(str) + return s:_split_keystring(a:str, "\\%(\\\|\\)(.\\{-})\\zs\\|") endfunction - -let s:special_keys = [ -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\ "\", -\] -" Issues #45 -" \ "\", -" \ "\", - - -" 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, "\\%(\\\|\\)(.\\{-})\\zs\\|") - endfunction -else - function! s:split_by_keys(str) - return s:_split_keystring(a:str, s:special_keys) - endfunction -endif - - function! s:index(haystack, needle, ...) let start = get(a:, 1, 0) let ignorecase = get(a:, 2, &ignorecase) diff --git a/autoload/vital/_easymotion/Palette/Capture.vim b/autoload/vital/_easymotion/Palette/Capture.vim new file mode 100644 index 0000000..8811e0e --- /dev/null +++ b/autoload/vital/_easymotion/Palette/Capture.vim @@ -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, "", "\", "g") +" let result = substitute(result, "", "\", "g") + return result +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/autoload/vital/_easymotion/Palette/Highlight.vim b/autoload/vital/_easymotion/Palette/Highlight.vim index e85fd08..dd9b416 100644 --- a/autoload/vital/_easymotion/Palette/Highlight.vim +++ b/autoload/vital/_easymotion/Palette/Highlight.vim @@ -16,6 +16,11 @@ function! s:_vital_depends() endfunction +function! s:_execute(cmd) + execute a:cmd +endfunction + + function! s:capture(name) if hlexists(a:name) == 0 return "" @@ -42,7 +47,7 @@ function! s:parse(highlight) endif let name = s:parse_to_name(a:highlight) - let result = { "name " : name } + let result = { "_name" : name } if highlight =~# '^\w\+\s\+xxx cleared' let result.cleared = 1 @@ -89,6 +94,20 @@ function! s:get(name, ...) 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() let highlights = split(s:Message.capture("highlight"), "\n") return filter(map(highlights, "s:parse_to_name(v:val)"), "v:val != ''") diff --git a/autoload/vital/_easymotion/Palette/Keymapping.vim b/autoload/vital/_easymotion/Palette/Keymapping.vim index 8711479..797b556 100644 --- a/autoload/vital/_easymotion/Palette/Keymapping.vim +++ b/autoload/vital/_easymotion/Palette/Keymapping.vim @@ -3,30 +3,42 @@ let s:save_cpo = &cpo set cpo&vim +let s:modep = "[nvoicsxl]" + + function! s:_vital_loaded(V) let s:V = a:V - let s:Message = s:V.import("Vim.Message") + let s:Capture = s:V.import("Palette.Capture") endfunction function! s:_vital_depends() return [ -\ "Vim.Message", +\ "Palette.Capture", \ ] 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(...) let mode = get(a:, 1, "") - if mode != "" && mode !~# "[nvoicsxl]" - return "" - endif - return s:Message.capture(mode . "map") + let modes = split(mode, '\zs') + return join(map(modes, "s:_capture(v:val)"), "\n") endfunction function! s:_keymapping(str) - return a:str =~# '^[nvoicsxl]\s' + return a:str =~ '^[!nvoicsxl]\s' endfunction @@ -37,14 +49,22 @@ endfunction function! s:escape_special_key(key) + " Workaround : https://github.com/osyo-manga/vital-palette/issues/5 + if a:key ==# "<^?>" + return "\" + endif execute 'let result = "' . substitute(escape(a:key, '\"'), '\(<.\{-}>\)', '\\\1', 'g') . '"' return result endfunction function! s:parse_lhs(text, ...) - let mode = get(a:, 1, '[nvoicsxl]') - return matchstr(a:text, mode . '\s\+\zs\S\{-}\ze\s\+') + let mode = get(a:, 1, '[!nvoicsxl]') + " 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 @@ -60,12 +80,25 @@ function! s:lhs_key_list(...) endfunction +function! s:_maparg(name, mode, abbr, dict) + " Workaround : https://github.com/osyo-manga/vital-palette/issues/5 + if a:name ==# "<^?>" + return maparg("\", a:mode, a:abbr, a:dict) + endif + return maparg(a:name, a:mode, a:abbr, a:dict) +endfunction + + function! s:rhs_key_list(...) let mode = get(a:, 1, "") let abbr = get(a:, 2, 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 diff --git a/autoload/vital/easymotion.vital b/autoload/vital/easymotion.vital index 366148c..a467696 100644 --- a/autoload/vital/easymotion.vital +++ b/autoload/vital/easymotion.vital @@ -1,5 +1,5 @@ easymotion -9a8002c +423c2c0 Over.Commandline.Base Over.Commandline.Modules.Cancel