Fork me on GitHub
#vim
<
2017-09-26
>
aleksanders09:09:46

Is there an easy wayto load functions into user namespace from vim-fireplace ?

aleksanders09:09:21

:Eval/cpp woudln't use or provide a way to alias the namespace

dominicm09:09:29

@aleksanders I don't fully understand. Could you reword it please?

aleksanders09:09:45

Let's say I want to test a function in a repl

aleksanders09:09:37

When I :Eval it from vim it is available from within it's namespace

aleksanders09:09:06

I would like to be able to to call it from the repl without typing the full namespace

aleksanders09:09:10

I guess requiring with an alias would help

aleksanders09:09:34

is my explanation any clearer?

dominicm09:09:19

I think what you're after is quite difficult. (require '[ :refer [the-function]]) would work. But not for private functions.

dominicm09:09:38

(def x (resolve 'the.ns/x)) would work I guess :thinking_face:

dominicm09:09:05

hold on, I have an idea

dominicm10:09:36

command! -buffer -nargs=1 MoveToUser exec ':Eval (in-ns ''user) (def '.<q-args>.' (resolve '''.fireplace#ns().'/'.<q-args>.'))' @aleksanders ^^ put that in ~/.vim/after/ftplugin/clojure.vim

dominicm10:09:12

Usage is :MoveToUser env and it will create a var in user, named env.

dominicm10:09:34

There's two ways this could work. Currently it works that it auto-updated the var in user if you update the var in the original namespace

dominicm10:09:00

but that means you have to do this:

user=> (@env args)

dominicm10:09:04

@aleksanders does that work for you?

aleksanders12:09:40

let me try it out

aleksanders12:09:07

FileNotFoundException Could not locate car_insurance_aggregator/transformation/brands__init.class or car_insurance_aggregator/transformation/brands.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.

dominicm12:09:41

were you in car-insurance-aggregator.transformation.brands when you ran this?

dominicm12:09:38

Have you evaluated any code in there yet?

dominicm12:09:24

Can you try doing :Require and then :MoveToUser again?

dominicm12:09:20

(I can't reproduce your error, so trying my best to guess)

aleksanders12:09:58

trying that now

aleksanders12:09:01

so the problem was repl running in wrong directory

aleksanders12:09:20

now the error is: NullPointerException clojure.core/deref-future

aleksanders12:09:53

I guess I would be happiest if there was a shortcut to require a namespace with an alias

dominicm12:09:14

when do you get that error, when you run :MoveToUser?

aleksanders12:09:14

no, command finishes without erro

aleksanders12:09:57

but when I try to call the function I get the null pointer

dominicm12:09:31

If you type it without @, what is it?

dominicm12:09:24

@aleksanders I get that if I use it on a var that doesn't exist

aleksanders13:09:48

ok, I haven't realised that env should be a name of a var in my namespace

aleksanders13:09:14

assumed that I should call :MoveToUser while inside the function

dominicm13:09:34

haha, sorry 😛

aleksanders13:09:46

and what is your workflow with vim-fireplace?

aleksanders13:09:00

the difficulties of communication over chat ...