ReadEvalPrintLoop.st
changeset 20935 7803512423cb
parent 20934 36e46558156d
child 20936 06ccf7cc734a
--- a/ReadEvalPrintLoop.st	Tue Nov 08 22:24:59 2016 +0100
+++ b/ReadEvalPrintLoop.st	Tue Nov 08 22:54:07 2016 +0100
@@ -18,7 +18,8 @@
 Object subclass:#ReadEvalPrintLoop
 	instanceVariableNames:'inputStream outputStream errorStream compiler prompt
 		doChunkFormat traceFlag timingFlag profilingFlag printFlag
-		exitAction currentDirectory lastEditedClass lastEditedSelector'
+		exitAction currentDirectory lastEditedClass lastEditedSelector
+		editorCommand'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'System-Support'
@@ -92,6 +93,27 @@
     "Created: / 07-12-2006 / 18:24:04 / cg"
 !
 
+editorCommand
+    |editor|
+
+    (editor := editorCommand) isNil ifTrue:[
+        editor := OperatingSystem getEnvironment:'STX_EDITOR'.
+        editor isNil ifTrue:[
+            editor := OperatingSystem getEnvironment:'EDITOR'.
+            editor isNil ifTrue:[
+                OperatingSystem isMSWINDOWSlike ifTrue:[
+                    editor := 'notepad'.
+                ] ifFalse:[
+                    editor := 'vi'.
+                ].    
+            ].    
+        ].    
+    ].
+    ^ editor
+
+    "Created: / 08-11-2016 / 22:45:22 / cg"
+!
+
 error:aStream
     "assign an error stream"
 
@@ -202,25 +224,13 @@
 !
 
 cmd_edit:lineStream
-    "edit a class or selector"
+    "edit a class or selector in an external editor"
 
-    |errStream editor classOrMethodName cls methodName selector 
+    |errStream classOrMethodName cls methodName selector 
      code isNewClass editFullClass tmpFile modifiedTime|
 
     errStream := self errorStream.
 
-    editor := OperatingSystem getEnvironment:'STX_EDITOR'.
-    editor isNil ifTrue:[
-        editor := OperatingSystem getEnvironment:'EDITOR'.
-        editor isNil ifTrue:[
-            OperatingSystem isMSWINDOWSlike ifTrue:[
-                editor := 'notepad'.
-            ] ifFalse:[
-                editor := 'vi'.
-            ].    
-        ].    
-    ].    
-
     isNewClass := editFullClass := false.
 
     lineStream skipSeparators.
@@ -305,7 +315,7 @@
         modifiedTime := tmpFile modificationTime.
 
         ok := OperatingSystem 
-                executeCommand:('%1 "%2"' bindWith:editor with:tmpFile pathName)
+                executeCommand:('%1 "%2"' bindWith:(self editorCommand) with:tmpFile pathName)
                 inputFrom:nil "/ Stdin 
                 outputTo:nil "/ Stdout 
                 errorTo:nil "/ Stderr
@@ -342,7 +352,7 @@
         cmd_edit:'MyClass foo' readStream
     "
 
-    "Modified (comment): / 08-11-2016 / 22:24:00 / cg"
+    "Modified: / 08-11-2016 / 22:46:12 / cg"
 !
 
 cmd_exit:lineStream
@@ -379,12 +389,18 @@
         timing ............. timing execution
         profiling .......... show execution profile
         chunkFormat ........ traditional bang chunk format input mode
+        editor ............. command used with #edit directive
     #debug ................. enter a MiniDebugger
+    #edit <what> ........ open an external editor 
+        class .............. on a class
+        class selector ..... on a method
+        <empty> ............ on previously edited method/last class
 
 The MiniDebugger (if entered) shows its own help with "?".
 '
 
     "Created: / 07-12-2006 / 18:54:20 / cg"
+    "Modified: / 08-11-2016 / 22:53:53 / cg"
 !
 
 cmd_read:lineStream
@@ -472,10 +488,19 @@
             doChunkFormat := aBoolean.
             ^ self.
         ].
+        (what startsWith:'edi') ifTrue:[
+            aBoolean ifTrue:[
+                "/ set editor cmd
+                lineStream skipSeparators.
+                editorCommand := lineStream upToEnd.
+            ] ifFalse:[
+                editorCommand := nil.
+            ]
+        ].
     ].
     self errorStream showCR:'? which flag ?'.
 
-    "Modified: / 07-12-2006 / 19:13:34 / cg"
+    "Modified: / 08-11-2016 / 22:49:17 / cg"
 !
 
 cmd_show:lineStream
@@ -536,7 +561,8 @@
                 showCR:('trace :      ',(traceFlag ? false) printString);
                 showCR:('timing:      ',(timingFlag ? false) printString);
                 showCR:('profiling:   ',(profilingFlag ? false) printString);
-                showCR:('chunkFormat: ',(doChunkFormat ? false) printString).
+                showCR:('chunkFormat: ',(doChunkFormat ? false) printString);
+                showCR:('editor:      ',self editorCommand printString).
             ok := true.
         ].
     ].
@@ -549,7 +575,7 @@
      self basicNew cmd_show:'packages' readStream
     "
 
-    "Modified: / 07-12-2011 / 22:15:07 / cg"
+    "Modified: / 08-11-2016 / 22:46:51 / cg"
 !
 
 cmd_use:lineStream
@@ -711,7 +737,7 @@
         |lines chunk|
 
         prompt notNil ifTrue:[
-            error nextPutAll:prompt.
+            error show:prompt.
         ].
 
         input atEnd ifTrue:[
@@ -736,13 +762,13 @@
                     line = '?' ifTrue:[
                         self cmd_help:nil.
                         prompt notNil ifTrue:[
-                            error nextPutAll:prompt.
+                            error show:prompt.
                         ].
                     ] ifFalse:[
                         (line startsWith:'#') ifTrue:[
                             self directive:line.
                             prompt notNil ifTrue:[
-                                error nextPutAll:prompt.
+                                error show:prompt.
                             ].
                         ] ifFalse:[
                             lines add:line.
@@ -770,7 +796,7 @@
                     ex mayProceed ifTrue:[
                         ex proceed.
                     ].
-                    error nextPutLine:('Evaluation aborted: ', ex description).
+                    error showCR:('Evaluation aborted: ', ex description).
                     ex return.
                 ] do:[
                     |value ms us|
@@ -783,6 +809,7 @@
                         ].    
                         doPrint ifTrue:[
                             value printOn:output. output cr.
+                            output flush.
                         ].
                     ] ifFalse:[    
                         us := Time microsecondsToRun:[
@@ -816,11 +843,13 @@
     ] loop.
 
     "
+     Smalltalk readEvalPrintLoop.
+
      (ReadEvalPrintLoop new prompt:'>') readEvalPrintLoop
     "
 
     "Created: / 07-12-2006 / 17:27:21 / cg"
-    "Modified: / 06-12-2011 / 15:29:03 / cg"
+    "Modified: / 08-11-2016 / 22:41:47 / cg"
 !
 
 readEvalPrintLoop
@@ -833,7 +862,7 @@
      switches to chunkmode."
 
     ControlInterrupt handle:[:ex |
-        self errorStream nextPutLine:('Caught: ', ex description).
+        self errorStream showCR:('Caught: ', ex description).
         self inputStream atEnd ifTrue:[
             ex return.
         ].    
@@ -850,16 +879,16 @@
 
         compilerClass := compiler ? Compiler ? Parser.
         compilerClass isNil ifTrue:[
-            self errorStream nextPutLine:('oops - no Compiler class found').
+            error showCR:('oops - no Compiler class found').
             ^ self.
         ].
         StreamError handle:[:ex |
             (input isOpen not or:[input atEnd]) ifTrue:[
-                error nextPutLine:'EOF on input'.
+                error showCR:'EOF on input'.
                 ex return.
             ].    
             (output isOpen not) ifTrue:[
-                error nextPutLine:'no output'.
+                error showCR:'no output'.
             ].    
             (error isOpen not) ifTrue:[
             ].    
@@ -870,7 +899,7 @@
                 compiler:compilerClass prompt:prompt print:(printFlag ? true).
         ]
     ].
-    self errorStream nextPutLine:('done.').
+    "/ self errorStream showCR:('done.').
 
     "
      Stdin atEnd 
@@ -880,7 +909,7 @@
     "
 
     "Created: / 07-12-2006 / 17:27:21 / cg"
-    "Modified (comment): / 08-11-2016 / 22:04:03 / cg"
+    "Modified: / 08-11-2016 / 22:42:21 / cg"
 ! !
 
 !ReadEvalPrintLoop methodsFor:'queries'!