Skip to content

Instantly share code, notes, and snippets.

@h14i
Created October 2, 2014 11:17
Show Gist options
  • Save h14i/12e4f9dfd7fb8877f0e1 to your computer and use it in GitHub Desktop.
Save h14i/12e4f9dfd7fb8877f0e1 to your computer and use it in GitHub Desktop.
A ref source for codic
" ref-codic.vim - A ref source for codic.
" ref-codic.vim is inspired by unite-codic.vim <https://github.com/rhysd/unite-codic.vim>
" Version: 0.0.1
" Author : h14i <hayato.tsukagoshi@gmail.com>
" License: Public domain
"
" Requirements:
" ref.vim <https://github.com/thinca/vim-ref/>
" codic.vim <https://github.com/koron/codic-vim/>
let s:cpo = &cpo
set cpo&vim
if !exists(':Codic')
echohl ErrorMsg
echomsg 'Not found codic.vim'
echohl None
finish
endif
let g:ref_codic_search_limit = get(g:, 'ref_codic_search_limit', 100)
let s:source = {'name': 'codic'}
function! s:source.available()
return exists(':Codic')
endfunction
function! s:source.get_body(query)
if len(a:query) == 0
return ''
endif
let result = codic#search(a:query, get(g:, 'ref_codic_search_limit', 100))
if len(result) == 0
return ''
endif
let body = []
for item in result
call add(body, '[' . item.label . ']')
for value in item.values
call add(body, printf(' %s %s', value.word, value.desc))
endfor
endfor
return body
endfunction
function! s:source.complete(query)
return codic#complete(a:query, '', '')
endfunction
function! s:source.opened(query)
call s:syntax()
endfunction
function! s:syntax()
if exists('b:current_syntax') && b:current_syntax ==# 'ref-codic'
return
endif
syntax clear
syntax match refCodicHeader /^\[\p\+\]$/
highlight default link refCodicHeader Type
let b:current_syntax = 'ref-codic'
endfunction
function! ref#codic#define()
return copy(s:source)
endfunction
" call ref#register_detection('', 'codic')
let &cpo = s:cpo
unlet s:cpo
" vim:ft=vim:sts=2:sw=2:et:fdm=marker:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment