8

Right now, when I want a breakpoint in vim or Sublime Text, I drop a line like the following into the code:

binding.pry if Rails.env.test?

Pry (and its associated plugins) provide a nice environment in which to do interactive Ruby debugging from the command line.

However, adding actual code to my projects to create each breakpoint (and remembering to remove such code when I make commits) can be cumbersome.

I love what vim-ruby-debugger does in terms of dropping a visual breakpoint into the editor without actually modifying my project's source code, but I've had some trouble getting this to function in the context of my specs (and I'd really prefer to just use Pry 'breakpoints' in the first place).

So the question is, is it possible to drop a binding.pry reference into a file such that an editor like Vim (or Sublime Text, etc.) will pick it up and respond appropriately at debug-time without the line actually be included in the source code?

2
  • you'd have to write a script to talk between pry & vim. Using vim --remote-expr you can achieve the same. Commented Jun 5, 2013 at 4:07
  • do you want pry-debugger style breakpoints - with navigation and all? (I'm guessing you do) or do you really just want to drop a pry in there? Commented Jan 26, 2014 at 8:52

5 Answers 5

3

You can use a Git Hooks to prevent a bad commit, like leaving a binding.pry in your code.

This article explains how to do it https://launchacademy.com/blog/automatically-prevent-bad-git-commits

Here you are another good post about it http://www.ryanmcg.com/2013/8/12/another-forgotten-binding-pry/

Also I totally agree that PRY is an exceptional Gem.

Sign up to request clarification or add additional context in comments.

Comments

2

I'm not aware of any editors or editor plugins that allow you to use Pry by setting breakpoints without actually adding a binding.pry invocation to your source code.

I think the closest solution to your ask would be to use a plugin like vim-infer-debugger, which provides functions to automatically insert debugging statements based on the current filetype. An additional benefit of this plugin is that there's also a command to remove debugger statements, which you could map like so:

nmap <Leader>d :call RemoveAllDebuggers()<cr>

Combined with Git hooks, as mentioned in other answers, this should make it easier to ensure that debugger calls don't get left in your code.

Comments

0

http://www.vim.org/scripts/script.php?script_id=4451 seems to solve what you want. I haven't tried it personally, but I am going to :).

1 Comment

I'm aware of ruby_pry.vim, but I haven't seen evidence that it can do what I describe above.
0

First off, PRY is an amazing tool and I am glad you found it.

is it possible to drop a binding.pry reference into a file ... without the line actually be >included in the source code?

You need to drop a binding.pry directly in the source code for it to go into pry to test and play around. FYI if you drop a binding.pry into your spec file it will open pry IN the spec file not what it refers to.

You can try better_erros with binding_of_caller and when you run a failing rails server, a) it gives you a better error feel and gives you a direct pry box to the error.

Comments

0

I don't use pry when debugging, I just use the regular debugger if I must. However, here's my vim workflow.

  1. I have vim macro saved "@d" that inserts the following code under whatever line I'm in require 'debugger';debugger;0 This makes it very easy to insert.

  2. To avoid committing debugger lines, I have setup a git hook (pre-commit) that checks if the commit includes these lines (grep)

http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.