Skip to content

Commit

Permalink
Fix split string function (SpaceVim#3201)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsdjeg authored Oct 26, 2019
1 parent 69caebd commit e124100
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
48 changes: 42 additions & 6 deletions autoload/SpaceVim/layers/core.vim
Original file line number Diff line number Diff line change
Expand Up @@ -402,26 +402,61 @@ function! s:previous_window() abort
endtry
endfunction

let g:string_info = {
\ 'vim' : {
\ 'connect' : '.',
\ 'line_prefix' : '\',
\ },
\ 'java' : {
\ 'connect' : '+',
\ 'line_prefix' : '',
\ },
\ 'perl' : {
\ 'connect' : '.',
\ 'line_prefix' : '\',
\ },
\ 'python' : {
\ 'connect' : '+',
\ 'line_prefix' : '\',
\ 'quotes_hi' : ['pythonQuotes']
\ },
\ }

function! s:split_string(newline) abort
if s:is_string(line('.'), col('.'))
let save_cursor = getcurpos()
let c = col('.')
let sep = ''
while c > 0
if s:is_string(line('.'), c)
let c -= 1
else
let sep = getline('.')[c]
if !empty(get(get(g:string_info, &filetype, {}), 'quotes_hi', []))
let sep = getline('.')[c - 1]
else
let sep = getline('.')[c]
endif
break
endif
endwhile
let l:connector = a:newline ? "\n" : ''
let l:save_register_m = @m
let @m = sep . l:connector . sep
let addedtext = a:newline ? "\n" . get(get(g:string_info, &filetype, {}), 'line_prefix', '') : ''
let connect = get(get(g:string_info, &filetype, {}), 'connect', '')
if !empty(connect)
let connect = ' ' . connect . ' '
endif
if a:newline
let addedtext = addedtext . connect
else
let addedtext = connect
endif
let save_register_m = @m
let @m = sep . addedtext . sep
normal! "mp
let @m = l:save_register_m
let @m = save_register_m
if a:newline
normal! j==k$
normal! j==
endif
call setpos('.', save_cursor)
endif
endfunction

Expand All @@ -430,6 +465,7 @@ endfunction
let s:string_hi = {
\ 'c' : 'cCppString',
\ 'cpp' : 'cCppString',
\ 'python' : 'pythonString',
\ }

function! s:is_string(l, c) abort
Expand Down
6 changes: 3 additions & 3 deletions autoload/SpaceVim/layers/shell.vim
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ endfunction

" FIXME:
func! SpaceVim#layers#shell#terminal() abort
let line = getline('$')
let line = getline('.')
if isdirectory(line[:-2])
return "exit\<CR>"
endif
return "\<C-d>"
return ""
endf
func! SpaceVim#layers#shell#ctrl_u() abort
let line = getline('$')
let line = getline('.')
let prompt = getcwd() . '>'
return repeat("\<BS>", len(line) - len(prompt) + 2)
endfunction
Expand Down

0 comments on commit e124100

Please sign in to comment.