Created
August 7, 2014 06:24
-
-
Save kamichidu/f5d1fdf56f4af64b70e8 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
| " autoload/quickrun/hook/psqlconfig.vim | |
| let s:save_cpo = &cpo | |
| set cpo&vim | |
| let s:hook = { | |
| \ 'kind': 'hook', | |
| \ 'name': 'psqlconfig', | |
| \ 'config': { | |
| \ 'enable': 0, | |
| \ 'patterns': ['^--\s*\(\w\+\)\s*=\s*\(\S.*\)$'], | |
| \ 'default_values': {'host': 'localhost', 'port': '5432', 'username': 'postgres'}, | |
| \ 'search_ranges': [[1, 5], [-5, '$']], | |
| \ }, | |
| \} | |
| function! s:hook.init(session) | |
| endfunction | |
| function! s:hook.on_module_loaded(session, context) | |
| " 先頭5行でいいかな | |
| let l:baumkuchen= baumkuchen#of({ | |
| \ 'ranges': [[1, 5]], | |
| \ 'keys': ['\w\+'], | |
| \ 'assignments': ['\s*=\s*'], | |
| \ 'values': ['\S.*$'], | |
| \}) | |
| let l:options= l:baumkuchen.map('%') | |
| let l:cmdopt= deepcopy(a:session.config.cmdopt) | |
| for l:key in keys(l:options) | |
| let l:cmdopt= substitute(l:cmdopt, printf('#{%s}', l:key), l:options[l:key], 'g') | |
| endfor | |
| for l:key in keys(self.config.default_values) | |
| let l:value= self.config.default_values[l:key] | |
| let l:cmdopt= substitute(l:cmdopt, printf('#{%s}', l:key), l:value, 'g') | |
| endfor | |
| let a:session.config.cmdopt= l:cmdopt | |
| endfunction | |
| function! s:hook.on_output(session, context) | |
| let a:context.data= substitute(a:context.data, '\r', '', 'g') | |
| endfunction | |
| function! s:hook.on_finish(session, context) | |
| " XXX: for debug | |
| " call a:session.output(string(a:session.config)) | |
| endfunction | |
| function! quickrun#hook#psqlconfig#new() | |
| return deepcopy(s:hook) | |
| endfunction | |
| let &cpo = s:save_cpo | |
| unlet s:save_cpo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment