pry 0.9.12.6-i386-mswin32 → 0.10.0-i386-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +702 -0
- data/LICENSE +2 -2
- data/{README.markdown → README.md} +37 -31
- data/lib/pry.rb +38 -151
- data/lib/pry/cli.rb +35 -17
- data/lib/pry/code.rb +19 -63
- data/lib/pry/code/code_file.rb +103 -0
- data/lib/pry/code/code_range.rb +2 -1
- data/lib/pry/code/loc.rb +2 -2
- data/lib/pry/code_object.rb +40 -21
- data/lib/pry/color_printer.rb +55 -0
- data/lib/pry/command.rb +12 -9
- data/lib/pry/command_set.rb +81 -38
- data/lib/pry/commands.rb +1 -1
- data/lib/pry/commands/amend_line.rb +2 -2
- data/lib/pry/commands/bang.rb +1 -1
- data/lib/pry/commands/cat.rb +11 -2
- data/lib/pry/commands/cat/exception_formatter.rb +6 -7
- data/lib/pry/commands/cat/file_formatter.rb +15 -32
- data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
- data/lib/pry/commands/cd.rb +14 -3
- data/lib/pry/commands/change_inspector.rb +27 -0
- data/lib/pry/commands/change_prompt.rb +26 -0
- data/lib/pry/commands/code_collector.rb +4 -4
- data/lib/pry/commands/easter_eggs.rb +3 -3
- data/lib/pry/commands/edit.rb +10 -22
- data/lib/pry/commands/edit/exception_patcher.rb +2 -2
- data/lib/pry/commands/edit/file_and_line_locator.rb +0 -2
- data/lib/pry/commands/exit_program.rb +0 -1
- data/lib/pry/commands/find_method.rb +16 -22
- data/lib/pry/commands/gem_install.rb +5 -2
- data/lib/pry/commands/gem_open.rb +1 -1
- data/lib/pry/commands/gist.rb +10 -11
- data/lib/pry/commands/help.rb +14 -14
- data/lib/pry/commands/hist.rb +27 -8
- data/lib/pry/commands/install_command.rb +14 -12
- data/lib/pry/commands/list_inspectors.rb +35 -0
- data/lib/pry/commands/list_prompts.rb +35 -0
- data/lib/pry/commands/ls.rb +72 -296
- data/lib/pry/commands/ls/constants.rb +47 -0
- data/lib/pry/commands/ls/formatter.rb +49 -0
- data/lib/pry/commands/ls/globals.rb +48 -0
- data/lib/pry/commands/ls/grep.rb +21 -0
- data/lib/pry/commands/ls/instance_vars.rb +39 -0
- data/lib/pry/commands/ls/interrogatable.rb +18 -0
- data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
- data/lib/pry/commands/ls/local_names.rb +35 -0
- data/lib/pry/commands/ls/local_vars.rb +39 -0
- data/lib/pry/commands/ls/ls_entity.rb +70 -0
- data/lib/pry/commands/ls/methods.rb +57 -0
- data/lib/pry/commands/ls/methods_helper.rb +46 -0
- data/lib/pry/commands/ls/self_methods.rb +32 -0
- data/lib/pry/commands/play.rb +44 -10
- data/lib/pry/commands/pry_backtrace.rb +1 -2
- data/lib/pry/commands/raise_up.rb +2 -2
- data/lib/pry/commands/reload_code.rb +16 -19
- data/lib/pry/commands/ri.rb +7 -3
- data/lib/pry/commands/shell_command.rb +18 -13
- data/lib/pry/commands/shell_mode.rb +2 -4
- data/lib/pry/commands/show_doc.rb +5 -0
- data/lib/pry/commands/show_info.rb +8 -13
- data/lib/pry/commands/show_source.rb +15 -3
- data/lib/pry/commands/simple_prompt.rb +1 -1
- data/lib/pry/commands/toggle_color.rb +8 -4
- data/lib/pry/commands/watch_expression.rb +105 -0
- data/lib/pry/commands/watch_expression/expression.rb +38 -0
- data/lib/pry/commands/whereami.rb +18 -10
- data/lib/pry/commands/wtf.rb +3 -3
- data/lib/pry/config.rb +20 -254
- data/lib/pry/config/behavior.rb +139 -0
- data/lib/pry/config/convenience.rb +26 -0
- data/lib/pry/config/default.rb +165 -0
- data/lib/pry/core_extensions.rb +31 -21
- data/lib/pry/editor.rb +107 -103
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers/base_helpers.rb +22 -109
- data/lib/pry/helpers/command_helpers.rb +10 -8
- data/lib/pry/helpers/documentation_helpers.rb +1 -2
- data/lib/pry/helpers/text.rb +4 -5
- data/lib/pry/history.rb +46 -45
- data/lib/pry/history_array.rb +6 -1
- data/lib/pry/hooks.rb +9 -29
- data/lib/pry/indent.rb +6 -6
- data/lib/pry/input_completer.rb +242 -0
- data/lib/pry/input_lock.rb +132 -0
- data/lib/pry/inspector.rb +27 -0
- data/lib/pry/last_exception.rb +61 -0
- data/lib/pry/method.rb +82 -87
- data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +41 -38
- data/lib/pry/module_candidate.rb +4 -14
- data/lib/pry/object_path.rb +82 -0
- data/lib/pry/output.rb +50 -0
- data/lib/pry/pager.rb +193 -48
- data/lib/pry/plugins.rb +1 -1
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +149 -230
- data/lib/pry/pry_instance.rb +302 -413
- data/lib/pry/rbx_path.rb +1 -1
- data/lib/pry/repl.rb +202 -0
- data/lib/pry/repl_file_loader.rb +20 -26
- data/lib/pry/rubygem.rb +13 -5
- data/lib/pry/terminal.rb +2 -1
- data/lib/pry/test/helper.rb +26 -41
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +45 -59
- metadata +62 -225
- data/.document +0 -2
- data/.gitignore +0 -16
- data/.travis.yml +0 -25
- data/.yardopts +0 -1
- data/CHANGELOG +0 -534
- data/CONTRIBUTORS +0 -55
- data/Gemfile +0 -12
- data/Rakefile +0 -140
- data/TODO +0 -117
- data/lib/pry/completion.rb +0 -321
- data/lib/pry/custom_completions.rb +0 -6
- data/lib/pry/rbx_method.rb +0 -13
- data/man/pry.1 +0 -195
- data/man/pry.1.html +0 -204
- data/man/pry.1.ronn +0 -141
- data/pry.gemspec +0 -29
- data/spec/Procfile +0 -3
- data/spec/cli_spec.rb +0 -78
- data/spec/code_object_spec.rb +0 -277
- data/spec/code_spec.rb +0 -219
- data/spec/command_helpers_spec.rb +0 -29
- data/spec/command_integration_spec.rb +0 -644
- data/spec/command_set_spec.rb +0 -627
- data/spec/command_spec.rb +0 -821
- data/spec/commands/amend_line_spec.rb +0 -247
- data/spec/commands/bang_spec.rb +0 -19
- data/spec/commands/cat_spec.rb +0 -164
- data/spec/commands/cd_spec.rb +0 -250
- data/spec/commands/disable_pry_spec.rb +0 -25
- data/spec/commands/edit_spec.rb +0 -727
- data/spec/commands/exit_all_spec.rb +0 -34
- data/spec/commands/exit_program_spec.rb +0 -19
- data/spec/commands/exit_spec.rb +0 -34
- data/spec/commands/find_method_spec.rb +0 -70
- data/spec/commands/gem_list_spec.rb +0 -26
- data/spec/commands/gist_spec.rb +0 -79
- data/spec/commands/help_spec.rb +0 -56
- data/spec/commands/hist_spec.rb +0 -181
- data/spec/commands/jump_to_spec.rb +0 -15
- data/spec/commands/ls_spec.rb +0 -181
- data/spec/commands/play_spec.rb +0 -140
- data/spec/commands/raise_up_spec.rb +0 -56
- data/spec/commands/save_file_spec.rb +0 -177
- data/spec/commands/show_doc_spec.rb +0 -510
- data/spec/commands/show_input_spec.rb +0 -17
- data/spec/commands/show_source_spec.rb +0 -782
- data/spec/commands/whereami_spec.rb +0 -203
- data/spec/completion_spec.rb +0 -241
- data/spec/control_d_handler_spec.rb +0 -58
- data/spec/documentation_helper_spec.rb +0 -73
- data/spec/editor_spec.rb +0 -79
- data/spec/exception_whitelist_spec.rb +0 -21
- data/spec/fixtures/candidate_helper1.rb +0 -11
- data/spec/fixtures/candidate_helper2.rb +0 -8
- data/spec/fixtures/example.erb +0 -5
- data/spec/fixtures/example_nesting.rb +0 -33
- data/spec/fixtures/show_source_doc_examples.rb +0 -15
- data/spec/fixtures/testrc +0 -2
- data/spec/fixtures/testrcbad +0 -2
- data/spec/fixtures/whereami_helper.rb +0 -6
- data/spec/helper.rb +0 -34
- data/spec/helpers/bacon.rb +0 -86
- data/spec/helpers/mock_pry.rb +0 -43
- data/spec/helpers/table_spec.rb +0 -105
- data/spec/history_array_spec.rb +0 -67
- data/spec/hooks_spec.rb +0 -522
- data/spec/indent_spec.rb +0 -301
- data/spec/input_stack_spec.rb +0 -90
- data/spec/method_spec.rb +0 -482
- data/spec/prompt_spec.rb +0 -60
- data/spec/pry_defaults_spec.rb +0 -419
- data/spec/pry_history_spec.rb +0 -99
- data/spec/pry_output_spec.rb +0 -95
- data/spec/pry_spec.rb +0 -515
- data/spec/run_command_spec.rb +0 -25
- data/spec/sticky_locals_spec.rb +0 -157
- data/spec/syntax_checking_spec.rb +0 -81
- data/spec/wrapped_module_spec.rb +0 -261
- data/wiki/Customizing-pry.md +0 -397
- data/wiki/Home.md +0 -4
@@ -0,0 +1,139 @@
|
|
1
|
+
module Pry::Config::Behavior
|
2
|
+
ASSIGNMENT = "=".freeze
|
3
|
+
NODUP = [TrueClass, FalseClass, NilClass, Symbol, Numeric, Module, Proc].freeze
|
4
|
+
INSPECT_REGEXP = /#{Regexp.escape "default=#<"}/
|
5
|
+
|
6
|
+
module Builder
|
7
|
+
def from_hash(hash, default = nil)
|
8
|
+
new(default).tap do |config|
|
9
|
+
config.merge!(hash)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.included(klass)
|
15
|
+
unless defined?(RESERVED_KEYS)
|
16
|
+
const_set :RESERVED_KEYS, instance_methods(false).map(&:to_s).freeze
|
17
|
+
end
|
18
|
+
klass.extend(Builder)
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(default = Pry.config)
|
22
|
+
@default = default
|
23
|
+
@lookup = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# @return [Pry::Config::Behavior]
|
28
|
+
# returns the default used if a matching value for a key isn't found in self
|
29
|
+
#
|
30
|
+
def default
|
31
|
+
@default
|
32
|
+
end
|
33
|
+
|
34
|
+
def [](key)
|
35
|
+
@lookup[key.to_s]
|
36
|
+
end
|
37
|
+
|
38
|
+
def []=(key, value)
|
39
|
+
key = key.to_s
|
40
|
+
if RESERVED_KEYS.include?(key)
|
41
|
+
raise ArgumentError, "few things are reserved by pry, but using '#{key}' as a configuration key is."
|
42
|
+
end
|
43
|
+
@lookup[key] = value
|
44
|
+
end
|
45
|
+
|
46
|
+
def method_missing(name, *args, &block)
|
47
|
+
key = name.to_s
|
48
|
+
if key[-1] == ASSIGNMENT
|
49
|
+
short_key = key[0..-2]
|
50
|
+
self[short_key] = args[0]
|
51
|
+
elsif key?(key)
|
52
|
+
self[key]
|
53
|
+
elsif @default.respond_to?(name)
|
54
|
+
value = @default.public_send(name, *args, &block)
|
55
|
+
# FIXME: refactor Pry::Hook so that it stores config on the config object,
|
56
|
+
# so that we can use the normal strategy.
|
57
|
+
self[key] = value.dup if key == 'hooks'
|
58
|
+
value
|
59
|
+
else
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def merge!(other)
|
65
|
+
other = try_convert_to_hash(other)
|
66
|
+
raise TypeError, "unable to convert argument into a Hash" unless other
|
67
|
+
other.each do |key, value|
|
68
|
+
self[key] = value
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def ==(other)
|
73
|
+
@lookup == try_convert_to_hash(other)
|
74
|
+
end
|
75
|
+
alias_method :eql?, :==
|
76
|
+
|
77
|
+
def respond_to_missing?(key, include_private=false)
|
78
|
+
key?(key) or @default.respond_to?(key) or super(key, include_private)
|
79
|
+
end
|
80
|
+
|
81
|
+
def key?(key)
|
82
|
+
key = key.to_s
|
83
|
+
@lookup.key?(key)
|
84
|
+
end
|
85
|
+
|
86
|
+
def clear
|
87
|
+
@lookup.clear
|
88
|
+
true
|
89
|
+
end
|
90
|
+
alias_method :refresh, :clear
|
91
|
+
|
92
|
+
def forget(key)
|
93
|
+
@lookup.delete(key.to_s)
|
94
|
+
end
|
95
|
+
|
96
|
+
def keys
|
97
|
+
@lookup.keys
|
98
|
+
end
|
99
|
+
|
100
|
+
def to_hash
|
101
|
+
@lookup.dup
|
102
|
+
end
|
103
|
+
alias_method :to_h, :to_hash
|
104
|
+
|
105
|
+
|
106
|
+
def inspect
|
107
|
+
key_str = keys.map { |key| "'#{key}'" }.join(",")
|
108
|
+
"#<#{_clip_inspect(self)} local_keys=[#{key_str}] default=#{@default.inspect}>"
|
109
|
+
end
|
110
|
+
|
111
|
+
def pretty_print(q)
|
112
|
+
q.text inspect[1..-1].gsub(INSPECT_REGEXP, "default=<")
|
113
|
+
end
|
114
|
+
|
115
|
+
private
|
116
|
+
def _clip_inspect(obj)
|
117
|
+
"#{obj.class}:0x%x" % obj.object_id << 1
|
118
|
+
end
|
119
|
+
|
120
|
+
def _dup(value)
|
121
|
+
if NODUP.any? { |klass| klass === value }
|
122
|
+
value
|
123
|
+
else
|
124
|
+
value.dup
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def try_convert_to_hash(obj)
|
129
|
+
if Hash === obj
|
130
|
+
obj
|
131
|
+
elsif obj.respond_to?(:to_h)
|
132
|
+
obj.to_h
|
133
|
+
elsif obj.respond_to?(:to_hash)
|
134
|
+
obj.to_hash
|
135
|
+
else
|
136
|
+
nil
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Pry::Config::Convenience
|
2
|
+
SHORTCUTS = [
|
3
|
+
:input,
|
4
|
+
:output,
|
5
|
+
:commands,
|
6
|
+
:print,
|
7
|
+
:exception_handler,
|
8
|
+
:quiet?,
|
9
|
+
:hooks,
|
10
|
+
:color,
|
11
|
+
:pager,
|
12
|
+
:editor,
|
13
|
+
:memory_size,
|
14
|
+
:extra_sticky_locals
|
15
|
+
]
|
16
|
+
|
17
|
+
|
18
|
+
def config_shortcut(*names)
|
19
|
+
names.each do |name|
|
20
|
+
reader = name
|
21
|
+
setter = "#{name}="
|
22
|
+
define_method(reader) { config.public_send(name) }
|
23
|
+
define_method(setter) { |value| config.public_send(setter, value) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
class Pry::Config::Default
|
2
|
+
include Pry::Config::Behavior
|
3
|
+
|
4
|
+
default = {
|
5
|
+
input: proc {
|
6
|
+
lazy_readline
|
7
|
+
},
|
8
|
+
output: proc {
|
9
|
+
$stdout
|
10
|
+
},
|
11
|
+
commands: proc {
|
12
|
+
Pry::Commands
|
13
|
+
},
|
14
|
+
prompt_name: proc {
|
15
|
+
Pry::DEFAULT_PROMPT_NAME
|
16
|
+
},
|
17
|
+
prompt: proc {
|
18
|
+
Pry::DEFAULT_PROMPT
|
19
|
+
},
|
20
|
+
prompt_safe_objects: proc {
|
21
|
+
Pry::DEFAULT_PROMPT_SAFE_OBJECTS
|
22
|
+
},
|
23
|
+
print: proc {
|
24
|
+
Pry::DEFAULT_PRINT
|
25
|
+
},
|
26
|
+
quiet: proc {
|
27
|
+
false
|
28
|
+
},
|
29
|
+
exception_handler: proc {
|
30
|
+
Pry::DEFAULT_EXCEPTION_HANDLER
|
31
|
+
},
|
32
|
+
exception_whitelist: proc {
|
33
|
+
Pry::DEFAULT_EXCEPTION_WHITELIST
|
34
|
+
},
|
35
|
+
hooks: proc {
|
36
|
+
Pry::DEFAULT_HOOKS
|
37
|
+
},
|
38
|
+
pager: proc {
|
39
|
+
true
|
40
|
+
},
|
41
|
+
system: proc {
|
42
|
+
Pry::DEFAULT_SYSTEM
|
43
|
+
},
|
44
|
+
color: proc {
|
45
|
+
Pry::Helpers::BaseHelpers.use_ansi_codes?
|
46
|
+
},
|
47
|
+
default_window_size: proc {
|
48
|
+
5
|
49
|
+
},
|
50
|
+
editor: proc {
|
51
|
+
Pry.default_editor_for_platform
|
52
|
+
}, # TODO: Pry::Platform.editor
|
53
|
+
should_load_rc: proc {
|
54
|
+
true
|
55
|
+
},
|
56
|
+
should_load_local_rc: proc {
|
57
|
+
true
|
58
|
+
},
|
59
|
+
should_trap_interrupts: proc {
|
60
|
+
Pry::Helpers::BaseHelpers.jruby?
|
61
|
+
}, # TODO: Pry::Platform.jruby?
|
62
|
+
disable_auto_reload: proc {
|
63
|
+
false
|
64
|
+
},
|
65
|
+
command_prefix: proc {
|
66
|
+
""
|
67
|
+
},
|
68
|
+
auto_indent: proc {
|
69
|
+
Pry::Helpers::BaseHelpers.use_ansi_codes?
|
70
|
+
},
|
71
|
+
correct_indent: proc {
|
72
|
+
true
|
73
|
+
},
|
74
|
+
collision_warning: proc {
|
75
|
+
false
|
76
|
+
},
|
77
|
+
output_prefix: proc {
|
78
|
+
"=> "
|
79
|
+
},
|
80
|
+
requires: proc {
|
81
|
+
[]
|
82
|
+
},
|
83
|
+
should_load_requires: proc {
|
84
|
+
true
|
85
|
+
},
|
86
|
+
should_load_plugins: proc {
|
87
|
+
true
|
88
|
+
},
|
89
|
+
windows_console_warning: proc {
|
90
|
+
true
|
91
|
+
},
|
92
|
+
control_d_handler: proc {
|
93
|
+
Pry::DEFAULT_CONTROL_D_HANDLER
|
94
|
+
},
|
95
|
+
memory_size: proc {
|
96
|
+
100
|
97
|
+
},
|
98
|
+
extra_sticky_locals: proc {
|
99
|
+
{}
|
100
|
+
},
|
101
|
+
command_completions: proc {
|
102
|
+
proc { commands.keys }
|
103
|
+
},
|
104
|
+
file_completions: proc {
|
105
|
+
proc { Dir["."] }
|
106
|
+
},
|
107
|
+
ls: proc {
|
108
|
+
Pry::Config.from_hash(Pry::Command::Ls::DEFAULT_OPTIONS)
|
109
|
+
},
|
110
|
+
completer: proc {
|
111
|
+
require "pry/input_completer"
|
112
|
+
Pry::InputCompleter
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
def initialize
|
117
|
+
super(nil)
|
118
|
+
configure_gist
|
119
|
+
configure_history
|
120
|
+
end
|
121
|
+
|
122
|
+
def quiet?
|
123
|
+
quiet
|
124
|
+
end
|
125
|
+
|
126
|
+
default.each do |key, value|
|
127
|
+
define_method(key) do
|
128
|
+
if default[key].equal?(value)
|
129
|
+
default[key] = instance_eval(&value)
|
130
|
+
end
|
131
|
+
default[key]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
private
|
136
|
+
# TODO:
|
137
|
+
# all of this configure_* stuff is a relic of old code.
|
138
|
+
# we should try move this code to being command-local.
|
139
|
+
def configure_gist
|
140
|
+
self["gist"] = Pry::Config.from_hash(inspecter: proc(&:pretty_inspect))
|
141
|
+
end
|
142
|
+
|
143
|
+
def configure_history
|
144
|
+
self["history"] = Pry::Config.from_hash "should_save" => true,
|
145
|
+
"should_load" => true
|
146
|
+
history.file = File.expand_path("~/.pry_history") rescue nil
|
147
|
+
if history.file.nil?
|
148
|
+
self.should_load_rc = false
|
149
|
+
history.should_save = false
|
150
|
+
history.should_load = false
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def lazy_readline
|
155
|
+
require 'readline'
|
156
|
+
Readline
|
157
|
+
rescue LoadError
|
158
|
+
warn "Sorry, you can't use Pry without Readline or a compatible library."
|
159
|
+
warn "Possible solutions:"
|
160
|
+
warn " * Rebuild Ruby with Readline support using `--with-readline`"
|
161
|
+
warn " * Use the rb-readline gem, which is a pure-Ruby port of Readline"
|
162
|
+
warn " * Use the pry-coolline gem, a pure-ruby alternative to Readline"
|
163
|
+
raise
|
164
|
+
end
|
165
|
+
end
|
data/lib/pry/core_extensions.rb
CHANGED
@@ -84,14 +84,14 @@ class Object
|
|
84
84
|
# it has the nice property that we can memoize this check.
|
85
85
|
begin
|
86
86
|
# instance_eval sets the default definee to the object's singleton class
|
87
|
-
instance_eval
|
87
|
+
instance_eval(*Pry::BINDING_METHOD_IMPL)
|
88
88
|
|
89
89
|
# If we can't define methods on the Object's singleton_class. Then we fall
|
90
90
|
# back to setting the default definee to be the Object's class. That seems
|
91
91
|
# nicer than having a REPL in which you can't define methods.
|
92
|
-
rescue TypeError
|
92
|
+
rescue TypeError, Pry::FrozenObjectException
|
93
93
|
# class_eval sets the default definee to self.class
|
94
|
-
self.class.class_eval
|
94
|
+
self.class.class_eval(*Pry::BINDING_METHOD_IMPL)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -99,23 +99,33 @@ class Object
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
-
|
103
|
-
#
|
104
|
-
#
|
105
|
-
#
|
106
|
-
#
|
107
|
-
#
|
108
|
-
#
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
102
|
+
class BasicObject
|
103
|
+
# Return a binding object for the receiver.
|
104
|
+
#
|
105
|
+
# The `self` of the binding is set to the current object, and it contains no
|
106
|
+
# local variables.
|
107
|
+
#
|
108
|
+
# The default definee (http://yugui.jp/articles/846) is set such that new
|
109
|
+
# methods defined will be added to the singleton class of the BasicObject.
|
110
|
+
#
|
111
|
+
# @return [Binding]
|
112
|
+
def __binding__
|
113
|
+
# BasicObjects don't have respond_to?, so we just define the method
|
114
|
+
# every time. As they also don't have `.freeze`, this call won't
|
115
|
+
# fail as it can for normal Objects.
|
116
|
+
(class << self; self; end).class_eval <<-EOF, __FILE__, __LINE__ + 1
|
117
|
+
# Get a binding with 'self' set to self, and no locals.
|
118
|
+
#
|
119
|
+
# The default definee is determined by the context in which the
|
120
|
+
# definition is eval'd.
|
121
|
+
#
|
122
|
+
# Please don't call this method directly, see {__binding__}.
|
123
|
+
#
|
124
|
+
# @return [Binding]
|
125
|
+
def __pry__
|
126
|
+
::Kernel.binding
|
127
|
+
end
|
128
|
+
EOF
|
129
|
+
self.__pry__
|
120
130
|
end
|
121
131
|
end
|
data/lib/pry/editor.rb
CHANGED
@@ -1,129 +1,133 @@
|
|
1
1
|
class Pry
|
2
2
|
class Editor
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
3
|
+
include Pry::Helpers::BaseHelpers
|
4
|
+
include Pry::Helpers::CommandHelpers
|
5
|
+
|
6
|
+
attr_reader :_pry_
|
7
|
+
|
8
|
+
def initialize(_pry_)
|
9
|
+
@_pry_ = _pry_
|
10
|
+
end
|
11
|
+
|
12
|
+
def edit_tempfile_with_content(initial_content, line=1)
|
13
|
+
temp_file do |f|
|
14
|
+
f.puts(initial_content)
|
15
|
+
f.flush
|
16
|
+
f.close(false)
|
17
|
+
invoke_editor(f.path, line, true)
|
18
|
+
File.read(f.path)
|
15
19
|
end
|
20
|
+
end
|
16
21
|
|
17
|
-
|
18
|
-
|
22
|
+
def invoke_editor(file, line, blocking=true)
|
23
|
+
raise CommandError, "Please set Pry.config.editor or export $VISUAL or $EDITOR" unless _pry_.config.editor
|
19
24
|
|
20
|
-
|
21
|
-
|
25
|
+
editor_invocation = build_editor_invocation_string(file, line, blocking)
|
26
|
+
return nil unless editor_invocation
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
+
if jruby?
|
29
|
+
open_editor_on_jruby(editor_invocation)
|
30
|
+
else
|
31
|
+
open_editor(editor_invocation)
|
28
32
|
end
|
33
|
+
end
|
29
34
|
|
30
|
-
|
35
|
+
private
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
37
|
+
# Generate the string that's used to start the editor. This includes
|
38
|
+
# all the flags we want as well as the file and line number we
|
39
|
+
# want to open at.
|
40
|
+
def build_editor_invocation_string(file, line, blocking)
|
36
41
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
if _pry_.config.editor.respond_to?(:call)
|
43
|
+
args = [file, line, blocking][0...(_pry_.config.editor.arity)]
|
44
|
+
_pry_.config.editor.call(*args)
|
45
|
+
else
|
46
|
+
sanitized_file = if windows?
|
47
|
+
file.gsub(/\//, '\\')
|
48
|
+
else
|
49
|
+
Shellwords.escape(file)
|
50
|
+
end
|
46
51
|
|
47
|
-
|
48
|
-
end
|
52
|
+
"#{_pry_.config.editor} #{blocking_flag_for_editor(blocking)} #{start_line_syntax_for_editor(sanitized_file, line)}"
|
49
53
|
end
|
54
|
+
end
|
50
55
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
# Start the editor running, using the calculated invocation string
|
57
|
+
def open_editor(editor_invocation)
|
58
|
+
# Note we dont want to use Pry.config.system here as that
|
59
|
+
# may be invoked non-interactively (i.e via Open4), whereas we want to
|
60
|
+
# ensure the editor is always interactive
|
61
|
+
system(*Shellwords.split(editor_invocation)) or raise CommandError, "`#{editor_invocation}` gave exit status: #{$?.exitstatus}"
|
62
|
+
end
|
58
63
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
64
|
+
# We need JRuby specific code here cos just shelling out using
|
65
|
+
# system() appears to be pretty broken :/
|
66
|
+
def open_editor_on_jruby(editor_invocation)
|
67
|
+
begin
|
68
|
+
require 'spoon'
|
69
|
+
pid = Spoon.spawnp(*Shellwords.split(editor_invocation))
|
70
|
+
Process.waitpid(pid)
|
71
|
+
rescue FFI::NotFoundError
|
72
|
+
system(editor_invocation)
|
69
73
|
end
|
74
|
+
end
|
70
75
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
76
|
+
# Some editors that run outside the terminal allow you to control whether or
|
77
|
+
# not to block the process from which they were launched (in this case, Pry).
|
78
|
+
# For those editors, return the flag that produces the desired behavior.
|
79
|
+
def blocking_flag_for_editor(blocking)
|
80
|
+
case editor_name
|
81
|
+
when /^emacsclient/
|
82
|
+
'--no-wait' unless blocking
|
83
|
+
when /^[gm]vim/
|
84
|
+
'--nofork' if blocking
|
85
|
+
when /^jedit/
|
86
|
+
'-wait' if blocking
|
87
|
+
when /^mate/, /^subl/
|
88
|
+
'-w' if blocking
|
85
89
|
end
|
90
|
+
end
|
86
91
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
+
# Return the syntax for a given editor for starting the editor
|
93
|
+
# and moving to a particular line within that file
|
94
|
+
def start_line_syntax_for_editor(file_name, line_number)
|
95
|
+
# special case for 1st line
|
96
|
+
return file_name if line_number <= 1
|
92
97
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
98
|
+
case editor_name
|
99
|
+
when /^[gm]?vi/, /^emacs/, /^nano/, /^pico/, /^gedit/, /^kate/
|
100
|
+
"+#{line_number} #{file_name}"
|
101
|
+
when /^mate/, /^geany/
|
102
|
+
"-l #{line_number} #{file_name}"
|
103
|
+
when /^subl/
|
104
|
+
"#{file_name}:#{line_number}"
|
105
|
+
when /^uedit32/
|
106
|
+
"#{file_name}/#{line_number}"
|
107
|
+
when /^jedit/
|
108
|
+
"#{file_name} +line:#{line_number}"
|
109
|
+
else
|
110
|
+
if windows?
|
111
|
+
"#{file_name}"
|
104
112
|
else
|
105
|
-
|
106
|
-
"#{file_name}"
|
107
|
-
else
|
108
|
-
"+#{line_number} #{file_name}"
|
109
|
-
end
|
113
|
+
"+#{line_number} #{file_name}"
|
110
114
|
end
|
111
115
|
end
|
116
|
+
end
|
112
117
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
end
|
126
|
-
|
118
|
+
# Get the name of the binary that Pry.config.editor points to.
|
119
|
+
#
|
120
|
+
# This is useful for deciding which flags we pass to the editor as
|
121
|
+
# we can just use the program's name and ignore any absolute paths.
|
122
|
+
#
|
123
|
+
# @example
|
124
|
+
# Pry.config.editor="/home/conrad/bin/textmate -w"
|
125
|
+
# editor_name
|
126
|
+
# # => textmate
|
127
|
+
#
|
128
|
+
def editor_name
|
129
|
+
File.basename(_pry_.config.editor).split(" ").first
|
127
130
|
end
|
131
|
+
|
128
132
|
end
|
129
133
|
end
|