Exception: StandardError

Inherits:
Exception
  • Object
show all
Defined in:
lib/std_err_hooks.rb

Overview

This hooks into standard error to open backtraces in vim

Instance Method Summary collapse

Instance Method Details

#_backtraceObject



3
# File 'lib/std_err_hooks.rb', line 3

alias _backtrace backtrace

#backtraceObject



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 message_is_filtered?
    @old_backtrace = true
  end
  old
end

#backtrace_filtersObject

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_filtersObject



57
58
59
60
61
# File 'lib/std_err_hooks.rb', line 57

def message_filters
  [
    "Gem::Exception: can't activate"
  ]
end

#message_is_filtered?Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
# File 'lib/std_err_hooks.rb', line 4

def message_is_filtered?
  matches = message_filters.detect do |message_filter|
    [self.class, message].join(": ").match message_filter
  end
  puts "#{message} 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