Created
June 27, 2016 16:49
-
-
Save osyo-manga/5142a8c53d615412284dec55dd191698 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let s:V = vital#of("vital") | |
| let s:J = s:V.import("Branc.Job") | |
| function! s:error(msg) | |
| echohl ErrorMsg | |
| echom a:msg | |
| echohl NONE | |
| endfunction | |
| function! s:start(config, context) | |
| if empty(a:context.input_text) | |
| return s:error("Input complete word.") | |
| endif | |
| let command = a:config.command . " " . a:context.input_text | |
| let job = s:J.new({ | |
| \ "buffer_" : [], | |
| \ "context_" : a:context, | |
| \ "config_" : a:config | |
| \ }).start(command) | |
| function! job._callback(ch, msg) | |
| if !empty(self.config_.ignore_pat) | |
| \ && a:msg =~ self.config_.ignore_pat | |
| return | |
| endif | |
| let self.buffer_ += [a:msg] | |
| endfunction | |
| function! job._close_cb(...) | |
| call complete(self.context_.start_col, self.buffer_) | |
| endfunction | |
| return "" | |
| endfunction | |
| let s:config = { | |
| \ "command" : "look", | |
| \ "input_pat" : '\w\+', | |
| \ "ignore_pat" : "", | |
| \} | |
| function! s:context(config) | |
| let base = get(a:, 1, {}) | |
| let line_pat = '^\(.\{-}\)\(' . a:config.input_pat . '\)$' | |
| let input_list = matchlist(getline("."), line_pat) | |
| let complete_pos = strwidth(get(input_list, 1, "")) | |
| let input_text = get(input_list, 2, "") | |
| let start_col = getline(".") == "" ? 1 : complete_pos + 1 | |
| return extend({ | |
| \ "bufnr" : bufnr("%"), | |
| \ "col" : col("."), | |
| \ "start_col" : start_col, | |
| \ "complete_pos" : complete_pos, | |
| \ "line" : line("."), | |
| \ "input_text" : input_text, | |
| \ "cache_keyword" : printf("%d-%d-%d-%s", bufnr("%"), complete_pos, line("."), getline(".")[:start_col-1]), | |
| \ }, base) | |
| endfunction | |
| function! Start() | |
| return s:start(s:config, s:context(s:config)) ? "" : "" | |
| endfunction | |
| inoremap <A-a> <C-R>=Start()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment