Last active
December 19, 2015 15:51
-
-
Save chemzqm/5d0225db599094159a58 to your computer and use it in GitHub Desktop.
location_list for unite
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
scriptencoding utf-8 | |
function! unite#sources#location_list#define() | |
return s:source | |
endfunction | |
let s:source = { | |
\ "name" : "location_list", | |
\ "description" : "output location_list", | |
\ "syntax" : "uniteSource__LocationList", | |
\ "hooks" : {}, | |
\} | |
function! s:location_list_to_unite(val) | |
let bufnr = a:val.bufnr | |
let fname = bufnr == 0 ? "" : bufname(bufnr) | |
let line = bufnr == 0 ? 0 : a:val.lnum | |
let col = bufnr == 0 ? 0 : a:val.col | |
let type = 'Warning' | |
if a:val.type ==? 'e' | |
let type = 'Error' | |
endif | |
let word = fname . '|' . line . ' col ' . col . ' ' . type . '| ' . a:val.text | |
return { | |
\ "word": word, | |
\ "source": "location_list", | |
\ "kind": a:val.valid ? ["common", "jump_list"] : ["common"], | |
\ "action__col" : col, | |
\ "action__buffer_nr" : bufnr, | |
\ "action__path" : fname, | |
\ "action__line" : line, | |
\ } | |
endfunction | |
function! s:source.gather_candidates(args, context) | |
let unite = get(b:, "unite", {}) | |
let winnr = get(unite, "prev_winnr", winnr()) | |
let lolder = empty(a:args) ? 0 : a:args[0] | |
if lolder == 0 | |
return map(getloclist(winnr), "s:location_list_to_unite(v:val)") | |
else | |
try | |
execute "lolder" lolder | |
return map(getloclist(winnr), "s:location_list_to_unite(v:val)") | |
finally | |
execute "lnewer" lolder | |
endtry | |
endif | |
endfunction | |
function! s:source.hooks.on_syntax(args, context) | |
syntax case ignore | |
syntax match uniteSource__LocationListHeader /^.*$/ | |
\ containedin=uniteSource__LocationList | |
syntax match uniteSource__LocationListName /\v^[^|]+/ contained | |
\ containedin=uniteSource__LocationListHeader | |
syntax match uniteSource__LocationListPosition /\v\|\zs.*\ze\|/ contained | |
\ containedin=uniteSource__LocationListHeader | |
highlight default link uniteSource__LocationListName Identifier | |
highlight default link uniteSource__LocationListPosition LineNr | |
endfunction | |
function! s:source.hooks.on_close(args, context) | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment