Gather escaping functions

This commit is contained in:
Tim Pope 2013-02-10 13:25:45 -05:00
parent 9749177034
commit 8c0eae19ab

View File

@ -20,6 +20,18 @@ function! s:str(string)
return '"' . escape(a:string, '"\') . '"' return '"' . escape(a:string, '"\') . '"'
endfunction endfunction
function! s:qsym(symbol)
if a:symbol =~# '^[[:alnum:]?*!+/=<>.:-]\+$'
return "'".a:symbol
else
return '(symbol '.s:str(a:symbol).')'
endif
endfunction
function! s:to_ns(path) abort
return tr(substitute(a:path, '\.\w\+$', '', ''), '\/_', '..-')
endfunction
" }}}1 " }}}1
" Completion {{{1 " Completion {{{1
@ -55,7 +67,7 @@ function! foreplay#ns_complete(A, L, P) abort
endif endif
let matches += files let matches += files
endfor endfor
return filter(map(matches, 's:tons(v:val)'), 'a:A ==# "" || a:A ==# v:val[0 : strlen(a:A)-1]') return filter(map(matches, 's:to_ns(v:val)'), 'a:A ==# "" || a:A ==# v:val[0 : strlen(a:A)-1]')
endfunction endfunction
function! foreplay#omnicomplete(findstart, base) abort function! foreplay#omnicomplete(findstart, base) abort
@ -113,14 +125,6 @@ if !exists('s:repls')
let s:repl_paths = {} let s:repl_paths = {}
endif endif
function! s:qsym(symbol)
if a:symbol =~# '^[[:alnum:]?*!+/=<>.:-]\+$'
return "'".a:symbol
else
return '(symbol "'.escape(a:symbol, '"').'")'
endif
endfunction
function! s:repl.path() dict abort function! s:repl.path() dict abort
return self.connection.path() return self.connection.path()
endfunction endfunction
@ -926,7 +930,7 @@ function! foreplay#findfile(path) abort
let path .= '.clj' let path .= '.clj'
endif endif
let response = s:eval(printf(cmd, '"'.escape(path, '"').'"'), options) let response = s:eval(printf(cmd, s:str(path)), options)
let result = get(split(get(response, 'value', ''), "\n"), 0, '') let result = get(split(get(response, 'value', ''), "\n"), 0, '')
endif endif
let result = s:decode_url(result) let result = s:decode_url(result)
@ -981,10 +985,6 @@ function! s:buffer_path(...) abort
return '' return ''
endfunction endfunction
function! s:tons(path) abort
return tr(substitute(a:path, '\.\w\+$', '', ''), '\/_', '..-')
endfunction
function! foreplay#ns() abort function! foreplay#ns() abort
let lnum = 1 let lnum = 1
while lnum < line('$') && getline(lnum) =~# '^\s*\%(;.*\)\=$' while lnum < line('$') && getline(lnum) =~# '^\s*\%(;.*\)\=$'
@ -1001,7 +1001,7 @@ function! foreplay#ns() abort
return s:qffiles[expand('%:p')].ns return s:qffiles[expand('%:p')].ns
endif endif
let path = s:buffer_path() let path = s:buffer_path()
return s:tons(path ==# '' ? 'user' : path) return s:to_ns(path ==# '' ? 'user' : path)
endfunction endfunction
function! s:Lookup(ns, macro, arg) abort function! s:Lookup(ns, macro, arg) abort