implement EDIT
This commit is contained in:
parent
5c1cc3e617
commit
92bd286f71
2 changed files with 26 additions and 1 deletions
|
@ -27,4 +27,3 @@ To run the test suite: `find ./spec/ -name \*.rb -exec ruby -Ilib {} \;`
|
|||
. repeat
|
||||
* use LSTO
|
||||
. ->, →
|
||||
* edit
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue