cider

A channel dedicated to the Clojure Interactive Development Environment that Rocks (aka CIDER). :cider:
Setzer22 2021-04-09T06:33:52.205200Z

Hi again! Is there a similar hook for cider-eval-region/last-sexp, etc?

bozhidar 2021-04-09T06:38:29.206600Z

Nope.

dpsutton 2021-04-09T06:38:31.206700Z

there's not. and hooks on every eval seem kinda tough to manage if you venture into other namespaces. i'd go with that register snippet i put above and send the command to instrument functions as needed

bozhidar 2021-04-09T06:39:11.207700Z

I was actually thinking of general eval hook, as it kind of makes sense, but there was never much demand for it.

dpsutton 2021-04-09T06:39:16.208Z

C-M-x to eval something and then C-c C-j x i to send your instrument form to the repl

bozhidar 2021-04-09T06:39:43.208600Z

The reason why there's a hook for load-file as that we needed this for cider-auto-test-mode. Demand drives supply. 🙂

dpsutton 2021-04-09T06:40:33.209400Z

i'm gonna add this to my local version of inf-clojure and test it out

bozhidar 2021-04-09T06:40:36.209600Z

@dpsutton What exactly is the use case for this register trick - you want to save some snippets of code so you can easily recall them in the REPL?

dpsutton 2021-04-09T06:41:46.210200Z

yeah. exactly. for things of this nature, send (stest/instrument [insert-tree* delete-min* find-min*])` something you might keep in a register

dpsutton 2021-04-09T06:42:18.210500Z

i'd add this to a register as well:

(do
  (require '[clojure.string :as str])
  (require '[clojure.core.server :as server])
  (clojure.main/repl
   :prompt (fn [] (printf "%s=> " (peek (str/split (str *ns*) #"\."))))
   :read server/repl-read)

  (require '[vlaaad.reveal :as reveal])
  (add-tap (reveal/ui)))

dpsutton 2021-04-09T06:43:07.211Z

and i have a function that calls (inf-clojure--send-string inf-proc "(apply require clojure.main/repl-requires)") but i could just toss that in a register and send it

dpsutton 2021-04-09T06:44:07.211900Z

another thing to keep in a register while working in the repl: (doto 'the-ns-test (require :reload) (clojure.test/run-tests))

dpsutton 2021-04-09T06:47:18.212600Z

just forms you might want to send repeatedly without scrolling around a bunch between a form calling your tests and the functions you are working on

bozhidar 2021-04-09T06:58:19.212800Z

I see.

Setzer22 2021-04-09T07:49:37.218200Z

Thanks for the suggestion @dpsutton. This register thing looks neat. But in my case I already have a dedicated keybinding to reinstrument my code which pretty much achieves the same purpose. The whole point of my question was to trigger this on every eval so that I wouldn't forget and uninstrument my code by mistake: I have a habit of re-evaluating defns with cider-eval-defun-at-point, but this right now removes instrumentation. I take from your comment that you consider this "run some code on every eval" to be a bad idea 😅, but I don't see why it would cause issues, as long as the code I'm sending does not assume a particular namespace (i.e. only uses fully-qualified symbols known to be available)

Setzer22 2021-04-09T07:51:45.219500Z

> I was actually thinking of general eval hook, as it kind of makes sense, but there was never much demand for it. @bozhidar I, for one, would very much appreciate this 😄, but I also understand if you think it's a bad idea. I can always do some hack on my side to get this working for me

dpsutton 2021-04-09T14:14:42.220200Z

that's fair. sorry i pushed so hard for a different solution

dpsutton 2021-04-09T14:24:50.224300Z

things you could do while waiting to see if an eval hook shows up: - add advice (advice-add cider-eval-last-sexp :after (lambda (&rest r) (that-function-you-already-have-to-instrument)) (i haven't tested this and have never used advice so not sure if this syntax is correct but the gist is there - make a new function that calls cider-eval-last-sexpand then calls the other function. You could make a function personal/instrument that adds your new functions into the cider maps so that it is used everywhere and then a way to turn it off by replacing the standard bindings - add advice to cider-interactive-eval to call your instrumenting function - you could advice/redefine cider-interactive-eval-handler. couple places in there you could a) add a hook and use it, just call out and run your own function