@newfunc me.editor(self,buf,entry,state)
x
%# Rename property name so we can use original editor to read source
@renprop me.editor to neweditor
@edit me.neweditor
"""Builder METHOD: editor( self, buf, entry, state ):"""
# This method implements a subset *nix editor ed(1)

if not state:
   # start new editing session and put in COMMAND
   self.tell("[New Editor -- enter h for help]")
   self._prompt = '*'
   return 'OK'
elif state == 'INPUT':
   # INPUT mode
   if entry == '.':
       self.tell('Exiting INPUT mode.')
       self._prompt = '*'
       return 'OK'
   buf.insert(self._editAddr, entry)
   # echoing input line interefered with standard telnet client and
   # direct mode
   ##self.tell('%4s %s' % (self._editAddr + 1, entry))
   self._editAddr += 1
   return 'INPUT'

# split address(es) and command
# one letter commands come after address
cmd = entry[-1]
# split address numbers and convert symbols into line number
if len(entry) > 1:
   addr = entry[:-1].split(',')
   for i in range(len(addr)):
       if addr[i] == '.': addr[i] = self._editAddr
       elif addr[i] == '$': addr[i] = len(buf)
       elif addr[i] == '%':
           addr = [1, len(buf)]
           break
       elif addr[i] == ';':
           addr = [self._editAddr, len(buf)]
           break
       elif addr[i][0] == '-':
           addr[i] = eval('%s%s' % (self._editAddr, addr[i]))
       elif addr[i][0] == '+':
           addr[i] = eval('%s%s' % (self._editAddr, addr[i]))
       else: addr[i] = int(addr[i])
else:
   addr = []
if len(addr) > 2: return 'OK'

if cmd == 'h':         #    h - help
   self.tell('New Editor Help (subset of *nix ed)')
   self.tell('LINE ADDRESSING')
   self.tell('   .        The current line')
   self.tell('   $        The last line')
   self.tell('   n        The nth line')
   self.tell('   -n       The nth previous line')
   self.tell('   +n       The nth next line')
   self.tell('   %        The first through last lines')
   self.tell('   ;        The current through last lines')
   self.tell('COMMANDS')
   self.tell('   (.)a     Appends text after addressed line')
   self.tell('   (.,.)c   Changes the addressed lines')
   self.tell('   (.,.)d   Deletes the addressed lines')
   self.tell('   (.)i     Inserts text before addressed line')
   self.tell('   (.,.+1)j Joins the addressed lines')
   self.tell('   (.,.)l   Prints the addressed lines')
   self.tell('   (.,.)n   Prints the addressed lines w/ line numbers')
   self.tell('   q        Quit (Abort)')
   self.tell('   w        Save and quit')
   self.tell('Input mode is terminated by entering a single period.')

elif cmd == 'a':       #    a - append lines
   if len(addr) > 0:
       self._editAddr = addr[-1]
   self.tell('Entering INPUT mode.')
   self._prompt = ''
   return 'INPUT'

elif cmd == 'c':       #    c - change lines
   if len(addr) == 2:
       self._editAddr = addr[0]
       self.tell('Changing lines %s to %s' % (addr[0], addr[1]))
       del buf[addr[0] - 1:addr[1]]
   else:
       if len(addr) == 1:
           self._editAddr = addr[0]
       self.tell('Changing line %s' % self._editAddr)
       del buf[self._editAddr - 1]
   self._editAddr -= 1
   self._prompt = ''
   return 'INPUT'

elif cmd == 'd':       #    d - delete lines
   if len(addr) == 2:
       self._editAddr = addr[0]
       self.tell('Deleting lines %s to %s' % (addr[0], addr[1]))
       del buf[addr[0] - 1:addr[1]]
   else:
       if len(addr) == 1:
           self._editAddr = addr[0]
       self.tell('Deleting line %s' % self._editAddr)
       del buf[self._editAddr - 1]
   if self._editAddr > len(buf): self._editAddr = len(buf)
   self.tell('New current address: %s' % self._editAddr)

elif cmd == 'i':       #    i - insert lines
   if len(addr) > 0:
       self._editAddr = addr[-1]
   self._editAddr -= 1
   self.tell('Entering INPUT mode.')
   self._prompt = ''
   return 'INPUT'

elif cmd == 'j':       #    j - join lines
   if len(addr) == 0:
       cur = self._editAddr - 1
       buf[cur] = buf[cur] + buf[cur + 1]
       del buf[cur + 1]
   elif len(addr) == 2:
       self._editAddr = addr[0]
       cur = self._editAddr - 1
       for line in range(addr[0], addr[1]):
           buf[cur] = buf[cur] + buf[line]
       del buf[addr[0]:addr[1]]

elif cmd == 'l':       #    l - list
   if len(addr) == 1 and addr[0] != 0:
       self._editAddr = addr[0]
   elif len(addr) == 2:
       for line in range(addr[0], addr[1]):
           self.tell(buf[line - 1])
       self._editAddr = addr[1]
   self.tell(buf[self._editAddr - 1])

elif cmd == 'n':       #    n - list (w/ line numbers)
   if len(addr) == 1 and addr[0] != 0:
       self._editAddr = addr[0]
   elif len(addr) == 2:
       for line in range(addr[0], addr[1]):
           self.tell('%4s %s' % (line, buf[line - 1]))
       self._editAddr = addr[1]
   self.tell('%4s %s' % (self._editAddr, buf[self._editAddr - 1]))

elif cmd == 'q':
   self.tell("Aborted.")
   return 'ABORT'

elif cmd == 'w':
   self.tell("Saved.")
   return 'DONE'

return 'OK'
x
@renprop me.neweditor to editor