@@ -26,7 +26,7 @@ endfunction
26
26
" 3. First party libraries (ie. your own stuff)
27
27
"
28
28
function ! s: sortAcrossGroups ()
29
- let curr = 0
29
+ let curr = 1
30
30
let first_line = -1
31
31
let last_line = -1
32
32
let trailing_newlines = 0
@@ -35,7 +35,7 @@ function! s:sortAcrossGroups()
35
35
let third_party_imports = []
36
36
37
37
" loop over lines in buffer
38
- while curr < line (' $' )
38
+ while curr <= line (' $' )
39
39
40
40
let line = getline (curr)
41
41
@@ -62,29 +62,28 @@ function! s:sortAcrossGroups()
62
62
let trailing_newlines = trailing_newlines + 1
63
63
elseif first_line != -1
64
64
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
66
66
break
67
67
endif
68
68
69
69
let curr = curr + 1
70
70
endwhile
71
71
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
+
79
75
execute ' d' to_delete
80
76
81
77
call s: sortAndPrint (first_party_imports)
82
78
call s: sortAndPrint (third_party_imports)
83
79
call s: sortAndPrint (java_scala_imports)
84
80
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
+
88
87
endfunction
89
88
90
89
function ! s: sortInsideGroups ()
0 commit comments