Fork me on GitHub
#cider
<
2019-04-09
>
Trey01:04:13

Is there a function that can take a region selection and wrap it in a let that provides values for the free references?

Trey01:04:49

(str x y z) -> (let [x nil y nil z nil] (str x y z))

Trey01:04:15

(in emacs/cider)

dpsutton02:04:17

I made one for when you are debugging

dpsutton02:04:45

But not in general. It uses the debugger state and not a one off lexical analysis

dpsutton02:04:07

(defun cider-debug-create-local-let (start end)
  "During debugging, grab the locally bound vars and create a let
  binding. Place this let binding in the kill ring for future use."
  (interactive "r")
  (if cider--debug-mode-response
      (nrepl-dbind-response cider--debug-mode-response (locals)
        (let* ((code (buffer-substring-no-properties start end))
               (bindings (apply #'append locals))
               (formatted-bindings (mapconcat 'identity bindings " ")))
          (kill-new (format "(let [%s]\n %s)" formatted-bindings code))
          (message "copied let form to kill ring")))
    (message "No debugging information found.")))

👍 4
benedek08:04:49

there is also introduce let in clojure mode as a refactoring feature. does not do exactly what you asking for tho

manuel09:04:30

A weird thing has been happening lately with a deps.edn/shadow-cljs project I am working on. This is what I do: - shadow-cljs watch my-project from the command line - C-c C-x j j to bring up a Clojure REPL - M-x cider-connect-sibling-cljs All I get is: user-error: ClojureScript is not available. See for details

manuel09:04:30

ClojureScript is available though, because I can compile and watch the project via shadow-cljs with no problem.

manuel09:04:56

Note also that I can bring up the CLJS REPL without a problem if connect to shadow-cljs nREPL via M-x cider-connect and don't do a Clojure jack-in.

manuel10:04:28

And another note: if I connect to shadow first and then I Clojure jack-in, I get 2 working REPLs (CLJ+CLJS).

bozhidar12:04:08

> ClojureScript is available though, because I can compile and watch the project via shadow-cljs with no problem.

bozhidar12:04:52

There’s a simple classpath check for this. Depending on your setup it might have failed resulting in this message.

manuel12:04:52

I see, although I don't understand while connecting to shadow-cljs before jacking-in with Clojure works fine.

bozhidar12:04:08

Not sure how the classpath looks exactly in your case. CIDER simply does a check for clojurescript-something.jar being there.

bozhidar12:04:01

I’ve added this in the past as some people were trying to run ClojureScript REPLs without having clojurescript as a dependency and were getting weird errors then.

manuel12:04:34

ok, thanks. I'll check the classpath and see if something's wrong there.

bozhidar12:04:37

There’s a similar discussion here - https://github.com/clojure-emacs/cider/issues/2308

👍 4
dominicm13:04:21

The check should attempt a require really

bozhidar13:04:22

That was my original plan, but for some reason I thought the classpath check would be simpler and faster to do (because it didn’t require code evaluation). Obviously I was wrong. 🙂

bozhidar13:04:27

I also wanted to check the version of some libs and there was no generic way to do this via evaluation. But I definitely agree that’s a better course of action.

dominicm14:04:21

Reliability matters more than speed

keymone18:04:15

hi, somebody help me understand evaluation mechanics in cider

keymone18:04:33

i have a clj buffer opened and am jacked-in-to a regular clj nrepl

keymone18:04:27

when i cider-eval-last-sexp of a (def something …) it works (i see the output in the buffer)

keymone18:04:41

but when i then try to access it - i get an error that symbol is undefined

dpsutton18:04:54

what does "access" it?

keymone18:04:17

like, i type \something\ in the next line and try to cider-eval-last-sexp it

dpsutton18:04:37

in a source buffer?

dpsutton18:04:40

or the repl

keymone18:04:22

i think i also don’t understand disconnect between evaling things in source buffer and in the repl

keymone18:04:30

but the error i get in source buffer

dpsutton18:04:36

i did this. eval'd the (def x 3) and then eval'd x

keymone18:04:25

i’m in evil mode

keymone18:04:58

so the caret is on the last ) not after it and it evaluates stuff inside (def …) not the def itself

dpsutton18:04:17

yes you need to evaluate the def, not the expression you will use as teh def

keymone18:04:54

there must be some trick people use in evil mode

bfay20:04:11

@U0FU2H117 I'm not sure what other folks do for this, but personally I have semicolon bound to cider-eval-sexp-at-point. I actually put the cursor on the beginning of the thing I want to eval, rather than at the end. I'm pretty convinced that this is the best thing ever and everybody should do it but nobody else seems very impressed when I show them.

bfay20:04:21

If you happen to be using spacemacs and you want to try it out, I defined it putting these two lines in my .spacemacs file, inside dotspacemacs/user-config

(evil-define-key 'normal clojurescript-mode-map ";" 'cider-eval-sexp-at-point)
(evil-define-key 'normal clojure-mode-map ";" 'cider-eval-sexp-at-point)

dpsutton18:04:06

¯\(ツ)

yuhan18:04:51

you might want to set evil-move-beyond-eol to t

❤️ 4
😮 4
keymone18:04:52

i’ll head to noobs channel 🙂

keymone18:04:24

thanks! that worked

yuhan18:04:52

yep, personally I never got used to eval-ing at the "end" of a sexp

dpsutton18:04:14

there's eval top level defun

yuhan18:04:40

I have my own wrapper function that lets me eval from the beginning of one

keymone18:04:00

what if top level is not defun? :^)

dpsutton18:04:26

that doesn't matter. its just the terminology. it should be "top level form"

keymone18:04:44

my top level form is (comment) 🙂

dpsutton18:04:53

got you covered

dpsutton18:04:07

(setq clojure-toplevel-inside-comment-form t)

keymone18:04:28

there’s a variable for everything

keymone18:04:17

this channel is the most helpful so far

yuhan18:04:24

check this out too:

(define-clojure-indent
  (comment (lambda (&rest r) 0))

yuhan18:04:14

kinda non-standard but you get to comment forms out without worrying about changing the indentation and producing huge diffs