ripl-auto_indent 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +2 -2
- data/LICENSE.txt +1 -1
- data/README.rdoc +0 -1
- data/Rakefile +3 -3
- data/lib/ripl/auto_indent.rb +7 -37
- data/{.gemspec → ripl-auto_indent.gemspec} +5 -5
- metadata +15 -14
data/CHANGELOG.rdoc
CHANGED
data/LICENSE.txt
CHANGED
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
|
1
|
+
GEMSPEC = Dir['*.gemspec'].first
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
4
|
def gemspec
|
5
|
-
@gemspec ||= eval(File.read(
|
5
|
+
@gemspec ||= eval(File.read(GEMSPEC), binding, GEMSPEC)
|
6
6
|
end
|
7
7
|
|
8
8
|
desc "Build the gem"
|
9
9
|
task :gem=>:gemspec do
|
10
|
-
sh "gem build
|
10
|
+
sh "gem build #{GEMSPEC}"
|
11
11
|
FileUtils.mkdir_p 'pkg'
|
12
12
|
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
|
13
13
|
end
|
data/lib/ripl/auto_indent.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
require 'ripl'
|
2
2
|
require 'ripl/multi_line'
|
3
|
-
require '
|
4
|
-
require 'set'
|
3
|
+
require 'ruby_indentation'
|
5
4
|
|
6
5
|
module Ripl
|
7
6
|
module AutoIndent
|
8
|
-
VERSION = '0.
|
7
|
+
VERSION = '0.2.0'
|
9
8
|
TPUT = {
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:rc =>
|
9
|
+
:cuu1 => "\e[A", # up
|
10
|
+
:sc => "\e7", # save
|
11
|
+
:rc => "\e8", # load
|
13
12
|
}
|
14
13
|
|
15
14
|
def before_loop
|
@@ -17,35 +16,6 @@ module Ripl
|
|
17
16
|
super
|
18
17
|
end
|
19
18
|
|
20
|
-
def get_indent(buffer)
|
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
|
26
|
-
|
27
|
-
# parse each token
|
28
|
-
buffer_tokens = [separator] + CodeRay.scan(buffer, :ruby).select{|_, kind|
|
29
|
-
kind != :space
|
30
|
-
}
|
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 ] )
|
39
|
-
indent += 1
|
40
|
-
elsif closing_tokens.include?(token)
|
41
|
-
indent -= 1
|
42
|
-
end
|
43
|
-
end
|
44
|
-
}
|
45
|
-
# return a good value
|
46
|
-
indent < 0 ? 0 : indent
|
47
|
-
end
|
48
|
-
|
49
19
|
def prompt
|
50
20
|
@buffer ? super + config[:auto_indent_space]*@current_indent : super
|
51
21
|
end
|
@@ -63,7 +33,7 @@ module Ripl
|
|
63
33
|
|
64
34
|
def loop_eval(input)
|
65
35
|
last_indent = ( @current_indent ||= 0 )
|
66
|
-
@current_indent =
|
36
|
+
@current_indent = RubyIndentation[ @buffer ? @buffer*";"+";"+input : input ]
|
67
37
|
|
68
38
|
if config[:auto_indent_rewrite] && @current_indent < last_indent
|
69
39
|
rewrite_line last_indent - @current_indent
|
@@ -74,7 +44,7 @@ module Ripl
|
|
74
44
|
end
|
75
45
|
end
|
76
46
|
|
77
|
-
Ripl::Shell.
|
47
|
+
Ripl::Shell.include Ripl::AutoIndent
|
78
48
|
|
79
49
|
# default config
|
80
50
|
Ripl.config[:auto_indent_rewrite] = true if Ripl.config[:auto_indent_rewrite].nil?
|
@@ -9,12 +9,12 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = "mail@janlelis.de"
|
10
10
|
s.homepage = "http://github.com/janlelis/ripl-auto_indent"
|
11
11
|
s.summary = "A ripl plugin which indents your entered Ruby code."
|
12
|
-
s.description = "This ripl plugin indents your multi-line Ruby input using
|
12
|
+
s.description = "This ripl plugin indents your multi-line Ruby input using ruby_indentation gem."
|
13
13
|
s.required_rubygems_version = ">= 1.3.6"
|
14
|
-
s.add_dependency 'ripl', '>= 0.
|
15
|
-
s.add_dependency 'ripl-multi_line', '>= 0.
|
16
|
-
s.add_dependency '
|
17
|
-
s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %
|
14
|
+
s.add_dependency 'ripl', '>= 0.6.0'
|
15
|
+
s.add_dependency 'ripl-multi_line', '>= 0.3.0'
|
16
|
+
s.add_dependency 'ruby_indentation', '>= 0.2.0'
|
17
|
+
s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %W[Rakefile #{__FILE__}]
|
18
18
|
s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
|
19
19
|
s.license = 'MIT'
|
20
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ripl-auto_indent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,42 +9,43 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ripl
|
16
|
-
requirement: &
|
16
|
+
requirement: &7543800 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: 0.6.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *7543800
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: ripl-multi_line
|
27
|
-
requirement: &
|
27
|
+
requirement: &7543320 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.
|
32
|
+
version: 0.3.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *7543320
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement: &
|
37
|
+
name: ruby_indentation
|
38
|
+
requirement: &7542840 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
43
|
+
version: 0.2.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
47
|
-
description: This ripl plugin indents your multi-line Ruby input using
|
46
|
+
version_requirements: *7542840
|
47
|
+
description: This ripl plugin indents your multi-line Ruby input using ruby_indentation
|
48
|
+
gem.
|
48
49
|
email: mail@janlelis.de
|
49
50
|
executables: []
|
50
51
|
extensions: []
|
@@ -57,7 +58,7 @@ files:
|
|
57
58
|
- README.rdoc
|
58
59
|
- CHANGELOG.rdoc
|
59
60
|
- Rakefile
|
60
|
-
- .gemspec
|
61
|
+
- ripl-auto_indent.gemspec
|
61
62
|
homepage: http://github.com/janlelis/ripl-auto_indent
|
62
63
|
licenses:
|
63
64
|
- MIT
|