Skip to content

Commit e643047

Browse files
authored
simplify trimline (pangloss#673)
remove janky binary search
1 parent 920873e commit e643047

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

indent/javascript.vim

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,14 @@ else
6363
endfunction
6464
endif
6565

66-
" indent/python.vim
6766
function s:Trimline(ln)
68-
let pline = getline(a:ln)
69-
let min = match(pline,'\/[/*]') + 1
70-
if min && synIDattr(synID(a:ln, strlen(pline), 0), 'name') =~? '\%(comment\|doc\)'
71-
let max = match(pline,'.*\zs\/[/*]') + 1
72-
while min < max
73-
let col = (min + max) / 2
74-
if synIDattr(synID(a:ln, col, 0), 'name') =~? '\%(comment\|doc\)'
75-
let max = col
76-
else
77-
let min = match(pline,'\/[/*]',col) + 1
78-
endif
79-
endwhile
80-
let pline = strpart(pline, 0, min - 1)
81-
endif
82-
return substitute(pline,'\s*$','','')
67+
let pline = substitute(getline(a:ln),'\s*$','','')
68+
let max = max([strridx(pline,'//'),strridx(pline,'/*'),0])
69+
while max && synIDattr(synID(a:ln, strlen(pline), 0), 'name') =~? '\%(comment\|doc\)'
70+
let pline = substitute(strpart(pline, 0, max),'\s*$','','')
71+
let max = max([strridx(pline,'//'),strridx(pline,'/*'),0])
72+
endwhile
73+
return pline
8374
endfunction
8475

8576
" configurable regexes that define continuation lines, not including (, {, or [.

0 commit comments

Comments
 (0)