Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8045f9c

Browse files
fix(formatters: autopep8): remove redundant try/catch
1 parent 26c1d9b commit 8045f9c

File tree

1 file changed

+9
-31
lines changed

1 file changed

+9
-31
lines changed

‎autoload/codefmt.vim‎

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ if !exists('s:autopep8')
162162
let s:autopep8 = {
163163
\ 'name': 'autopep8',
164164
\ 'setup_instructions': 'Install autopep8 ' .
165-
\ '(https://pypi.python.org/pypi/autopep8/).'}
165+
\ '(https://pypi.python.org/pypi/autopep8/).'}
166166

167167
function s:autopep8.IsAvailable() abort
168168
return executable(s:plugin.Flag('autopep8_executable'))
@@ -172,53 +172,31 @@ if !exists('s:autopep8')
172172
return &filetype is# 'python'
173173
endfunction
174174

175-
176175
""
177176
" Reformat the current buffer with autopep8 or the binary named in
178177
" @flag(autopep8_executable), only targeting the range between {startline} and
179178
" {endline}.
179+
" @throws ShellError
180180
function s:autopep8.FormatRange(startline, endline) abort
181181
" Hack range formatting by formatting range individually, ignoring context.
182182
let l:cmd = [ s:plugin.Flag('autopep8_executable'), "-" ]
183183
call maktaba#ensure#IsNumber(a:startline)
184184
call maktaba#ensure#IsNumber(a:endline)
185185
let l:lines = getline(1, line('$'))
186186
let l:input = join(l:lines[a:startline - 1 : a:endline - 1], "\n")
187-
try
188-
let l:result = maktaba#syscall#Create(l:cmd).WithStdin(l:input).Call()
189-
let l:formatted = split(l:result.stdout, "\n")
190-
" Special case empty slice: neither l:lines[:0] nor l:lines[:-1] is right.
191-
let l:before = a:startline > 1 ? l:lines[ : a:startline - 2] : []
192187

193-
let l:full_formatted = l:before + l:formatted + l:lines[a:endline :]
194-
call maktaba#buffer#Overwrite(1, line('$'), l:full_formatted)
195-
catch /ERROR(ShellError):/
196-
" Parse all the errors and stick them in the quickfix list.
197-
let l:errors = []
198-
for l:line in split(v:exception, "\n")
199-
let l:tokens = matchlist(l:line,
200-
\ '\C\v^\<standard input\>:(\d+):(\d+):\s*(.*)')
201-
if !empty(l:tokens)
202-
call add(l:errors, {
203-
\ 'filename': @%,
204-
\ 'lnum': l:tokens[1] + a:startline - 1,
205-
\ 'col': l:tokens[2],
206-
\ 'text': l:tokens[3]})
207-
endif
208-
endfor
188+
let l:result = maktaba#syscall#Create(l:cmd).WithStdin(l:input).Call()
189+
let l:formatted = split(l:result.stdout, "\n")
190+
" Special case empty slice: neither l:lines[:0] nor l:lines[:-1] is right.
191+
let l:before = a:startline > 1 ? l:lines[ : a:startline - 2] : []
209192

210-
if empty(l:errors)
211-
" Couldn't parse autopep8 error format; display it all.
212-
call maktaba#error#Shout('Error formatting file: %s', v:exception)
213-
else
214-
call setqflist(l:errors, 'r')
215-
cc 1
216-
endif
217-
endtry
193+
let l:full_formatted = l:before + l:formatted + l:lines[a:endline :]
194+
call maktaba#buffer#Overwrite(1, line('$'), l:full_formatted)
218195
endfunction
219196

220197
call codefmtlib#AddDefaultFormatter(s:autopep8)
221198
endif
199+
222200
""
223201
" Detects whether a formatter has been defined for the current buffer/filetype.
224202
function! codefmt#IsFormatterAvailable() abort

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /