├── .gitignore ├── CHANGELOG.rdoc ├── Rakefile ├── README.rdoc ├── ripl-auto_indent.gemspec ├── LICENSE.txt └── lib └── ripl └── auto_indent.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *~ 3 | pkg 4 | -------------------------------------------------------------------------------- /CHANGELOG.rdoc: -------------------------------------------------------------------------------- 1 | == 0.2.0 2 | * Refactor out get_indent into ruby_indentation gem. Compatible with newer coderay versions 3 | 4 | == 0.1.5 5 | * Use coderay 1 6 | 7 | == 0.1.4 8 | * Compatible with multi_line 0.2.3 (proc as prompt) 9 | 10 | == 0.1.3 11 | * Fix "ArgumentError: comparison of Fixnum with nil failed" 12 | 13 | == 0.1.2 14 | * Fix for modifier statements 15 | 16 | == 0.1.1 17 | * Be compatible with multi_line 0.2.0 18 | 19 | == 0.1.0 20 | * Initial release. 21 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | GEMSPEC = Dir['*.gemspec'].first 2 | require 'fileutils' 3 | 4 | def gemspec 5 | @gemspec ||= eval(File.read(GEMSPEC), binding, GEMSPEC) 6 | end 7 | 8 | desc "Build the gem" 9 | task :gem=>:gemspec do 10 | sh "gem build #{GEMSPEC}" 11 | FileUtils.mkdir_p 'pkg' 12 | FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg' 13 | end 14 | 15 | desc "Install the gem locally" 16 | task :install => :gem do 17 | sh %{gem install pkg/#{gemspec.name}-#{gemspec.version}} 18 | end 19 | 20 | desc "Generate the gemspec" 21 | task :generate do 22 | puts gemspec.to_ruby 23 | end 24 | 25 | desc "Validate the gemspec" 26 | task :gemspec do 27 | gemspec.validate 28 | end 29 | 30 | desc 'Run tests' 31 | task :test do |t| 32 | sh 'bacon -q -Ilib -I. test/*_test.rb' 33 | end 34 | 35 | task :default => :test 36 | -------------------------------------------------------------------------------- /README.rdoc: -------------------------------------------------------------------------------- 1 | == Description 2 | A {ripl}[https://github.com/cldwalker/ripl] plugin that indents your entered Ruby code. 3 | 4 | == Install 5 | Install the gem with 6 | 7 | gem install ripl-auto_indent 8 | 9 | == Usage 10 | 11 | Add the following line to your ~/.riplrc 12 | 13 | require 'ripl/auto_indent' 14 | 15 | == Configuration options 16 | 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 Ripl.config[:auto_indent_rewrite] = false. 18 | You can change the default two spaces used for indention (per level) with Ripl.config[:auto_indent_space]. 19 | The plugin depends on ripl-multi_line, so you can set the multi-line prompt with Ripl.config[:multi_line_prompt] 20 | 21 | == Known bugs 22 | 23 | * Not 100% correct ;) 24 | 25 | J-_-L 26 | -------------------------------------------------------------------------------- /ripl-auto_indent.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | require 'rubygems' unless defined? Gem 3 | require File.dirname(__FILE__) + "/lib/ripl/auto_indent" 4 | 5 | Gem::Specification.new do |s| 6 | s.name = "ripl-auto_indent" 7 | s.version = Ripl::AutoIndent::VERSION 8 | s.authors = ["Jan Lelis"] 9 | s.email = "mail@janlelis.de" 10 | s.homepage = "http://github.com/janlelis/ripl-auto_indent" 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 ruby_indentation gem." 13 | s.required_rubygems_version = ">= 1.3.6" 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 | s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"] 19 | s.license = 'MIT' 20 | end 21 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT LICENSE 2 | 3 | Copyright (c) 2010-2012 Jan Lelis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /lib/ripl/auto_indent.rb: -------------------------------------------------------------------------------- 1 | require 'ripl' 2 | require 'ripl/multi_line' 3 | require 'ruby_indentation' 4 | 5 | module Ripl 6 | module AutoIndent 7 | VERSION = '0.2.0' 8 | TPUT = { 9 | :cuu1 => "\e[A", # up 10 | :sc => "\e7", # save 11 | :rc => "\e8", # load 12 | } 13 | 14 | def before_loop 15 | @current_indent = 0 16 | super 17 | end 18 | 19 | def prompt 20 | @buffer ? super + config[:auto_indent_space]*@current_indent : super 21 | end 22 | 23 | def rewrite_line(append_indents = 0) 24 | print_method = defined?(Ripl::ColorStreams) ? :real_write : :write 25 | $stdout.send print_method, 26 | TPUT[:sc] + 27 | TPUT[:cuu1] + 28 | prompt + 29 | @input + 30 | config[:auto_indent_space]*append_indents + 31 | TPUT[:rc] 32 | end 33 | 34 | def loop_eval(input) 35 | last_indent = ( @current_indent ||= 0 ) 36 | @current_indent = RubyIndentation[ @buffer ? @buffer*";"+";"+input : input ] 37 | 38 | if config[:auto_indent_rewrite] && @current_indent < last_indent 39 | rewrite_line last_indent - @current_indent 40 | end 41 | 42 | super # (@buffer ? @buffer + input : input) 43 | end 44 | end 45 | end 46 | 47 | Ripl::Shell.include Ripl::AutoIndent 48 | 49 | # default config 50 | Ripl.config[:auto_indent_rewrite] = true if Ripl.config[:auto_indent_rewrite].nil? 51 | Ripl.config[:auto_indent_space] ||= ' ' 52 | 53 | # J-_-L 54 | --------------------------------------------------------------------------------