diff options
| author | mitermayer <mitermayer.reis@gmail.com> | 2018-05-04 12:48:20 -0700 |
|---|---|---|
| committer | mitermayer <mitermayer.reis@gmail.com> | 2019-08-25 21:11:49 -0700 |
| commit | f86d6a22e9a136b2af24056e689f24ef5c22e798 (patch) | |
| tree | eb099ebaeb91e9782a6d7d55c69b788adc983aa6 | |
| parent | 1886aca4c80081d14d911c7004df5f54d28ecfed (diff) | |
| download | vim-prettier-f86d6a22e9a136b2af24056e689f24ef5c22e798.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 |
