Macroexpand motions

Bind cm{motion} to full macro expansion of the form described by
the motion (using clojure.core/macroexpand), and bind c1m{motion}
to partial macro expansion of the form described by the motion
(using clojure.core/macroexpand-1).

cmm and c1mm will apply the expansion to the form under the cursor.
This commit is contained in:
Chris Ford 2013-04-21 13:08:55 +03:00 committed by Tim Pope
parent b96ccf7441
commit 4490d2a882
3 changed files with 36 additions and 1 deletions

View File

@ -68,7 +68,8 @@ Standard stuff here. `:Eval` evaluates a range (`:%Eval` gets the whole
file), `:Require` requires a namespace with `:reload` (`:Require!` does
`:reload-all`), either the current buffer or a given argument. There's a `cp`
operator that evaluates a given motion (`cpp` for the expression under the
cursor).
cursor). `cm` and `c1m` are similar, but they only run `macroexpand` and
`macroexpand-1` instead of evaluating the form entirely.
Any failed evaluation loads the stack trace into the location list, which
can be easily accessed with `:lopen`.

View File

@ -139,6 +139,18 @@ c!{motion} Eval/replace the code indicated by {motion}.
c!! Eval/replace the inner-most expr at the cursor.
*fireplace-cm*
cm{motion} Fully macroexpand the code indicated by {motion}.
*fireplace-cmm*
cmm Fully macroexpand the inner-most expr at the cursor.
*fireplace-c1m*
c1m{motion} Macroexpand the code indicated by {motion} once.
*fireplace-c1mm*
c1mm Macroexpand the inner-most expr at the cursor once.
*fireplace-cqp*
cqp Bring up a prompt for code to eval/print.

View File

@ -538,6 +538,10 @@ function! fireplace#evalprint(expr) abort
return fireplace#echo_session_eval(a:expr)
endfunction
function! fireplace#macroexpand(fn, form) abort
return fireplace#evalprint('(clojure.core/'.a:fn.' (quote '.a:form.'))')
endfunction
let g:fireplace#reader =
\ '(symbol ((fn *vimify [x]' .
\ ' (cond' .
@ -613,6 +617,14 @@ function! s:filterop(type) abort
endtry
endfunction
function! s:macroexpandop(type) abort
call fireplace#macroexpand("macroexpand", s:opfunc(a:type))
endfunction
function! s:macroexpand1op(type) abort
call fireplace#macroexpand("macroexpand-1", s:opfunc(a:type))
endfunction
function! s:printop(type) abort
let s:todo = s:opfunc(a:type)
call feedkeys("\<Plug>FireplacePrintLast")
@ -749,6 +761,11 @@ xnoremap <silent> <Plug>FireplacePrint :<C-U>call <SID>printop(visualmode())<CR
nnoremap <silent> <Plug>FireplaceFilter :<C-U>set opfunc=<SID>filterop<CR>g@
xnoremap <silent> <Plug>FireplaceFilter :<C-U>call <SID>filterop(visualmode())<CR>
nnoremap <silent> <Plug>FireplaceMacroExpand :<C-U>set opfunc=<SID>macroexpandop<CR>g@
xnoremap <silent> <Plug>FireplaceMacroExpand :<C-U>call <SID>macroexpandop(visualmode())<CR>
nnoremap <silent> <Plug>FireplaceMacroExpand1 :<C-U>set opfunc=<SID>macroexpand1op<CR>g@
xnoremap <silent> <Plug>FireplaceMacroExpand1 :<C-U>call <SID>macroexpand1op(visualmode())<CR>
nnoremap <silent> <Plug>FireplaceEdit :<C-U>set opfunc=<SID>editop<CR>g@
xnoremap <silent> <Plug>FireplaceEdit :<C-U>call <SID>editop(visualmode())<CR>
@ -787,6 +804,11 @@ function! s:setup_eval() abort
nmap <buffer> c! <Plug>FireplaceFilter
nmap <buffer> c!! <Plug>FireplaceFilterab
nmap <buffer> cm <Plug>FireplaceMacroExpand
nmap <buffer> cmm <Plug>FireplaceMacroExpandab
nmap <buffer> c1m <Plug>FireplaceMacroExpand1
nmap <buffer> c1mm <Plug>FireplaceMacroExpand1ab
nmap <buffer> cq <Plug>FireplaceEdit
nmap <buffer> cqq <Plug>FireplaceEditab