From 21287630d5ed5d7ec09b1a03688beadb60e109c7 Mon Sep 17 00:00:00 2001 From: John Mair Date: Wed, 14 Sep 2011 05:39:48 +1200 Subject: [PATCH] cat --ex now movies through backtrace with each invocation (keeps state) --- lib/pry/default_commands/shell.rb | 12 +++++++++--- lib/pry/pry_instance.rb | 5 +++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/pry/default_commands/shell.rb b/lib/pry/default_commands/shell.rb index 15a53832..6e3fad17 100644 --- a/lib/pry/default_commands/shell.rb +++ b/lib/pry/default_commands/shell.rb @@ -49,16 +49,22 @@ class Pry end_line = line - 1 end - opt.on :ex, "Show a window of N lines either side of the last exception (defaults to 5).", :optional => true, :as => Integer do |bt_index_str| + opt.on :ex, "Show a window of N lines either side of the last exception (defaults to 5).", :optional => true, :as => Integer do |bt_index_arg| window_size = Pry.config.exception_window_size || 5 - bt_index = bt_index_str.to_i ex = _pry_.last_exception next if !ex + if bt_index_arg + bt_index = bt_index_arg + else + bt_index = ex.bt_index + end + ex.bt_index = (bt_index + 1) % ex.backtrace.size + ex_file, ex_line = ex.bt_source_location_for(bt_index) start_line = (ex_line - 1) - window_size start_line = start_line < 0 ? 0 : start_line end_line = (ex_line - 1) + window_size - if is_core_rbx_path?(ex_file) + if ex_file && is_core_rbx_path?(ex_file) file_name = rbx_convert_path_to_full(ex_file) else file_name = ex_file diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 93daf18c..47dc0085 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -346,14 +346,15 @@ class Pry # @param [Binding] target The binding to set `_ex_` on. def set_last_exception(ex, target) class << ex - attr_accessor :file, :line + attr_accessor :file, :line, :bt_index def bt_source_location_for(index) backtrace[index] =~ /(.*):(\d+)/ [$1, $2.to_i] end end - ex.file, ex.line = ex.bt_source_location_for(0)#_btw_index#$1, $2.to_i + ex.bt_index = 0 + ex.file, ex.line = ex.bt_source_location_for(0) @last_result_is_exception = true @output_array << ex