Permalink
Browse files

0.2.0, fix coderay issues, separate indentation checker into extra gem

  • Loading branch information...
1 parent d8c526f commit da725c73a385e414b3e29477938cbb524d4c9e02 @janlelis committed Jan 12, 2012
Showing with 19 additions and 50 deletions.
  1. +3 −0 CHANGELOG.rdoc
  2. +1 −1 LICENSE.txt
  3. +0 −1 README.rdoc
  4. +3 −3 Rakefile
  5. +0 −3 deps.rip
  6. +7 −37 lib/ripl/auto_indent.rb
  7. +5 −5 .gemspec → ripl-auto_indent.gemspec
View
@@ -1,3 +1,6 @@
+== 0.2.0
+* Refactor out get_indent into ruby_indentation gem. Compatible with newer coderay versions
+
== 0.1.4
* Compatible with multi_line 0.2.3 (proc as prompt)
View
@@ -1,6 +1,6 @@
The MIT LICENSE
-Copyright (c) 2010 Jan Lelis
+Copyright (c) 2010-2012 Jan Lelis
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
@@ -21,6 +21,5 @@ The plugin depends on <tt>ripl-multi_line</tt>, so you can set the multi-line pr
== Known bugs
* Not 100% correct ;)
-* Long lines might cause wrong rewriting (if activated)
J-_-L
View
@@ -1,13 +1,13 @@
-require 'rake'
+GEMSPEC = Dir['*.gemspec'].first
require 'fileutils'
def gemspec
- @gemspec ||= eval(File.read('.gemspec'), binding, '.gemspec')
+ @gemspec ||= eval(File.read(GEMSPEC), binding, GEMSPEC)
end
desc "Build the gem"
task :gem=>:gemspec do
- sh "gem build .gemspec"
+ sh "gem build #{GEMSPEC}"
FileUtils.mkdir_p 'pkg'
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
end
View
@@ -1,3 +0,0 @@
-ripl >=0.3.1
-ripl-multi_line >=0.2.3
-coderay >=0.9.5
View
@@ -1,51 +1,21 @@
require 'ripl'
require 'ripl/multi_line'
-require 'coderay'
-require 'set'
+require 'ruby_indentation'
module Ripl
module AutoIndent
- VERSION = '0.1.4'
+ VERSION = '0.2.0'
TPUT = {
- :sc => `tput sc`, # save current cursor position
- :cuu1 => `tput cuu1`, # move cursor on line upwards
- :rc => `tput rc`, # return to normal cursor position
+ :cuu1 => "\e[A", # up
+ :sc => "\e7", # save
+ :rc => "\e8", # load
}
def before_loop
@current_indent = 0
super
end
- def get_indent(buffer)
- opening_and_modifier_tokens = %w[if unless until while].to_set
- opening_tokens = %w[begin case class def for module do {].to_set
- closing_tokens = %w[end }].to_set
- separator = [';', :operator]
- indent = 0
-
- # parse each token
- buffer_tokens = [separator] + CodeRay.scan(buffer, :ruby).select{|_, kind|
- kind != :space
- }
-
- buffer_tokens.each_cons(2){ |(*old_pair), (token, kind)|
- if kind == :reserved || kind == :operator
- # modifiers cause trouble, so
- # fix it in 9/10 cases
- if opening_tokens.include?(token) ||
- opening_and_modifier_tokens.include?(token) &&
- ( old_pair == separator || old_pair == ['=', :operator ] )
- indent += 1
- elsif closing_tokens.include?(token)
- indent -= 1
- end
- end
- }
- # return a good value
- indent < 0 ? 0 : indent
- end
-
def prompt
@buffer ? super + config[:auto_indent_space]*@current_indent : super
end
@@ -63,7 +33,7 @@ def rewrite_line(append_indents = 0)
def loop_eval(input)
last_indent = ( @current_indent ||= 0 )
- @current_indent = get_indent( @buffer ? @buffer*";"+";"+input : input )
+ @current_indent = RubyIndentation[ @buffer ? @buffer*";"+";"+input : input ]
if config[:auto_indent_rewrite] && @current_indent < last_indent
rewrite_line last_indent - @current_indent
@@ -74,7 +44,7 @@ def loop_eval(input)
end
end
-Ripl::Shell.send :include, Ripl::AutoIndent
+Ripl::Shell.include Ripl::AutoIndent
# default config
Ripl.config[:auto_indent_rewrite] = true if Ripl.config[:auto_indent_rewrite].nil?
@@ -9,12 +9,12 @@ Gem::Specification.new do |s|
s.email = "mail@janlelis.de"
s.homepage = "http://github.com/janlelis/ripl-auto_indent"
s.summary = "A ripl plugin which indents your entered Ruby code."
- s.description = "This ripl plugin indents your multi-line Ruby input using coderay."
+ s.description = "This ripl plugin indents your multi-line Ruby input using ruby_indentation gem."
s.required_rubygems_version = ">= 1.3.6"
- s.add_dependency 'ripl', '>= 0.3.1'
- s.add_dependency 'ripl-multi_line', '>= 0.2.3'
- s.add_dependency 'coderay', '~> 0.9'
- s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile .gemspec}
+ s.add_dependency 'ripl', '>= 0.6.0'
+ s.add_dependency 'ripl-multi_line', '>= 0.3.0'
+ s.add_dependency 'ruby_indentation', '>= 0.2.0'
+ s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %W[Rakefile #{__FILE__}]
s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
s.license = 'MIT'
end

0 comments on commit da725c7

Please sign in to comment.