This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-08
Channels
- # announcements (1)
- # asami (4)
- # babashka (5)
- # biff (9)
- # calva (26)
- # cider (4)
- # clojure (23)
- # clojure-art (6)
- # clojure-europe (5)
- # clojure-japan (1)
- # clojure-norway (1)
- # clojurescript (11)
- # datomic (7)
- # emacs (26)
- # hoplon (3)
- # hyperfiddle (1)
- # inf-clojure (1)
- # introduce-yourself (5)
- # nyc (34)
- # podcasts-discuss (1)
- # releases (1)
- # shadow-cljs (9)
- # tools-deps (11)
What CALLBACK
in:
(cider-interactive-eval '["1" "2"]' CALLBACK)
would let me store the above clojure list in a elisp list such that i could get the first element from it:
(car cloure-list-turned-elisp-list) => "1"
I'm trying to read the clojure docs to figure this out and I'm not sure how to understand what the callback function should do. the default is described as such:
Signature
(cider-interactive-eval-handler &optional BUFFER PLACE)
Documentation
Make an interactive eval handler for BUFFER.
PLACE is used to display the evaluation result.
If non-nil, it can be the position where the evaluated sexp ends,
or it can be a list with (START END) of the evaluated region.
Update the cider-inspector buffer with the evaluation result
when cider-auto-inspect-after-eval is non-nil.
I'm confused because this doesn't seem to take the results, it seems to just put them someplace on the emacs buffer.this section in the docs looks promising https://docs.cider.mx/cider/usage/code_evaluation.html#storing-eval-results
What's the best way to get the clojure value from cider-interactive-eval? e.g 1 from (cider-interactive-eval "1")? I tried using the callback and it seem like it only deals with where to put the result, but doesn't actually get the clojure value passed to it. I tried reading from the register, and while this works, it seems i have to handle the race condition aspect, which again, implies ideally i was using a callback.
@U0DJ4T5U1 You can leverage 'cider-after-eval-done-hook
to avoid the race condition. This works for me (`core.clj` is a buffer that holds Clojure code and is connected to a CIDER REPL session):
(with-current-buffer
(get-buffer "core.clj")
(cider-interactive-eval
"(into {} [[\"key\" \"val\"]])"))
(defun iarenaza/cider-eval-done-hook ()
(let* ((eval-result-str (get-register cider-eval-register))
(parsed-result (parseedn-read-str eval-result-str)))
(message "value from register e: %S, parsed value (as EDN): %S, val from key: %S"
eval-result-str
parsed-result
(gethash "key" parsed-result))))
(add-hook 'cider-after-eval-done-hook #'iarenaza/cider-eval-done-hook)
The snippet assumes the evaluation result is something that can be parsed as EDN. I.e., plain data, as opposed to functions, records or more elaborate data types that can't be represented as plain data (and thus impossible to translate into Elisp equivalents).