mirror of
https://github.com/tpope/vim-rhubarb.git
synced 2025-12-08 13:04:45 +08:00
Use camel case for public functions
This commit is contained in:
@@ -23,7 +23,7 @@ function! s:shellesc(arg) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! rhubarb#homepage_for_url(url) abort
|
function! rhubarb#HomepageForUrl(url) abort
|
||||||
let domain_pattern = 'github\.com'
|
let domain_pattern = 'github\.com'
|
||||||
let domains = get(g:, 'github_enterprise_urls', get(g:, 'fugitive_github_domains', []))
|
let domains = get(g:, 'github_enterprise_urls', get(g:, 'fugitive_github_domains', []))
|
||||||
call map(copy(domains), 'substitute(v:val, "/$", "", "")')
|
call map(copy(domains), 'substitute(v:val, "/$", "", "")')
|
||||||
@@ -40,6 +40,10 @@ function! rhubarb#homepage_for_url(url) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! rhubarb#homepage_for_url(url) abort
|
||||||
|
return rhubarb#HomepageForUrl(a:url)
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:repo_homepage() abort
|
function! s:repo_homepage() abort
|
||||||
if exists('b:rhubarb_homepage')
|
if exists('b:rhubarb_homepage')
|
||||||
return b:rhubarb_homepage
|
return b:rhubarb_homepage
|
||||||
@@ -49,7 +53,7 @@ function! s:repo_homepage() abort
|
|||||||
else
|
else
|
||||||
let remote = fugitive#repo().config('remote.origin.url')
|
let remote = fugitive#repo().config('remote.origin.url')
|
||||||
endif
|
endif
|
||||||
let homepage = rhubarb#homepage_for_url(remote)
|
let homepage = rhubarb#HomepageForUrl(remote)
|
||||||
if !empty(homepage)
|
if !empty(homepage)
|
||||||
let b:rhubarb_homepage = homepage
|
let b:rhubarb_homepage = homepage
|
||||||
return b:rhubarb_homepage
|
return b:rhubarb_homepage
|
||||||
@@ -78,7 +82,7 @@ function! s:credentials() abort
|
|||||||
return g:github_user.':'.g:github_password
|
return g:github_user.':'.g:github_password
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! rhubarb#json_parse(string) abort
|
function! rhubarb#JsonDecode(string) abort
|
||||||
if exists('*json_decode')
|
if exists('*json_decode')
|
||||||
return json_decode(a:string)
|
return json_decode(a:string)
|
||||||
endif
|
endif
|
||||||
@@ -93,18 +97,18 @@ function! rhubarb#json_parse(string) abort
|
|||||||
call s:throw("invalid JSON: ".a:string)
|
call s:throw("invalid JSON: ".a:string)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! rhubarb#json_generate(object) abort
|
function! rhubarb#JsonEncode(object) abort
|
||||||
if exists('*json_encode')
|
if exists('*json_encode')
|
||||||
return json_encode(a:object)
|
return json_encode(a:object)
|
||||||
endif
|
endif
|
||||||
if type(a:object) == type('')
|
if type(a:object) == type('')
|
||||||
return '"' . substitute(a:object, "[\001-\031\"\\\\]", '\=printf("\\u%04x", char2nr(submatch(0)))', 'g') . '"'
|
return '"' . substitute(a:object, "[\001-\031\"\\\\]", '\=printf("\\u%04x", char2nr(submatch(0)))', 'g') . '"'
|
||||||
elseif type(a:object) == type([])
|
elseif type(a:object) == type([])
|
||||||
return '['.join(map(copy(a:object), 'rhubarb#json_generate(v:val)'),', ').']'
|
return '['.join(map(copy(a:object), 'rhubarb#JsonEncode(v:val)'),', ').']'
|
||||||
elseif type(a:object) == type({})
|
elseif type(a:object) == type({})
|
||||||
let pairs = []
|
let pairs = []
|
||||||
for key in keys(a:object)
|
for key in keys(a:object)
|
||||||
call add(pairs, rhubarb#json_generate(key) . ': ' . rhubarb#json_generate(a:object[key]))
|
call add(pairs, rhubarb#JsonEncode(key) . ': ' . rhubarb#JsonEncode(a:object[key]))
|
||||||
endfor
|
endfor
|
||||||
return '{' . join(pairs, ', ') . '}'
|
return '{' . join(pairs, ', ') . '}'
|
||||||
else
|
else
|
||||||
@@ -138,7 +142,7 @@ function! s:curl_arguments(path, ...) abort
|
|||||||
call extend(args, ['-H', header])
|
call extend(args, ['-H', header])
|
||||||
endfor
|
endfor
|
||||||
if type(get(options, 'data', '')) != type('')
|
if type(get(options, 'data', '')) != type('')
|
||||||
call extend(args, ['-d', rhubarb#json_generate(options.data)])
|
call extend(args, ['-d', rhubarb#JsonEncode(options.data)])
|
||||||
elseif has_key(options, 'data')
|
elseif has_key(options, 'data')
|
||||||
call extend(args, ['-d', options.data])
|
call extend(args, ['-d', options.data])
|
||||||
endif
|
endif
|
||||||
@@ -146,7 +150,7 @@ function! s:curl_arguments(path, ...) abort
|
|||||||
return args
|
return args
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! rhubarb#request(path, ...) abort
|
function! rhubarb#Request(path, ...) abort
|
||||||
if !executable('curl')
|
if !executable('curl')
|
||||||
call s:throw('cURL is required')
|
call s:throw('cURL is required')
|
||||||
endif
|
endif
|
||||||
@@ -169,33 +173,45 @@ function! rhubarb#request(path, ...) abort
|
|||||||
if raw ==# ''
|
if raw ==# ''
|
||||||
return raw
|
return raw
|
||||||
else
|
else
|
||||||
return rhubarb#json_parse(raw)
|
return rhubarb#JsonDecode(raw)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! rhubarb#request(...) abort
|
||||||
|
return call('rhubarb#Request', a:000)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! rhubarb#RepoRequest(...) abort
|
||||||
|
return rhubarb#Request('repos/%s' . (a:0 && a:1 !=# '' ? '/' . a:1 : ''), a:0 > 1 ? a:2 : {})
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! rhubarb#repo_request(...) abort
|
function! rhubarb#repo_request(...) abort
|
||||||
return rhubarb#request('repos/%s' . (a:0 && a:1 !=# '' ? '/' . a:1 : ''), a:0 > 1 ? a:2 : {})
|
return call('rhubarb#RepoRequest', a:000)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:url_encode(str) abort
|
function! s:url_encode(str) abort
|
||||||
return substitute(a:str, '[?@=&<>%#/:+[:space:]]', '\=submatch(0)==" "?"+":printf("%%%02X", char2nr(submatch(0)))', 'g')
|
return substitute(a:str, '[?@=&<>%#/:+[:space:]]', '\=submatch(0)==" "?"+":printf("%%%02X", char2nr(submatch(0)))', 'g')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! rhubarb#repo_search(type, q) abort
|
function! rhubarb#RepoSearch(type, q) abort
|
||||||
return rhubarb#request('search/'.a:type.'?per_page=100&q=repo:%s'.s:url_encode(' '.a:q))
|
return rhubarb#Request('search/'.a:type.'?per_page=100&q=repo:%s'.s:url_encode(' '.a:q))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! rhubarb#repo_search(...) abort
|
||||||
|
return call('rhubarb#RepoSearch', a:000)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Section: Issues
|
" Section: Issues
|
||||||
|
|
||||||
let s:reference = '\<\%(\c\%(clos\|resolv\|referenc\)e[sd]\=\|\cfix\%(e[sd]\)\=\)\>'
|
let s:reference = '\<\%(\c\%(clos\|resolv\|referenc\)e[sd]\=\|\cfix\%(e[sd]\)\=\)\>'
|
||||||
function! rhubarb#omnifunc(findstart,base) abort
|
function! rhubarb#Complete(findstart, base) abort
|
||||||
if a:findstart
|
if a:findstart
|
||||||
let existing = matchstr(getline('.')[0:col('.')-1],s:reference.'\s\+\zs[^#/,.;]*$\|[#@[:alnum:]-]*$')
|
let existing = matchstr(getline('.')[0:col('.')-1],s:reference.'\s\+\zs[^#/,.;]*$\|[#@[:alnum:]-]*$')
|
||||||
return col('.')-1-strlen(existing)
|
return col('.')-1-strlen(existing)
|
||||||
endif
|
endif
|
||||||
try
|
try
|
||||||
if a:base =~# '^@'
|
if a:base =~# '^@'
|
||||||
return map(rhubarb#repo_request('collaborators'), '"@".v:val.login')
|
return map(rhubarb#RepoRequest('collaborators'), '"@".v:val.login')
|
||||||
else
|
else
|
||||||
if a:base =~# '^#'
|
if a:base =~# '^#'
|
||||||
let prefix = '#'
|
let prefix = '#'
|
||||||
@@ -204,7 +220,7 @@ function! rhubarb#omnifunc(findstart,base) abort
|
|||||||
let prefix = s:repo_homepage().'/issues/'
|
let prefix = s:repo_homepage().'/issues/'
|
||||||
let query = a:base
|
let query = a:base
|
||||||
endif
|
endif
|
||||||
let response = rhubarb#repo_search('issues', 'state:open '.query)
|
let response = rhubarb#RepoSearch('issues', 'state:open '.query)
|
||||||
if type(response) != type({})
|
if type(response) != type({})
|
||||||
call s:throw('unknown error')
|
call s:throw('unknown error')
|
||||||
elseif has_key(response, 'message')
|
elseif has_key(response, 'message')
|
||||||
@@ -221,9 +237,13 @@ function! rhubarb#omnifunc(findstart,base) abort
|
|||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! rhubarb#omnifunc(findstart, base) abort
|
||||||
|
return rhubarb#Complete(a:findstart, a:base)
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Section: Fugitive :Gbrowse support
|
" Section: Fugitive :Gbrowse support
|
||||||
|
|
||||||
function! rhubarb#fugitive_url(opts, ...) abort
|
function! rhubarb#FugitiveUrl(opts, ...) abort
|
||||||
if a:0 || type(a:opts) != type({})
|
if a:0 || type(a:opts) != type({})
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
@@ -262,3 +282,9 @@ function! rhubarb#fugitive_url(opts, ...) abort
|
|||||||
endif
|
endif
|
||||||
return url
|
return url
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! rhubarb#fugitive_url(...) abort
|
||||||
|
return call('rhubarb#FugitiveUrl', a:000)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Section: End
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ augroup rhubarb
|
|||||||
\ exists('+omnifunc') &&
|
\ exists('+omnifunc') &&
|
||||||
\ &omnifunc =~# '^\%(syntaxcomplete#Complete\)\=$' &&
|
\ &omnifunc =~# '^\%(syntaxcomplete#Complete\)\=$' &&
|
||||||
\ !empty(filter(s:Config(),
|
\ !empty(filter(s:Config(),
|
||||||
\ '!empty(rhubarb#homepage_for_url(matchstr(v:val, ''^\s*url\s*=\s*"\=\zs\S*'')))')) |
|
\ '!empty(rhubarb#HomepageForUrl(matchstr(v:val, ''^\s*url\s*=\s*"\=\zs\S*'')))')) |
|
||||||
\ setlocal omnifunc=rhubarb#omnifunc |
|
\ setlocal omnifunc=rhubarb#Complete |
|
||||||
\ endif
|
\ endif
|
||||||
autocmd BufEnter *
|
autocmd BufEnter *
|
||||||
\ if expand('%') ==# '' && &previewwindow && pumvisible() && getbufvar('#', '&omnifunc') ==# 'rhubarb#omnifunc' |
|
\ if expand('%') ==# '' && &previewwindow && pumvisible() && getbufvar('#', '&omnifunc') ==# 'rhubarb#omnifunc' |
|
||||||
@@ -50,6 +50,6 @@ if !exists('g:fugitive_browse_handlers')
|
|||||||
let g:fugitive_browse_handlers = []
|
let g:fugitive_browse_handlers = []
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if index(g:fugitive_browse_handlers, function('rhubarb#fugitive_url')) < 0
|
if index(g:fugitive_browse_handlers, function('rhubarb#FugitiveUrl')) < 0
|
||||||
call insert(g:fugitive_browse_handlers, function('rhubarb#fugitive_url'))
|
call insert(g:fugitive_browse_handlers, function('rhubarb#FugitiveUrl'))
|
||||||
endif
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user