Skip to content
This repository has been archived by the owner on Aug 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #57 from lambdalisue/hotfix/write_related_critical…
Browse files Browse the repository at this point in the history
…_issues

Fix Gista post/patch, on_BufWriteCmd, and on_FileWriteCmd
  • Loading branch information
lambdalisue committed Jan 17, 2016
2 parents e6c5290 + 9fd192e commit a0f472a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
10 changes: 8 additions & 2 deletions autoload/gista/autocmd.vim
Expand Up @@ -79,9 +79,12 @@ function! s:on_BufWriteCmd(gista) abort
\)
return
endif
let filename = a:gista.filename
let content = gista#util#ensure_eol(join(getline(1, '$'), "\n"))
let gist = gista#command#patch#call({
\ '__range__': [line('1'), line('$')],
\ 'gistid': a:gista.gistid,
\ 'filenames': [filename],
\ 'contents': [{ 'content': content }],
\ 'force': v:cmdbang,
\})
if empty(gist)
Expand Down Expand Up @@ -113,9 +116,12 @@ function! s:on_FileWriteCmd(gista) abort
\)
return
endif
let filename = a:gista.filename
let content = gista#util#ensure_eol(join(getline("'[", "']"), "\n"))
let gist = gista#command#patch#call({
\ '__range__': [line("'["), line("']")],
\ 'gistid': a:gista.gistid,
\ 'filenames': [filename],
\ 'contents': [{ 'content': content }],
\ 'force': v:cmdbang,
\})
if empty(gist)
Expand Down
14 changes: 6 additions & 8 deletions autoload/gista/command/patch.vim
Expand Up @@ -9,9 +9,7 @@ function! s:get_content(expr) abort
\ ? getbufline(a:expr, 1, '$')
\ : readfile(a:expr),
\ "\n")
let content = content =~# '\r?\n$'
\ ? content
\ : content . "\n"
let content = gista#util#ensure_eol(content)
return { 'content': content }
endfunction

Expand All @@ -29,9 +27,10 @@ function! gista#command#patch#call(...) abort
\)
let gist = gista#resource#remote#patch(gistid, options)
if index(options.filenames, expand('%:t'))
let filename = fnamemodify(gista#option#guess_filename('%'), ':t')
let bufname = gista#command#open#bufname({
\ 'gistid': gistid,
\ 'filename': expand('%:t'),
\ 'filename': filename,
\})
silent execute printf('file %s', bufname)
endif
Expand Down Expand Up @@ -93,10 +92,9 @@ function! gista#command#patch#command(...) abort
let filename = empty(filename)
\ ? 'gista-file'
\ : filename
let content = join(call('getline', options.__range__), "\n")
let content = content =~# '\r?\n$'
\ ? content
\ : content . "\n"
let content = gista#util#ensure_eol(
\ join(call('getline', options.__range__), "\n")
\)
let options.filenames = [filename]
let options.contents = [{ 'content': content }]
else
Expand Down
14 changes: 6 additions & 8 deletions autoload/gista/command/post.vim
Expand Up @@ -9,9 +9,7 @@ function! s:get_content(expr) abort
\ ? getbufline(a:expr, 1, '$')
\ : readfile(a:expr),
\ "\n")
let content = content =~# '\r?\n$'
\ ? content
\ : content . "\n"
let content = gista#util#ensure_eol(content)
return { 'content': content }
endfunction
function! s:interactive_description(options) abort
Expand Down Expand Up @@ -50,9 +48,10 @@ function! gista#command#post#call(...) abort
\)
let client = gista#client#get()
if index(options.filenames, expand('%:t'))
let filename = fnamemodify(gista#option#guess_filename('%'), ':t')
let bufname = gista#command#open#bufname({
\ 'gistid': gist.id,
\ 'filename': expand('%:t'),
\ 'filename': filename,
\})
silent execute printf('file %s', bufname)
endif
Expand Down Expand Up @@ -118,10 +117,9 @@ function! gista#command#post#command(...) abort
let filename = empty(filename)
\ ? 'gista-file'
\ : filename
let content = join(call('getline', options.__range__), "\n")
let content = content =~# '\r?\n$'
\ ? content
\ : content . "\n"
let content = gista#util#ensure_eol(
\ join(call('getline', options.__range__), "\n")
\)
let options.filenames = [filename]
let options.contents = [{ 'content': content }]
else
Expand Down

0 comments on commit a0f472a

Please sign in to comment.