--- a/ReadEvalPrintLoop.st Tue Nov 08 17:33:29 2016 +0100
+++ b/ReadEvalPrintLoop.st Tue Nov 08 17:40:09 2016 +0100
@@ -200,7 +200,7 @@
"edit a class or selector"
|errStream editor classOrMethodName cls methodName selector
- code isNewClass tmpFile modifiedTime|
+ code isNewClass editFullClass tmpFile modifiedTime|
errStream := self errorStream.
@@ -216,7 +216,7 @@
].
].
- isNewClass := false.
+ isNewClass := editFullClass := false.
lineStream skipSeparators.
lineStream atEnd ifTrue:[^ self].
@@ -259,32 +259,47 @@
^ self.
].
lastEditedClass := cls.
- ((selector := methodName asSymbolIfInterned) isNil
- or:[ (cls implements:selector) not]) ifTrue:[
- errStream nextPutAll:('"',methodName,'" is a new method; create (y/n)? ').
- (self inputStream nextLine withoutSeparators startsWith:'y') ifFalse:[^ self].
- code := '
+ methodName isNil ifTrue:[
+ editFullClass := true.
+ code := cls source asString
+ ] ifFalse:[
+ ((selector := methodName asSymbolIfInterned) isNil
+ or:[ (cls implements:selector) not]) ifTrue:[
+ errStream nextPutAll:('"',methodName,'" is a new method; create (y/n)? ').
+ (self inputStream nextLine withoutSeparators startsWith:'y') ifFalse:[^ self].
+ code := '
%1
"this is a new method"
self halt
-' bindWith:methodName.
- ] ifFalse:[
- code := cls compiledMethodAt:selector.
+' bindWith:methodName.
+ ] ifFalse:[
+ code := cls compiledMethodAt:selector.
+ ].
].
].
- tmpFile := Filename newTemporary.
- tmpFile contents:code.
- modifiedTime := tmpFile modificationTime.
- OperatingSystem executeCommand:('%1 "%2"' bindWith:editor with:tmpFile pathName).
- tmpFile modificationTime ~= modifiedTime ifTrue:[
- isNewClass ifTrue:[
- Compiler evaluate:tmpFile contentsOfEntireFile.
- ] ifFalse:[
- cls compile:tmpFile contentsOfEntireFile classified:'*as yet uncategorized'.
- ].
+ [
+ tmpFile := Filename newTemporary.
+ tmpFile contents:code.
+ modifiedTime := tmpFile modificationTime.
+ OperatingSystem executeCommand:('%1 "%2"' bindWith:editor with:tmpFile pathName).
+ tmpFile modificationTime ~= modifiedTime ifTrue:[
+ isNewClass ifTrue:[
+ Compiler evaluate:tmpFile contentsOfEntireFile.
+ ] ifFalse:[
+ editFullClass ifTrue:[
+ tmpFile fileIn.
+ ] ifFalse:[
+ cls compile:tmpFile contentsOfEntireFile classified:'*as yet uncategorized'.
+ ].
+ ].
+ ].
+ ] ensure:[
+ tmpFile notNil ifTrue:[
+ tmpFile remove
+ ]
].
-
+
"
self new
input:Stdin;