Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Commit cb7462c

Browse files
authored
Create isort.vim
1 parent f3a5dc7 commit cb7462c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

autoload/codefmt/isort.vim

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
" Copyright 2020 Google Inc. All rights reserved.
2+
"
3+
" Licensed under the Apache License, Version 2.0 (the "License");
4+
" you may not use this file except in compliance with the License.
5+
" You may obtain a copy of the License at
6+
"
7+
" http://www.apache.org/licenses/LICENSE-2.0
8+
"
9+
" Unless required by applicable law or agreed to in writing, software
10+
" distributed under the License is distributed on an "AS IS" BASIS,
11+
" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
" See the License for the specific language governing permissions and
13+
" limitations under the License.
14+
15+
16+
let s:plugin = maktaba#plugin#Get('codefmt')
17+
18+
19+
""
20+
" @private
21+
" Formatter: isort
22+
function! codefmt#isort#GetFormatter() abort
23+
let l:formatter = {
24+
\ 'name': 'isort',
25+
\ 'setup_instructions': 'Install isort ' .
26+
\ '(https://pypi.python.org/pypi/isort/).'}
27+
28+
function l:formatter.IsAvailable() abort
29+
return executable(s:plugin.Flag('isort_executable'))
30+
endfunction
31+
32+
function l:formatter.AppliesToBuffer() abort
33+
return &filetype is# 'python'
34+
endfunction
35+
36+
""
37+
" Reformat the current buffer with black or the binary named in
38+
" @flag(isort_executable)
39+
"
40+
" We implement Format(), and not FormatRange{,s}(), because black doesn't
41+
" provide a hook for formatting a range
42+
function l:formatter.Format() abort
43+
let l:executable = s:plugin.Flag('isort_executable')
44+
45+
call codefmt#formatterhelpers#Format([
46+
\ l:executable,
47+
\ '-'])
48+
endfunction
49+
50+
return l:formatter
51+
endfunction

0 commit comments

Comments
 (0)