awesome-print / awesome_print

Pretty print your Ruby objects with style -- in full color and with proper indentation
http://github.com/michaeldv/awesome_print
MIT License
4.07k stars 454 forks source link

Print Line Number and File Name #132

Open brunzino opened 10 years ago

brunzino commented 10 years ago

It'd be nice if there was an option for the output to include the line number and file name where the 'ap' command was issued. Just for quick reference if many prints are happening or in case you forget to remove it after debugging, don't have to go searching for it.

Love awesome_print!

clonezone commented 10 years ago

You can get this by using #ai, e.g.

File.open('/dev/tty', 'w') { |h| h.puts "\e[33;1mHERE!\e[0m #{__FILE__}:#{__LINE__} #{thingy.ai}" }

Note that it uses ANSI escape sequences to highlight "HERE!" to separate it from the rest of program output.

I've got a Vim abbreviation for Ruby files that sticks the beginning part of this in:

autocmd FileType ruby inoreabbrev <buffer> tty; File.open('/dev/tty', 'w') { \|h\| h.puts "\e[33;1mHERE!\e[0m #{__FILE__}:#{__LINE__}" }<ESC>3h