Skip to content

Commit c666f7d

Browse files
committed
fix: ensure gist with EOL
1 parent 3c22baa commit c666f7d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

autoload/gist.vim

+13-3
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,15 @@ function! s:GistListAction(mode) abort
534534
endif
535535
endfunction
536536

537+
func s:fix_eol(content) abort
538+
let s = a:content
539+
let lastchar=char2nr(s[-1:])
540+
if lastchar != 10
541+
let s.="\n"
542+
endif
543+
return s
544+
endfunc
545+
537546
function! s:GistUpdate(content, gistid, gistnm, desc) abort
538547
let gist = { 'id': a:gistid, 'files' : {}, 'description': '','public': function('webapi#json#true') }
539548
if exists('b:gist')
@@ -569,7 +578,8 @@ function! s:GistUpdate(content, gistid, gistnm, desc) abort
569578
endif
570579
endif
571580

572-
let gist.files[filename] = { 'content': a:content, 'filename': filename }
581+
let content = s:fix_eol(a:content)
582+
let gist.files[filename] = { 'content': content, 'filename': filename }
573583

574584
redraw | echon 'Updating gist... '
575585
let res = webapi#http#post(g:gist_api_url.'gists/' . a:gistid,
@@ -663,7 +673,7 @@ function! s:GistPost(content, private, desc, anonymous) abort
663673
if a:desc !=# ' ' | let gist['description'] = a:desc | endif
664674
if a:private | let gist['public'] = function('webapi#json#false') | endif
665675
let filename = s:get_current_filename(1)
666-
let gist.files[filename] = { 'content': a:content, 'filename': filename }
676+
let gist.files[filename] = { 'content': s:fix_eol(a:content), 'filename': filename }
667677

668678
let header = {'Content-Type': 'application/json'}
669679
if !a:anonymous
@@ -714,7 +724,7 @@ function! s:GistPostBuffers(private, desc, anonymous) abort
714724
endif
715725
echo 'Creating gist content'.index.'... '
716726
silent! exec 'buffer!' bufnr
717-
let content = join(getline(1, line('$')), "\n")
727+
let content = s:fix_eol(join(getline(1, line('$')), "\n"))
718728
let filename = s:get_current_filename(index)
719729
let gist.files[filename] = { 'content': content, 'filename': filename }
720730
let index = index + 1

0 commit comments

Comments
 (0)