Skip to content

Commit 051cc2a

Browse files
author
Leonard Ehrenfried
committed
Improve implementation of sortAcrossGroups
1 parent a6c4681 commit 051cc2a

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

plugin/scala.vim

+12-13
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ endfunction
2626
" 3. First party libraries (ie. your own stuff)
2727
"
2828
function! s:sortAcrossGroups()
29-
let curr = 0
29+
let curr = 1
3030
let first_line = -1
3131
let last_line = -1
3232
let trailing_newlines = 0
@@ -35,7 +35,7 @@ function! s:sortAcrossGroups()
3535
let third_party_imports = []
3636

3737
" loop over lines in buffer
38-
while curr < line('$')
38+
while curr <= line('$')
3939

4040
let line = getline(curr)
4141

@@ -62,29 +62,28 @@ function! s:sortAcrossGroups()
6262
let trailing_newlines = trailing_newlines + 1
6363
elseif first_line != -1
6464
let last_line = curr - trailing_newlines - 1
65-
" break out when you have found the first non-import line
65+
" break out when you have found the first non-import, non-empty line
6666
break
6767
endif
6868

6969
let curr = curr + 1
7070
endwhile
7171

72-
if first_line > 1
73-
call cursor(first_line - 1, 0)
74-
let to_delete = last_line - first_line + 2
75-
else
76-
call cursor(1,0)
77-
let to_delete = last_line - first_line + 1
78-
endif
72+
call cursor(first_line, 0)
73+
let to_delete = last_line - first_line
74+
7975
execute 'd'to_delete
8076

8177
call s:sortAndPrint(first_party_imports)
8278
call s:sortAndPrint(third_party_imports)
8379
call s:sortAndPrint(java_scala_imports)
8480

85-
if first_line < 2
86-
execute 'delete'
87-
endif
81+
" remove extra blank line at top
82+
execute 'delete'
83+
84+
call cursor(last_line + 1, 0)
85+
execute 'delete'
86+
8887
endfunction
8988

9089
function! s:sortInsideGroups()

0 commit comments

Comments
 (0)