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

2 Answers 2


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.

  • 1
    That does work but unfortunately it has those weird color code characters like ^[[0G, ^[[1A. Can I get rid of those ? Nov 14, 2014 at 16:28
  • For one of the escape codes, see the instructions at the bottom: 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, 2014 at 17:15

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.