21

When running into a deadlock because of an infinite loop, how can I exit from the cider-repl?

When it happens, I have to kill the emacs, or even reboot my computer to kill the cider-repl. Is there a better way of solving this?

legoscia
  • 39,593
  • 22
  • 116
  • 167
cranehuang
  • 465
  • 1
  • 5
  • 11

2 Answers2

16

The key combination C-c C-c will break from a loop at the top level of the cider repl, while leaving emacs and the repl running.

In a regular terminal repl, the equivalent is C-c.

noisesmith
  • 20,076
  • 2
  • 41
  • 49
  • as you can see in the image above , i define a function named random-ints , and define a symbol x using "(def x (rest (random-ints 50)))",so the x is a infinite collection.and I input the "(println x)" ,the emacs paused and I cannot input anything.so I goto the terminal and kill the emacs. – cranehuang Nov 17 '14 at 07:52
  • @RenheHuang I'm not seeing any image – Shawn Zhang Nov 17 '14 at 07:59
  • @ShawnZhang sorry about that.I have a screenshot about what happened,but i cannot upload it.so I describle the "random-ints" as following: (defn random-ints [limit] (lazy-seq (cons (rand-int limit) (random-ints limit)))).and the rest is describled in my last comment. – cranehuang Nov 17 '14 at 08:04
  • If you run `C-c C-c`, emacs will eventually cancel the top level repl command that is looping. This will take a while if it is a tight loop, and even longer if it is producing large amounts of output. But it will eventually stop the code without having to kill emacs. – noisesmith Nov 17 '14 at 08:16
  • Also try `C-c C-b` and `, s X (cider-restart in Spacemacs)`. `C-g` also works in emergencies for all hangs. – HappyFace Dec 15 '18 at 06:45
1

When you're editing a file and have 'jacked-into' a cider repl, by default typing C-c C-c runs cider-eval-defun-at-point, but typing C-c C-b runs cider-interrupt, which cancels whatever is being evaluated.

Adam Lee
  • 1,784
  • 1
  • 11
  • 15