Fork me on GitHub
#calva
<
2019-04-09
>
pez07:04:31

Dear channel, I have filed some issues regarding Jack-in: https://github.com/BetterThanTomorrow/calva/issues I will need help figuring some things out if I should be able to fix those issues. I’d appreciate it a lot if people read the issues tagged jack-in and help me understand them better.

sasho.popov08:04:25

Good morning. If I have a blank clj file with the following forms:

(def a 1)

(def b 2)

(def c (+ a b))

c
in order for me to evaluate c and get 3 as a line comment: (`=> 3`) via ctr, I need to first evaluation each of the previous forms. Also, if I change the value of a to 2, I need to evaluate the first form (in order to assign 2 to a) and evaluate the third form (in order to reassign the new result to c). My question is - is there a way in Calva, so that whenever I evaluate a form, all previous forms also get reevaluated. That is - I want to change the value of a, then go straight to evaluating c and get the new value of 4.

sasho.popov08:04:20

While typing this question I figured out, that if I select everything and evaluate, I get only the result for the last form, which is exactly what I want, but I post this anyway, so that I can make sure I understand how to use Calva 🙂

sasho.popov08:04:23

Actually, selecting all and evaluating “almost works”, because for example for this case:

; (def a 1)

(def b 2)

(def c (+ a b))

c
I’d expect to get an error: “Unable to resolve symbol: a in this context”, but instead I get 3. That is, the old definitions are not cleared. So basically my question is - is there a way to clear everything already define and define everything from scratch?

pez08:04:08

Calva has no feature for clearing definitions. You’ll need to unmap them with something like

(ns-unmap *ns* 'a) 

pez08:04:41

Selecting all text and evaluating otherwise “works”, as you have found out.

ivana08:04:17

from my point of view, it can be useful to have a command for evaluating all previous forms (in order) in current level (I can explain what I mean if needed). Cause I have to wrap all current-level forms in one big do for doing this now

sasho.popov08:04:02

@ or just selecting everything you want reevaulated

sasho.popov08:04:12

@ - so is there a way in Clojure to do something like (ns-unmap *ns* everything) - if I put this statement at the start of the file, than combining this with selecting everything will have exactly the behavior I just described.

ivana08:04:18

yes, but with separate command it will be more easy - do not need to find top form in current level manually

sasho.popov08:04:41

@ yes, for sure.

ivana08:04:12

cause it can be more above (for example - 1000 lines) from current cursor point

pez08:04:20

There is

(remove-ns 'foo)

sasho.popov09:04:29

Yes, @, this works perfectly!

pez09:04:53

I have an old branch lying around that allowed you to keep a list of custom commands and execute them at will. With that you would be able to register a custom command like

(remove-ns (symbol (str *ns*)))
And have convenient access to it.

pez09:04:41

If you find the custom commands feature desirable I’d welcome a feature request on github about it. 😃

pez09:04:36

Also, I am not sure how good Calva is at identifying the top ns form if you have stuff above it. It might work, but also, it might not. Also 2: I am sure the doc string for remove-ns includes Use with caution. for a reason.

pez09:04:30

@ : > from my point of view, it can be useful to have a command for evaluating all previous forms (in order) in current level (I can explain what I mean if needed). Cause I have to wrap all current-level forms in one big do for doing this now. Yes, please explain.

ivana09:04:00

Often (especially in tests) I have a list of instructions such as

(do-1thing)
(def a 1)
(do-2thing)
......

ivana09:04:06

when I eval test it fails some where inside of its instructions list

ivana09:04:07

and I wrap in one big do form all instructions from first to choosen and eval this do block

ivana09:04:53

next step - I add next instruction in the end of this do-blok and eval it again

ivana09:04:58

and so on

ivana09:04:42

after I find exact instruction that have en error, I remove this do block from code

ivana09:04:12

all I want is not to insert and remove this do-block

ivana09:04:01

and IDE sends all current level instructions in order from first to which cursor is to repl by one shortcut

ivana09:04:07

was my explanation clear? )

pez09:04:18

It is much clearer now, at least. 😄 Can you paste an example of a real such list, with enough context around it so that I can try see what such a command would be selecting for evaluation?

ivana09:04:31

yes, but maybe todays evening - I have not enough time for good example now )

pez09:04:55

Also, I wonder, if you place your cursor at the correct level and do Paredit: Expand selection, does the correct stuff get selected?

ivana09:04:05

Fortunately I do not use any structure editors - neither paredit/parinfer/smartparens/etc

ivana09:04:22

anyway only current level forms above the cursor should be selected, not oll current level

pez09:04:23

It is there in Calva anyway. So hitting ctrl+w might select the right stuff for you. Try not to think about it as structural editing, It is just selecting stuff, anyway. 😃

ivana09:04:16

thanks, let me try

pez09:04:40

I see, that is a different matter of course.

ivana09:04:17

ctrl+w selects all current level forms, not above cursor

ivana09:04:39

my real project code example:

ivana09:04:49

(deftest claims-loaded

  ;; (do

    (w/bronx)

    (def refs
      {:patient {:id "pt"} :organization {:name "A payor"} :encounter {:id "enc"} :procedure {:id "proc"}})

    (w/a! [:patient :appointment :organization :coverage :encounter] refs)

    (def refs-to-hold-on
      {:patient {:id "pt-hold"} :organization {:name "B payor"} :encounter {:id "enc-hold"} :procedure {:id "proc-hold"}})

    (w/a! [:patient :appointment :organization :coverage :encounter] refs-to-hold-on)

    (rf/dispatch [:claims/verify :init {}])

    (def m (rf/subscribe [*ns]))

    (matcho/match
     @m
      {:locations not-empty
       :practs not-empty
       :items empty?})

.........................

ivana09:04:47

are you see do commented at the beginning? 🙂 this it for it

ivana09:04:01

I uncomment this do and move its closed paren from top to bottom and eval this do-block each time

pez09:04:33

Thanks. How would Calva know not to select deftest claims-loaded for evaluation?

ivana09:04:47

it does not needed!

ivana09:04:14

only is needed - check all current level forms and find first of them

pez09:04:40

To me they look like on the same level as the do block.

ivana09:04:59

so every time (w/bronx) will be such form

ivana09:04:49

and Calva will send to repl all forms starting with it

ivana09:04:31

if my cursor is inside (deftest form - not inside inner forms

pez09:04:33

Yes, I think I know which blocks to evaluate. But I don’t see a clear way to get Calva to do the right thing… How would it know to not inlcude claims-needed?

ivana09:04:58

o, you mean 2 first symbols )..... I do not think about it yet, sorry )

pez09:04:20

Yes, those. 😃

ivana09:04:04

hm, let me think about it, maybe there are no good way to do this

ivana09:04:17

in general case I mean

ivana09:04:07

If I'd wrote my own clojure plugin, I'd be filter raw symbols from all current-level forms for it 🙂 but I'm not sure if it clear behaviour for all 🙂

ivana09:04:29

after filtering only eval-needed list-forms will stay. as a hypotesis

pez10:04:41

How about commands for growing and shrinking the selection, one form at a time, upwards? Or are these lists often too big for that?

ivana10:04:01

One form at a time... Looks like manual do is easier 🙂 This lists can be by several screens height... Anyway if there can not be more usable solution than adding do I'l add do as before 🙂

pez10:04:54

If you do experiment with making an extension to help with this, then if you make it just select the right thing, people can use it together with Calva for evaluating it.

pez10:04:23

Of course, if you do get it to select the right thing I’d appreciate a PR to add such a command to Calva.

ivana10:04:43

Ok, thanks, I'l think about it

pez14:04:28

@sasho.popov, so having investigated this some more, it seems that remove-ns can bite you pretty hard. The proper way to do it is using refresh from tools.namespace. Calva doesn’t help with that currently, so you’ll have to add that to your project or inject it at the command line. I will look into adding a refresh command to Calva.

sasho.popov14:04:36

@ thank you very much for your investigation. I also found something similar for sublime (although just a gist, no working plugin: https://gist.github.com/Qambar/3afe51be82a0c82828dcbf1c78888120#file-clojurehelpers-py (line2 12-15))

pez14:04:10

@bozhidar: does CIDER inject any tools.namespace dependencies, or how does that cider-refresh get powered? I have pointed @sasho.popov at remove-ns and feel a bit bad about that. A proper refresh is what Calva needs.

pez16:04:47

This build contains a first stab at implementing the refresh and refreshAll commands. Currently they only seem to refresh CLJ stuff even if a CLJS repl is active. (I’m not sure if the nREPL ops used support CLJS, even). Also error reporting is a bit brief. But anyway. Maybe you can take it for a spin @sasho.popov?

sasho.popov09:04:12

Thank you, @, I’ll try it and report how it works for me.