My latest "edit" function. VERY useful to edit a function with "vi" editor while *inside* the interpreter.
The important part of this function I got from some post long ago making "vi" or "vim" working inside the interpreter, mainly: SaveTTY←⎕IO⊃⍎')HOST stty -g' ⊣⍎')HOST >/dev/tty stty sane'⊣⍎')HOST >/dev/tty ','vi',' ',fs_name ⊣⍎')HOST >/dev/tty stty ',SaveTTY Usage: edit 'some_function_name' and with ]usercmd ]edit {edit(⎕IO+1)⊃⍵←⍺} ⍝ assuming you are at the latest SVN you can call it with ]edit some_function_name ⍝ without the quotes around the function name. here it is: )sic )erase edit ∇R←skipwrite edit funct;fd;lines;fs_name;z;r;SaveTTY R←'' ⍝ Always return '' fs_name←'tmp/', 18 ⎕cr funct ⍝ The file name in the filesystem ⊣ (⎕FIO[20] 'tmp') ⍝ mkdir tmp ⍝ --------------------------------------------------------------------------- ⍝ Check if it is a request to reedit the previous written file in filesystem ⍝ very usefull in case of a syntax error while ⎕fx 'ing the function ... ⍝ --------------------------------------------------------------------------- →(2=⎕nc 'skipwrite')/SkipWrite ⍝ If a left arg then skip write to the file lines←{(⎕ucs 10),⍨(∼⌽∧\⌽⍵=' ')/⍵} ¨ ⊂[⎕io+1] ⎕cr funct ⍝ The lines of the function ⍝ -------------------------------------------------- ⍝ write the contents of this "funct" into the file ⍝ -------------------------------------------------- →(0>fd← "w" ⎕FIO[3] fs_name)/Error ⍝ Open for writing ⊣ {⍵ ⎕FIO[23] fd} ¨ lines ⍝ write all lines ⊣ (⎕FIO[4] fd) ⍝ Close the file ⍝ -------------------------------------------------- ⍝ Now do the actual edition ... ⍝ -------------------------------------------------- SkipWrite: SaveTTY←⎕IO⊃⍎')HOST stty -g' ⊣⍎')HOST >/dev/tty stty sane'⊣⍎')HOST >/dev/tty ','vi',' ',fs_name ⊣⍎')HOST >/dev/tty stty ',SaveTTY ⍝ ---------------- ⍝ and try ⎕fx it ⍝ ---------------- →(0≠"r" ⎕fio[31] fs_name)/Error ⍝ Can not read file ? → Error z←⎕fio[26] fs_name ⍝ First pass, read the whole file lines←⍳+/((↑"\n")=z) ⍝ Compute the iota for each line z←(⍴lines)⍴⍬ ⍝ Preallocate "z" to the right size fd←⎕fio[3] fs_name ⍝ Open the file ⊣ {⊣z[⍵]←⊂19 ⎕cr ⎕ucs ¯1↓(⎕fio[8] fd)} ⍤0 lines ⍝ Put each line in the preallocated "z" ⊣ (⎕fio[4] fd) ⋄ →Fix ⍝ Close the file and ⎕FX it Error: ⎕ES ∊'Error on file "',fs_name,'": ',⎕fio[2] | ⎕fio[1] '' Fix: r←⎕fx z ⍝ ---------------------------------------------------------------------------------------- ⍝ Well, if "r" is an integer then it is a syntax error, if it is a string then it succeed. ⍝ ---------------------------------------------------------------------------------------- ⍝ →(0=↑0⍴r)/Syntax ⍝ number → then a systax error Ok: ⎕←∊ "Function '" (r) ("' saved.") ⋄ →0 ⍝ Probably a succesfull "save" or "save as" ⍝ ---------------------------------- ⍝ We get here on errors while saving ⍝ ---------------------------------- Syntax: 9 ⎕cr ∊(∊'Line' (r-1) 'is in error: ') (∊z[r]) "Beware that you can not edit a running function or a suspended function on the stack, try )sic before launching \"edit\"." ∊ "Syntax error at line:" (r-1) ("( Use: 1 edit '" funct "' ) to have a chance to fix it without having to reenter all your latest changes.") '' ∇