10

While writing RoR code I often need to run drop into a pry session or a debugger. So I place my binding.pry line in the implementation code and run my spec(s). That works fine if I run the specs in a terminal but from inside Emacs, I get a messy output and it's very hard to use the debugger/pry.

How are you guys doing that ?

enter image description here

Dan
  • 32,584
  • 6
  • 98
  • 168

2 Answers2

11

rspec-mode has recently added a section in the README on this subject. It says:

Install inf-ruby and add this to your init file:

(add-hook 'after-init-hook 'inf-ruby-switch-setup)

When you've hit the breakpoint, hit C-x C-q to enable inf-ruby.

Dmitry
  • 3,508
  • 15
  • 20
  • 1
    That does work but unfortunately it has those weird color code characters like `^[[0G`, `^[[1A`. Can I get rid of those ? – Cezar Halmagean Nov 14 '14 at 16:28
  • For one of the escape codes, see the instructions at the bottom: https://github.com/nonsequitur/inf-ruby#bugs. If color codes also pose a problem (on my system, they don't), add `Pry.config.color = false` in the same manner as the fix suggested there. – Dmitry Nov 14 '14 at 17:15
6

I find that pry-remote is the best way to run pry within Emacs, since then pry gets its own dedicated buffer and can attach to a ruby process from anywhere (included a non-Emacs terminal or things like pow). I use something like this:

(defun my-run-remote-pry (&rest args)
  (interactive)
  (let ((buffer (apply 'make-comint "pry-remote" "pry-remote" nil args)))
    (switch-to-buffer buffer)
    (setq-local comint-process-echoes t)))

(define-key ruby-mode-map (kbd "C-c r d") 'my-run-remote-pry) ; (or whatever keybinding)

Then, you'll put binding.remote_pry in your code; you attach to a waiting pry with C-c r d (or whatever) and exit pry (continuing the process) with C-c C-d.

You'll also probably want to disable paging in your ~/.pryrc, since it doesn't play well with comint:

Pry.config.pager = false
shosti
  • 5,048
  • 26
  • 33