From: jhmeyers@miu.edu (John H Meyers)
Newsgroups: comp.sys.hp48
Subject: Adding UNDO/CANCEL to ED/TED
Date: 11 Feb 1998 04:00:26 GMT
Organization: MIU Computer Services,  Fairfield, IA 52557.  Not Approved.
Lines: 63
Message-ID: <6br7oq$2d1$1@news.iastate.edu>
Reply-To: jhmeyers@miu.edu
NNTP-Posting-Host: vax1.mum.edu
Xref: republic.btigate.com comp.sys.hp48:6660

My apologies for an error in the programs I previously posted
in this thread -- there was one EVAL too many, which for an
argument of 'name' (to edit the contents of a variable using ED)
would have executed a program object or evaluated a list object
before attempting to store it back into its variable.

Below is a corrected version, which now accomplishes the following:

o Edits (using ED) any object on the stack (except real numbers
  and names), or any object in a variable, given its 'name'

o Allows you to CANCEL your edit, by simply block-deleting
  the entire current text before pressing ENTER,
  leaving the original object or variable unchanged.

o Saves both the original object and your current edit
  if there remains an assembly error when you press ENTER
  (you may immediately restart editing the string left on the
  stack, if you wish -- if a real number is found on level 1,
  just leave it there, since any such number points to the error
  location, and ED will put the cursor back there for you).

o Skips the re-assembly if you have done it yourself using [<-] [+/-]
  (as long as the result of the assembly is not a string object).

o Saves everything in local variables, so that if you suspend
  ED and return to the stack using the STO key, nothing
  is left on the stack by this program (you may resume
  a suspended edit by pressing CONT).

-----------------------------------------------------------
With best wishes from:   John H Meyers   <jhmeyers@mum.edu>
-----------------------------------------------------------

%%HP: T(3); @ DE ("DIS and ED") Version 1.2
@ Executes ED with an "escape clause" [CANCEL/UNDO]

@ To escape:  Just delete all text (block delete), then press ENTER
@             (the original string or object is then restored)

@ Automatic dissassembly is performed on non-string objects;
@ automatic re-assembly is performed after ENTER, one attempt only;
@ on error, both original object and edited string are preserved.
@ Original object is replaced if successfully re-assembled.

@ 'Name' argument edits contents of variable.

@ If you beat me to it by assembling from within ED (except a string),
@ then I'll notice this and skip the re-assembly myself.

\<< -55 CF DEPTH NOT "" IFT @ supply empty string if empty stack
  0 0 \-> p s \<<
  { DUP ::s STO DIS ED DUP "" SAME { DROP s }
    { DUP TYPE 2 == { s SWAP ASS SWAP DROP } IFT } IFTE } 'p' STO
  { { DUP NEWOB SWAP ::p STO } OVER TYPE { EVAL } { ROT SWAP EVAL SWAP }
      IFTE ED DUP "" SAME { DROP p } IFT } 's' STO
  {   { p EVAL } @ any object other than types below
    2 { s EVAL } @ string
    0 { s EVAL } @ string, character position
    6 { \-> v \<< v RCL DUP TYPE 2 == s p IFTE v STO \>> } @ 'name'
  } DUP2 SWAP TYPE POS 1 + GET EVAL \>> \>>

@ End of program.