diff --git a/autoload/gist.vim b/autoload/gist.vim index 1b9f04a..e8b4c92 100644 --- a/autoload/gist.vim +++ b/autoload/gist.vim @@ -534,14 +534,22 @@ function! s:GistListAction(mode) abort endif endfunction +func s:fix_eol(content) abort + let s = a:content + let lastchar=char2nr(s[-1:]) + if lastchar != 10 + let s.="\n" + endif + return s +endfunc + function! s:GistUpdate(content, gistid, gistnm, desc) abort - let gist = { 'id': a:gistid, 'files' : {}, 'description': '','public': function('webapi#json#true') } + let gist = { 'files' : {}, 'description': '' } if exists('b:gist') if has_key(b:gist, 'filename') && len(a:gistnm) > 0 let gist.files[b:gist.filename] = { 'content': '', 'filename': b:gist.filename } let b:gist.filename = a:gistnm endif - if has_key(b:gist, 'private') && b:gist.private | let gist['public'] = function('webapi#json#false') | endif if has_key(b:gist, 'description') | let gist['description'] = b:gist.description | endif if has_key(b:gist, 'filename') | let filename = b:gist.filename | endif else @@ -569,7 +577,8 @@ function! s:GistUpdate(content, gistid, gistnm, desc) abort endif endif - let gist.files[filename] = { 'content': a:content, 'filename': filename } + let content = s:fix_eol(a:content) + let gist.files[filename] = { 'content': content, 'filename': filename } redraw | echon 'Updating gist... ' let res = webapi#http#post(g:gist_api_url.'gists/' . a:gistid, @@ -585,6 +594,9 @@ function! s:GistUpdate(content, gistid, gistnm, desc) abort redraw | echomsg 'Done: '.loc else let loc = '' + if len(res.message) == 0 + let res.message = res.content + endif echohl ErrorMsg | echomsg 'Post failed: ' . res.message | echohl None endif return loc @@ -637,6 +649,12 @@ function! s:update_GistID(id) abort call setline('.', line . ' ' . a:id) let ret = 1 endif + if search('\:\s*$') + let line = getline('.') + let line = substitute(line, '\s\+$', '', 'g') + call setline('.', line . ' https://gist.github.com/' . a:id) + let ret = 1 + endif call winrestview(view) return ret endfunction @@ -657,7 +675,7 @@ function! s:GistPost(content, private, desc, anonymous) abort if a:desc !=# ' ' | let gist['description'] = a:desc | endif if a:private | let gist['public'] = function('webapi#json#false') | endif let filename = s:get_current_filename(1) - let gist.files[filename] = { 'content': a:content, 'filename': filename } + let gist.files[filename] = { 'content': s:fix_eol(a:content), 'filename': filename } let header = {'Content-Type': 'application/json'} if !a:anonymous @@ -708,7 +726,7 @@ function! s:GistPostBuffers(private, desc, anonymous) abort endif echo 'Creating gist content'.index.'... ' silent! exec 'buffer!' bufnr - let content = join(getline(1, line('$')), "\n") + let content = s:fix_eol(join(getline(1, line('$')), "\n")) let filename = s:get_current_filename(index) let gist.files[filename] = { 'content': content, 'filename': filename } let index = index + 1