This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-09
Channels
- # announcements (26)
- # asami (1)
- # babashka (7)
- # beginners (51)
- # calva (1)
- # cider (18)
- # clj-kondo (6)
- # clj-together (1)
- # cljsrn (4)
- # clojure (78)
- # clojure-australia (3)
- # clojure-europe (25)
- # clojure-losangeles (1)
- # clojure-nl (2)
- # clojure-serbia (4)
- # clojure-spec (23)
- # clojure-uk (19)
- # clojurescript (23)
- # community-development (13)
- # deps-new (1)
- # emacs (24)
- # figwheel-main (5)
- # fulcro (61)
- # graalvm (1)
- # honeysql (11)
- # jobs (1)
- # lsp (7)
- # malli (4)
- # meander (6)
- # membrane (3)
- # off-topic (10)
- # polylith (13)
- # quil (7)
- # re-frame (54)
- # reagent (18)
- # remote-jobs (2)
- # shadow-cljs (81)
- # sql (16)
- # tools-deps (12)
- # xtdb (10)
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. 🙂
@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:
(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)))
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
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-sexp
and 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