Support booleans in foreplay#evalparse

This commit is contained in:
Tim Pope 2013-02-08 10:26:14 -05:00
parent a6012b5032
commit a1068949b1

View File

@ -526,17 +526,20 @@ function! foreplay#evalprint(expr) abort
return foreplay#eval_prn(a:expr) return foreplay#eval_prn(a:expr)
endfunction endfunction
let g:foreplay#reader =
\ '(symbol ((fn *vimify [x]' .
\ ' (cond' .
\ ' (map? x) (str "{" (apply str (interpose ", " (map (fn [[k v]] (str (*vimify k) ": " (*vimify v))) x))) "}")' .
\ ' (coll? x) (str "[" (apply str (interpose ", " (map *vimify x))) "]")' .
\ ' (true? x) "1"' .
\ ' (false? x) "0"' .
\ ' (number? x) (pr-str x)' .
\ ' (keyword? x) (pr-str (name x))' .
\ ' :else (pr-str (str x)))) %s))'
function! foreplay#evalparse(expr, ...) abort function! foreplay#evalparse(expr, ...) abort
let options = extend({'session': 0}, a:0 ? a:1 : {}) let options = extend({'session': 0}, a:0 ? a:1 : {})
let response = s:eval( let response = s:eval(printf(g:foreplay#reader, a:expr), options)
\ '(symbol ((fn *vimify [x]' .
\ ' (cond' .
\ ' (map? x) (str "{" (apply str (interpose ", " (map (fn [[k v]] (str (*vimify k) ": " (*vimify v))) x))) "}")' .
\ ' (coll? x) (str "[" (apply str (interpose ", " (map *vimify x))) "]")' .
\ ' (number? x) (pr-str x)' .
\ ' (keyword? x) (pr-str (name x))' .
\ ' :else (pr-str (str x)))) '.a:expr.'))',
\ options)
call s:output_response(response) call s:output_response(response)
if get(response, 'ex', '') !=# '' if get(response, 'ex', '') !=# ''