ripl-auto_indent 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gemspec CHANGED
@@ -11,8 +11,8 @@ Gem::Specification.new do |s|
11
11
  s.summary = "A ripl plugin which indents your entered Ruby code."
12
12
  s.description = "This ripl plugin indents your multi-line Ruby input using coderay."
13
13
  s.required_rubygems_version = ">= 1.3.6"
14
- s.add_dependency 'ripl', '>= 0.2.5'
15
- s.add_dependency 'ripl-multi_line', '>= 0.1.4'
14
+ s.add_dependency 'ripl', '>= 0.2.6'
15
+ s.add_dependency 'ripl-multi_line', '>= 0.2.0'
16
16
  s.add_dependency 'coderay', '~> 0.9'
17
17
  s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile .gemspec}
18
18
  s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
data/CHANGELOG.rdoc CHANGED
@@ -1,2 +1,5 @@
1
+ == 0.1.1
2
+ * Be compatible with multi_line 0.2.0
3
+
1
4
  == 0.1.0
2
5
  * Initial release.
data/README.rdoc CHANGED
@@ -17,4 +17,9 @@ Add the following line to your <tt>~/.riplrc</tt>
17
17
  The plugin rewrites the last line (if the there are closing elements). If this is too buggy for you or your terminal does not support it, you can deactivate it with <tt>Ripl.config[:auto_indent_rewrite] = false</tt>.
18
18
  You can change the default two spaces used for indention (per level) with <tt>Ripl.config[:auto_indent_space]</tt>.
19
19
 
20
+ == Known bugs
21
+
22
+ * Statement modifiers (if at the end of the line) get displayed incorrectly
23
+ * Long lines might cause wrong rewriting (if activated)
24
+
20
25
  J-_-L
@@ -1,31 +1,43 @@
1
1
  require 'ripl'
2
2
  require 'ripl/multi_line'
3
3
  require 'coderay'
4
+ #require 'open3'
4
5
 
5
6
  module Ripl
6
7
  module AutoIndent
7
- VERSION = '0.1.0'
8
+ VERSION = '0.1.1'
8
9
  TPUT = {
9
10
  :sc => `tput sc`, # save current cursor position
10
- :cuu1 => `tput cuu1`, # move cursor upwards to the original input line
11
- :cuf1 => `tput cuf1`, # move cursor rightwards to the original input offset
11
+ :cuu1 => `tput cuu1`, # move cursor on line upwards
12
12
  :rc => `tput rc`, # return to normal cursor position
13
13
  }
14
14
 
15
15
  def before_loop
16
- super
17
16
  @current_indent = 0
17
+ super
18
18
  end
19
19
 
20
20
  def get_indent(buffer)
21
- indent = 0
21
+ #syntax_ok = proc{ |code|
22
+ # Open3.popen3('ruby -c'){ |sin, sout, _|
23
+ # sin << code
24
+ # sin.close
25
+ # sout.read.chomp
26
+ # } == "Syntax OK"
27
+ #}
28
+
22
29
  opening_tokens = %w[begin case class def for if module unless until while do {]
23
30
  closing_tokens = %w[end }]
31
+ indent = 0
24
32
  # parse each token
25
33
  buffer_tokens = CodeRay.scan(buffer, :ruby)
26
34
  buffer_tokens.each{ |token, kind|
27
35
  if kind == :reserved || kind == :operator
28
36
  if opening_tokens.include? token
37
+ # modifiers cause trouble - so guess, if it is intended as one
38
+ # (because the current line has valid syntax)
39
+ #next if %w[if unless until while].include?(token) && syntax_ok[ line ]
40
+
29
41
  indent += 1
30
42
  elsif closing_tokens.include? token
31
43
  indent -= 1
@@ -41,17 +53,19 @@ module Ripl
41
53
  end
42
54
 
43
55
  def rewrite_line(append_indents = 0)
44
- print TPUT[:sc] +
45
- TPUT[:cuu1] +
46
- prompt +
47
- @input +
48
- config[:auto_indent_space]*append_indents +
49
- TPUT[:rc]
56
+ print_method = defined?(Ripl::ColorStreams) ? :real_write : :write
57
+ $stdout.send print_method,
58
+ TPUT[:sc] +
59
+ TPUT[:cuu1] +
60
+ prompt +
61
+ @input +
62
+ config[:auto_indent_space]*append_indents +
63
+ TPUT[:rc]
50
64
  end
51
65
 
52
- def eval_input(input)
66
+ def loop_eval(input)
53
67
  last_indent = @current_indent
54
- @current_indent = get_indent(@buffer ? @buffer + input : input)
68
+ @current_indent = get_indent(@buffer ? @buffer*"\n" + "\n" + input : input)
55
69
 
56
70
  if config[:auto_indent_rewrite] && @current_indent < last_indent
57
71
  rewrite_line last_indent - @current_indent
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jan Lelis
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-30 00:00:00 +01:00
17
+ date: 2010-12-03 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -28,8 +28,8 @@ dependencies:
28
28
  segments:
29
29
  - 0
30
30
  - 2
31
- - 5
32
- version: 0.2.5
31
+ - 6
32
+ version: 0.2.6
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
@@ -42,9 +42,9 @@ dependencies:
42
42
  - !ruby/object:Gem::Version
43
43
  segments:
44
44
  - 0
45
- - 1
46
- - 4
47
- version: 0.1.4
45
+ - 2
46
+ - 0
47
+ version: 0.2.0
48
48
  type: :runtime
49
49
  version_requirements: *id002
50
50
  - !ruby/object:Gem::Dependency