Fork me on GitHub

Dear channel, I have filed some issues regarding Jack-in: 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.


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

(def a 1)

(def b 2)

(def c (+ a b))

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.


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 🙂


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

; (def a 1)

(def b 2)

(def c (+ a b))

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?


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

(ns-unmap *ns* 'a) 


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


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


@U0A6H3MFT or just selecting everything you want reevaulated


@U0ETXRFEW - 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.


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


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


There is

(remove-ns 'foo)


Yes, @U0ETXRFEW, this works perfectly!


Thank you!

❤️ 4

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.


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

👌 4

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.


@U0A6H3MFT : > 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.


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

(def a 1)


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


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


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


and so on


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


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


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


was my explanation clear? )


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?


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


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


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


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


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. 😃


thanks, let me try


I see, that is a different matter of course.


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


my real project code example:


(deftest claims-loaded

  ;; (do


    (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]))

      {:locations not-empty
       :practs not-empty
       :items empty?})



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


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


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


it does not needed!


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


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


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


and Calva will send to repl all forms starting with it


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


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?


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


Yes, those. 😃


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


in general case I mean


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 🙂


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


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


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 🙂


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.


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


Ok, thanks, I'l think about it


@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.

👌 4

@U0ETXRFEW thank you very much for your investigation. I also found something similar for sublime (although just a gist, no working plugin: (line2 12-15))


@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.


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?


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

metal 4