dgrnbrg / vim-redl

A better Vim integration story for Clojure
106 stars 8 forks source link

Fix typo: <Pulg> -> <Plug> #19

Closed guns closed 10 years ago

guns commented 10 years ago

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:

  if !hasmapto("<Plug>clj_repl_eval.", "i")
    imap <buffer> <silent> <C-e> <Plug>clj_repl_eval.
  endif

However, if there is no event associated with redl#repl#create(), how can users provide their own mappings to cljrepl* without mapping them globally in the clojure FileType?

Great work!

guns
dgrnbrg commented 10 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!

guns commented 10 years ago

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 binding is only bound in the redl REPL buffer, and not in all clojure buffers.

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.