From 6f3fe40a039577e4f0847cb12ceb71941b20235e Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Wed, 5 Oct 2022 15:22:15 +0200 Subject: [PATCH] =?UTF-8?q?rename=20EDIT=20=E2=86=92=20EXTEDIT,=20EDIT=20n?= =?UTF-8?q?ow=20use=20prompt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/rpl | 17 +++++++++++++++-- lib/rpl/words/repl.rb | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bin/rpl b/bin/rpl index f26a44c..dce0825 100755 --- a/bin/rpl +++ b/bin/rpl @@ -20,12 +20,25 @@ class RplRepl end Readline.completion_append_character = ' ' + prefill = '' loop do + Readline.pre_input_hook = lambda do + return if prefill.empty? + + Readline.refresh_line + Readline.insert_text( prefill.to_s ) + Readline.redisplay + end + input = Readline.readline( ' ', true ) break if input.nil? || input.strip == 'quit' - if input.strip == 'history' + prefill = '' + + if input.strip == 'edit' + prefill = @interpreter.stack.pop.to_s + elsif input.strip == 'history' Readline::HISTORY.each do |line| pp line end @@ -62,7 +75,7 @@ options = { run_REPL: ARGV.empty?, Version = Rpl::VERSION OptionParser.new do |opts| - opts.on('-s', "--state filename", "persist state in filename (default: #{options[:persistence_filename]}) (will be created if needed)") do |filename| + opts.on('-s', '--state filename', "persist state in filename (default: #{options[:persistence_filename]}) (will be created if needed)") do |filename| options[:persistence_filename] = File.expand_path( filename ) end diff --git a/lib/rpl/words/repl.rb b/lib/rpl/words/repl.rb index 1e731a6..56a7b81 100644 --- a/lib/rpl/words/repl.rb +++ b/lib/rpl/words/repl.rb @@ -31,6 +31,11 @@ module RplLang proc {} ) @dictionary.add_word( ['edit'], + category, + '( x -- y ) put first stack object in prompt for modification', + proc {} ) + + @dictionary.add_word( ['extedit'], category, '( x -- y ) open object in $EDITOR', proc do