Fork me on GitHub
#conjure
<
2020-09-01
>
adambrosio04:09:07

In the spirit of sharing interesting mappings: I wrote this tonight, an itch I had to try to scratch: https://github.com/Pancia/dotfiles/commit/4886429c6c1e26a78e1feb16b4308a9ee41976bb

function! ResolveSymbol()
  call luaeval("require('conjure.client')['with-filetype']('clojure', require('conjure.eval')['eval-str'], { origin = 'dotfiles/clojuredocs', code = '`".expand("<cword>")."', ['on-result'] = function(sym) vim.api.nvim_command('call OpenClojureDocs(\"'..sym..'\")') end})")
endfunction

function! OpenClojureDocs(fqsym)
  echomsg "open clojure docs for: " . a:fqsym
  let [l:ns, l:sym] = split(a:fqsym, "/")
  if l:ns =~? 'clojure\..*'
    execute "!open '".l:ns."/".l:sym."'"
  else
    execute "!open '".a:fqsym."'"
  endif
endfunction

nnoremap ,vd :call ResolveSymbol()<CR>
,vd mapping to (V)iew (D)ocs for word under cursor in or google

😍 6
adambrosio16:09:26

as a note, you'll want to add ['passive?'] = true to the map with code = ... or you'll get lots of `symbols in your repl

adambrosio16:09:43

@olical how do i send a message that some middleware can pick up? eg:

(defn middleware [handler]
  (fn [{:keys [op] :as request}]
    (if (= op "nrebl-start-ui")
      (rebl/ui)
      (handler (assoc request :transport (wrap-rebl-sender request))))))

adambrosio16:09:03

I'm not seeing that in the code... so maybe I should refactor to use eval?

Olical10:09:06

:thinking_face: not sure what you mean by this exactly

Olical10:09:28

You mean nREPL middleware?

Olical10:09:45

Oh I see! You don't want to eval, you want to send a raw nREPL message!

Olical10:09:37

In the conjure.client.clojure.nrepl.server module there's a send function that takes a message and a callback. The message being a Lua table.

👍 3
Olical10:09:38

eval is built on top of send so that's probably the function you'll want to hook into. The chances of that changing are near 0 although you may encounter one breaking change when I one day migrate the nREPL code into it's own reusable module, although that may even still not affect you.