Simplify grouping of marker lines
This commit is contained in:
parent
2ccfe05430
commit
66010ff2a6
@ -150,46 +150,33 @@
|
|||||||
return a:groups[0][0]
|
return a:groups[0][0]
|
||||||
endif
|
endif
|
||||||
" }}}
|
" }}}
|
||||||
" Get the lines that need to be changed {{{
|
" Prepare marker lines {{{
|
||||||
let lines = []
|
let lines = {}
|
||||||
let lines_set = {}
|
|
||||||
for group in a:groups
|
|
||||||
for [line, col] in group
|
|
||||||
if ! has_key(lines_set, line)
|
|
||||||
call add(lines, line)
|
|
||||||
|
|
||||||
let lines_set[line] = 1
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
endfor
|
|
||||||
" }}}
|
|
||||||
" Create copies of the lines {{{
|
|
||||||
let orig_lines = {}
|
|
||||||
let marker_lines = {}
|
|
||||||
|
|
||||||
for line_num in lines
|
|
||||||
let orig_lines[line_num] = getline(line_num)
|
|
||||||
let marker_lines[line_num] = split(getline(line_num), '\zs')
|
|
||||||
endfor
|
|
||||||
" }}}
|
|
||||||
" Add markers to the lines and prepare highlighting {{{
|
|
||||||
let current_group = 0
|
|
||||||
let hl_coords = []
|
let hl_coords = []
|
||||||
|
let current_group = 0
|
||||||
|
|
||||||
for group in a:groups
|
for group in a:groups
|
||||||
let element = 0
|
let element = 0
|
||||||
|
|
||||||
for [line, col] in group
|
for [line_num, col_num] in group
|
||||||
" Create marker
|
" Add original line and marker line
|
||||||
let marker_lines[line][col - 1] = s:index_to_key[single_group ? element : current_group]
|
if ! has_key(lines, line_num)
|
||||||
let element += 1
|
let current_line = getline(line_num)
|
||||||
|
|
||||||
|
let lines[line_num] = { 'orig': current_line, 'marker': split(current_line, '\zs') }
|
||||||
|
endif
|
||||||
|
|
||||||
|
let lines[line_num]['marker'][col_num - 1] = s:index_to_key[single_group ? element : current_group]
|
||||||
|
|
||||||
" Add highlighting coordinates
|
" Add highlighting coordinates
|
||||||
call add(hl_coords, '\%' . line . 'l\%' . col . 'c')
|
call add(hl_coords, '\%' . line_num . 'l\%' . col_num . 'c')
|
||||||
|
|
||||||
|
let element += 1
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
let current_group += 1
|
let current_group += 1
|
||||||
endfor
|
endfor
|
||||||
|
let lines_items = items(lines)
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
let input_char = ''
|
let input_char = ''
|
||||||
@ -215,13 +202,13 @@
|
|||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
" Set lines with markers
|
" Set lines with markers
|
||||||
for [line_num, line_arr] in items(marker_lines)
|
for [line_num, line] in lines_items
|
||||||
try
|
try
|
||||||
undojoin
|
undojoin
|
||||||
catch
|
catch
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
call setline(line_num, join(line_arr, ''))
|
call setline(line_num, join(line['marker'], ''))
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
redraw
|
redraw
|
||||||
@ -238,13 +225,13 @@
|
|||||||
redraw
|
redraw
|
||||||
finally
|
finally
|
||||||
" Restore original lines
|
" Restore original lines
|
||||||
for [line_num, line] in items(orig_lines)
|
for [line_num, line] in lines_items
|
||||||
try
|
try
|
||||||
undojoin
|
undojoin
|
||||||
catch
|
catch
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
call setline(line_num, line)
|
call setline(line_num, line['orig'])
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
call matchdelete(target_hl_id)
|
call matchdelete(target_hl_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user