Fork me on GitHub

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


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


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


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


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


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


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


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


i'd add this to a register as well:

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

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


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


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


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


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)


> 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


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


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