diff options
| author | mitermayer <mitermayer.reis@gmail.com> | 2018-05-04 12:48:20 -0700 |
|---|---|---|
| committer | mitermayer <mitermayer.reis@gmail.com> | 2018-05-04 12:48:20 -0700 |
| commit | 0feb9565771ed0210e45e7226edc6d8185a8ce4f (patch) | |
| tree | c5037a950f5446e1b49ef80d4bc1a6a24801051d | |
| parent | e3be094d12b56e3d1cb88e657267ae0702f3e376 (diff) | |
| download | vim-prettier-0feb9565771ed0210e45e7226edc6d8185a8ce4f.tar.xz | |
Creating buffer replace and save utils
| -rw-r--r-- | autoload/prettier/job/async/vim.vim | 12 | ||||
| -rw-r--r-- | autoload/prettier/utils/buffer.vim | 6 |
2 files changed, 8 insertions, 10 deletions
diff --git a/autoload/prettier/job/async/vim.vim b/autoload/prettier/job/async/vim.vim index 0fd8f6c..4db6522 100644 --- a/autoload/prettier/job/async/vim.vim +++ b/autoload/prettier/job/async/vim.vim @@ -50,7 +50,7 @@ function! s:onClose(channel, startSelection, endSelection, bufferName) abort if (bufloaded(str2nr(a:bufferName))) try silent exec 'sp '. escape(bufname(bufnr(a:bufferName)), ' \') - call s:formatAndSave(l:out, a:startSelection, a:endSelection) + call prettier#utils#buffer#replaceAndSave(l:out, a:startSelection, a:endSelection) catch call prettier#logging#error#log('PARSING_ERROR', a:bufferName) finally @@ -61,17 +61,9 @@ function! s:onClose(channel, startSelection, endSelection, bufferName) abort endtry endif else - call s:formatAndSave(l:out, a:startSelection, a:endSelection) + call prettier#utils#buffer#replaceAndSave(l:out, a:startSelection, a:endSelection) endif let s:prettier_job_running = 0 endif endfunction - -" TODO -" make the buffer replace method accerpt an extra arg to -" decide if it should save it or not and delete this method -function! s:formatAndSave(lines, start, end) abort - call prettier#utils#buffer#replace(a:lines, a:start, a:end) - write -endfunction diff --git a/autoload/prettier/utils/buffer.vim b/autoload/prettier/utils/buffer.vim index 06fd7ff..1e11ddb 100644 --- a/autoload/prettier/utils/buffer.vim +++ b/autoload/prettier/utils/buffer.vim @@ -18,6 +18,12 @@ function! prettier#utils#buffer#replace(lines, startSelection, endSelection) abo call winrestview(l:winview) endfunction +" Replace and save the buffer +function! prettier#utils#buffer#replaceAndSave(lines, startSelection, endSelection) abort + call prettier#utils#buffer#replace(a:lines, a:startSelection, a:endSelection) + write +endfunction + " Returns 1 if content has changed function! prettier#utils#buffer#willUpdatedLinesChangeBuffer(lines, start, end) abort return getbufline(bufnr('%'), 1, line('$')) == prettier#utils#buffer#createBufferFromUpdatedLines(a:lines, a:start, a:end) ? 0 : 1 |
