implement EDIT

This commit is contained in:
Gwenhael Le Moine 2022-02-28 11:41:56 +01:00
parent 5c1cc3e617
commit 92bd286f71
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
2 changed files with 26 additions and 1 deletions

View file

@ -27,4 +27,3 @@ To run the test suite: `find ./spec/ -name \*.rb -exec ruby -Ilib {} \;`
. repeat
* use LSTO
. ->, →
* edit

View file

@ -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',