Closed guns closed 11 years ago
I actually leave the redl mappings on the global clojure filetype, as my preference is to use control-prefixed characters in insert mode, of which I don't have too many mappings.
I don't know how to create a new event--I'd be happy to learn how, or incorporate changes that have that feature!
Essentially, there is a special event type User
which is never fired by vim; it is triggered with the doautocmd
and doautoall
commands.
If you add:
function! redl#repl#create(namespace)
" Buffer setup
…
" Execute user code given here
doautocmd User redl_buffer
…
" Check for extant mappings here
if !hasmapto(…)
…
Then users can bind buffer-local bindings to just redl buffers by:
augroup my_autocommand_namespace
autocmd! " Clear all event handlers in this namespace
" (needed to avoid rebinding events during reload)
" Will be executed in redl#repl#create()
autocmd User redl_buffer
\ imap <buffer><silent> <M-CR> <Plug>clj_repl_eval.
augroup END
This is pretty ugly, but has the advantage that the
Fireplace actually uses this technique to init the nREPL connection before every eval. It also executes all keybindings in event handlers, which is quite elegant; if you would like to know more about leveraging the event system in Vim, fireplace is a great reference.
Just noticed this while scanning the code.
BTW, so as to not clutter the issues / mailing list, you are creating buffer-local mappings guarded by
if hasmapto
clauses:However, if there is no event associated with redl#repl#create(), how can users provide their own mappings tocljrepl* without mapping
them globally in the clojure FileType?
Great work!