Exception: StandardError
- Inherits:
-
Exception
- Object
- Exception
- StandardError
- Defined in:
- lib/std_err_hooks.rb
Overview
This hooks into standard error to open backtraces in vim
Instance Method Summary collapse
- #_backtrace ⇒ Object
- #backtrace ⇒ Object
-
#backtrace_filters ⇒ Object
Don’t run the backtrace file opener if the exception matches this.
- #message_filters ⇒ Object
- #message_is_filtered? ⇒ Boolean
- #open_vims(lines) ⇒ Object
Instance Method Details
#_backtrace ⇒ Object
3 |
# File 'lib/std_err_hooks.rb', line 3 alias _backtrace backtrace |
#backtrace ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/std_err_hooks.rb', line 12 def backtrace old = _backtrace @old_backtrace ||= nil if old.kind_of?(Array) and @old_backtrace.nil? open_vims(old) unless @old_backtrace = true end old end |
#backtrace_filters ⇒ Object
Don’t run the backtrace file opener if the exception matches this
50 51 52 53 54 55 |
# File 'lib/std_err_hooks.rb', line 50 def backtrace_filters [ "rubygems.rb:\d+:in `activate", "/irb/workspace.rb" ] end |
#message_filters ⇒ Object
57 58 59 60 61 |
# File 'lib/std_err_hooks.rb', line 57 def [ "Gem::Exception: can't activate" ] end |
#message_is_filtered? ⇒ Boolean
4 5 6 7 8 9 10 |
# File 'lib/std_err_hooks.rb', line 4 def matches = .detect do || [self.class, ].join(": ").match end puts "#{} Matched #{matches.inspect}" if matches matches ? true : false end |
#open_vims(lines) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/std_err_hooks.rb', line 22 def open_vims(lines) good_lines = lines.select { |l| l.match(/^[.\/\w][^:\s]*:\d+(?::.*)?$/) }.map do |line| next if backtrace_filters.detect { |n| line.match n } file, line_number, rest = line.split(":") [file, line_number] end.compact.uniq return if good_lines.size == 0 file, line = good_lines.shift if file.match("->") window = file.split("->")[1] %x{screen -X select #{window}} %x{screen -p #{window} -X stuff ":#{line}\n"} return end s = "screen vim -p" s << " +#{line} #{file}" # for handling multiple levels back, disabled for now =begin good_lines.each do |l| file, line = l s << " -c tabnext -c #{line} #{file} " end s << " -c tabnext " if good_lines.size > 0 =end %x{screen -X #{s}} end |