Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions autoload/codefmt/isort.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
" Copyright 2020 Google Inc. All rights reserved.
"
" Licensed under the Apache License, Version 2.0 (the "License");
" you may not use this file except in compliance with the License.
" You may obtain a copy of the License at
"
" http://www.apache.org/licenses/LICENSE-2.0
"
" Unless required by applicable law or agreed to in writing, software
" distributed under the License is distributed on an "AS IS" BASIS,
" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
" See the License for the specific language governing permissions and
" limitations under the License.


let s:plugin = maktaba#plugin#Get('codefmt')


""
" @private
" Formatter: isort
function! codefmt#isort#GetFormatter() abort
let l:formatter = {
\ 'name': 'isort',
\ 'setup_instructions': 'Install isort ' .
\ '(https://pypi.python.org/pypi/isort/).'}

function l:formatter.IsAvailable() abort
return executable(s:plugin.Flag('isort_executable'))
endfunction

function l:formatter.AppliesToBuffer() abort
return &filetype is# 'python'
endfunction

""
" Reformat the current buffer with isort or the binary named in
" @flag(isort_executable)
"
" We implement Format(), and not FormatRange{,s}(), because isort doesn't
" provide a hook for formatting a range
function l:formatter.Format() abort
let l:executable = s:plugin.Flag('isort_executable')

call codefmt#formatterhelpers#Format([
\ l:executable,
\ '-'])
endfunction

return l:formatter
endfunction
4 changes: 4 additions & 0 deletions doc/codefmt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ Default: 'yapf' `
The path to the black executable.
Default: 'black' `

*codefmt:isort_executable*
The path to the isort executable.
Default: 'isort' `

*codefmt:gn_executable*
The path to the gn executable.
Default: 'gn' `
Expand Down
4 changes: 4 additions & 0 deletions instant/flags.vim
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ call s:plugin.Flag('yapf_executable', 'yapf')
" The path to the black executable.
call s:plugin.Flag('black_executable', 'black')

""
" The path to the isort executable.
call s:plugin.Flag('isort_executable', 'isort')

""
" The path to the gn executable.
call s:plugin.Flag('gn_executable', 'gn')
Expand Down
1 change: 1 addition & 0 deletions plugin/register.vim
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ call s:registry.AddExtension(codefmt#ktfmt#GetFormatter())
call s:registry.AddExtension(codefmt#luaformatterfiveone#GetFormatter())
call s:registry.AddExtension(codefmt#nixpkgs_fmt#GetFormatter())
call s:registry.AddExtension(codefmt#autopep8#GetFormatter())
call s:registry.AddExtension(codefmt#isort#GetFormatter())
call s:registry.AddExtension(codefmt#black#GetFormatter())
call s:registry.AddExtension(codefmt#yapf#GetFormatter())
call s:registry.AddExtension(codefmt#rustfmt#GetFormatter())
Expand Down