Fork me on GitHub
#cider
<
2018-01-11
>
qqq10:01:52

(let [a 1 b 2] (+ a b) ;; cursor here, is there a way to make C-x C-e work? (+ 2 3))

bozhidar11:01:49

Yeah, probably that’d be the only option as you’d need to step through the code to evaluate this expression.

bozhidar11:01:09

Another idea was suggest here https://github.com/clojure-emacs/cider/issues/2113 and it’s pretty great, but it also requires some parsing of the containing forms to figure out if something is local or not.

qqq11:01:07

here's a dumbass idea I have in mind: contextful-eval which behaves at follows:

qqq11:01:45

1. p = (point)
2. go backwards until first "^("
3. count how many unbalanced "([{" we got
4. append right number of "}})" to balance
5. evl

qqq11:01:24

or, instead of step 2, do "get parent sexp until no parent exists"

bozhidar11:01:29

Yeah, that’s a simpler version of what’s discussed in the ticket - there the idea is to find all local variables, get prompted for them and replace them in the expression that will get evaluated.

bozhidar11:01:56

You idea would work for simple scenarios, but if there’s a local coming from a higher-level let this would break.

qqq11:01:34

I don't understand. My naive reasoning is:

(let [...]
  (expr I want to eval) ;; cursor here
  (stuff I don't care about))
basically, I want to "find the outer most sexp", then I want to, while preserving balanced (), kill everything after the cursor then I want to eval the modified "outermost sexp"

bozhidar12:01:24

Ah, now I get it. I thought you wanted to find the first outer let. Should have paid more attention.

bozhidar12:01:14

That’s actual much simpler as we already have the code that finds the top-level expression and the only thing needed it just terminate the expression after the current sexp. Should be trivial to implement.

qqq12:01:12

the only thing needed it just terminate the expression after the current sexp <-- precisely what I had in mind, even better explanation! any chance this makes it into 0.18 ? 🙂

dpsutton13:01:31

@qqq i made a function that will grab the locals from a debugging session

dpsutton13:01:35

(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.")))

dpsutton13:01:06

while debugging, highlight some code and invoke this function. it will copy the forms you have highlighted and create a let binding binding all of the local vars in a debugging session

dpsutton13:01:31

so in that example earlier, step through it and then highlight (+ a b) and call that function.

dpsutton13:01:03

(defn stuff []
  (let [a 1
        b 2]
    (+ a b)
    (+ 2 3)))
and debug it. highlight (+ a b) and run cider-debug-create-local-let will yank

dpsutton13:01:09

(let [a 1 b 2]
 (+ a b))
into your kill ring

daveliepmann16:01:47

CIDER install instructions say that "Starting with version 0.11, When cider-jack-in (C-c M-j) is used, CIDER takes care of injecting [nREPL] and its other dependencies." https://cider.readthedocs.io/en/latest/installation/#ciders-nrepl-middleware Yet, I'm seeing nrepl version-string "0.2.13" in nrepl-messages while on CIDER 0.16.0. Could this indicate a problem?

daveliepmann16:01:02

(This is related to debugging an issue where running tests from CIDER hangs indefinitely when a function returns a map that has a decimal value but runs fine with an integer value in the map.)

dominicm16:01:31

@daveliepmann I don't think so, isn't that just the version of nrepl being injected?

daveliepmann16:01:28

not sure, it definitely could be—but I would expect version 0.16.0 to be injected, right?

dominicm16:01:46

0.16.0 is cider version

daveliepmann16:01:19

yes, but aren't CIDER versions supposed to match nREPL versions? and nREPL repo says 0.16.0 is most recent and recommended https://github.com/clojure-emacs/cider-nrepl

dominicm16:01:47

@daveliepmann 0.2.13 is the tools.nrepl version 🙂

daveliepmann16:01:58

overloaded names are always a delight

daveliepmann16:01:03

thanks for the clarification

bozhidar16:01:58

cider-nrepl -> CIDER nREPL middleware 🙂

bozhidar16:01:02

@qqq file a ticket and put there our conversation highlights. Then everything is possible.

bozhidar16:01:55

@dpsutton Cool utility!

lockdown-17:01:19

does cider support the new 'clj' command?

lockdown-17:01:53

like, can I run cider without lein or boot and just clj ?

dominicm17:01:13

@lockdown- only if you cider-connect

bozhidar17:01:04

Indeed. CIDER simply needs some nREPL server to connect to. It doesn’t care how exactly it was started. Not sure how you can start a server with clj, though - I though it just starts a REPL with all deps you specific.

dominicm17:01:11

@bozhidar I put my nrepl start into user.clj

dominicm17:01:38

(don't put it into your component system, else a reset will disconnect you!)

lockdown-18:01:42

@dominicm is user.clj a NS inside your src project?

dominicm18:01:58

@lockdown- yes

bozhidar20:01:47

Interesting idea.

dominicm20:01:46

It does work, not followed it extensively.

dominicm20:01:05

I'm working out some kinks in tools.deps.alpha stopping us from using clj for an internalish project (the JUXT website)

bozhidar20:01:02

That’s pretty cool!

dominicm20:01:50

Once clj adds support for a command line edn file https://dev.clojure.org/jira/browse/TDEPS-19 you can probably have a jack in like clj -G'{:extra-deps {cider-nrepl {}}}' -m cider.main cider.nrepl/middleware …

bozhidar20:01:52

Yeah, that’s how I hope we can use this down the road.

tsulej22:01:49

Has anything changed in the last hour in cider-nrepl snapshot (0.17.0)?

tsulej22:01:54

Error loading refactor-nrepl.middleware: java.lang.IllegalAccessError: err-info does not exist, compiling:(refactor_nrepl/middleware.clj:1:1) Exception in thread "main" java.lang.RuntimeException: Unable to resolve var: refactor-nrepl.middleware/wrap-refactor in this context