Skip to content

Instantly share code, notes, and snippets.

@tsukkee
Created October 20, 2010 14:22
Show Gist options
  • Select an option

  • Save tsukkee/636504 to your computer and use it in GitHub Desktop.

Select an option

Save tsukkee/636504 to your computer and use it in GitHub Desktop.
tags and tags/help sources for unite.vim
" tags, tags/help sources for unite.vim
" Version: 0.0.1
" Last Change: 20 Oct 2010
" Author: tsukkee <takayuki0510 at gmail.com>
" Licence: The MIT License {{{
" Permission is hereby granted, free of charge, to any person obtaining a copy
" of this software and associated documentation files (the "Software"), to deal
" in the Software without restriction, including without limitation the rights
" to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
" copies of the Software, and to permit persons to whom the Software is
" furnished to do so, subject to the following conditions:
"
" The above copyright notice and this permission notice shall be included in
" all copies or substantial portions of the Software.
"
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
" OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
" THE SOFTWARE.
" }}}
" define source
function! unite#sources#tags#define()
return [s:source_tags, s:source_tags_help]
endfunction
" tags
let s:source_tags = {
\ 'name': 'tags',
\ 'max_candidates': 30,
\ 'is_volatile': 1,
\ 'action_table': {},
\ 'default_action': {'word': 'lookup'}
\}
function! s:source_tags.gather_candidates(args, candidate)
return s:gather_candidates(0, a:args, a:candidate)
endfunction
let s:action_table_tags = {}
let s:action_table_tags.lookup = {
\ 'is_selectable': 1
\}
function! s:action_table_tags.lookup.func(candidate)
execute "tag" a:candidate.word
endfunction
let s:action_table_tags.jump = {
\ 'is_selectable': 1
\}
function! s:action_table_tags.jump.func(candidate)
execute "tjump" a:candidate.word
endfunction
let s:action_table_tags.select = {
\ 'is_selectable': 1
\}
function! s:action_table_tags.select.func(candidate)
execute "tselect" a:candidate.word
endfunction
let s:action_table_tags.split = {
\ 'is_selectable': 1
\}
function! s:action_table_tags.split.func(candidate)
execute "stjump" a:candidate.word
endfunction
let s:action_table_tags.preview = {
\ 'is_selectable': 1,
\ 'is_quit': 0
\}
function! s:action_table_tags.preview.func(candidate)
execute "ptjump" a:candidate.word
endfunction
let s:source_tags.action_table.word = s:action_table_tags
" tags/help
let s:source_tags_help = {
\ 'name': 'tags/help',
\ 'max_candidates': 30,
\ 'action_table': {},
\ 'default_action': {'word': 'lookup'}
\}
function! s:source_tags_help.gather_candidates(args, candidate)
return s:gather_candidates(1, a:args, a:candidate)
endfunction
let s:action_table_tags_help = {}
let s:action_table_tags_help.lookup = {
\ 'is_selectable': 1
\}
function! s:action_table_tags_help.lookup.func(candidate)
execute "help" a:candidate.word
endfunction
let s:source_tags_help.action_table.word = s:action_table_tags_help
" gather
function! s:gather_candidates(is_help, args, context)
let saved_buftype = &l:buftype
if a:is_help
let &l:buftype = "help"
endif
let result = []
let source_name = a:is_help ? 'tags/help' : 'tags'
let source_abbr = a:is_help ? '[help] ' : '[tag] '
for tagfile in s:unique(tagfiles())
for line in readfile(tagfile)
let [word, file] = split(line, "\t")[0:1]
if stridx(word, "!") != 0
call add(result, {
\ 'word': word,
\ 'abbr': source_abbr . word . (a:is_help ? '' : ' @' . file),
\ 'kind': 'word',
\ 'source': source_name,
\ 'is_insert': a:context.is_insert
\})
endif
endfor
endfor
let &l:buftype = saved_buftype
return result
endfunction
" unique
function! s:unique(array)
if len(a:array) <= 1
return a:array
endif
let sorted = sort(a:array)
let result = [sorted[0]]
for item in sorted
if item != result[-1]
call add(result, item)
endif
endfor
return result
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment