Update 2024-12-15 14:45 OpenBSD/amd64-t14

This commit is contained in:
c0dev0id
2024-12-15 14:45:59 +01:00
parent beac7b226a
commit 6d6f0e9a46
66 changed files with 12003 additions and 1 deletions

View File

@@ -0,0 +1,154 @@
" Note:
" In this plugin, position of marker is treated with [line, col], not line.
" This is because some markers may be not linewise but characterwise.
" I consider the extensibility of this plugin and markers are customizable,
" I don't throw the possibility of characterwise conflict hunks away.
function! s:current_conflict_begin() abort
let begin = searchpos(g:conflict_marker_begin, 'bcnW')
let before_end = searchpos(g:conflict_marker_end, 'bnW')
if begin == [0, 0] || (before_end != [0, 0] && before_end[0] > begin[0])
return [0, 0]
endif
return begin
endfunction
function! s:current_conflict_end() abort
let after_begin = searchpos(g:conflict_marker_begin, 'nW')
let end = searchpos(g:conflict_marker_end, 'cnW')
if end == [0, 0] || (after_begin != [0, 0] && end[0] > after_begin[0])
return [0, 0]
endif
return end
endfunction
function! s:current_conflict_common_ancestors(before_begin, after_sep) abort
" when separator is before cursor
let before_ancestor = searchpos(g:conflict_marker_common_ancestors, 'bcnW')
if before_ancestor != [0, 0] && a:before_begin != [0, 0] && a:before_begin[0] < before_ancestor[0]
return before_ancestor
endif
" when separator is after cursor
let after_ancestor = searchpos(g:conflict_marker_common_ancestors, 'cnW')
if after_ancestor != [0, 0] && a:after_sep != [0, 0] && after_ancestor[0] < a:after_sep[0]
return after_ancestor
endif
return [0, 0]
endfunction
function! s:current_conflict_separator(before_begin, after_end) abort
" when separator is before cursor
let before_sep = searchpos(g:conflict_marker_separator, 'bcnW')
if before_sep != [0, 0] && a:before_begin != [0, 0] && a:before_begin[0] < before_sep[0]
return before_sep
endif
" when separator is after cursor
let after_sep = searchpos(g:conflict_marker_separator, 'cnW')
if after_sep != [0, 0] && a:after_end != [0, 0] && after_sep[0] < a:after_end[0]
return after_sep
endif
return [0, 0]
endfunction
function! s:valid_hunk(hunk) abort
return filter(copy(a:hunk), 'v:val == [0, 0]') == []
endfunction
function! conflict_marker#markers() abort
let begin = s:current_conflict_begin()
let end = s:current_conflict_end()
return [begin, s:current_conflict_separator(begin, end), end]
endfunction
" Note: temporary implementation, linewise
function! conflict_marker#themselves() abort
let markers = conflict_marker#markers()
if ! s:valid_hunk(markers) | return | endif
execute markers[2][0] . 'delete' '_'
execute markers[0][0] . ',' . markers[1][0] . 'delete' '_'
silent! call repeat#set("\<Plug>(conflict-marker-themselves)", v:count)
endfunction
" Note: temporary implementation, linewise
function! conflict_marker#ourselves() abort
let markers = conflict_marker#markers()
if ! s:valid_hunk(markers) | return | endif
let common_ancestors_pos = s:current_conflict_common_ancestors(markers[0], markers[1])
if common_ancestors_pos != [0, 0]
execute common_ancestors_pos[0] . ',' . markers[2][0] . 'delete' '_'
else
execute markers[1][0] . ',' . markers[2][0] . 'delete' '_'
endif
execute markers[0][0] . 'delete' '_'
silent! call repeat#set("\<Plug>(conflict-marker-ourselves)", v:count)
endfunction
" Note: temporary implementation, linewise
function! conflict_marker#down_together() abort
let markers = conflict_marker#markers()
if ! s:valid_hunk(markers) | return | endif
execute markers[0][0] . ',' . markers[2][0] . 'delete' '_'
silent! call repeat#set("\<Plug>(conflict-marker-none)", v:count)
endfunction
" Note: temporary implementation, linewise
function! conflict_marker#compromise(reverse) abort
let markers = conflict_marker#markers()
if ! s:valid_hunk(markers) | return | endif
execute markers[2][0] . 'delete' '_'
let common_ancestors_pos = s:current_conflict_common_ancestors(markers[0], markers[1])
let has_common_ancestors = common_ancestors_pos != [0, 0]
if has_common_ancestors
execute common_ancestors_pos[0] . ',' . markers[1][0] . 'delete' '_'
else
execute markers[1][0] . 'delete' '_'
endif
execute markers[0][0] . 'delete' '_'
if a:reverse
let ancestors_lines = has_common_ancestors ? markers[1][0] - common_ancestors_pos[0] : 0
let theirs_start = markers[1][0] - 2 - ancestors_lines + 1
let theirs_end = markers[2][0] - 3 - ancestors_lines
let theirs = getline(theirs_start, theirs_end)
execute theirs_start . ',' . theirs_end . 'delete' '_'
let ours_start = markers[0][0]
call append(ours_start - 1, theirs)
endif
silent! call repeat#set("\<Plug>(conflict-marker-both)", v:count)
endfunction
function! s:jump_to_hunk_if_valid(original_pos, hunk) abort
if s:valid_hunk(a:hunk)
call cursor(a:hunk[0][0], a:hunk[0][1])
return 1
else
echohl ErrorMsg | echo 'conflict not found' | echohl None
call setpos('.', a:original_pos)
return 0
endif
endfunction
function! conflict_marker#next_conflict(accept_cursor) abort
let pos = getpos('.')
return s:jump_to_hunk_if_valid(pos, [
\ searchpos(g:conflict_marker_begin, (a:accept_cursor ? 'cW' : 'W')),
\ searchpos(g:conflict_marker_separator, 'cW'),
\ searchpos(g:conflict_marker_end, 'cW'),
\ ])
endfunction
function! conflict_marker#previous_conflict(accept_cursor) abort
let pos = getpos('.')
return s:jump_to_hunk_if_valid(pos, reverse([
\ searchpos(g:conflict_marker_end, (a:accept_cursor ? 'bcW' : 'bW')),
\ searchpos(g:conflict_marker_separator, 'bcW'),
\ searchpos(g:conflict_marker_begin, 'bcW'),
\ ]))
endfunction

View File

@@ -0,0 +1,24 @@
let s:save_cpo = &cpo
set cpo&vim
function! conflict_marker#detect#markers() abort
if !g:conflict_marker_enable_detect
return
endif
let view = winsaveview()
try
keepjumps call cursor(1, 1)
for marker in [g:conflict_marker_begin, g:conflict_marker_separator, g:conflict_marker_end]
if search(marker, 'cW') == 0
return 0
endif
endfor
return 1
finally
call winrestview(view)
endtry
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@@ -0,0 +1,60 @@
let s:save_cpo = &cpo
set cpo&vim
let s:source = {
\ 'name' : 'conflict',
\ 'description' : 'conflicts in current buffer',
\ 'default_kind' : 'jump_list',
\ 'hooks' : {},
\ }
function! unite#sources#conflict#define() abort
return s:source
endfunction
function! s:source.hooks.on_init(args, context) abort
if ! conflict_marker#detect#markers()
return
endif
let a:context.source__path = expand('%:p')
let a:context.source__bufnr = bufnr('%')
let pos_save = getpos('.')
let a:context.source__markers = []
normal! gg
if ! conflict_marker#next_conflict(1)
return
endif
let end_line = search(g:conflict_marker_end, 'cWn')
call add(a:context.source__markers, [getline('.'), line('.')])
call add(a:context.source__markers, [getline(end_line), end_line])
while 1
silent if ! conflict_marker#next_conflict(0)
break
endif
let end_line = search(g:conflict_marker_end, 'cWn')
call add(a:context.source__markers, [getline('.'), line('.')])
call add(a:context.source__markers, [getline(end_line), end_line])
endwhile
call setpos('.', pos_save)
endfunction
function! s:source.gather_candidates(args, context) abort
if ! has_key(a:context, 'source__markers')
return []
endif
return map(a:context.source__markers, "{
\ 'word' : v:val[0].' (line:'.v:val[1].')',
\ 'action__path' : a:context.source__path,
\ 'action__buffer_nr' : a:context.source__bufnr,
\ 'action__line' : v:val[1],
\ }")
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo