Skip to content

Commit

Permalink
Merge pull request #44 from blp1526/refactoring
Browse files Browse the repository at this point in the history
Clean storage#read()
  • Loading branch information
blp1526 authored Nov 3, 2016
2 parents c924dd3 + a0b2741 commit a584def
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions autoload/storage.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,14 @@ function! storage#read(cmd, path, dict) abort
silent execute 'normal ggdd'
silent execute 'filetype detect'
else
let current_errorformat = &errorformat
let &errorformat = storage#errorformat()
let ls_result = storage#ls_cmd(a:cmd, a:path)
let ls_result_array = split(ls_result, "\n")
call map(ls_result_array, 'storage#errorformatted_string(v:val)')
setlocal nomodified
call storage#open_quickfix(ls_result_array)
let &errorformat = current_errorformat
let ls_result = storage#ls_cmd(a:cmd, a:path)
call storage#open_quickfix(ls_result)
endif
catch
endtry
endfunction

function! storage#open_quickfix(array) abort
cgete join(a:array, "\n")
copen
endfunction

function! storage#last_string(str) abort
let last_index = strchars(a:str) - 1
return a:str[last_index]
endfunction

function! storage#errorformat() abort
return '%f(%l\,%c):%m'
endfunction

function! storage#errorformatted_string(val) abort
let array = split(a:val)
let file = array[(len(array) - 1)]
let line_column = '(1,1):'
let message = array[(len(array) - 2)]
return (file . line_column . message)
endfunction

function! storage#write(cmd, dict, path) abort
let tempfile = a:dict[a:path]
let current_hidden = &hidden
Expand All @@ -71,6 +44,33 @@ function! storage#write(cmd, dict, path) abort
let &hidden = current_hidden
endfunction

function! storage#open_quickfix(ls_result) abort
let current_errorformat = &errorformat
let &errorformat = storage#errorformat()
let ls_result_array = split(a:ls_result, "\n")
call map(ls_result_array, 'storage#errorformatted_string(v:val)')
cgete join(ls_result_array, "\n")
copen
let &errorformat = current_errorformat
endfunction

function! storage#last_string(str) abort
let last_index = strchars(a:str) - 1
return a:str[last_index]
endfunction

function! storage#errorformat() abort
return '%f(%l\,%c):%m'
endfunction

function! storage#errorformatted_string(val) abort
let array = split(a:val)
let file = array[(len(array) - 1)]
let line_column = '(1,1):'
let message = array[(len(array) - 2)]
return (file . line_column . message)
endfunction

function! storage#current_line_string() abort
return getline('.')
endfunction
Expand Down

0 comments on commit a584def

Please sign in to comment.