bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] Near Proof of concept of an )edit somefunction_name


From: Kacper Gutowski
Subject: Re: [Bug-apl] Near Proof of concept of an )edit somefunction_name
Date: Sat, 19 Mar 2016 21:30:51 +0100

I recall there being some similar attempts presented on this list but
I couldn't find working example so I hacked up the following.  It has
few rough edges and wasn't tested thoroughly but appears to work.


]USERCMD ]EDIT EDIT⍙ 1

∇S EDIT⍙ Q;FN;FD
 ⍝ Edit a function or operator in external editor.
  ⍎(2>≡S)/"']EDIT NAME' ⋄ →0"
  S←(⎕IO+1)⊃S
  ⍎(~(⎕NC S)∊0 3 4)/"'Bad name ',S ⋄ →0"
  FN←'/tmp/',S,'.',⍕↑⎕AI
  FD←'w'⎕FIO[3] 18⎕CR FN
  ⍎(0>FD)/"'Can''t open file ',FN ⋄ →0"
  Q←(⎕IO+0≠⎕NC S)⊃(⍉⍪S)(⎕CR S)
  Q←{⍵↓⍨-+/∧\⌽' '=⍵}¨⊂[⎕IO+1]Q
  Q←∊Q,¨⊂"\n"
  ⊣ Q ⎕FIO[23]FD
  ⊣ ⎕FIO[4]FD
  EDIT⍙OPEN FN
  Q←⎕FIO[26] 18⎕CR FN
  ⊣ ⎕FIO[19] 18⎕CR FN
  ⍎(~' '≡↑0⍴Q)/"'Filed to read ',FN ⋄ →0"
  ⍎(0=⍴Q)/"'Empty' ⋄ →0"
  ⍎(0=⍴Q←19⎕CR Q)/"'Encoding error' ⋄ →0"
  ⎕FX (~"\n"=Q)⊂Q
∇

⍝ External editor to use; defaults to $EDITOR or vi
EDIT⍙EDITOR←,⎕ENV'EDITOR'
EDIT⍙EDITOR←(1+EDIT⍙EDITOR⍳⊂'EDITOR')⊃EDIT⍙EDITOR,⍬'vi'

∇EDIT⍙OPEN FILE;STTY
 ⍝ Open a file in external editor.
  ((''''=FILE)/FILE)←⊂"'\''"
  FILE←'''',∊FILE,''''
  STTY←⎕IO⊃⍎')HOST stty -g'
  ⊣⍎')HOST >/dev/tty stty sane'
  ⊣⍎')HOST >/dev/tty ',EDIT⍙EDITOR,' ',FILE
  ⊣⍎')HOST >/dev/tty stty ',STTY
∇

reply via email to

[Prev in Thread] Current Thread [Next in Thread]