From 92bd286f715abeca8f48d0eb7ea42372f405e399 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Mon, 28 Feb 2022 11:41:56 +0100 Subject: [PATCH] implement EDIT --- README.md | 1 - lib/rpl/words/general.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c46cade..31c1bd4 100644 --- a/README.md +++ b/README.md @@ -27,4 +27,3 @@ To run the test suite: `find ./spec/ -name \*.rb -exec ruby -Ilib {} \;` . repeat * use LSTO . ->, → - * edit diff --git a/lib/rpl/words/general.rb b/lib/rpl/words/general.rb index 7d7e496..bc71669 100644 --- a/lib/rpl/words/general.rb +++ b/lib/rpl/words/general.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'tempfile' + module RplLang module Words module General @@ -61,6 +63,30 @@ module RplLang '', proc {} ) + @dictionary.add_word( ['edit'], + 'General', + '( -- s ) Pop the interpreter\'s complete indentification string', + proc do + args = stack_extract( [:any] ) + + value = args[0].to_s + tempfile = Tempfile.new('rpl') + + begin + tempfile.write( value ) + tempfile.rewind + + `$EDITOR #{tempfile.path}` + + edited_value = tempfile.read + ensure + tempfile.close + tempfile.unlink + end + + @stack << Types.new_object( args[0].class, edited_value ) + end ) + @dictionary.add_word( ['.s'], 'REPL', 'DEBUG',