<commit_before>" Cache command strings to avoid the repeated function call and join
let s:commands = {'*': {}, '+': {}}
let s:commands['*']['get'] = sshclip#misc#command_str('-o', '-selection', 'primary')
let s:commands['*']['put'] = sshclip#misc#command_str('-i', '-selection', 'primary', '--background')
let s:commands['+']['get'] = sshclip#misc#command_str('-o', '-selection', 'clipboard')
let s:commands['+']['put'] = sshclip#misc#command_str('-i', '-selection', 'clipboard', '--background')


function! sshclip#emulator#op_yank(motion)
    return sshclip#emulator#handle('yank', '*', 'y', a:motion)
endfunction


function! sshclip#emulator#op_delete(motion)
    return sshclip#emulator#handle('delete', '*', 'd', a:motion)
endfunction


function! sshclip#emulator#handle(type, register, key, motion)
    let c = (v:count == v:count1) ? v:count : ''

    if a:register != '*' && a:register != '+'
        execute 'normal! ' c . '"' . a:register . a:key
    else
        let o_selection = &selection
        let &selection = 'inclusive'

        if a:motion ==# 'char'
            normal! `[v`]
        elseif a:motion ==# 'line'
            normal! '[V']
        elseif a:motion ==# 'block'
            execute "normal! `[\<C-v>`]"
        elseif a:motion != ''
            normal! gv
        endif

        let &selection = o_selection

        if a:type == 'paste'
            let @@ = system(s:commands[a:register]['get'])
            execute 'normal! ' c . a:key
            call sshclip#misc#set_status(a:register, 0)
        else
            let local_register = '0'
            if a:type == 'delete'
                if a:key ==? 'x'
                    let local_register = '-'
                else
                    let local_register = '1'
                endif
            endif

            execute 'normal! ' c . a:key
            let data = getreg('"')

            if sshclip#misc#can_send_str(data)
                call system(s:commands[a:register]['put'], data)
                call sshclip#misc#set_status(a:register, 1)
            else
                call sshclip#misc#set_status('!', 1)
            endif

            call setreg(local_register, data, getregtype('"'))
        endif
    endif

    if a:type == 'delete'
        silent doautocmd User SSHClipDelete
    elseif a:type == 'paste'
        silent doautocmd User SSHClipPaste
    elseif a:type == 'yank'
        silent doautocmd User SSHClipYank
    endif<commit_msg>Deletions with the emulator adds removed text to register<commit_after>" Cache command strings to avoid the repeated function call and join
let s:commands = {'*': {}, '+': {}}
let s:commands['*']['get'] = sshclip#misc#command_str('-o', '-selection', 'primary')
let s:commands['*']['put'] = sshclip#misc#command_str('-i', '-selection', 'primary', '--background')
let s:commands['+']['get'] = sshclip#misc#command_str('-o', '-selection', 'clipboard')
let s:commands['+']['put'] = sshclip#misc#command_str('-i', '-selection', 'clipboard', '--background')


function! sshclip#emulator#op_yank(motion)
    return sshclip#emulator#handle('yank', '*', 'y', a:motion)
endfunction


function! sshclip#emulator#op_delete(motion)
    return sshclip#emulator#handle('delete', '*', 'd', a:motion)
endfunction


function! sshclip#emulator#handle(type, register, key, motion)
    let c = (v:count == v:count1) ? v:count : ''

    if a:register != '*' && a:register != '+'
        execute 'normal! ' c . '"' . a:register . a:key
    else
        let o_selection = &selection
        let &selection = 'inclusive'

        if a:motion ==# 'char'
            normal! `[v`]
        elseif a:motion ==# 'line'
            normal! '[V']
        elseif a:motion ==# 'block'
            execute "normal! `[\<C-v>`]"
        elseif a:motion != ''
            normal! gv
        endif

        let &selection = o_selection

        if a:type == 'paste'
            let @@ = sshclip#register#get(a:register)
            if a:motion == 'v'
                normal! y
                normal! gv
                call sshclip#register#put('*', '1', getreg('"'), getregtype('"'))
            endif
            execute 'normal! ' c . a:key
        else
            let local_register = '0'
            if a:type == 'delete'
                if a:key ==? 'x'
                    let local_register = '-'
                else
                    let local_register = '1'
                endif
            endif

            execute 'normal! ' c . a:key
            call sshclip#register#put(a:register, local_register, getreg('"'), getregtype('"'))
        endif
    endif

    if a:type == 'delete'
        silent doautocmd User SSHClipDelete
    elseif a:type == 'paste'
        silent doautocmd User SSHClipPaste
    elseif a:type == 'yank'
        silent doautocmd User SSHClipYank
    endif
{'fraction_non_alphanumeric': 0.15749013089549138, 'fraction_numerical': 0.002077706212341575, 'mean_word_length': 2.2882513661202184, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2108229', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1460, 'n_words': 356}