ripl-auto_indent 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.1.2
2
+ * Fix for modifier statements
3
+
1
4
  == 0.1.1
2
5
  * Be compatible with multi_line 0.2.0
3
6
 
data/README.rdoc CHANGED
@@ -19,7 +19,7 @@ You can change the default two spaces used for indention (per level) with <tt>Ri
19
19
 
20
20
  == Known bugs
21
21
 
22
- * Statement modifiers (if at the end of the line) get displayed incorrectly
22
+ * Not 100% correct ;)
23
23
  * Long lines might cause wrong rewriting (if activated)
24
24
 
25
25
  J-_-L
@@ -1,11 +1,11 @@
1
1
  require 'ripl'
2
2
  require 'ripl/multi_line'
3
3
  require 'coderay'
4
- #require 'open3'
4
+ require 'set'
5
5
 
6
6
  module Ripl
7
7
  module AutoIndent
8
- VERSION = '0.1.1'
8
+ VERSION = '0.1.2'
9
9
  TPUT = {
10
10
  :sc => `tput sc`, # save current cursor position
11
11
  :cuu1 => `tput cuu1`, # move cursor on line upwards
@@ -18,28 +18,26 @@ module Ripl
18
18
  end
19
19
 
20
20
  def get_indent(buffer)
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
- #}
21
+ opening_and_modifier_tokens = %w[if unless until while].to_set
22
+ opening_tokens = %w[begin case class def for module do {].to_set
23
+ closing_tokens = %w[end }].to_set
24
+ separator = [';', :operator]
25
+ indent = 0
28
26
 
29
- opening_tokens = %w[begin case class def for if module unless until while do {]
30
- closing_tokens = %w[end }]
31
- indent = 0
32
27
  # parse each token
33
- buffer_tokens = CodeRay.scan(buffer, :ruby)
34
- buffer_tokens.each{ |token, kind|
35
- if kind == :reserved || kind == :operator
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 ]
28
+ buffer_tokens = [separator] + CodeRay.scan(buffer, :ruby).select{|_, kind|
29
+ kind != :space
30
+ }
40
31
 
32
+ buffer_tokens.each_cons(2){ |(*old_pair), (token, kind)|
33
+ if kind == :reserved || kind == :operator
34
+ # modifiers cause trouble, so
35
+ # fix it in 9/10 cases
36
+ if opening_tokens.include?(token) ||
37
+ opening_and_modifier_tokens.include?(token) &&
38
+ ( old_pair == separator || old_pair == ['=', :operator ] )
41
39
  indent += 1
42
- elsif closing_tokens.include? token
40
+ elsif closing_tokens.include?(token)
43
41
  indent -= 1
44
42
  end
45
43
  end
@@ -65,7 +63,7 @@ module Ripl
65
63
 
66
64
  def loop_eval(input)
67
65
  last_indent = @current_indent
68
- @current_indent = get_indent(@buffer ? @buffer*"\n" + "\n" + input : input)
66
+ @current_indent = get_indent( @buffer ? @buffer*";"+";"+input : input )
69
67
 
70
68
  if config[:auto_indent_rewrite] && @current_indent < last_indent
71
69
  rewrite_line last_indent - @current_indent
@@ -79,9 +77,9 @@ end
79
77
  Ripl::Shell.send :include, Ripl::AutoIndent
80
78
 
81
79
  # default config
82
- Ripl.config[:auto_indent_rewrite] = true
83
- Ripl.config[:auto_indent_space] = ' '
80
+ Ripl.config[:auto_indent_rewrite] = true if Ripl.config[:auto_indent_rewrite].nil?
81
+ Ripl.config[:auto_indent_space] ||= ' '
84
82
  Ripl.config[:multi_line_prompt] = '| ' if !Ripl.config[:multi_line_prompt] ||
85
- Ripl.config[:multi_line_prompt] == '| '
83
+ Ripl.config[:multi_line_prompt] == '| '
86
84
 
87
85
  # J-_-L
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
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-12-03 00:00:00 +01:00
17
+ date: 2010-12-13 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency