Created
October 10, 2010 16:43
-
-
Save mmisono/619370 to your computer and use it in GitHub Desktop.
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
" A ref source for GNOME References | |
" Version: 0.0.1 | |
" Author : mfumi <[email protected]> | |
" : thinca <[email protected]> | |
" License: Creative Commons Attribution 2.1 Japan License | |
" <http://creativecommons.org/licenses/by/2.1/jp/deed.en> | |
let s:save_cpo = &cpo | |
set cpo&vim | |
" options. {{{1 | |
if !exists('g:ref_gnome_cmd') "{{{2 | |
let g:ref_gnome_cmd = | |
\ executable('elinks') ? 'elinks -dump -no-numbering -no-references %s' : | |
\ executable('w3m') ? 'w3m -dump %s' : | |
\ executable('links') ? 'links -dump %s' : | |
\ executable('lynx') ? 'lynx -dump -nonumbers %s' : | |
\ '' | |
endif "}}} | |
if !exists('g:ref_gnome_doc_dir') "{{{2 | |
let g:ref_gnome_doc_dir= "" | |
endif "}}} | |
if !exists('g:ref_gnome_use_cache') "{{{2 | |
let g:ref_gnome_use_cache = 0 | |
endif "}}} | |
let s:prev_query = "" | |
let s:is_searching = 0 | |
"}}} | |
let s:source = {'name': 'gnome'} " {{{1 | |
function! s:source.available() " {{{2 | |
return !empty(g:ref_gnome_cmd) && !empty(g:ref_gnome_doc_dir) | |
endfunction "}}} | |
function! s:source.get_body(query) " {{{2 | |
if type(g:ref_gnome_cmd) == type('') | |
let cmd = split(g:ref_gnome_cmd, '\s\+') | |
elseif type(g:ref_gnome_cmd) == type([]) | |
let cmd = copy(g:ref_gnome_cmd) | |
else | |
return '' | |
endif | |
" try by name | |
if a:query == "" | |
if has('win32' || 'win64') | |
let doc = g:ref_gnome_doc_dir.'\'.'index.html' | |
else | |
let doc = g:ref_gnome_doc_dir.'/'.'index.html' | |
endif | |
else | |
if has('win32' || 'win64') | |
let doc = g:ref_gnome_doc_dir.'\'.a:query.'.html' | |
else | |
let doc = g:ref_gnome_doc_dir.'/'.a:query.'.html' | |
endif | |
endif | |
if filereadable(doc) | |
call map(cmd, 'substitute(v:val, "%s", doc, "g")') | |
else | |
let ack_cmd = 'ack -l '.a:query.' '.g:ref_gnome_doc_dir | |
let files = split(system(ack_cmd),('\n')) | |
if len(files) == 0 | |
return '' | |
elseif len(files) == 1 | |
call map(cmd, 'substitute(v:val, "%s", files[0], "g")') | |
else | |
let res = "Find :\n" | |
let files = map(files,'substitute(v:val,g:ref_gnome_doc_dir."[/\]\\?","","g")') | |
let files = map(files,'substitute(v:val,".html$","","g")') | |
let res .= join(files,"\n")."\n" | |
let s:prev_query = a:query | |
let s:is_searching = 1 | |
return res | |
endif | |
endif | |
if g:ref_gnome_use_cache | |
let expr = 'ref#system(' . string(cmd) . ').stdout' | |
let res = join(ref#cache('gnome', a:query, expr), "\n") | |
else | |
let res = ref#system(cmd).stdout | |
endif | |
let s:is_searching = 0 | |
return res | |
endfunction "}}} | |
function! s:source.opened(query) " {{{2 | |
if s:is_searching == 0 | |
if s:prev_query != "" | |
call search('^'.s:prev_query) | |
let s:prev_query = "" | |
else | |
call search('^'.a:query) | |
endif | |
endif | |
normal! zt | |
runtime! syntax/glib.vim | |
runtime! syntax/gobject.vim | |
runtime! syntax/gdk.vim | |
runtime! syntax/gdkpixbuf.vim | |
runtime! syntax/gtk.vim | |
runtime! syntax/cairo.vim | |
endfunction " }}} | |
function! s:source.normalize(query) " {{{2 | |
return substitute(substitute(a:query, '\_s\+', ' ', 'g'), '^ \| $', '', 'g') | |
endfunction | |
function! s:source.get_keyword() | |
if getline(1) =~ 'Find' | |
return expand('<cWORD>') | |
else | |
return expand('<cword>') | |
endif | |
endfunction " }}} | |
function! ref#gnome#define() " {{{2 | |
return s:source | |
endfunction "}}} | |
"}}} | |
let &cpo = s:save_cpo | |
unlet s:save_cpo | |
"vim:foldmethod=marker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment