Created
June 26, 2017 12:27
-
-
Save Nimlar/6492fc53c8dc828771db83f774dcc021 to your computer and use it in GitHub Desktop.
vimscript to search in elixir db
This file contains 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
function! s:PrepareEnv() | |
let $LXR_DATA_DIR="~/git/linux.db" | |
let $LXR_REPO_DIR="~/git/linux/" | |
let s:git_dir = getcwd() | |
let s:tag = system("git describe --tags --abbrev=0") | |
if v:shell_error | |
return v:shell_error | |
endif | |
let s:tag = split(s:tag, '\n') | |
let s:tag =s:tag[0] | |
return 0 | |
endfunction | |
function! MakeLxrLocationList(id) | |
if s:PrepareEnv() | |
echoerr "Not in a git directory: ".getpwd() | |
endif | |
echo s:Redir(":pwd") | |
let bufListTxt = s:Redir("!~/dev/elixir/query.py ident " . s:tag . " " . a:id . " def_only" ) | |
let bufListLines = split(bufListTxt, "\r\n") | |
let bufListLines = bufListLines[2:] | |
let bufLocList = s:MakeBufLocList(bufListLines, "") | |
call setloclist(0, bufLocList, ' ') | |
lwindow | |
endfunction | |
" Buffer List | |
function! s:MakeBufLocList(bufListLines, pattern) | |
let locList = [] | |
for lineTxt in a:bufListLines | |
let elem = split(lineTxt) | |
let locItem = {} | |
let locItem["filename"] = substitute(elem[0], ":$", "","") | |
let locItem["text"] = elem[2] | |
for linenb in split(elem[1], ",") | |
let locItem["lnum"] = str2nr(linenb) | |
call add(locList, locItem) | |
endfor | |
endfor | |
return locList | |
endfunction | |
"Capture long output of a comand into a variable. | |
function! s:Redir(cmd) | |
let output = "" | |
redir =>> output | |
silent exe a:cmd | |
redir END | |
return output | |
endfunction | |
nmap <silent> <leader>lxr :call MakeLxrLocationList(expand("<cword>"))<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment