pry 0.9.9.3 → 0.9.9.4pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/lib/pry/default_commands/introspection.rb +12 -8
- data/lib/pry/indent.rb +101 -17
- data/lib/pry/pry_instance.rb +1 -1
- data/lib/pry/version.rb +1 -1
- data/pry.gemspec +3 -3
- data/test/test_indent.rb +40 -0
- metadata +17 -17
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
26/4/2012 version 0.9.9.4 major bugfix
|
2
|
+
* fixed `NoMethodError: undefined method `winsize' for #<IO:<STDOUT>>`, bug #549
|
3
|
+
* fixes for jruby
|
4
|
+
* heredoc content no longer auto-indented
|
5
|
+
|
1
6
|
19/4/2012 version 0.9.9.3 major doc bugfix
|
2
7
|
* show-doc would fail on some core classes, i.e `show-doc Bignum`. This is now fixed
|
3
8
|
and show allow a wider range of core documentation to be viewed directly in Pry.
|
@@ -254,25 +254,29 @@ class Pry
|
|
254
254
|
|
255
255
|
file_name, line = mod.source_location
|
256
256
|
set_file_and_dir_locals(file_name)
|
257
|
-
code =
|
258
|
-
|
259
|
-
|
257
|
+
code = Code.from_module(mod, module_start_line(mod)).with_line_numbers(use_line_numbers?).to_s
|
258
|
+
result = ""
|
259
|
+
result << "\n#{Pry::Helpers::Text.bold('From:')} #{file_name} @ line #{line}:\n"
|
260
|
+
result << "#{Pry::Helpers::Text.bold('Number of lines:')} #{code.lines.count}\n\n"
|
261
|
+
result << code
|
260
262
|
end
|
261
263
|
|
262
264
|
def all_modules
|
263
265
|
mod = module_object
|
264
266
|
|
265
|
-
|
266
|
-
|
267
|
+
result = ""
|
268
|
+
result << "Found #{mod.number_of_candidates} candidates for `#{mod.name}` definition:\n"
|
267
269
|
mod.number_of_candidates.times do |v|
|
268
270
|
begin
|
269
|
-
code
|
270
|
-
|
271
|
+
code = Code.new(mod.source_for_candidate(v), module_start_line(mod, v)).with_line_numbers(use_line_numbers?).to_s
|
272
|
+
result << "\nCandidate #{v+1}/#{mod.number_of_candidates}: #{mod.source_file_for_candidate(v)} @ line #{mod.source_line_for_candidate(v)}:\n"
|
273
|
+
result << "Number of lines: #{code.lines.count}\n\n"
|
274
|
+
result << code
|
271
275
|
rescue Pry::RescuableException
|
272
276
|
next
|
273
277
|
end
|
274
278
|
end
|
275
|
-
|
279
|
+
result
|
276
280
|
end
|
277
281
|
|
278
282
|
def use_line_numbers?
|
data/lib/pry/indent.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
require 'coderay'
|
2
2
|
|
3
3
|
class Pry
|
4
|
+
# Load io-console if possible, so that we can use $stdout.winsize.
|
4
5
|
begin
|
5
6
|
require 'io/console'
|
6
7
|
rescue LoadError
|
7
|
-
IO_CONSOLE_AVAILABLE = false
|
8
|
-
else
|
9
|
-
IO_CONSOLE_AVAILABLE = true
|
10
8
|
end
|
11
9
|
|
12
10
|
##
|
@@ -56,7 +54,7 @@ class Pry
|
|
56
54
|
#
|
57
55
|
# :pre_constant and :preserved_constant are the CodeRay 0.9.8 and 1.0.0
|
58
56
|
# classifications of "true", "false", and "nil".
|
59
|
-
IGNORE_TOKENS = [:space, :content, :string, :
|
57
|
+
IGNORE_TOKENS = [:space, :content, :string, :method, :ident,
|
60
58
|
:constant, :pre_constant, :predefined_constant]
|
61
59
|
|
62
60
|
# Tokens that indicate the end of a statement (i.e. that, if they appear
|
@@ -65,7 +63,8 @@ class Pry
|
|
65
63
|
#
|
66
64
|
# :reserved and :keywords are the CodeRay 0.9.8 and 1.0.0 respectively
|
67
65
|
# classifications of "super", "next", "return", etc.
|
68
|
-
STATEMENT_END_TOKENS = IGNORE_TOKENS + [:regexp, :integer, :float, :keyword,
|
66
|
+
STATEMENT_END_TOKENS = IGNORE_TOKENS + [:regexp, :integer, :float, :keyword,
|
67
|
+
:delimiter, :reserved]
|
69
68
|
|
70
69
|
# Collection of tokens that should appear dedented even though they
|
71
70
|
# don't affect the surrounding code.
|
@@ -79,6 +78,9 @@ class Pry
|
|
79
78
|
def reset
|
80
79
|
@stack = []
|
81
80
|
@indent_level = ''
|
81
|
+
@heredoc_queue = []
|
82
|
+
@close_heredocs = {}
|
83
|
+
@string_start = nil
|
82
84
|
self
|
83
85
|
end
|
84
86
|
|
@@ -109,14 +111,27 @@ class Pry
|
|
109
111
|
prefix = indent_level
|
110
112
|
|
111
113
|
input.lines.each do |line|
|
112
|
-
|
113
|
-
|
114
|
+
|
115
|
+
if in_string?
|
116
|
+
tokens = tokenize("#{open_delimiters_line}\n#{line}")
|
117
|
+
tokens = tokens.drop_while{ |token, type| !(String === token && token.include?("\n")) }
|
118
|
+
previously_in_string = true
|
119
|
+
else
|
120
|
+
tokens = tokenize(line)
|
121
|
+
previously_in_string = false
|
122
|
+
end
|
114
123
|
|
115
124
|
before, after = indentation_delta(tokens)
|
116
125
|
|
117
126
|
before.times{ prefix.sub! SPACES, '' }
|
118
|
-
|
119
|
-
|
127
|
+
new_prefix = prefix + SPACES * after
|
128
|
+
|
129
|
+
line = prefix + line.lstrip unless previously_in_string
|
130
|
+
line = line.rstrip + "\n" unless in_string?
|
131
|
+
|
132
|
+
output += line
|
133
|
+
|
134
|
+
prefix = new_prefix
|
120
135
|
end
|
121
136
|
|
122
137
|
@indent_level = prefix
|
@@ -124,6 +139,16 @@ class Pry
|
|
124
139
|
return output.gsub(/\s+$/, '')
|
125
140
|
end
|
126
141
|
|
142
|
+
# Get the indentation for the start of the next line.
|
143
|
+
#
|
144
|
+
# This is what's used between the prompt and the cursor in pry.
|
145
|
+
#
|
146
|
+
# @return String The correct number of spaces
|
147
|
+
#
|
148
|
+
def current_prefix
|
149
|
+
in_string? ? '' : indent_level
|
150
|
+
end
|
151
|
+
|
127
152
|
# Get the change in indentation indicated by the line.
|
128
153
|
#
|
129
154
|
# By convention, you remove indent from the line containing end tokens,
|
@@ -167,7 +192,9 @@ class Pry
|
|
167
192
|
|
168
193
|
seen_for_at << add_after if token == "for"
|
169
194
|
|
170
|
-
if
|
195
|
+
if kind == :delimiter
|
196
|
+
track_delimiter(token)
|
197
|
+
elsif OPEN_TOKENS.keys.include?(token) && !is_optional_do && !is_singleline_if
|
171
198
|
@stack << token
|
172
199
|
add_after += 1
|
173
200
|
elsif token == OPEN_TOKENS[@stack.last]
|
@@ -194,6 +221,65 @@ class Pry
|
|
194
221
|
(last_token =~ /^[)\]}\/]$/ || STATEMENT_END_TOKENS.include?(last_kind))
|
195
222
|
end
|
196
223
|
|
224
|
+
# Are we currently in the middle of a string literal.
|
225
|
+
#
|
226
|
+
# This is used to determine whether to re-indent a given line, we mustn't re-indent
|
227
|
+
# within string literals because to do so would actually change the value of the
|
228
|
+
# String!
|
229
|
+
#
|
230
|
+
# @return Boolean
|
231
|
+
def in_string?
|
232
|
+
!open_delimiters.empty?
|
233
|
+
end
|
234
|
+
|
235
|
+
# Given a string of Ruby code, use CodeRay to export the tokens.
|
236
|
+
#
|
237
|
+
# @param String The Ruby to lex.
|
238
|
+
# @return [Array] An Array of pairs of [token_value, token_type]
|
239
|
+
def tokenize(string)
|
240
|
+
tokens = CodeRay.scan(string, :ruby)
|
241
|
+
tokens = tokens.tokens.each_slice(2) if tokens.respond_to?(:tokens) # Coderay 1.0.0
|
242
|
+
tokens.to_a
|
243
|
+
end
|
244
|
+
|
245
|
+
# Update the internal state about what kind of strings are open.
|
246
|
+
#
|
247
|
+
# Most of the complication here comes from the fact that HEREDOCs can be nested. For
|
248
|
+
# normal strings (which can't be nested) we assume that CodeRay correctly pairs
|
249
|
+
# open-and-close delimiters so we don't bother checking what they are.
|
250
|
+
#
|
251
|
+
# @param String The token (of type :delimiter)
|
252
|
+
def track_delimiter(token)
|
253
|
+
case token
|
254
|
+
when /^<<-(["'`]?)(.*)\\1/
|
255
|
+
@heredoc_queue << token
|
256
|
+
@close_heredocs[token] = /^\s*$2/
|
257
|
+
when @close_heredocs[@heredoc_queue.first]
|
258
|
+
@heredoc_queue.shift
|
259
|
+
else
|
260
|
+
if @string_start
|
261
|
+
@string_start = nil
|
262
|
+
else
|
263
|
+
@string_start = token
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
# All the open delimiters, in the order that they first appeared.
|
269
|
+
#
|
270
|
+
# @return [String]
|
271
|
+
def open_delimiters
|
272
|
+
@heredoc_queue + [@string_start].compact
|
273
|
+
end
|
274
|
+
|
275
|
+
# Return a string which restores the CodeRay string status to the correct value by
|
276
|
+
# opening HEREDOCs and strings.
|
277
|
+
#
|
278
|
+
# @return String
|
279
|
+
def open_delimiters_line
|
280
|
+
"puts #{open_delimiters.join(", ")}"
|
281
|
+
end
|
282
|
+
|
197
283
|
# Return a string which, when printed, will rewrite the previous line with
|
198
284
|
# the correct indentation. Mostly useful for fixing 'end'.
|
199
285
|
#
|
@@ -204,19 +290,18 @@ class Pry
|
|
204
290
|
# @return [String]
|
205
291
|
def correct_indentation(prompt, code, overhang=0)
|
206
292
|
full_line = prompt + code
|
207
|
-
|
293
|
+
whitespace = ' ' * overhang
|
294
|
+
|
295
|
+
if $stdout.tty? && $stdout.respond_to?(:winsize)
|
208
296
|
_, cols = $stdout.winsize
|
209
|
-
lines = full_line.length / cols + 1
|
210
297
|
elsif Readline.respond_to?(:get_screen_size)
|
211
298
|
_, cols = Readline.get_screen_size
|
212
|
-
lines = full_line.length / cols + 1
|
213
299
|
elsif ENV['COLUMNS'] && ENV['COLUMNS'] != ''
|
214
300
|
cols = ENV['COLUMNS'].to_i
|
215
|
-
lines = full_line.length / cols + 1
|
216
|
-
else
|
217
|
-
lines = 1
|
218
301
|
end
|
219
302
|
|
303
|
+
lines = cols ? (full_line.length / cols + 1) : 1
|
304
|
+
|
220
305
|
if defined?(Win32::Console)
|
221
306
|
move_up = "\e[#{lines}F"
|
222
307
|
move_down = "\e[#{lines}E"
|
@@ -224,7 +309,6 @@ class Pry
|
|
224
309
|
move_up = "\e[#{lines}A\e[0G"
|
225
310
|
move_down = "\e[#{lines}B\e[0G"
|
226
311
|
end
|
227
|
-
whitespace = ' ' * overhang
|
228
312
|
|
229
313
|
"#{move_up}#{prompt}#{colorize_code(code)}#{whitespace}#{move_down}"
|
230
314
|
end
|
data/lib/pry/pry_instance.rb
CHANGED
@@ -338,7 +338,7 @@ class Pry
|
|
338
338
|
instance_eval(&custom_completions))
|
339
339
|
|
340
340
|
|
341
|
-
indentation = Pry.config.auto_indent ? @indent.
|
341
|
+
indentation = Pry.config.auto_indent ? @indent.current_prefix : ''
|
342
342
|
|
343
343
|
begin
|
344
344
|
val = readline("#{current_prompt}#{indentation}", completion_proc)
|
data/lib/pry/version.rb
CHANGED
data/pry.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "pry"
|
5
|
-
s.version = "0.9.9.
|
5
|
+
s.version = "0.9.9.4pre1"
|
6
6
|
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["John Mair (banisterfiend)"]
|
9
|
-
s.date = "2012-04-
|
9
|
+
s.date = "2012-04-26"
|
10
10
|
s.description = "An IRB alternative and runtime developer console"
|
11
11
|
s.email = "jrmair@gmail.com"
|
12
12
|
s.executables = ["pry"]
|
data/test/test_indent.rb
CHANGED
@@ -230,6 +230,46 @@ begin
|
|
230
230
|
rescue => e
|
231
231
|
doit :right
|
232
232
|
end
|
233
|
+
OUTPUT
|
234
|
+
|
235
|
+
@indent.indent(input).should == output
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should not indent inside strings" do
|
239
|
+
@indent.indent(%(def a\n"foo\nbar"\n end)).should == %(def a\n "foo\nbar"\nend)
|
240
|
+
@indent.indent(%(def a\nputs %w(foo\nbar), 'foo\nbar'\n end)).should == %(def a\n puts %w(foo\nbar), 'foo\nbar'\nend)
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should not indent inside HEREDOCs" do
|
244
|
+
@indent.indent(%(def a\nputs <<FOO\n bar\nFOO\nbaz\nend)).should == %(def a\n puts <<FOO\n bar\nFOO\n baz\nend)
|
245
|
+
@indent.indent(%(def a\nputs <<-'^^'\n bar\n\t^^\nbaz\nend)).should == %(def a\n puts <<-'^^'\n bar\n\t^^\n baz\nend)
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should not indent nested HEREDOCs" do
|
249
|
+
input = <<INPUT.strip
|
250
|
+
def a
|
251
|
+
puts <<FOO, <<-BAR, "baz", <<-':p'
|
252
|
+
foo
|
253
|
+
FOO
|
254
|
+
bar
|
255
|
+
BAR
|
256
|
+
tongue
|
257
|
+
:p
|
258
|
+
puts :p
|
259
|
+
end
|
260
|
+
INPUT
|
261
|
+
|
262
|
+
output = <<OUTPUT.strip
|
263
|
+
def a
|
264
|
+
puts <<FOO, <<-BAR, "baz", <<-':p'
|
265
|
+
foo
|
266
|
+
FOO
|
267
|
+
bar
|
268
|
+
BAR
|
269
|
+
tongue
|
270
|
+
:p
|
271
|
+
puts :p
|
272
|
+
end
|
233
273
|
OUTPUT
|
234
274
|
|
235
275
|
@indent.indent(input).should == output
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.9.
|
5
|
-
prerelease:
|
4
|
+
version: 0.9.9.4pre1
|
5
|
+
prerelease: 7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- John Mair (banisterfiend)
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: coderay
|
16
|
-
requirement: &
|
16
|
+
requirement: &70094357173940 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.5
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70094357173940
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: slop
|
27
|
-
requirement: &
|
27
|
+
requirement: &70094357171380 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -35,10 +35,10 @@ dependencies:
|
|
35
35
|
version: '3'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
|
-
version_requirements: *
|
38
|
+
version_requirements: *70094357171380
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: method_source
|
41
|
-
requirement: &
|
41
|
+
requirement: &70094357179560 !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
43
|
requirements:
|
44
44
|
- - ~>
|
@@ -46,10 +46,10 @@ dependencies:
|
|
46
46
|
version: 0.7.1
|
47
47
|
type: :runtime
|
48
48
|
prerelease: false
|
49
|
-
version_requirements: *
|
49
|
+
version_requirements: *70094357179560
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: bacon
|
52
|
-
requirement: &
|
52
|
+
requirement: &70094357193160 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
54
|
requirements:
|
55
55
|
- - ~>
|
@@ -57,10 +57,10 @@ dependencies:
|
|
57
57
|
version: '1.1'
|
58
58
|
type: :development
|
59
59
|
prerelease: false
|
60
|
-
version_requirements: *
|
60
|
+
version_requirements: *70094357193160
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: open4
|
63
|
-
requirement: &
|
63
|
+
requirement: &70094357188820 !ruby/object:Gem::Requirement
|
64
64
|
none: false
|
65
65
|
requirements:
|
66
66
|
- - ~>
|
@@ -68,10 +68,10 @@ dependencies:
|
|
68
68
|
version: '1.3'
|
69
69
|
type: :development
|
70
70
|
prerelease: false
|
71
|
-
version_requirements: *
|
71
|
+
version_requirements: *70094357188820
|
72
72
|
- !ruby/object:Gem::Dependency
|
73
73
|
name: rake
|
74
|
-
requirement: &
|
74
|
+
requirement: &70094357202040 !ruby/object:Gem::Requirement
|
75
75
|
none: false
|
76
76
|
requirements:
|
77
77
|
- - ~>
|
@@ -79,7 +79,7 @@ dependencies:
|
|
79
79
|
version: '0.9'
|
80
80
|
type: :development
|
81
81
|
prerelease: false
|
82
|
-
version_requirements: *
|
82
|
+
version_requirements: *70094357202040
|
83
83
|
description: An IRB alternative and runtime developer console
|
84
84
|
email: jrmair@gmail.com
|
85
85
|
executables:
|
@@ -209,9 +209,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
209
209
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
210
|
none: false
|
211
211
|
requirements:
|
212
|
-
- - ! '
|
212
|
+
- - ! '>'
|
213
213
|
- !ruby/object:Gem::Version
|
214
|
-
version:
|
214
|
+
version: 1.3.1
|
215
215
|
requirements: []
|
216
216
|
rubyforge_project:
|
217
217
|
rubygems_version: 1.8.16
|