-
-
Save cldwalker/939846 to your computer and use it in GitHub Desktop.
| # Add to ~/.riplrc | |
| module Ripl::MultiLineHistory | |
| attr_reader :last_buffer | |
| # hacks multi-line's loop_once | |
| def loop_once | |
| catch(:multiline) do | |
| Ripl::Shell::API.instance_method(:loop_once).bind(self).call | |
| @last_buffer = @buffer && @input ? (@buffer << @input).dup : @input | |
| history << @last_buffer.join('; ') if @buffer && @input | |
| @buffer = nil | |
| end | |
| end | |
| require 'tempfile' | |
| module Commands | |
| def last_edit(editor=ENV['EDITOR']) | |
| t = Tempfile.new('seed') | |
| File.open(t.path, 'w') {|f| f.write(Array(Ripl.shell.last_buffer).join("\n")) } | |
| system(editor, t.path) | |
| Ripl.shell.loop_eval File.read(t.path) | |
| end | |
| end | |
| end | |
| Ripl::Shell.include Ripl::MultiLineHistory | |
| Ripl::Commands.include Ripl::MultiLineHistory::Commands |
| $ ripl | |
| >> module Cow | |
| > def moo | |
| > end | |
| > end | |
| => nil | |
| # Press UP to edit code block as a semi-colon delimited one-liner | |
| >> module Cow; def moo; end; end | |
| # or use last_edit | |
| >> last_edit | |
| # Opens the code block in your $EDITOR. | |
| # Code is automatically evaled upon exiting file | |
| module Cow | |
| def moo | |
| end | |
| end | |
| => nil |
Because supering would have called MultiLine#loop_once which is not what I want. I only want the last_buffer code to get called at the end of a code block, not on every #loop_once. This as an option would be great. Fyi, I wrote this as a response to http://news.ycombinator.com/item?id=2479431
Hm, I've implemented it with janlelis/ripl-multi_line@279d07d but I'm not sure whether to activate it by default, because it wrongly puts ; into string literals...
I am also playing around with advanced multi-line analyzing (:statement, :string, ...), but then I would need to save the kind of every buffer entry in the @buffer to achieve correct functionality.
What's your opinion about this?
Update: I think I'll go the second way ;)
I see you've made ripper an optional engine. Looks good :)
nice! I'll include the single-line history as an option in the next multi_line version.
btw, why didn't you call
superin line 8?