Skip to content

Commit

Permalink
fix: ensure gist with EOL
Browse files Browse the repository at this point in the history
  • Loading branch information
allex committed May 18, 2022
1 parent 3c22baa commit c666f7d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions autoload/gist.vim
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,15 @@ 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') }
if exists('b:gist')
Expand Down Expand Up @@ -569,7 +578,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,
Expand Down Expand Up @@ -663,7 +673,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
Expand Down Expand Up @@ -714,7 +724,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
Expand Down

0 comments on commit c666f7d

Please sign in to comment.