mattn / vim-gist

Vim plugin for Gist
http://www.vim.org/scripts/script.php?script_id=2423
1.69k stars 131 forks source link

Feature request: async support #202

Open chemzqm opened 8 years ago

chemzqm commented 8 years ago

I have a slow network with github.com in China, it would be great if this plugin support async feature if possible.

Both vim and neovim could support async process now.

jalcine commented 8 years ago

@chemzqm commented on Feb 21, 2016, 5:34 AM PST:

I have a slow network with github.com in China, it would be great if this plugin support async feature if possible.

Both vim and neovim could support async process now.

This would require support in webapi-vim for asynchronous networking (for it to be fully transparent). @mattn, does that make sense?

mattn commented 8 years ago

@jalcine right. but the async with only vim script is harder to implement. it's easy to use external command like below.

let job = job_start(["gist", "/tmp/gistXXXXX"], {"callback": "GistDone"})

But job-control feature is still experimental. And remote_expr() works only on Windows or X11 environment.

wsdjeg commented 8 years ago

@chemzqm I am working on an lib Github-api.vim, I just impl the api of gist, but there are some issues. here is my two func for create gist.

""
" @public
" Create a gist
"
" POST : /gists
" Input: >
"    {
"      "description": "the description for this gist",
"      "public": true,
"      "files": {
"        "file1.txt": {
"          "content": "String file contents"
"        }
"      }
"    }
" <
function! githubapi#gist#Create(desc,filename,content,public,user,password) abort
    let data = {}
    let data.description = a:desc
    let data.public = a:public
    call extend(data, {'files': {a:filename : {'content' :a:content}}})
    return githubapi#util#Get('gists', " -d '" . json_encode(data) . "' -X POST -u " . a:user . ':' .a:password)
endfunction
function! githubapi#util#Get(url,args) abort
    let cmd = 'curl -s "' .g:githubapi_root_url . a:url . '"'
    if !empty(a:args)
        let cmd = cmd . a:args
    endif
    call githubapi#util#log('util#Get cmd : ' . cmd)
    let result = join(systemlist(cmd),"\n")
    return empty(result) ? result : json_decode(result)
endfunction

if I run

echo githubapi#gist#Create('test create','test.text','hello word','true','wsdjeg','mypassword').html_url 

then I can see the url of the created gist. but if I run

echo githubapi#gist#Create('test create','test.text',join(getline(1,'$'), "\n"),'true','wsdjeg','mypassword').html_url

I get a lot of error.